Commit a73bbdf9 authored by zhujiashun's avatar zhujiashun

refine code

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