Commit adec01cc authored by zhujiashun's avatar zhujiashun

health_check_using_rpc: change async Appcheck to sync

parent 938f2e85
...@@ -70,7 +70,6 @@ class HealthCheckManager { ...@@ -70,7 +70,6 @@ class HealthCheckManager {
public: public:
static void StartCheck(SocketId id, int64_t check_interval_s); static void StartCheck(SocketId id, int64_t check_interval_s);
static void* AppCheck(void* arg); static void* AppCheck(void* arg);
static void RunAppCheck(void* arg);
}; };
void HealthCheckManager::StartCheck(SocketId id, int64_t check_interval_s) { void HealthCheckManager::StartCheck(SocketId id, int64_t check_interval_s) {
...@@ -110,17 +109,6 @@ void* HealthCheckManager::AppCheck(void* arg) { ...@@ -110,17 +109,6 @@ void* HealthCheckManager::AppCheck(void* arg) {
return NULL; return NULL;
} }
void HealthCheckManager::RunAppCheck(void* arg) {
bthread_t th = 0;
int rc = bthread_start_background(
&th, &BTHREAD_ATTR_NORMAL, AppCheck, arg);
if (rc != 0) {
LOG(ERROR) << "Fail to start AppCheck";
AppCheck(arg);
return;
}
}
void OnAppHealthCheckDone::Run() { void OnAppHealthCheckDone::Run() {
std::unique_ptr<OnAppHealthCheckDone> self_guard(this); std::unique_ptr<OnAppHealthCheckDone> self_guard(this);
SocketUniquePtr ptr; SocketUniquePtr ptr;
...@@ -145,23 +133,13 @@ void OnAppHealthCheckDone::Run() { ...@@ -145,23 +133,13 @@ void OnAppHealthCheckDone::Run() {
int64_t sleep_time_ms = int64_t sleep_time_ms =
last_check_time_ms + interval_s * 1000 - butil::gettimeofday_ms(); last_check_time_ms + interval_s * 1000 - butil::gettimeofday_ms();
if (sleep_time_ms > 0) { if (sleep_time_ms > 0) {
const timespec abstime = butil::milliseconds_from_now(sleep_time_ms); // TODO(zhujiashun): we need to handle the case when timer fails
bthread_timer_t timer_id; // and bthread_usleep returns immediately. In most situations,
const int rc = bthread_timer_add( // the possibility of this case is quite small, so currently we
&timer_id, abstime, HealthCheckManager::RunAppCheck, this); // just keep sending the hc call.
if (rc != 0) { bthread_usleep(sleep_time_ms * 1000);
LOG(ERROR) << "Fail to add timer for RunAppCheck";
// TODO(zhujiashun): we need to handle the case when timer fails.
// In most situations, the possibility of this case is quite small,
// so currently we just keep sending the hc call.
HealthCheckManager::AppCheck(this);
return;
}
} else {
// the time of next call has passed, just AppCheck immediately
HealthCheckManager::AppCheck(this);
} }
self_guard.release(); HealthCheckManager::AppCheck(self_guard.release());
} }
class HealthCheckTask : public PeriodicTask { class HealthCheckTask : public PeriodicTask {
......
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