支持多业务系统的配置并发进行同步

This commit is contained in:
linuxrc@163.com
2021-07-22 10:25:42 +08:00
parent 8b236b38cb
commit 5217e9188e
10 changed files with 453 additions and 327 deletions

View File

@@ -17,7 +17,7 @@
#include "doris_server_http.h"
struct doris_global_info g_doris_server_info;
static unsigned long doris_vesion_20210719=20210719L;
static unsigned long doris_vesion_20210722=20210722L;
int doris_mkdir_according_path(const char * path)
{
@@ -54,9 +54,24 @@ int doris_mkdir_according_path(const char * path)
return 0;
}
static int doris_chech_name_valid(const char *name)
{
size_t i, namelen=strlen(name);
for(i=0; i<namelen; i++)
{
if(!((name[i]>='a' && name[i]<='z')||(name[i]>='A' && name[i]<='Z') ||
(name[i]>='0' && name[i]<='9') || name[i]=='_' || name[i]==':'))
{
return false;
}
}
return true;
}
int32_t doris_read_profile_configs(const char *config_file)
{
char tmp_buf[4096], tmp_dir[512], tmp_dir2[512];
char tmp_buf[4096], tmp_dir[512];
MESA_load_profile_string_def(config_file, "DORIS_SERVER", "run_log_dir", g_doris_server_info.root_log_dir, sizeof(g_doris_server_info.root_log_dir), "./log");
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "run_log_lv", &g_doris_server_info.log_level, 10);
@@ -86,37 +101,8 @@ int32_t doris_read_profile_configs(const char *config_file)
}
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "cache_file_frag_size", &g_doris_server_info.cache_frag_size, 67108864);
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "doris_server_role_on", &g_doris_server_info.server_role_sw, 1);
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "doris_write_file_on", &g_doris_server_info.write_file_sw, 1);
if(0>MESA_load_profile_string_nodef(config_file, "DORIS_SERVER", "store_config_path", g_doris_server_info.store_path_root, sizeof(g_doris_server_info.store_path_root)))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "%s: [DORIS_SERVER]store_config_path not found!", config_file);
assert(0);return -1;
}
snprintf(tmp_dir, 512, "%s/full/index", g_doris_server_info.store_path_root);
snprintf(tmp_dir2,512, "%s/inc/index", g_doris_server_info.store_path_root);
if(doris_mkdir_according_path(tmp_dir) || doris_mkdir_according_path(tmp_dir2))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "mkdir %s failed: %s\n", tmp_dir, strerror(errno));
return -1;
}
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "receive_config_way", &g_doris_server_info.recv_way, RECV_WAY_DRS_CLIENT);
if(g_doris_server_info.recv_way == RECV_WAY_IDX_FILE)
{
if(0>MESA_load_profile_string_nodef(config_file, "DORIS_SERVER", "receive_config_path_full", g_doris_server_info.recv_path_full, sizeof(g_doris_server_info.recv_path_full)))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "%s: [DORIS_SERVER]receive_config_path not found!", config_file);
assert(0);return -1;
}
if(0>MESA_load_profile_string_nodef(config_file, "DORIS_SERVER", "receive_config_path_inc", g_doris_server_info.recv_path_inc, sizeof(g_doris_server_info.recv_path_inc)))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "%s: [DORIS_SERVER]receive_config_path not found!", config_file);
assert(0);return -1;
}
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "scan_index_file_interval", &g_doris_server_info.scan_idx_interval, 10);
}
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "scan_index_file_interval", &g_doris_server_info.scan_idx_interval, 10);
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "https_connection_on", &g_doris_server_info.ssl_conn_on, 0);
if(g_doris_server_info.ssl_conn_on)
{
@@ -143,9 +129,11 @@ int32_t doris_read_profile_configs(const char *config_file)
static int doris_server_register_field_stat(struct doris_global_info *param)
{
const char *field_names[DRS_FSSTAT_FIELD_NUM]={"RecvFullVer", "RecvIncVer", "RecvErrVer", "FileStarts", "FileComplete",
"ClientInvReq", "ClientMetaReq", "SendResMeta", "SendNoNewMeta", "ClientFileReq", "SendFiles", "SendBytes", "SendFile404"};
const char *status_names[DRS_FSSTAT_STATUS_NUM]={"MemoryUsed", "CurFullVer", "CurIncVer", "TotalCfgNum"};
const char *field_names[DRS_FSSTAT_FIELD_NUM]={"RecvErrVer", "FileStarts", "FileComplete", "ClientInvReq",
"ClientMetaReq", "SendNoNewMeta", "ClientFileReq", "SendBytes", "SendFile404"};
const char *status_names[DRS_FSSTAT_STATUS_NUM]={"MemoryUsed"};
const char *column_names[DRS_FSSTAT_CLUMN_NUM]={"RecvFullVer", "RecvIncVer", "RecvFiles", "SendResMeta", "SendFiles",
"CurFullVer", "CurIncVer", "TotalCfgNum"};
int value;
param->fsstat_handle = FS_create_handle();
@@ -176,6 +164,10 @@ static int doris_server_register_field_stat(struct doris_global_info *param)
{
param->fsstat_status[i] = FS_register(param->fsstat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, status_names[i]);
}
for(int i=0; i<DRS_FSSTAT_CLUMN_NUM; i++)
{
param->fsstat_column[i] = FS_register(param->fsstat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, column_names[i]);
}
FS_start(param->fsstat_handle);
return 0;
}
@@ -191,6 +183,96 @@ static void instance_fsstat_output_timer_cb(int fd, short kind, void *userp)
event_add((struct event*)userp, &tv);
}
static int32_t doris_init_config_for_business(struct doris_global_info *info, struct event_base *manage_evbase, const char *config_file)
{
char tmpbuffer[4096], tmp_dir[256], tmp_dir2[256], *bizname, *save=NULL;
struct doris_business *business;
map<string, struct doris_parameter *>::iterator iter;
if(0>=MESA_load_profile_string_nodef(config_file, "DORIS_SERVER", "business_system_list", tmpbuffer, sizeof(tmpbuffer)))
{
MESA_RUNTIME_LOGV3(info->log_runtime, RLOG_LV_FATAL, "%s: [DORIS_SERVER]business_system_list not found!", config_file);
assert(0);return -1;
}
for(bizname=strtok_r(tmpbuffer, ";", &save); bizname!=NULL; bizname=strtok_r(NULL, ";", &save))
{
if(!doris_chech_name_valid(bizname))
{
MESA_RUNTIME_LOGV3(info->log_runtime, RLOG_LV_FATAL, "%s: [DORIS_SERVER]business_system_list bizname %s invalid, name must match: [a-zA-Z_:][a-zA-Z0-9_:]", bizname, config_file);
assert(0);return -1;
}
business = &info->business[info->business_num++];
snprintf(business->bizname, sizeof(business->bizname), "%s", bizname);
pthread_rwlock_init(&business->rwlock, NULL);
business->cfgver_head = config_version_handle_new();
if(info->name2business->find(string(business->bizname)) != info->name2business->end())
{
MESA_RUNTIME_LOGV3(info->log_runtime, RLOG_LV_FATAL, "%s: [%s]business_system_list duplicate system name: %s!", bizname, config_file, business->bizname);
assert(0);return -1;
}
info->name2business->insert(make_pair(string(business->bizname), business));
MESA_load_profile_uint_def(config_file, business->bizname, "grafana_monitor_status_id", &business->mm_status_codeid, 3);
MESA_load_profile_uint_def(config_file, business->bizname, "doris_write_file_on", &business->write_file_sw, 1);
if(0>MESA_load_profile_string_nodef(config_file, business->bizname, "store_config_path", business->store_path_root, sizeof(business->store_path_root)))
{
MESA_RUNTIME_LOGV3(info->log_runtime, RLOG_LV_FATAL, "%s: [%s]store_config_path not found!", bizname, config_file);
assert(0);return -1;
}
snprintf(tmp_dir, 512, "%s/full/index", business->store_path_root);
snprintf(tmp_dir2,512, "%s/inc/index", business->store_path_root);
if(doris_mkdir_according_path(tmp_dir) || doris_mkdir_according_path(tmp_dir2))
{
MESA_RUNTIME_LOGV3(info->log_runtime, RLOG_LV_FATAL, "mkdir %s failed: %s\n", tmp_dir, strerror(errno));
return -1;
}
MESA_load_profile_uint_def(config_file, business->bizname, "receive_config_way", &business->recv_way, RECV_WAY_DRS_CLIENT);
if(business->recv_way == RECV_WAY_DRS_CLIENT)
{
if(0>=MESA_load_profile_string_nodef(config_file, business->bizname, "doris_client_confile", tmp_dir, sizeof(tmp_dir)))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "%s: [DORIS_SERVER]doris_client_confile not found!", config_file);
assert(0);return -1;
}
if((iter=info->confile2param->find(string(tmp_dir))) != info->confile2param->end())
{
business->param = iter->second;
}
else
{
business->param = doris_parameter_new(tmp_dir, manage_evbase, info->log_runtime);
if(business->param == NULL)
{
assert(0);return -2;
}
info->confile2param->insert(make_pair(string(tmp_dir), business->param));
}
}
else
{
if(0>MESA_load_profile_string_nodef(config_file, business->bizname, "receive_config_path_full", business->recv_path_full, sizeof(business->recv_path_full)))
{
MESA_RUNTIME_LOGV3(info->log_runtime, RLOG_LV_FATAL, "%s: [%s]receive_config_path not found!", bizname, config_file);
assert(0);return -1;
}
if(0>MESA_load_profile_string_nodef(config_file, business->bizname, "receive_config_path_inc", business->recv_path_inc, sizeof(business->recv_path_inc)))
{
MESA_RUNTIME_LOGV3(info->log_runtime, RLOG_LV_FATAL, "%s: [%s]receive_config_path not found!", bizname, config_file);
assert(0);return -1;
}
}
business->fs_lineid = FS_register(info->fsstat_handle, FS_STYLE_LINE, FS_CALC_CURRENT, business->bizname);;
snprintf(tmp_dir, 512, "latest_cfg_version_%s", business->bizname);
business->mm_latest_ver = MESA_Monitor_register(info->monitor, tmp_dir, MONITOR_METRICS_GAUGE, "Latest doris config version.");
snprintf(tmp_dir, 512, "total_config_num_%s", business->bizname);
business->mm_total_cfgnum = MESA_Monitor_register(info->monitor, tmp_dir, MONITOR_METRICS_GAUGE, "Total config num from latest full version till now.");
}
return 0;
}
static void manager_statistic_threads_requests_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_error(req, HTTP_BADREQUEST, "Not Supported.");
@@ -224,30 +306,11 @@ int main(int argc, char **argv)
{
return -1;
}
g_doris_server_info.cfgver_head = config_version_handle_new();
pthread_rwlock_init(&g_doris_server_info.rwlock, NULL);
evthread_use_pthreads();
g_doris_server_info.name2business = new map<string, struct doris_business*>;
g_doris_server_info.confile2param = new map<string, struct doris_parameter *>;
manage_evbase = event_base_new();
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if(g_doris_server_info.recv_way == RECV_WAY_DRS_CLIENT)
{
if(pthread_create(&thread_desc, &attr, thread_doris_client_recv_cfg, manage_evbase))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "pthread_create(): %s", strerror(errno));
assert(0);return -4;
}
}
else
{
if(pthread_create(&thread_desc, &attr, thread_index_file_recv_cfg, NULL))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "pthread_create(): %s", strerror(errno));
assert(0);return -4;
}
}
/*Doris manager server*/
g_doris_server_info.manager = doris_create_listen_socket(g_doris_server_info.manager_port);
if(g_doris_server_info.manager < 0)
@@ -263,10 +326,7 @@ int main(int argc, char **argv)
evhttp_set_cb(manager_http, "/doris/statistic/status", manager_statistic_status_requests_cb, NULL);
evhttp_set_cb(manager_http, "/doris/statistic/threads", manager_statistic_threads_requests_cb, NULL);
evhttp_set_gencb(manager_http, manager_generic_requests_cb, NULL);
g_doris_server_info.monitor = MESA_Monitor_instance_evhttp_new(manager_http, doris_vesion_20210719);
g_doris_server_info.mm_latest_ver = MESA_Monitor_register(g_doris_server_info.monitor, "latest_cfg_version", MONITOR_METRICS_GAUGE, "Latest doris config version.");
g_doris_server_info.mm_total_cfgnum = MESA_Monitor_register(g_doris_server_info.monitor, "total_config_num", MONITOR_METRICS_GAUGE, "Total config num from latest full version till now.");
g_doris_server_info.monitor = MESA_Monitor_instance_evhttp_new(manager_http, doris_vesion_20210722);
if(evhttp_accept_socket(manager_http, g_doris_server_info.manager))
{
printf("evhttp_accept_socket %d error!\n", g_doris_server_info.manager);
@@ -274,6 +334,34 @@ int main(int argc, char **argv)
assert(0); return -7;
}
//Ϊÿ<CEAA><C3BF>ҵ<EFBFBD><D2B5>ϵͳ<CFB5><CDB3>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>õĽṹ
if(doris_init_config_for_business(&g_doris_server_info, manage_evbase, NIRVANA_CONFIG_FILE))
{
return -8;
}
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
for(u_int32_t i=0; i<g_doris_server_info.business_num; i++)
{
if(g_doris_server_info.business[i].recv_way == RECV_WAY_DRS_CLIENT)
{
if(pthread_create(&thread_desc, &attr, thread_doris_client_recv_cfg, &g_doris_server_info.business[i]))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "pthread_create(): %s", strerror(errno));
assert(0);return -4;
}
}
else
{
if(pthread_create(&thread_desc, &attr, thread_index_file_recv_cfg, &g_doris_server_info.business[i]))
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "pthread_create(): %s", strerror(errno));
assert(0);return -4;
}
}
}
/*Doris http server*/
if(g_doris_server_info.server_role_sw)
{