增加HTTP Post上传配置接口,支持主从双机备份与同步(冷备)

This commit is contained in:
linuxrc@163.com
2021-08-25 18:40:20 +08:00
parent 67bafbefc9
commit 1aca701f12
28 changed files with 3295 additions and 648 deletions

View File

@@ -4,7 +4,7 @@ add_definitions(-fPIC -Wall -g)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_CURRENT_SOURCE_DIR}/,,$(abspath $<))\"'")
add_executable(doris ${NIRVANA_PLATFORM_SRC})
target_link_libraries(doris doris_client_static libMesaMonitor libevent-static libevent-pthreads-static libcurl-static libevent-openssl-static openssl-ssl-static openssl-crypto-static cjson libLevelDB)
target_link_libraries(doris doris_client_static libMesaMonitor libevent-static libevent-pthreads-static libcurl-static libevent-openssl-static openssl-ssl-static openssl-crypto-static cjson)
target_link_libraries(doris MESA_handle_logger MESA_htable MESA_prof_load MESA_field_stat2 pthread z dl)
set_target_properties(doris PROPERTIES CLEAN_DIRECT_OUTPUT 1)
target_include_directories(doris PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

View File

@@ -1,35 +0,0 @@
[DORIS_CLIENT]
fetch_fail_retry_interval=5
fetch_fragmet_size=5242880
fetch_confile_max_tries=3
fsstat_log_appname=DorisClient
fsstat_log_filepath=./log/doris_client.fs
fsstat_log_interval=2
fsstat_log_print_mode=1
fsstat_log_dst_ip=192.168.10.90
fsstat_log_dst_port=8125
[DORIS_CLIENT.master_server]
max_connection_per_host=1
max_cnnt_pipeline_num=10
https_connection_on=0
max_curl_session_num=10
http_server_listen_port=9897
http_server_manage_port=9897
http_server_ip_list=192.168.10.8
[DORIS_CLIENT.backup1_server]
max_connection_per_host=1
max_cnnt_pipeline_num=10
https_connection_on=0
max_curl_session_num=10
http_server_listen_port=9897
http_server_manage_port=9897
http_server_ip_list=192.168.11.241
[DORIS_CLIENT.backup2_server]

View File

@@ -0,0 +1,30 @@
[DORIS_CLIENT]
fetch_fail_retry_interval=5
fetch_fragmet_size=5242880
fetch_confile_max_tries=3
fsstat_log_appname=DrsCsmClient
fsstat_log_filepath=./log/doris_client_csm.fs
fsstat_log_interval=2
fsstat_log_print_mode=1
fsstat_log_dst_ip=192.168.10.90
fsstat_log_dst_port=8125
[DORIS_CLIENT.master_server]
https_connection_on=1
http_server_listen_port=9898
http_server_manage_port=2233
http_server_ip_list=192.168.10.8
[DORIS_CLIENT.backup1_server]
https_connection_on=1
http_server_listen_port=9898
http_server_manage_port=2233
http_server_ip_list=192.168.11.241
[DORIS_CLIENT.backup2_server]
https_connection_on=1
http_server_listen_port=9898
http_server_manage_port=2233
http_server_ip_list=192.168.11.242

View File

@@ -0,0 +1,28 @@
[DORIS_CLIENT]
fetch_fail_retry_interval=5
fetch_fragmet_size=5242880
fetch_confile_max_tries=3
upload_fragmet_size=5242880
master_slave_sync_on=1
fsstat_log_appname=DrsPrdClient
fsstat_log_filepath=./log/doris_sync_t1c.fs
fsstat_log_filepath_p=./log/doris_sync_t1p.fs
fsstat_log_interval=2
fsstat_log_print_mode=1
fsstat_log_dst_ip=192.168.10.90
fsstat_log_dst_port=8125
[DORIS_CLIENT.master_server]
https_connection_on=1
http_server_listen_port=9898
http_server_manage_port=2233
http_server_ip_list=192.168.10.9
[DORIS_CLIENT.produce]
https_connection_on=1
http_server_listen_port=9800
http_server_manage_port=2233
http_server_ip_list=192.168.10.9

View File

@@ -0,0 +1,28 @@
[DORIS_CLIENT]
fetch_fail_retry_interval=5
fetch_fragmet_size=5242880
fetch_confile_max_tries=3
upload_fragmet_size=5242880
master_slave_sync_on=1
fsstat_log_appname=DrsPrdClient
fsstat_log_filepath=./log/doris_sync_voipc.fs
fsstat_log_filepath_p=./log/doris_sync_voipp.fs
fsstat_log_interval=2
fsstat_log_print_mode=1
fsstat_log_dst_ip=192.168.10.90
fsstat_log_dst_port=8125
[DORIS_CLIENT.master_server]
https_connection_on=1
http_server_listen_port=9898
http_server_manage_port=2233
http_server_ip_list=192.168.10.9
[DORIS_CLIENT.produce]
https_connection_on=1
http_server_listen_port=9801
http_server_manage_port=2233
http_server_ip_list=192.168.10.9

View File

@@ -1,13 +1,15 @@
[DORIS_SERVER]
worker_thread_num=2
server_listen_port=9898
manage_listen_port=2233
consumer_listen_port=9898
manager_listen_port=2233
https_connection_on=1
cache_file_frag_size=100
#doris_server_role_on=1
#cache_file_frag_size=67108864
#index_file_format_maat=0
local_net_name=em1
http_post_cluster_on=1
#http_post_max_concurrence=100000
business_system_list=T1_1;VoIP
business_system_list=VoIP;T1_1
run_log_dir=./log
run_log_lv=20
@@ -19,20 +21,25 @@ fsstat_log_dst_ip=192.168.10.90
fsstat_log_dst_port=8125
[T1_1]
#1-Doris client; 2-local file
receive_config_way=2
#1-Doris client; 2-local file; 3-HTTP post server
receive_config_way=1
grafana_monitor_status_id=3
#producer_listen_port=9800
#producer_concurrence_allowed=0
store_config_path=./doris_store_t1
receive_config_path_full=./doris_receive_t1/full/index
receive_config_path_inc=./doris_receive_t1/inc/index
#doris_client_confile=./conf/doris_client.conf
doris_client_confile=./conf/doris_client_csum.conf
#doris_client_confile=./conf/doris_client_sync_t1.conf
[VoIP]
receive_config_way=2
receive_config_way=3
producer_listen_port=9801
producer_concurrence_allowed=1
mem_cache_max_versions=2
grafana_monitor_status_id=4
store_config_path=./doris_store_voip
receive_config_path_full=./doris_receive_voip/full/index
receive_config_path_inc=./doris_receive_voip/inc/index
#doris_client_confile=./conf/doris_client.conf
doris_client_confile=./conf/doris_client_sync_voip.conf

View File

@@ -16,64 +16,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <event2/bufferevent_ssl.h>
#include "doris_server_main.h"
#include "doris_server_http.h"
extern struct doris_global_info g_doris_server_info;
static inline void set_sockopt_keepalive(int sd, int keepidle, int keepintvl, int keepcnt)
{
int keepalive = 1;
setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (void*)&keepalive, sizeof(keepalive));
setsockopt(sd, SOL_TCP, TCP_KEEPIDLE, (void*)&keepidle, sizeof(keepidle));
setsockopt(sd, SOL_TCP, TCP_KEEPINTVL, (void*)&keepintvl, sizeof(keepintvl));
setsockopt(sd, SOL_TCP, TCP_KEEPCNT, (void*)&keepcnt, sizeof(keepcnt));
}
static inline void set_listen_sockopt(int sd)
{
if(g_doris_server_info.sock_recv_bufsize > 0)
{
setsockopt(sd, SOL_SOCKET, SO_RCVBUF, &g_doris_server_info.sock_recv_bufsize, sizeof(u_int32_t));
}
}
int doris_create_listen_socket(int bind_port)
{
evutil_socket_t listener;
struct sockaddr_in sin;
listener = socket(AF_INET, SOCK_STREAM, 0);
if(listener < 0)
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "create socket error!\n");
return -1;
}
set_sockopt_keepalive(listener, 300, 10, 2);
set_listen_sockopt(listener);
evutil_make_listen_socket_reuseable(listener);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr=htonl(INADDR_ANY);
sin.sin_port = htons(bind_port);
if (bind(listener, (struct sockaddr *)&sin, sizeof(sin)) < 0)
{
printf("bind socket to port: %d error: %s!\n", bind_port, strerror(errno));
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "bind socket to port: %d error: %s!\n", bind_port, strerror(errno));
assert(0);return -2;
}
if (listen(listener, 1024)<0)
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "listen socket 1024 error!\n");
return -3;
}
evutil_make_socket_nonblocking(listener);
return listener;
}
struct version_list_node *lookup_vernode_accord_version(struct version_list_handle *handle, int64_t version)
{
struct version_list_node *vernode;
@@ -96,16 +43,49 @@ struct version_list_node *lookup_vernode_accord_version(struct version_list_hand
return NULL;
}
/*<2A><><EFBFBD><EFBFBD>ֵ:
*304-<2D>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>Ѵ<D1B4><EFB5BD><EFBFBD>°汾<C2B0><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>consumer<65><72>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*300-<2D><>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Client<6E><74><EFBFBD>ð汾<C3B0><E6B1BE><EFBFBD><EFBFBD>*/
static int32_t check_producer_ready_sync(struct doris_business *business, struct evhttp_request *req, int64_t cur_version)
{
const char *client_version;
int64_t clientversion;
if(NULL == (client_version=evhttp_find_header(evhttp_request_get_input_headers(req), "X-Doris-Sync-Current-Version")))
{
return HTTP_NOTMODIFIED;
}
/*request from sync client, check http posts-on-the-way first*/
if(business->posts_on_the_way)
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_DEBUG, "HttpProducer, posts-on-the-way: %d, meta response 300", business->posts_on_the_way);
return 300;
}
/*Client<6E><EFBFBD><E6B1BE><EFBFBD><EFBFBD>? <20><><EFBFBD><EFBFBD><EFBFBD>˴ӻ<CBB4><D3BB><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD>Client<6E><74><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD>ȡ*/
/*<2A><><EFBFBD><EFBFBD>ȡʱ<C8A1><CAB1><EFBFBD>õ<EFBFBD>300<30><30>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʱ<C8A1><CAB1>ֱ<EFBFBD><D6B1>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ汾<C4B0><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B1BE><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD>304*/
if((clientversion=atol(client_version)) > cur_version)
{
business_set_sync_peer_abnormal(business);
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_INFO, "HttpProducer, client version(%lu) is newer than server(%lu)", clientversion, cur_version);
return 300;
}
business_resume_sync_peer_normal(business);
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "HttpProducer, doris client is OK to sync for business: %s", business->bizname);
return HTTP_NOTMODIFIED;
}
void doris_http_server_meta_cb(struct evhttp_request *req, void *arg)
{
struct evkeyvalq params;
const char *version, *bizname;
const char *version;
int64_t verlong;
char *endptr=NULL, length[64];
struct version_list_node *vernode;
struct evbuffer *evbuf;
struct doris_business *business;
map<string, struct doris_business*>::iterator iter;
FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_CLIENT_META_REQ], 0, FS_OP_ADD, 1);
if(evhttp_parse_query(evhttp_request_get_uri(req), &params))
@@ -128,29 +108,21 @@ void doris_http_server_meta_cb(struct evhttp_request *req, void *arg)
evhttp_send_error(req, HTTP_BADREQUEST, "Parameter version invalid");
return;
}
if(NULL == (bizname = evhttp_find_header(&params, "business")))
if(NULL == (business = lookup_bizstruct_from_name(&params)))
{
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(&params);
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(&params);
evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid, business invalid");
evhttp_send_error(req, HTTP_BADREQUEST, "Parameter business invalid");
return;
}
evhttp_clear_headers(&params);
business = iter->second;
pthread_rwlock_rdlock(&business->rwlock);
if(NULL == (vernode = lookup_vernode_accord_version(business->cfgver_head, verlong)))
{
int code = check_producer_ready_sync(business, req, business->cfgver_head->latest_version);
pthread_rwlock_unlock(&business->rwlock);
FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_SEND_META_NONEW], 0, FS_OP_ADD, 1);
evhttp_send_error(req, HTTP_NOTMODIFIED, "No new configs found");
evhttp_send_error(req, code, "No new configs found");
return;
}
evbuf = evbuffer_new();
@@ -210,24 +182,14 @@ struct evbuffer *evbuf_content_from_disk(struct table_list_node *tablenode, size
return evbuf;
}
void doris_response_file_range(struct evhttp_request *req, const char *bizname, const char *tablename,
int64_t verlong, size_t start, size_t end, bool range)
void doris_response_file_range(struct evhttp_request *req, struct doris_business *business,
const char *tablename, int64_t verlong, size_t start, size_t end, bool range)
{
struct version_list_node *vernode;
struct table_list_node *tablenode;
struct evbuffer *evbuf;
char length[128];
size_t filesize, res_length;
struct doris_business *business;
map<string, struct doris_business*>::iterator iter;
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_send_error(req, HTTP_BADREQUEST, "Parameters invalid, business invalid");
return;
}
business = iter->second;
pthread_rwlock_rdlock(&business->rwlock);
if(NULL == (vernode = lookup_vernode_accord_version(business->cfgver_head, verlong)))
@@ -266,24 +228,29 @@ void doris_response_file_range(struct evhttp_request *req, const char *bizname,
assert(res_length == end + 1 - start);
sprintf(length, "%lu", res_length);
FS_operate(g_doris_server_info.fsstat_handle, business->fs_lineid, g_doris_server_info.fsstat_column[DRS_FSCLM_SEND_FILE_RES], FS_OP_ADD, 1);
FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_SEND_FILES], 0, FS_OP_ADD, 1);
FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_SEND_FILE_BYTES], 0, FS_OP_ADD, res_length);
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Length", length);
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "application/stream");
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "keep-alive");
if(range)
{
sprintf(length, "bytes %lu-%lu/%lu", start, end, filesize);
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Range", length);
evhttp_send_reply(req, 206, "Partial Content", evbuf);
}
else
{
evhttp_send_reply(req, HTTP_OK, "OK", evbuf);
}
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "application/stream");
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "keep-alive");
evhttp_send_reply(req, HTTP_OK, "OK", evbuf);
evbuffer_free(evbuf);
}
void doris_http_server_file_cb(struct evhttp_request *req, void *arg)
{
struct evkeyvalq params;
const char *version, *tablename, *content_range, *bizname;
struct doris_business *business;
const char *version, *tablename, *content_range;
int64_t verlong;
char *endptr=NULL;
size_t req_start=0, req_end=0;
@@ -316,25 +283,22 @@ void doris_http_server_file_cb(struct evhttp_request *req, void *arg)
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, "Header Range invalid");
return;
}
if(NULL == (bizname = evhttp_find_header(&params, "business")))
}
if(NULL == (business = lookup_bizstruct_from_name(&params)))
{
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(&params);
evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid, no business found");
evhttp_send_error(req, HTTP_BADREQUEST, "Parameter business invalid");
return;
}
doris_response_file_range(req, bizname, tablename, verlong, req_start, req_end, (content_range==NULL)?false:true);
doris_response_file_range(req, business, tablename, verlong, req_start, req_end, (content_range==NULL)?false:true);
evhttp_clear_headers(&params);
}
void doris_http_server_version_cb(struct evhttp_request *req, void *arg)
{
struct evkeyvalq params;
const char *bizname;
struct doris_business *business;
map<string, struct doris_business*>::iterator iter;
char verbuf[32];
if(evhttp_parse_query(evhttp_request_get_uri(req), &params))
@@ -343,23 +307,13 @@ void doris_http_server_version_cb(struct evhttp_request *req, void *arg)
evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid");
return;
}
if(NULL == (bizname = evhttp_find_header(&params, "business")))
if(NULL == (business = lookup_bizstruct_from_name(&params)))
{
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(&params);
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(&params);
evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid, business invalid");
evhttp_send_error(req, HTTP_BADREQUEST, "Parameter business invalid");
return;
}
evhttp_clear_headers(&params);
business = iter->second;
pthread_rwlock_rdlock(&business->rwlock);
sprintf(verbuf, "%lu", business->cfgver_head->latest_version);
@@ -464,13 +418,6 @@ SSL_CTX *doris_connections_create_ssl_ctx(void)
return ssl_ctx;
}
struct bufferevent *doris_https_bufferevent_cb(struct event_base *evabse, void *arg)
{
SSL_CTX *ssl_instance = (SSL_CTX *)arg;
return bufferevent_openssl_socket_new(evabse, -1, SSL_new(ssl_instance), BUFFEREVENT_SSL_ACCEPTING, BEV_OPT_CLOSE_ON_FREE);
}
void* thread_doris_http_server(void *arg)
{
struct event_base *worker_evbase;
@@ -492,9 +439,9 @@ void* thread_doris_http_server(void *arg)
evhttp_set_gencb(worker_http, doris_http_server_generic_cb, NULL);
evhttp_set_allowed_methods(worker_http, EVHTTP_REQ_GET|EVHTTP_REQ_HEAD);
if(evhttp_accept_socket(worker_http, g_doris_server_info.listener))
if(evhttp_accept_socket(worker_http, g_doris_server_info.listener_csum))
{
printf("evhttp_accept_socket %d error!\n", g_doris_server_info.listener);
printf("evhttp_accept_socket %d error!\n", g_doris_server_info.listener_csum);
assert(0); return NULL;
}

View File

@@ -3,7 +3,6 @@
#include <openssl/ssl.h>
int doris_create_listen_socket(int bind_port);
SSL_CTX *doris_connections_create_ssl_ctx(void);
void* thread_doris_http_server(void *arg);

View File

@@ -7,17 +7,24 @@
#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <event2/thread.h>
#include <MESA/MESA_prof_load.h>
#include "doris_client.h"
#include "doris_consumer_client.h"
#include "doris_producer_client.h"
#include "doris_server_main.h"
#include "doris_server_http.h"
struct doris_global_info g_doris_server_info;
static unsigned long doris_vesion_20210804=20210804L;
static unsigned long doris_version_20210825=20210825L;
int doris_mkdir_according_path(const char * path)
{
@@ -54,6 +61,79 @@ int doris_mkdir_according_path(const char * path)
return 0;
}
int32_t get_ip_by_ifname(const char *ifname)
{
int sockfd;
struct ifreq ifr;
int32_t ip;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (-1 == sockfd)
return INADDR_NONE;
strcpy(ifr.ifr_name,ifname);
if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0)
{
close(sockfd);
return INADDR_NONE;
}
ip = ((struct sockaddr_in*)&(ifr.ifr_addr))->sin_addr.s_addr;
close(sockfd);
return ip;
}
static inline void set_sockopt_keepalive(int sd, int keepidle, int keepintvl, int keepcnt)
{
int keepalive = 1;
setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (void*)&keepalive, sizeof(keepalive));
setsockopt(sd, SOL_TCP, TCP_KEEPIDLE, (void*)&keepidle, sizeof(keepidle));
setsockopt(sd, SOL_TCP, TCP_KEEPINTVL, (void*)&keepintvl, sizeof(keepintvl));
setsockopt(sd, SOL_TCP, TCP_KEEPCNT, (void*)&keepcnt, sizeof(keepcnt));
}
static inline void set_listen_sockopt(int sd)
{
if(g_doris_server_info.sock_recv_bufsize > 0)
{
setsockopt(sd, SOL_SOCKET, SO_RCVBUF, &g_doris_server_info.sock_recv_bufsize, sizeof(u_int32_t));
}
}
int doris_create_listen_socket(int bind_port)
{
evutil_socket_t listener;
struct sockaddr_in sin;
listener = socket(AF_INET, SOCK_STREAM, 0);
if(listener < 0)
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "create socket error!\n");
return -1;
}
set_sockopt_keepalive(listener, 300, 10, 2);
set_listen_sockopt(listener);
evutil_make_listen_socket_reuseable(listener);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr=htonl(INADDR_ANY);
sin.sin_port = htons(bind_port);
if (bind(listener, (struct sockaddr *)&sin, sizeof(sin)) < 0)
{
printf("bind socket to port: %d error: %s!\n", bind_port, strerror(errno));
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "bind socket to port: %d error: %s!\n", bind_port, strerror(errno));
assert(0);return -2;
}
if (listen(listener, 1024)<0)
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "listen socket 1024 error!\n");
return -3;
}
evutil_make_socket_nonblocking(listener);
return listener;
}
static int doris_chech_name_valid(const char *name)
{
size_t i, namelen=strlen(name);
@@ -100,8 +180,11 @@ int32_t doris_read_profile_configs(const char *config_file)
assert(0);return -1;
}
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", "http_post_max_frag_size", &g_doris_server_info.max_http_body_size, 67108864);
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "index_file_format_maat", &g_doris_server_info.idx_file_maat, 0);
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "http_post_max_concurrence", &g_doris_server_info.max_concurrent_reqs, 100000);
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "http_post_cluster_on", &g_doris_server_info.cluster_sync_mode, 0);
MESA_load_profile_uint_def(config_file, "DORIS_SERVER", "http_post_op_expires", &g_doris_server_info.post_vernode_ttl, 1200);
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);
@@ -122,18 +205,19 @@ int32_t doris_read_profile_configs(const char *config_file)
MESA_load_profile_int_def(config_file, "DORIS_SERVER", "fsstat_log_dst_port", &g_doris_server_info.fsstat_dst_port, 8125);
//LIBEVENT
MESA_load_profile_int_def(config_file, "DORIS_SERVER", "server_listen_port", &g_doris_server_info.server_port, 9898);
MESA_load_profile_int_def(config_file, "DORIS_SERVER", "manage_listen_port", &g_doris_server_info.manager_port, 2233);
MESA_load_profile_int_def(config_file, "DORIS_SERVER", "consumer_listen_port", &g_doris_server_info.consumer_port, 0);
MESA_load_profile_int_def(config_file, "DORIS_SERVER", "manager_listen_port", &g_doris_server_info.manager_port, 2233);
MESA_load_profile_int_def(config_file, "DORIS_SERVER", "socket_recv_bufsize", &g_doris_server_info.sock_recv_bufsize, 524288);
pthread_mutex_init(&g_doris_server_info.mutex_lock, NULL);
return 0;
}
static int doris_server_register_field_stat(struct doris_global_info *param)
{
const char *field_names[DRS_FSSTAT_FIELD_NUM]={"RecvErrVer", "FileStarts", "FileComplete", "ClientInvReq",
"ClientMetaReq", "SendNoNewMeta", "ClientFileReq", "SendBytes", "SendFile404"};
"ClientMetaReq", "SendNoNewMeta", "ClientFileReq", "SendFiles", "SendBytes", "SendFile404", "VerExpire"};
const char *status_names[DRS_FSSTAT_STATUS_NUM]={"MemoryUsed"};
const char *column_names[DRS_FSSTAT_CLUMN_NUM]={"RecvFullVer", "RecvIncVer", "RecvFiles", "SendResMeta", "SendFiles",
const char *column_names[DRS_FSSTAT_CLUMN_NUM]={"RecvFullVer", "RecvIncVer", "RecvFiles", "PostOnWay", "SendResMeta",
"CurFullVer", "CurIncVer", "TotalCfgNum"};
int value;
@@ -188,7 +272,8 @@ static int32_t doris_init_config_for_business(struct doris_global_info *info, st
{
char tmpbuffer[4096], tmp_dir[256], tmp_dir2[256], *bizname, *save=NULL;
struct doris_business *business;
map<string, struct doris_parameter *>::iterator iter;
map<string, struct doris_csum_param *>::iterator iter_csm;
map<string, struct doris_prod_param *>::iterator iter_prd;
if(0>=MESA_load_profile_string_nodef(config_file, "DORIS_SERVER", "business_system_list", tmpbuffer, sizeof(tmpbuffer)))
{
@@ -214,7 +299,7 @@ static int32_t doris_init_config_for_business(struct doris_global_info *info, st
}
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, "grafana_monitor_status_id", &business->mmval_status_codeid, 3);
MESA_load_profile_uint_def(config_file, business->bizname, "mem_cache_max_versions", &business->cache_max_versions, 0);
if(0>MESA_load_profile_string_nodef(config_file, business->bizname, "store_config_path", business->store_path_root, sizeof(business->store_path_root)))
{
@@ -230,28 +315,8 @@ static int32_t doris_init_config_for_business(struct doris_global_info *info, st
}
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
assert(business->recv_way==RECV_WAY_IDX_FILE || business->recv_way==RECV_WAY_DRS_CLIENT || business->recv_way==RECV_WAY_HTTP_POST);
if(business->recv_way == RECV_WAY_IDX_FILE)
{
if(0>MESA_load_profile_string_nodef(config_file, business->bizname, "receive_config_path_full", business->recv_path_full, sizeof(business->recv_path_full)))
{
@@ -264,12 +329,52 @@ static int32_t doris_init_config_for_business(struct doris_global_info *info, st
assert(0);return -1;
}
}
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>Ҳ<EFBFBD><D2B2>Ҫ
{
if(business->recv_way==RECV_WAY_DRS_CLIENT || g_doris_server_info.cluster_sync_mode)
{
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_csm=info->confile2csmparam->find(string(tmp_dir))) != info->confile2csmparam->end())
{
business->param_csum = iter_csm->second;
}
else
{
business->param_csum = doris_csum_parameter_new(tmp_dir, manage_evbase, info->log_runtime);
if(business->param_csum == NULL)
{
assert(0);return -2;
}
info->confile2csmparam->insert(make_pair(string(tmp_dir), business->param_csum));
}
}
if(business->recv_way == RECV_WAY_HTTP_POST) //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
{
MESA_load_profile_uint_def(config_file, business->bizname, "producer_concurrence_allowed", &business->concurrency_allowed, 0);
if(MESA_load_profile_int_nodef(config_file, business->bizname, "producer_listen_port", &business->producer_port)<0)
{
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "%s: [%s]producer_listen_port not found!", config_file, business->bizname);
assert(0);return -1;
}
if(g_doris_server_info.cluster_sync_mode &&
NULL==(business->param_prod = doris_prod_parameter_new(tmp_dir, manage_evbase, info->log_runtime)))
{
assert(0);return -2;
}
g_doris_server_info.business_post_num++;
business->token2node = new map<string, struct version_list_node *>;
}
}
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.");
business->mmid_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.");
business->mmid_total_cfgnum = MESA_Monitor_register(info->monitor, tmp_dir, MONITOR_METRICS_GAUGE, "Total config num from latest full version till now.");
}
return 0;
}
@@ -302,14 +407,16 @@ int main(int argc, char **argv)
struct timeval tv;
struct event timer_statistic_fsstat;
struct evhttp *manager_http;
char netname[32];
memset(&g_doris_server_info, 0, sizeof(struct doris_global_info));
if(doris_read_profile_configs(NIRVANA_CONFIG_FILE) || doris_server_register_field_stat(&g_doris_server_info))
{
return -1;
}
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 *>;
g_doris_server_info.confile2csmparam = new map<string, struct doris_csum_param *>;
manage_evbase = event_base_new();
/*Doris manager server*/
@@ -327,7 +434,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_20210804);
g_doris_server_info.monitor = MESA_Monitor_instance_evhttp_new(manager_http, doris_version_20210825);
if(evhttp_accept_socket(manager_http, g_doris_server_info.manager))
{
printf("evhttp_accept_socket %d error!\n", g_doris_server_info.manager);
@@ -340,6 +447,24 @@ int main(int argc, char **argv)
{
return -4;
}
if(g_doris_server_info.business_post_num > 0)
{
if((MESA_load_profile_string_nodef(NIRVANA_CONFIG_FILE, "DORIS_SERVER", "local_net_name", netname, sizeof(netname))<0) ||
(g_doris_server_info.local_ip = get_ip_by_ifname(netname))<0)
{
printf("%s: [DORIS_SERVER]local_net_name not valid", NIRVANA_CONFIG_FILE);
MESA_RUNTIME_LOGV3(g_doris_server_info.log_runtime, RLOG_LV_FATAL, "%s: [DORIS_SERVER]local_net_name not valid", NIRVANA_CONFIG_FILE);
assert(0);return -11;
}
g_doris_server_info.mmid_post_server = MESA_Monitor_register(g_doris_server_info.monitor,
"http_post_server_status", MONITOR_METRICS_GAUGE, "Running status of doris http post server.");
MESA_Monitor_operation(g_doris_server_info.monitor, g_doris_server_info.mmid_post_server, MONITOR_VALUE_SET, PROMETHUES_POST_SERVER_DOWN);
}
if(g_doris_server_info.ssl_conn_on && NULL==(g_doris_server_info.ssl_instance=doris_connections_create_ssl_ctx()))
{
assert(0);return -8;
}
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -353,6 +478,14 @@ int main(int argc, char **argv)
assert(0);return -5;
}
}
else if(g_doris_server_info.business[i].recv_way == RECV_WAY_HTTP_POST)
{
if(pthread_create(&thread_desc, &attr, thread_http_post_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 -6;
}
}
else
{
if(pthread_create(&thread_desc, &attr, thread_index_file_recv_cfg, &g_doris_server_info.business[i]))
@@ -364,17 +497,13 @@ int main(int argc, char **argv)
}
/*Doris http server*/
if(g_doris_server_info.server_role_sw)
if(g_doris_server_info.consumer_port)
{
g_doris_server_info.listener = doris_create_listen_socket(g_doris_server_info.server_port);
if(g_doris_server_info.listener < 0)
g_doris_server_info.listener_csum = doris_create_listen_socket(g_doris_server_info.consumer_port);
if(g_doris_server_info.listener_csum < 0)
{
return -7;
}
if(g_doris_server_info.ssl_conn_on && NULL==(g_doris_server_info.ssl_instance=doris_connections_create_ssl_ctx()))
{
assert(0);return -8;
}
for(u_int32_t i=0; i<g_doris_server_info.iothreads; i++)
{
if(pthread_create(&thread_desc, &attr, thread_doris_http_server, NULL))
@@ -396,4 +525,3 @@ int main(int argc, char **argv)
return 0;
}

View File

@@ -18,7 +18,7 @@
#include "MESA_Monitor.h"
#include "doris_client.h"
#include "doris_consumer_client.h"
#include "doris_server_receive.h"
#include <map>
@@ -39,35 +39,65 @@ using namespace std;
#define RECV_WAY_IDX_FILE 2
#define RECV_WAY_HTTP_POST 3
#define PROMETHUES_POST_SERVER_OK 0
#define PROMETHUES_POST_SERVER_UPING 1
#define PROMETHUES_POST_SERVER_DOWN 2
struct doris_business
{
/*first for configuration*/
char bizname[32];
u_int32_t recv_way;
u_int32_t cache_max_versions;
u_int32_t concurrency_allowed;
char recv_path_full[256];
char recv_path_inc[256];
char store_path_root[256];
struct version_list_handle *cfgver_head;
struct doris_parameter *param;
struct doris_csum_param *param_csum;
struct doris_prod_param *param_prod;
u_int32_t ready_to_sync;
u_int32_t posts_on_the_way;
int32_t producer_port; //<2F><>֤ÿ<D6A4><C3BF>biz<69><7A><EFBFBD><EFBFBD>server<65>߳<EFBFBD>ֻ<EFBFBD><D6BB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>instance
evutil_socket_t listener_prod;
int64_t total_cfgnum;
int32_t mm_latest_ver;
int32_t mm_total_cfgnum;
u_int32_t mm_status_codeid; //MM<4D>ڲ<EFBFBD><DAB2>쳣״̬id
int32_t mmid_latest_ver;
int32_t mmid_total_cfgnum;
u_int32_t mmval_status_codeid; //MM<4D>ڲ<EFBFBD><DAB2>쳣״̬id<EFBFBD><EFBFBD>Grafana<EFBFBD><EFBFBD>value
u_int32_t fs_lineid;
pthread_rwlock_t rwlock;
/*next for updating*/
struct event_base *worker_evbase;
struct doris_prod_instance *instance;
map<string, struct version_list_node *> *token2node;
int64_t version;
int32_t source_from;
int32_t type;
int64_t version_cfgnum;
char inc_index_path[256]; //incĿ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>
char tmp_index_path[256]; //incĿ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>
char full_index_path[256]; //fullĿ¼<C4BF>µ<EFBFBD>ȫ<EFBFBD><C8AB>
char cfg_file_path[256];
FILE *fp_cfg_file; //<2F><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6>ļ<EFBFBD><C4BC><EFBFBD>DRS Client<6E>ӿ<EFBFBD>
FILE *fp_idx_file; //<2F><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6>ļ<EFBFBD><C4BC><EFBFBD>DRS Client<6E>ӿ<EFBFBD>
struct version_list_node *cur_vernode;
};
struct doris_global_info
{
u_int32_t iothreads;
int32_t server_port;
int32_t consumer_port;
int32_t manager_port;
int32_t sock_recv_bufsize;
u_int32_t ssl_conn_on;
u_int32_t scan_idx_interval;
u_int32_t cache_frag_size;
u_int32_t server_role_sw;
u_int32_t max_http_body_size;
u_int32_t idx_file_maat;
u_int32_t max_concurrent_reqs;
u_int32_t cluster_sync_mode;
u_int32_t post_vernode_ttl;
char ssl_CA_path[256];
char ssl_cert_file[256];
@@ -76,16 +106,21 @@ struct doris_global_info
pthread_mutex_t *lock_cs;
SSL_CTX *ssl_instance;
evutil_socket_t listener;
evutil_socket_t listener_csum;
evutil_socket_t manager;
u_int32_t token_seq;
int32_t local_ip;
struct doris_business business[MAX_BUSINESS_NUM];
u_int32_t business_num;
u_int32_t idx_file_maat;
u_int32_t business_post_num; //postģʽ<C4A3>м<EFBFBD><D0BC><EFBFBD>
int32_t business_post_ups; //<2F><><EFBFBD><EFBFBD><EFBFBD>˼<EFBFBD><CBBC><EFBFBD>
int32_t mmid_post_server; //value=PROMETHUES_POST_*
map<string, struct doris_business*> *name2business;
map<string, struct doris_parameter *> *confile2param;
map<string, struct doris_csum_param *> *confile2csmparam;
struct MESA_MonitorHandler *monitor;
pthread_mutex_t mutex_lock;
/*logs*/
u_int32_t log_level;
@@ -106,6 +141,7 @@ struct doris_global_info
};
int doris_mkdir_according_path(const char * path);
int doris_create_listen_socket(int bind_port);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -4,8 +4,23 @@
#include <stdio.h>
#include <sys/queue.h>
#include <event.h>
#include <openssl/md5.h>
#include <cjson/cJSON.h>
#include <evhttp.h>
#include "doris_producer_client.h"
#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 410)
#define atomic_inc(x) __sync_add_and_fetch((x),1)
#define atomic_dec(x) __sync_sub_and_fetch((x),1)
#define atomic_add(x,y) __sync_add_and_fetch((x),(y))
#define atomic_sub(x,y) __sync_sub_and_fetch((x),(y))
#define atomic_read(x) __sync_add_and_fetch((x),0)
#define atomic_set(x,y) __sync_lock_test_and_set((x),y)
#else
#error "GCC version should be 4.1.2 later"
#endif
#include <map>
using namespace std;
@@ -20,8 +35,10 @@ enum DORIS_SERVER_FS_FILED
DRS_FSSTAT_CLIENT_META_REQ,
DRS_FSSTAT_SEND_META_NONEW,
DRS_FSSTAT_CLIENT_FILE_REQ,
DRS_FSSTAT_SEND_FILES,
DRS_FSSTAT_SEND_FILE_BYTES,
DRS_FSSTAT_SEND_FILE_RES_404,
DRS_FSSTAT_VERSION_EXPIRES,
DRS_FSSTAT_FIELD_NUM,
};
@@ -31,8 +48,8 @@ enum DORIS_SERVER_FS_COLUMN
DRS_FSCLM_RECV_FULL_VER=0,
DRS_FSCLM_RECV_INC_VER,
DRS_FSCLM_RECV_FILES,
DRS_FSCLM_POST_ON_THE_WAY,
DRS_FSCLM_SEND_META_RES,
DRS_FSCLM_SEND_FILE_RES,
DRS_FSCLM_CUR_FULL_VERSION,
DRS_FSCLM_CUR_INC_VERSION,
DRS_FSCLM_CONFIG_TOTAL_NUM,
@@ -58,6 +75,14 @@ struct cont_frag_node
TAILQ_ENTRY(cont_frag_node) frag_node;
};
struct internal_tablemeta
{
char tablename[64];
char filename[64];
size_t offset;
int32_t islast;
};
struct table_list_node
{
char tablename[64];
@@ -65,20 +90,49 @@ struct table_list_node
size_t filesize;
size_t cur_totallen;
/*this part for http post server*/
bool onceupload;
int32_t finished;
MD5_CTX md5ctx;
char tmppath[256];
char filename[128];
char fragmd5[36];
u_int32_t cfgnum;
char *fragcontent;
size_t fragsize;
cJSON *table_meta;
FILE *fp_cfg_file;
struct cont_frag_node *cur_frag;
TAILQ_HEAD(__table_cont_node, cont_frag_node) frag_head;
TAILQ_ENTRY(table_list_node) table_node;
};
struct doris_business;
struct version_list_node
{
int64_t version;
char *metacont;
int32_t metalen;
int16_t cfg_type; //1-full, 2-inc
int16_t cont_in_disk;
int8_t cont_in_disk;
int8_t version_finished;
cJSON *metajson, *arrayjson;
cJSON *table_meta;
/*this part for http post server*/
FILE *fp_idx_file;
char token[64];
char tmp_index_path[256]; //incĿ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱÿ<CAB1><C3BF><EFBFBD><EFBFBD><E6B1BE>һ<EFBFBD><D2BB>
int16_t retry_times;
int16_t syncing;
int32_t total_cfgs;
struct doris_business *business;
struct evhttp_request *req;
struct doris_upload_ctx *synctx;
struct table_list_node *cur_table;
struct event timer_expire;
TAILQ_HEAD(__table_list_node, table_list_node) table_head;
TAILQ_ENTRY(version_list_node) version_node;
};
@@ -95,35 +149,21 @@ struct version_list_handle
struct version_list_handle *config_version_handle_new(void);
struct doris_business;
struct confile_save
{
struct event_base *evbase;
struct doris_business *business;
int64_t version;
int32_t source_from;
int32_t type;
int64_t version_cfgnum;
char inc_index_path[256]; //incĿ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>
char tmp_index_path[256]; //incĿ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>
char full_index_path[256]; //fullĿ¼<C4BF>µ<EFBFBD>ȫ<EFBFBD><C8AB>
char cfg_file_path[256];
FILE *fp_cfg_file;
FILE *fp_idx_file;
struct version_list_node *cur_vernode;
struct table_list_node *cur_table;
struct cont_frag_node *cur_frag;
};
struct common_timer_event
{
struct event timer_event;
void *data;
};
struct doris_business;
struct bufferevent *doris_https_bufferevent_cb(struct event_base *evabse, void *arg);
struct doris_business *lookup_bizstruct_from_name(const struct evkeyvalq *params);
void business_set_sync_peer_abnormal(struct doris_business *business);
void business_resume_sync_peer_normal(struct doris_business *business);
void* thread_doris_client_recv_cfg(void *arg);
void* thread_index_file_recv_cfg(void *arg);
void* thread_http_post_recv_cfg(void *arg);
#endif

