Skip to content
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

Fix restart failed #4269

Merged
merged 2 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ MetaClient::~MetaClient() {
VLOG(3) << "~MetaClient";
}

#ifdef BUILD_STANDALONE
StatusOr<bool> MetaClient::checkLocalMachineRegistered() {
auto ret = heartbeat().get();
if (!ret.ok()) {
if (ret.status().toString() == "Machine not existed!") {
return false;
}
LOG(ERROR) << "Check register failed: " << ret.status();
return Status::Error("Check register failed!");
}
return true;
}
#endif

bool MetaClient::isMetadReady() {
// UNKNOWN is reserved for tools such as upgrader, in that case the ip/port is not set. We do
// not send heartbeat to meta to avoid writing error host info (e.g. Host("", 0))
Expand Down
4 changes: 4 additions & 0 deletions src/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ class MetaClient : public BaseMetaClient {

~MetaClient() override;

#ifdef BUILD_STANDALONE
StatusOr<bool> checkLocalMachineRegistered();
#endif

bool isMetadReady();

bool waitForMetadReady(int count = -1, int retryIntervalSecs = FLAGS_heartbeat_interval_secs);
Expand Down
35 changes: 22 additions & 13 deletions src/storage/StorageServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,29 @@ bool StorageServer::start() {

#ifdef BUILD_STANDALONE
if (FLAGS_add_local_host) {
std::vector<HostAddr> hosts = {{FLAGS_local_ip, FLAGS_storage_port}};
folly::Baton<> baton;
bool isAdded = false;
metaClient_->addHosts(hosts).thenValue([&isAdded, &baton](StatusOr<bool> resp) {
if (!resp.ok() || !resp.value()) {
LOG(ERROR) << "Add hosts for standalone failed.";
} else {
LOG(INFO) << "Add hosts for standalone succeed.";
isAdded = true;
// meta allready ready when standalone.
auto ret = metaClient_->checkLocalMachineRegistered();
if (ret.ok()) {
if (!ret.value()) {
std::vector<HostAddr> hosts = {{FLAGS_local_ip, FLAGS_storage_port}};
folly::Baton<> baton;
bool isAdded = false;
metaClient_->addHosts(hosts).thenValue([&isAdded, &baton](StatusOr<bool> resp) {
if (!resp.ok() || !resp.value()) {
LOG(ERROR) << "Add hosts for standalone failed.";
} else {
LOG(INFO) << "Add hosts for standalone succeed.";
isAdded = true;
}
baton.post();
});

baton.wait();
if (!isAdded) {
return false;
}
}
baton.post();
});
baton.wait();
if (!isAdded) {
} else {
return false;
}
}
Expand Down