TSG-9700: 支持优雅退出
This commit is contained in:
@@ -2317,10 +2317,11 @@ extern "C" int TSG_MASTER_INIT()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" int TSG_MASTER_UNLOAD()
|
extern "C" int TSG_MASTER_UNLOAD()
|
||||||
{
|
{
|
||||||
|
tsg_sendlog_destroy(g_tsg_log_instance);
|
||||||
|
tsg_statistic_destroy();
|
||||||
|
|
||||||
Maat_burn_feather(g_tsg_maat_feather);
|
Maat_burn_feather(g_tsg_maat_feather);
|
||||||
g_tsg_maat_feather=NULL;
|
g_tsg_maat_feather=NULL;
|
||||||
|
|
||||||
@@ -2330,5 +2331,10 @@ extern "C" int TSG_MASTER_UNLOAD()
|
|||||||
g_tsg_dynamic_maat_feather=NULL;
|
g_tsg_dynamic_maat_feather=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FS_stop(&(g_tsg_para.fs2_handle));
|
||||||
|
|
||||||
|
MESA_destroy_runtime_log_handle(g_tsg_para.logger);
|
||||||
|
g_tsg_para.logger=NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -382,6 +382,8 @@ typedef struct tsg_statistic
|
|||||||
{
|
{
|
||||||
int cycle;
|
int cycle;
|
||||||
int fs_line_id;
|
int fs_line_id;
|
||||||
|
int thread_alive;
|
||||||
|
pthread_t stat_thread_id;
|
||||||
int fs_field_id[STATIS_MAX];
|
int fs_field_id[STATIS_MAX];
|
||||||
long long statistic_opt[_OPT_TYPE_MAX];
|
long long statistic_opt[_OPT_TYPE_MAX];
|
||||||
struct _traffic_info *traffic_info[TSG_ACTION_MAX+1];
|
struct _traffic_info *traffic_info[TSG_ACTION_MAX+1];
|
||||||
@@ -390,6 +392,8 @@ typedef struct tsg_statistic
|
|||||||
}tsg_statis_para_t;
|
}tsg_statis_para_t;
|
||||||
|
|
||||||
int tsg_statistic_init(const char *conffile, void *logger);
|
int tsg_statistic_init(const char *conffile, void *logger);
|
||||||
|
void tsg_statistic_destroy(void);
|
||||||
|
|
||||||
int tsg_gtp_signaling_hash_init(const char* conffile, void *logger);
|
int tsg_gtp_signaling_hash_init(const char* conffile, void *logger);
|
||||||
|
|
||||||
int set_struct_project(const struct streaminfo *a_stream, int project_id, void *data);
|
int set_struct_project(const struct streaminfo *a_stream, int project_id, void *data);
|
||||||
|
|||||||
@@ -820,7 +820,7 @@ static int parse_answer_records(struct dns_user_region *user_region_records, cJS
|
|||||||
}
|
}
|
||||||
|
|
||||||
answer_type=get_dns_qtype(a_item->valuestring, strlen(a_item->valuestring));
|
answer_type=get_dns_qtype(a_item->valuestring, strlen(a_item->valuestring));
|
||||||
switch(answer_type==-1)
|
if(answer_type==-1)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1648,6 +1648,48 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile)
|
|||||||
|
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
void tsg_sendlog_destroy(struct tsg_log_instance_t * instance)
|
||||||
|
{
|
||||||
|
for(int i=0; i<instance->max_service; i++)
|
||||||
|
{
|
||||||
|
if(instance->topic_rkt[i]==NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rd_kafka_topic_destroy(instance->topic_rkt[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
rd_kafka_destroy_flags(instance->kafka_handle, 4);
|
||||||
|
rd_kafka_destroy(instance->kafka_handle);
|
||||||
|
|
||||||
|
MESA_destroy_runtime_log_handle(instance->logger);
|
||||||
|
instance->logger=NULL;
|
||||||
|
|
||||||
|
free(instance->topic_rkt);
|
||||||
|
instance->topic_rkt=NULL;
|
||||||
|
|
||||||
|
free(instance->service2topic);
|
||||||
|
instance->service2topic=NULL;
|
||||||
|
|
||||||
|
free(instance);
|
||||||
|
instance=NULL;
|
||||||
|
/*
|
||||||
|
int ret=0,count=0;
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
ret=rd_kafka_wait_destroyed(1000);
|
||||||
|
if(ret==0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handle, tsg_log_t *log_msg, int thread_id)
|
int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handle, tsg_log_t *log_msg, int thread_id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ struct tsg_log_instance_t
|
|||||||
|
|
||||||
char *log_field_id2name(struct tsg_log_instance_t *instance, tsg_log_field_id_t id);
|
char *log_field_id2name(struct tsg_log_instance_t *instance, tsg_log_field_id_t id);
|
||||||
struct tsg_log_instance_t *tsg_sendlog_init(const char *filename);
|
struct tsg_log_instance_t *tsg_sendlog_init(const char *filename);
|
||||||
|
void tsg_sendlog_destroy(struct tsg_log_instance_t * instance);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ static void *tsg_statistic_thread(void *arg)
|
|||||||
|
|
||||||
FS_start(g_tsg_statis_para.fs2_handle);
|
FS_start(g_tsg_statis_para.fs2_handle);
|
||||||
|
|
||||||
while(1)
|
while(g_tsg_statis_para.thread_alive)
|
||||||
{
|
{
|
||||||
memset(&policy_traffic_info, 0, sizeof(policy_traffic_info));
|
memset(&policy_traffic_info, 0, sizeof(policy_traffic_info));
|
||||||
memset(&total_traffic_info, 0, sizeof(total_traffic_info));
|
memset(&total_traffic_info, 0, sizeof(total_traffic_info));
|
||||||
@@ -370,6 +370,7 @@ int tsg_statistic_init(const char *conffile, void *logger)
|
|||||||
MESA_load_profile_int_def(conffile, "STATISTIC", "PROMETHEUS", &output_prometheus, 1);
|
MESA_load_profile_int_def(conffile, "STATISTIC", "PROMETHEUS", &output_prometheus, 1);
|
||||||
|
|
||||||
g_tsg_statis_para.fs2_handle=FS_create_handle();
|
g_tsg_statis_para.fs2_handle=FS_create_handle();
|
||||||
|
g_tsg_statis_para.thread_alive=1;
|
||||||
|
|
||||||
value=1;//Rewrite
|
value=1;//Rewrite
|
||||||
FS_set_para(g_tsg_statis_para.fs2_handle, PRINT_MODE, &value, sizeof(value));
|
FS_set_para(g_tsg_statis_para.fs2_handle, PRINT_MODE, &value, sizeof(value));
|
||||||
@@ -460,9 +461,18 @@ int tsg_statistic_init(const char *conffile, void *logger)
|
|||||||
|
|
||||||
g_tsg_statis_para.fs_line_id=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_LINE, FS_CALC_CURRENT, (const char *)"TRAFFIC");
|
g_tsg_statis_para.fs_line_id=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_LINE, FS_CALC_CURRENT, (const char *)"TRAFFIC");
|
||||||
|
|
||||||
pthread_t stat_thread_t;
|
pthread_create(&g_tsg_statis_para.stat_thread_id, NULL, tsg_statistic_thread, NULL);
|
||||||
pthread_create(&stat_thread_t, NULL, tsg_statistic_thread, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tsg_statistic_destroy(void)
|
||||||
|
{
|
||||||
|
pthread_cancel(g_tsg_statis_para.stat_thread_id);
|
||||||
|
g_tsg_statis_para.thread_alive=0;
|
||||||
|
sleep(g_tsg_statis_para.cycle);
|
||||||
|
FS_stop(&(g_tsg_statis_para.fs2_handle));
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user