Skip to content

Commit 3279622

Browse files
committed
2: add k_is_server_ready
1 parent 4573e26 commit 3279622

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

be/src/http/action/health_action.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,39 @@
2424
#include "http/http_headers.h"
2525
#include "http/http_request.h"
2626
#include "http/http_status.h"
27+
#include "runtime/exec_env.h"
2728

2829
namespace doris {
2930

3031
const static std::string HEADER_JSON = "application/json";
3132

3233
void HealthAction::handle(HttpRequest* req) {
34+
std::string status;
35+
std::string msg;
36+
HttpStatus st;
37+
if (!doris::k_is_server_ready) {
38+
status = "Server is not available";
39+
msg = "Server is not ready";
40+
st = HttpStatus::SERVICE_UNAVAILABLE;
41+
} else if (doris::k_doris_exit) {
42+
status = "Server is not available";
43+
msg = "Server is shutting down";
44+
st = HttpStatus::SERVICE_UNAVAILABLE;
45+
} else {
46+
status = "OK";
47+
msg = "OK";
48+
st = HttpStatus::OK;
49+
}
50+
3351
std::stringstream ss;
3452
ss << "{";
35-
ss << "\"status\": \"OK\",";
36-
ss << "\"msg\": \"To Be Added\"";
53+
ss << "\"status\": \"" << status << "\",";
54+
ss << "\"msg\": \"" << msg << "\"";
3755
ss << "}";
3856
std::string result = ss.str();
3957

4058
req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.c_str());
41-
HttpChannel::send_reply(req, HttpStatus::OK, result);
59+
HttpChannel::send_reply(req, st, result);
4260
}
4361

4462
} // end namespace doris

be/src/runtime/exec_env.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ class IndexPolicyMgr;
133133
struct SyncRowsetStats;
134134
class DeleteBitmapAggCache;
135135

136+
// set to true when BE is shutting down
136137
inline bool k_doris_exit = false;
138+
// set to true after BE start ready
139+
inline bool k_is_server_ready = false;
137140

138141
// Execution environment for queries/plan fragments.
139142
// Contains all required global structures, and handles to

be/src/service/doris_main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,15 @@ int main(int argc, char** argv) {
602602

603603
exec_env->storage_engine().notify_listeners();
604604

605+
doris::k_is_server_ready = true;
606+
605607
while (!doris::k_doris_exit) {
606608
#if defined(LEAK_SANITIZER)
607609
__lsan_do_leak_check();
608610
#endif
609611
sleep(3);
610612
}
613+
doris::k_is_server_ready = false;
611614
LOG(INFO) << "Doris main exiting.";
612615
#if defined(LLVM_PROFILE)
613616
__llvm_profile_write_file();

0 commit comments

Comments
 (0)