From 67bafbefc972158f9ddd4fb9e45dc76ff2c8a540 Mon Sep 17 00:00:00 2001 From: "linuxrc@163.com" Date: Tue, 10 Aug 2021 10:02:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/doris_server_http.cpp | 41 +++++++++++++++++++++++++++++++++ server/doris_server_scandir.cpp | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/server/doris_server_http.cpp b/server/doris_server_http.cpp index 8a82518..6c2dad1 100644 --- a/server/doris_server_http.cpp +++ b/server/doris_server_http.cpp @@ -329,6 +329,46 @@ void doris_http_server_file_cb(struct evhttp_request *req, void *arg) evhttp_clear_headers(¶ms); } +void doris_http_server_version_cb(struct evhttp_request *req, void *arg) +{ + struct evkeyvalq params; + const char *bizname; + struct doris_business *business; + map::iterator iter; + char verbuf[32]; + + if(evhttp_parse_query(evhttp_request_get_uri(req), ¶ms)) + { + FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_CLIENT_INVALID_REQ], 0, FS_OP_ADD, 1); + evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid"); + return; + } + + if(NULL == (bizname = evhttp_find_header(¶ms, "business"))) + { + FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_CLIENT_INVALID_REQ], 0, FS_OP_ADD, 1); + evhttp_clear_headers(¶ms); + evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid, no business found"); + return; + } + if((iter = g_doris_server_info.name2business->find(string(bizname)))==g_doris_server_info.name2business->end()) + { + FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_CLIENT_INVALID_REQ], 0, FS_OP_ADD, 1); + evhttp_clear_headers(¶ms); + evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid, business invalid"); + return; + } + evhttp_clear_headers(¶ms); + business = iter->second; + + pthread_rwlock_rdlock(&business->rwlock); + sprintf(verbuf, "%lu", business->cfgver_head->latest_version); + pthread_rwlock_unlock(&business->rwlock); + + evhttp_add_header(evhttp_request_get_output_headers(req), "X-Latest-Version", verbuf); + evhttp_send_reply(req, HTTP_OK, "OK", NULL); +} + void doris_http_server_generic_cb(struct evhttp_request *req, void *arg) { evhttp_send_error(req, HTTP_BADREQUEST, "Not Supported."); @@ -448,6 +488,7 @@ void* thread_doris_http_server(void *arg) evhttp_set_cb(worker_http, "/configmeta", doris_http_server_meta_cb, NULL); evhttp_set_cb(worker_http, "/configfile", doris_http_server_file_cb, NULL); + evhttp_set_cb(worker_http, "/latestversion", doris_http_server_version_cb, NULL); evhttp_set_gencb(worker_http, doris_http_server_generic_cb, NULL); evhttp_set_allowed_methods(worker_http, EVHTTP_REQ_GET|EVHTTP_REQ_HEAD); diff --git a/server/doris_server_scandir.cpp b/server/doris_server_scandir.cpp index 85c276e..8840b64 100644 --- a/server/doris_server_scandir.cpp +++ b/server/doris_server_scandir.cpp @@ -317,7 +317,7 @@ enum DORIS_UPDATE_TYPE doris_index_file_traverse(struct doris_idxfile_scanner *s table_num=cm_read_cfg_index_file(idx_path_array[i].path, table_array, CM_MAX_TABLE_NUM, logger); if(table_num<0) { - MESA_RUNTIME_LOGV4(logger,RLOG_LV_INFO, "load %s faild, abandon udpate.", idx_path_array[i].path); + MESA_RUNTIME_LOGV4(logger,RLOG_LV_FATAL, "load %s faild, abandon udpate.", idx_path_array[i].path); update_type = CFG_UPDATE_TYPE_ERR; break; }