Skip to content

Commit

Permalink
Delete the retry logic while launching metadata service and reset the…
Browse files Browse the repository at this point in the history
… etcd client while probing (#1649)

Fixes #1648

Signed-off-by: Ye Cao <[email protected]>
  • Loading branch information
dashanji authored Dec 18, 2023
1 parent 513cb1c commit 63dd6ad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
3 changes: 3 additions & 0 deletions src/server/services/etcd_meta_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ void EtcdMetaService::retryDaeminWatch(
}

Status EtcdMetaService::probe() {
std::string const& etcd_endpoint =
etcd_spec_["etcd_endpoint"].get_ref<std::string const&>();
etcd_.reset(new etcd::Client(etcd_endpoint));
if (EtcdLauncher::probeEtcdServer(etcd_, prefix_)) {
return Status::OK();
} else {
Expand Down
36 changes: 11 additions & 25 deletions src/server/util/etcd_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ Status EtcdLauncher::LaunchEtcdServer(
return Status::OK();
}

LOG(INFO) << "Starting the etcd server";

// resolve etcd binary
std::string etcd_cmd = etcd_spec_["etcd_cmd"].get_ref<std::string const&>();
if (etcd_cmd.empty()) {
setenv("LC_ALL", "C", 1); // makes boost's path works as expected.
etcd_cmd = boost::process::search_path("etcd").string();
}
LOG(INFO) << "Found etcd at: " << etcd_cmd;

RETURN_ON_ERROR(initHostInfo());
bool try_launch = false;
if (local_hostnames_.find(endpoint_host_) != local_hostnames_.end() ||
Expand All @@ -129,22 +119,18 @@ Status EtcdLauncher::LaunchEtcdServer(
}

if (!try_launch) {
LOG(INFO) << "Will not launch an etcd instance.";
int retries = 0;
while (retries < max_probe_retries) {
if (probeEtcdServer(etcd_client, sync_lock)) {
break;
}
retries += 1;
sleep(1);
}
if (retries >= max_probe_retries) {
return Status::EtcdError(
"Etcd has been launched but failed to connect to it");
} else {
return Status::OK();
}
return Status::OK();
}

LOG(INFO) << "Starting the etcd server";

// resolve etcd binary
std::string etcd_cmd = etcd_spec_["etcd_cmd"].get_ref<std::string const&>();
if (etcd_cmd.empty()) {
setenv("LC_ALL", "C", 1); // makes boost's path works as expected.
etcd_cmd = boost::process::search_path("etcd").string();
}
LOG(INFO) << "Found etcd at: " << etcd_cmd;

std::string host_to_advertise;
if (host_to_advertise.empty()) {
Expand Down
36 changes: 11 additions & 25 deletions src/server/util/redis_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ Status RedisLauncher::LaunchRedisServer(
return Status::OK();
}

RETURN_ON_ERROR(initHostInfo());
bool try_launch = false;
if (local_hostnames_.find(endpoint_host_) != local_hostnames_.end() ||
local_ip_addresses_.find(endpoint_host_) != local_ip_addresses_.end()) {
try_launch = true;
}

if (!try_launch) {
return Status::OK();
}

LOG(INFO) << "Starting the redis server";

// resolve redis binary
Expand All @@ -84,31 +95,6 @@ Status RedisLauncher::LaunchRedisServer(
}
LOG(INFO) << "Found redis at: " << redis_cmd;

RETURN_ON_ERROR(initHostInfo());
bool try_launch = false;
if (local_hostnames_.find(endpoint_host_) != local_hostnames_.end() ||
local_ip_addresses_.find(endpoint_host_) != local_ip_addresses_.end()) {
try_launch = true;
}

if (!try_launch) {
LOG(INFO) << "Will not launch a redis instance.";
int retries = 0;
while (retries < max_probe_retries) {
if (probeRedisServer(redis_client, syncredis_client, watch_client)) {
break;
}
retries += 1;
sleep(1);
}
if (retries >= max_probe_retries) {
return Status::RedisError(
"Redis has been launched but failed to connect to it");
} else {
return Status::OK();
}
}

std::vector<std::string> args;
args.emplace_back("--port");
args.emplace_back(std::to_string(endpoint_port_));
Expand Down

0 comments on commit 63dd6ad

Please sign in to comment.