View File

@@ -17,7 +17,7 @@
#define MESA_RUNTIME_LOGV4(handle, lv, fmt, args...) \
MESA_handle_runtime_log((handle), (lv), "DorisServer", "%s:%d, " fmt, __FILENAME__, __LINE__, ##args)
static int scandir_md5_final_string(MD5_CTX *c, char *result, unsigned int size)
int scandir_md5_final_string(MD5_CTX *c, char *result, unsigned int size)
{
unsigned char md5[17]={0};
int i;
@@ -202,12 +202,12 @@ int cm_read_cfg_index_file(const char* path, struct cfg_table_info* idx/*OUT*/,
memset(line, 0, sizeof(line));
fgets(line, sizeof(line), fp);
ret=sscanf(line,"%[^ \t]%*[ \t]%d%*[ \t]%s%*[ \t]%s", idx[i].table_name, &(idx[i].cfg_num), idx[i].cfg_path, idx[i].user_region);
if((ret!=3 && ret!=4) || idx[i].cfg_num==0)//jump over empty line
if((ret!=3 && ret!=4))//jump over empty line
{
continue;
}
ret=stat(idx[i].cfg_path, &file_info);
if(ret!=0)
if(ret!=0 || file_info.st_size==0) //<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>·<EFBFBD>
{
MESA_RUNTIME_LOGV4(logger,RLOG_LV_FATAL, "%s of %s not exisit", idx[i].cfg_path, path);
fclose(fp);
@@ -315,12 +315,14 @@ enum DORIS_UPDATE_TYPE doris_index_file_traverse(struct doris_idxfile_scanner *s
{
MESA_RUNTIME_LOGV4(logger, RLOG_LV_INFO, "load %s", idx_path_array[i].path);
table_num=cm_read_cfg_index_file(idx_path_array[i].path, table_array, CM_MAX_TABLE_NUM, logger);
if(table_num<0)
if(table_num<=0)
{
MESA_RUNTIME_LOGV4(logger,RLOG_LV_FATAL, "load %s faild, abandon udpate.", idx_path_array[i].path);
MESA_RUNTIME_LOGV4(logger,RLOG_LV_FATAL, "\033[1;31;40mAlert! Load %s failed, skip this wrong version!!!!\033[0m\n", idx_path_array[i].path);
update_type = CFG_UPDATE_TYPE_ERR;
scanner->cur_version = idx_path_array[i].version; //<2F><><EFBFBD><EFBFBD><EFBFBD>İ汾<C4B0><E6B1BE><EFBFBD><EFBFBD>
break;
}
scanner->cur_version = idx_path_array[i].version;
cJSON *meta = doris_index_version_start(idx_path_array[i].version, table_array, table_num, update_type, doris_cbs);
for(j=0; j<table_num && update_rslt; j++)
@@ -329,7 +331,6 @@ enum DORIS_UPDATE_TYPE doris_index_file_traverse(struct doris_idxfile_scanner *s
}
if(update_rslt)
{
scanner->cur_version = idx_path_array[i].version;
doris_cbs->version_finish(NULL, doris_cbs->userdata);
}
else
@@ -337,6 +338,7 @@ enum DORIS_UPDATE_TYPE doris_index_file_traverse(struct doris_idxfile_scanner *s
update_type = CFG_UPDATE_TYPE_ERR;
doris_cbs->version_error(NULL, doris_cbs->userdata);
cJSON_Delete(meta);
MESA_RUNTIME_LOGV4(logger,RLOG_LV_FATAL, "\033[1;31;40mAlert! Load %s failed, skip this wrong version!!!!\033[0m\n", idx_path_array[i].path);
break;
}
cJSON_Delete(meta);

View File

@@ -1,7 +1,7 @@
#ifndef __DORIS_SERVER_SCANDIR_H__
#define __DORIS_SERVER_SCANDIR_H__
#include "doris_client.h"
#include "doris_consumer_client.h"
#define CM_MAX_TABLE_NUM 256
#define MAX_CONFIG_FN_LEN 256
@@ -45,6 +45,8 @@ struct doris_idxfile_scanner
char oncebuf[ONCE_BUF_SIZE];
};
int scandir_md5_final_string(MD5_CTX *c, char *result, unsigned int size);
struct doris_idxfile_scanner *doris_index_file_scanner(int64_t start_version);
enum DORIS_UPDATE_TYPE doris_index_file_traverse(struct doris_idxfile_scanner *scanner, const char*idx_dir,
struct doris_callbacks *doris_cbs, const char* dec_key, void* logger);