修复回调类配置注册线程不安全问题:若注册时恰好有配置更新,将产生无start的update callback。该问题由刘学利在线发现。

This commit is contained in:
zhengchao
2017-01-03 09:38:10 +08:00
parent c52c998343
commit 9ee4a7a5ea
3 changed files with 8 additions and 9 deletions

View File

@@ -454,6 +454,7 @@ Maat_feather_t Maat_feather(int max_thread_num,const char* table_info_path,void*
feather->hit_cnt=aligment_int64_array_alloc(max_thread_num); feather->hit_cnt=aligment_int64_array_alloc(max_thread_num);
feather->maat_version=0; feather->maat_version=0;
feather->last_full_version=0; feather->last_full_version=0;
pthread_mutex_init(&(feather->plugin_table_reg_mutex),NULL);
snprintf(feather->table_info_fn,sizeof(feather->table_info_fn),"%s",table_info_path); snprintf(feather->table_info_fn,sizeof(feather->table_info_fn),"%s",table_info_path);
return feather; return feather;
} }
@@ -699,11 +700,11 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id,
{ {
return -1; return -1;
} }
pthread_mutex_lock(&(p_table->cb_info->plugin_mutex)); pthread_mutex_lock(&(_feather->plugin_table_reg_mutex));
idx=p_table->cb_info->cb_plug_cnt; idx=p_table->cb_info->cb_plug_cnt;
if(idx==MAX_PLUGING_NUM) if(idx==MAX_PLUGING_NUM)
{ {
pthread_mutex_unlock(&(p_table->cb_info->plugin_mutex)); pthread_mutex_unlock(&(_feather->plugin_table_reg_mutex));
return -1; return -1;
} }
p_table->cb_info->cb_plug_cnt++; p_table->cb_info->cb_plug_cnt++;
@@ -731,7 +732,7 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id,
finish(u_para); finish(u_para);
} }
} }
pthread_mutex_unlock(&(p_table->cb_info->plugin_mutex)); pthread_mutex_unlock(&(_feather->plugin_table_reg_mutex));
return 1; return 1;
} }
int Maat_full_scan_string_detail(Maat_feather_t feather,int table_id int Maat_full_scan_string_detail(Maat_feather_t feather,int table_id

View File

@@ -609,7 +609,6 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
{ {
p->cb_info=(struct _plugin_table_info*)calloc(sizeof(struct _plugin_table_info),1); p->cb_info=(struct _plugin_table_info*)calloc(sizeof(struct _plugin_table_info),1);
p->cb_info->cache_lines=dynamic_array_create(1024,1024); p->cb_info->cache_lines=dynamic_array_create(1024,1024);
pthread_mutex_init(&(p->cb_info->plugin_mutex),NULL);
} }
p_table_info[p->table_id]=p; p_table_info[p->table_id]=p;
table_cnt++; table_cnt++;
@@ -2681,7 +2680,6 @@ void plugin_table_callback(struct _Maat_table_info_t* table,const char* table_li
unsigned int len=strlen(table_line)+1; unsigned int len=strlen(table_line)+1;
struct _plugin_table_info* p_table_cb=table->cb_info; struct _plugin_table_info* p_table_cb=table->cb_info;
char *p=NULL; char *p=NULL;
pthread_mutex_lock(&(p_table_cb->plugin_mutex));
p_table_cb->acc_line_num++; p_table_cb->acc_line_num++;
if(p_table_cb->cb_plug_cnt>0) if(p_table_cb->cb_plug_cnt>0)
{ {
@@ -2698,7 +2696,6 @@ void plugin_table_callback(struct _Maat_table_info_t* table,const char* table_li
dynamic_array_write(p_table_cb->cache_lines,p_table_cb->cache_line_num,p); dynamic_array_write(p_table_cb->cache_lines,p_table_cb->cache_line_num,p);
p_table_cb->cache_line_num++; p_table_cb->cache_line_num++;
} }
pthread_mutex_unlock(&(p_table_cb->plugin_mutex));
} }
void do_scanner_update(struct _Maat_scanner_t* scanner,MESA_lqueue_head garbage_q,int scan_thread_num,void* logger) void do_scanner_update(struct _Maat_scanner_t* scanner,MESA_lqueue_head garbage_q,int scan_thread_num,void* logger)
{ {
@@ -2766,7 +2763,6 @@ void clear_plugin_table_info(struct _plugin_table_info *cb_info)
{ {
int i=0; int i=0;
void *line=NULL; void *line=NULL;
pthread_mutex_lock(&(cb_info->plugin_mutex));
for(i=0;i<cb_info->cache_line_num;i++) for(i=0;i<cb_info->cache_line_num;i++)
{ {
line=dynamic_array_read(cb_info->cache_lines,i); line=dynamic_array_read(cb_info->cache_lines,i);
@@ -2776,7 +2772,6 @@ void clear_plugin_table_info(struct _plugin_table_info *cb_info)
cb_info->cache_line_num=0; cb_info->cache_line_num=0;
cb_info->cache_size=0; cb_info->cache_size=0;
cb_info->acc_line_num=0; cb_info->acc_line_num=0;
pthread_mutex_unlock(&(cb_info->plugin_mutex));
return; return;
} }
void maat_start_cb(unsigned int new_version,int update_type,void*u_para) void maat_start_cb(unsigned int new_version,int update_type,void*u_para)
@@ -2988,6 +2983,8 @@ void *thread_rule_monitor(void *arg)
{ {
usleep(feather->scan_interval_ms*1000); usleep(feather->scan_interval_ms*1000);
scan_dir_cnt++; scan_dir_cnt++;
//plugin table register is not allowed during update;
pthread_mutex_lock(&(feather->plugin_table_reg_mutex));
config_monitor_traverse(feather->maat_version, config_monitor_traverse(feather->maat_version,
inc_cfg_dir, inc_cfg_dir,
maat_start_cb, maat_start_cb,
@@ -2995,6 +2992,7 @@ void *thread_rule_monitor(void *arg)
maat_finish_cb, maat_finish_cb,
feather, feather,
feather->logger); feather->logger);
pthread_mutex_unlock(&(feather->plugin_table_reg_mutex));
if(feather->update_tmp_scanner!=NULL) if(feather->update_tmp_scanner!=NULL)
{ {
old_scanner=feather->scanner; old_scanner=feather->scanner;

View File

@@ -221,7 +221,6 @@ struct _plugin_table_info
int acc_line_num; int acc_line_num;
int update_type; int update_type;
long cache_size; long cache_size;
pthread_mutex_t plugin_mutex;
}; };
struct _region_stat_t struct _region_stat_t
{ {
@@ -372,6 +371,7 @@ struct _Maat_feather_t
char stat_file[MAX_TABLE_NAME_LEN]; char stat_file[MAX_TABLE_NAME_LEN];
char instance_name[MAX_TABLE_NAME_LEN]; char instance_name[MAX_TABLE_NAME_LEN];
char table_info_fn[MAX_TABLE_NAME_LEN]; char table_info_fn[MAX_TABLE_NAME_LEN];
pthread_mutex_t plugin_table_reg_mutex;
//for stat>>>> //for stat>>>>
screen_stat_handle_t stat_handle; screen_stat_handle_t stat_handle;
int total_stat_id; int total_stat_id;