-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust meta client ctor && implement heartbeat logic inside. #379
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ DEFINE_string(local_ip, "", "Local ip speicified for NetworkUtils::getLocalIP"); | |
DEFINE_bool(mock_server, true, "start mock server"); | ||
DEFINE_bool(daemonize, true, "Whether to run the process as a daemon"); | ||
DEFINE_string(pid_file, "pids/nebula-storaged.pid", ""); | ||
DEFINE_string(meta_server_addrs, "", "list of meta server addresses," | ||
"the format looks like ip1:port1, ip2:port2, ip3:port3"); | ||
DEFINE_int32(io_handlers, 10, "io handlers"); | ||
|
||
using nebula::Status; | ||
|
||
|
@@ -72,7 +75,7 @@ int main(int argc, char *argv[]) { | |
} | ||
|
||
if (FLAGS_data_path.empty()) { | ||
LOG(FATAL) << "Storage Data Path should not empty"; | ||
LOG(ERROR) << "Storage Data Path should not empty"; | ||
return -1; | ||
} | ||
LOG(INFO) << "Starting the storage Daemon on port " << FLAGS_port | ||
|
@@ -88,7 +91,15 @@ int main(int argc, char *argv[]) { | |
uint32_t localIP; | ||
CHECK(NetworkUtils::ipv4ToInt(result.value(), localIP)); | ||
|
||
auto metaClient = std::make_unique<nebula::meta::MetaClient>(); | ||
if (FLAGS_meta_server_addrs.empty()) { | ||
LOG(ERROR) << "meta_server_addrs flag should be set!"; | ||
return -1; | ||
} | ||
auto ioThreadPool = std::make_shared<folly::IOThreadPoolExecutor>(FLAGS_io_handlers); | ||
auto addrs = nebula::network::NetworkUtils::toHosts(FLAGS_meta_server_addrs); | ||
auto metaClient = std::make_unique<nebula::meta::MetaClient>(ioThreadPool, | ||
std::move(addrs), | ||
true); | ||
metaClient->init(); | ||
|
||
nebula::kvstore::KVOptions options; | ||
|
@@ -114,7 +125,10 @@ int main(int argc, char *argv[]) { | |
|
||
auto handler = std::make_shared<StorageServiceHandler>(kvstore.get(), std::move(schemaMan)); | ||
gServer = std::make_unique<apache::thrift::ThriftServer>(); | ||
CHECK(!!gServer) << "Failed to create the thrift server"; | ||
if (!!gServer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By default, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your reminding. Good point. 👍 |
||
LOG(ERROR) << "Failed to create the thrift server"; | ||
return -1; | ||
} | ||
|
||
// Setup the signal handlers | ||
status = setupSignalHandler(); | ||
|
@@ -126,7 +140,7 @@ int main(int argc, char *argv[]) { | |
gServer->setInterface(std::move(handler)); | ||
gServer->setPort(FLAGS_port); | ||
gServer->setIdleTimeout(std::chrono::seconds(0)); // No idle timeout on client connection | ||
|
||
gServer->setIOThreadPool(ioThreadPool); | ||
gServer->serve(); // Will wait until the server shuts down | ||
|
||
LOG(INFO) << "The storage Daemon on port " << FLAGS_port << " stopped"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,25 +10,18 @@ | |
#include "meta/NebulaSchemaProvider.h" | ||
|
||
DEFINE_int32(load_data_interval_second, 2 * 60, "Load data interval, unit: second"); | ||
DEFINE_string(meta_server_addrs, "", "list of meta server addresses," | ||
"the format looks like ip1:port1, ip2:port2, ip3:port3"); | ||
DEFINE_int32(meta_client_io_threads, 3, "meta client io threads"); | ||
DEFINE_int32(heartbeat_interval_sec, 10, "Heartbeat interval, unit: second"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. secs or seconds? Maybe we should unify them, e.g. the above line. |
||
|
||
namespace nebula { | ||
namespace meta { | ||
|
||
MetaClient::MetaClient(std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool, | ||
std::vector<HostAddr> addrs) | ||
std::vector<HostAddr> addrs, | ||
bool sendHeartBeat) | ||
: ioThreadPool_(ioThreadPool) | ||
, addrs_(std::move(addrs)) { | ||
if (ioThreadPool_ == nullptr) { | ||
ioThreadPool_ | ||
= std::make_shared<folly::IOThreadPoolExecutor>(FLAGS_meta_client_io_threads); | ||
} | ||
if (addrs_.empty() && !FLAGS_meta_server_addrs.empty()) { | ||
addrs_ = network::NetworkUtils::toHosts(FLAGS_meta_server_addrs); | ||
} | ||
CHECK(!addrs_.empty()); | ||
, addrs_(std::move(addrs)) | ||
, sendHeartBeat_(sendHeartBeat) { | ||
CHECK(ioThreadPool_ != nullptr && !addrs_.empty()); | ||
clientsMan_ = std::make_shared<thrift::ThriftClientManager< | ||
meta::cpp2::MetaServiceAsyncClient>>(); | ||
updateHost(); | ||
|
@@ -44,13 +37,39 @@ MetaClient::~MetaClient() { | |
void MetaClient::init() { | ||
loadDataThreadFunc(); | ||
CHECK(loadDataThread_.start()); | ||
size_t delayMS = FLAGS_load_data_interval_second * 1000 + folly::Random::rand32(900); | ||
loadDataThread_.addTimerTask(delayMS, | ||
FLAGS_load_data_interval_second * 1000, | ||
&MetaClient::loadDataThreadFunc, this); | ||
{ | ||
size_t delayMS = FLAGS_load_data_interval_second * 1000 + folly::Random::rand32(900); | ||
LOG(INFO) << "Register timer task for load data!"; | ||
loadDataThread_.addTimerTask(delayMS, | ||
FLAGS_load_data_interval_second * 1000, | ||
&MetaClient::loadDataThreadFunc, this); | ||
} | ||
if (sendHeartBeat_) { | ||
LOG(INFO) << "Register time task for heartbeat!"; | ||
size_t delayMS = FLAGS_heartbeat_interval_sec * 1000 + folly::Random::rand32(900); | ||
loadDataThread_.addTimerTask(delayMS, | ||
FLAGS_heartbeat_interval_sec * 1000, | ||
&MetaClient::heartBeatThreadFunc, this); | ||
} | ||
} | ||
|
||
void MetaClient::heartBeatThreadFunc() { | ||
if (listener_ == nullptr) { | ||
VLOG(1) << "Can't send heartbeat due to listener_ is nullptr!"; | ||
return; | ||
} | ||
auto ret = heartbeat().get(); | ||
if (!ret.ok()) { | ||
LOG(ERROR) << "Heartbeat failed, status:" << ret.status(); | ||
return; | ||
} | ||
} | ||
|
||
void MetaClient::loadDataThreadFunc() { | ||
if (ioThreadPool_->numThreads() <= 0) { | ||
LOG(ERROR) << "The threads number in ioThreadPool should be greater than 0"; | ||
return; | ||
} | ||
auto ret = listSpaces().get(); | ||
if (!ret.ok()) { | ||
LOG(ERROR) << "List space failed, status:" << ret.status(); | ||
|
@@ -824,5 +843,20 @@ SchemaVer MetaClient::getNewestEdgeVerFromCache(const GraphSpaceID& space, | |
return it->second; | ||
} | ||
|
||
folly::Future<StatusOr<bool>> MetaClient::heartbeat() { | ||
CHECK_NOTNULL(listener_); | ||
auto localHost = listener_->getLocalHost(); | ||
cpp2::HBReq req; | ||
nebula::cpp2::HostAddr thriftHost; | ||
thriftHost.set_ip(localHost.first); | ||
thriftHost.set_port(localHost.second); | ||
req.set_host(std::move(thriftHost)); | ||
return getResponse(std::move(req), [] (auto client, auto request) { | ||
return client->future_heartBeat(request); | ||
}, [] (cpp2::HBResp&& resp) -> decltype(auto) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI. I sincerely suggest not to use decltype(auto) get() {
int var = 0;
int &ref = var;
return ref;
// or return (var);
// or return (var &= 0xF)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. We should be careful about it. |
||
return resp.code == cpp2::ErrorCode::SUCCEEDED; | ||
}, true); | ||
} | ||
|
||
} // namespace meta | ||
} // namespace nebula |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we share the same pool with the hosting service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hosting service? If it means the thrift service, yes of course. Please note line 143.