Commit a73bbdf9 authored by zhujiashun's avatar zhujiashun

refine code

parent e9fe8b1e
......@@ -261,19 +261,21 @@ void* DiscoveryClient::PeriodicRenew(void* arg) {
while (!bthread_stopped(bthread_self())) {
if (consecutive_renew_error == FLAGS_discovery_reregister_threshold) {
LOG(WARNING) << "Reregister since discovery renew error threshold reached";
std::unique_lock<butil::Mutex> mu(d->_mutex);
switch (d->_state) {
case INIT:
CHECK(false) << "Impossible";
return NULL;
case REGISTERING:
case REGISTERED:
break;
case CANCELED:
return NULL;
default:
CHECK(false) << "Impossible";
return NULL;
{
std::unique_lock<butil::Mutex> mu(d->_mutex);
switch (d->_state) {
case INIT:
CHECK(false) << "Impossible";
return NULL;
case REGISTERING:
case REGISTERED:
break;
case CANCELED:
return NULL;
default:
CHECK(false) << "Impossible";
return NULL;
}
}
// Do register until succeed or Cancel is called
while (!bthread_stopped(bthread_self())) {
......@@ -303,8 +305,7 @@ void* DiscoveryClient::PeriodicRenew(void* arg) {
continue;
}
std::string error_text;
int rc = ParseCommonResult(cntl.response_attachment(), &error_text);
if (rc != 0) {
if (ParseCommonResult(cntl.response_attachment(), &error_text) != 0) {
LOG(ERROR) << "Fail to renew " << d->_hostname << " to " << d->_appid
<< ": " << error_text;
consecutive_renew_error++;
......@@ -412,8 +413,7 @@ int DiscoveryClient::do_register() {
return -1;
}
std::string error_text;
int rc = ParseCommonResult(cntl.response_attachment(), &error_text);
if (rc != 0) {
if (ParseCommonResult(cntl.response_attachment(), &error_text) != 0) {
LOG(ERROR) << "Fail to register " << _hostname << " to " << _appid
<< ": " << error_text;
return -1;
......@@ -439,6 +439,7 @@ int DiscoveryClient::Cancel() {
return -1;
}
}
CHECK_NE(_th, INVALID_BTHREAD);
bthread_stop(_th);
bthread_join(_th, NULL);
return do_cancel();
......@@ -462,8 +463,7 @@ int DiscoveryClient::do_cancel() {
return -1;
}
std::string error_text;
int rc = ParseCommonResult(cntl.response_attachment(), &error_text);
if (rc != 0) {
if (ParseCommonResult(cntl.response_attachment(), &error_text) != 0) {
LOG(ERROR) << "Fail to cancel " << _hostname << " in " << _appid
<< ": " << error_text;
return -1;
......
......@@ -51,8 +51,8 @@ struct DiscoveryRegisterParam {
};
// ONE DiscoveryClient corresponds to ONE service instance.
// If your program has multiple instances to register, you need multiple
// DiscoveryClient.
// If your program has multiple service instances to register,
// you need multiple DiscoveryClient.
class DiscoveryClient {
public:
DiscoveryClient();
......@@ -87,7 +87,6 @@ private:
std::string _metadata;
};
} // namespace policy
} // namespace brpc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment