使用有向图(Directed Acyclic Graph)描述分组间的引用关系,引入igraph库。
This commit is contained in:
@@ -20,6 +20,7 @@ set_target_properties(maat_frame_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
target_include_directories(maat_frame_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/)
|
||||
#target_include_directories(maat_frame_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/hiredis)
|
||||
target_link_libraries(maat_frame_static hiredis-vip-static)
|
||||
target_link_libraries(maat_frame_static igraph-static)
|
||||
|
||||
# Shared Library Output
|
||||
add_library(maat_frame_shared SHARED ${MAAT_SRC})
|
||||
@@ -32,6 +33,7 @@ set_target_properties(maat_frame_shared PROPERTIES LINK_FLAGS "-Wl,--version-scr
|
||||
target_include_directories(maat_frame_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/)
|
||||
target_include_directories(maat_frame_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/hiredis)
|
||||
target_link_libraries(maat_frame_shared hiredis-vip-static ${MAAT_DEPEND_DYN_LIB})
|
||||
target_link_libraries(maat_frame_shared igraph-static ${MAAT_DEPEND_DYN_LIB})
|
||||
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/inc/Maat_rule.h DESTINATION include/MESA/)
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/inc/Maat_command.h DESTINATION include/MESA/)
|
||||
|
||||
@@ -135,9 +135,9 @@ size_t pickup_hit_region_from_compile(struct bool_expr *compile_hit,
|
||||
}
|
||||
return k;
|
||||
}
|
||||
void fill_maat_rule(struct Maat_rule_t *rule, const struct _head_Maat_rule_t* rule_head, const char* srv_def, int srv_def_len)
|
||||
void fill_maat_rule(struct Maat_rule_t *rule, const struct _head_Maat_rule* rule_head, const char* srv_def, int srv_def_len)
|
||||
{
|
||||
memcpy(rule, rule_head, sizeof(struct _head_Maat_rule_t));
|
||||
memcpy(rule, rule_head, sizeof(struct _head_Maat_rule));
|
||||
memcpy(rule->service_defined, srv_def, MIN(srv_def_len,MAX_SERVICE_DEFINE_LEN));
|
||||
return;
|
||||
}
|
||||
@@ -158,21 +158,21 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int
|
||||
int shortcut_avilable_cnt=0;
|
||||
unsigned char has_not_flag=0;
|
||||
struct bool_matcher* bm=feather->scanner->bool_matcher_expr_compiler;
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_compile_inner_t* array_mi_rule[MAX_SCANNER_HIT_NUM];
|
||||
struct Maat_compile_inner_t* _mi_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
struct Maat_compile_inner* array_mi_rule[MAX_SCANNER_HIT_NUM];
|
||||
struct Maat_compile_inner* _mi_rule=NULL;
|
||||
int region_pos[MAX_SCANNER_HIT_NUM];
|
||||
_mid->cur_hit_cnt=0;
|
||||
for(i=0;i<region_hit_num;i++)
|
||||
{
|
||||
group_rule=*(struct Maat_group_inner_t**)((char*)region_hit+region_type_size*i+group_offset);
|
||||
group_rule=*(struct Maat_group_inner**)((char*)region_hit+region_type_size*i+group_offset);
|
||||
if(group_rule->group_id<0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(group_rule->compile_shortcut!=NULL&&group_rule->ref_cnt==1&&shortcut_avilable_cnt<MAX_SCANNER_HIT_NUM)
|
||||
{
|
||||
array_mi_rule[shortcut_avilable_cnt]=(struct Maat_compile_inner_t*)(group_rule->compile_shortcut);
|
||||
array_mi_rule[shortcut_avilable_cnt]=(struct Maat_compile_inner*)(group_rule->compile_shortcut);
|
||||
shortcut_avilable_cnt++;
|
||||
}
|
||||
_mid->cur_hit_id[_mid->cur_hit_cnt]=group_rule->group_id;
|
||||
@@ -252,15 +252,15 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int
|
||||
return result_cnt;
|
||||
}
|
||||
|
||||
int exprid2region_id(struct Maat_group_inner_t* group_rule,int expr_id,int* district_id)
|
||||
int exprid2region_id(struct Maat_group_inner* group_rule,int expr_id,int* district_id)
|
||||
{
|
||||
int i=0,region_id=-1;
|
||||
struct _Maat_region_inner_t* region_rule=NULL;
|
||||
struct Maat_region_inner* region_rule=NULL;
|
||||
assert(group_rule->group_id>=0);
|
||||
pthread_mutex_lock(&(group_rule->mutex));
|
||||
for(i=0;i<group_rule->region_boundary;i++)
|
||||
{
|
||||
region_rule=(struct _Maat_region_inner_t*)dynamic_array_read(group_rule->regions, i);
|
||||
region_rule=(struct Maat_region_inner*)dynamic_array_read(group_rule->regions, i);
|
||||
if(region_rule==NULL)
|
||||
{
|
||||
continue;
|
||||
@@ -277,13 +277,13 @@ int exprid2region_id(struct Maat_group_inner_t* group_rule,int expr_id,int* dist
|
||||
}
|
||||
int match_district(struct _OUTER_scan_status_t *_mid,scan_result_t *region_hit,int region_hit_num)
|
||||
{
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
int i=0;
|
||||
int district_id=-1,region_id=-1;
|
||||
int ret_region_num=region_hit_num;
|
||||
while(i<ret_region_num)
|
||||
{
|
||||
group_rule=(struct Maat_group_inner_t*)(region_hit[i].tag);
|
||||
group_rule=(struct Maat_group_inner*)(region_hit[i].tag);
|
||||
region_id=exprid2region_id(group_rule, region_hit[i].expr_id,&district_id);
|
||||
if(region_id>0&&district_id!=_mid->district_id)
|
||||
{
|
||||
@@ -379,7 +379,7 @@ int fill_region_hit_detail(const char* scan_buff,const _INNER_scan_status_t* _mi
|
||||
memset(r_in_c_flag,0,sizeof(r_in_c_flag));
|
||||
memset(region_pos,0,sizeof(region_pos));
|
||||
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
//for each hitted compile cfg,find its region_ids
|
||||
for(i=0;i<compile_cnt&&i<detail_num;i++)
|
||||
{
|
||||
@@ -391,7 +391,7 @@ int fill_region_hit_detail(const char* scan_buff,const _INNER_scan_status_t* _mi
|
||||
{
|
||||
pos=region_pos[j];
|
||||
r_in_c_flag[pos]=1;
|
||||
group_rule=(struct Maat_group_inner_t*)(region_hit[pos].tag);
|
||||
group_rule=(struct Maat_group_inner*)(region_hit[pos].tag);
|
||||
region_id=exprid2region_id(group_rule,region_hit[pos].expr_id,&district_id);
|
||||
if(region_id<0)
|
||||
{
|
||||
@@ -411,7 +411,7 @@ int fill_region_hit_detail(const char* scan_buff,const _INNER_scan_status_t* _mi
|
||||
{
|
||||
if(r_in_c_flag[k]==0)
|
||||
{
|
||||
group_rule=(struct Maat_group_inner_t*)(region_hit[k].tag);
|
||||
group_rule=(struct Maat_group_inner*)(region_hit[k].tag);
|
||||
hit_detail[j].config_id=-2;
|
||||
hit_detail[j].hit_region_cnt=1;
|
||||
hit_detail[j].region_pos[0].region_id=exprid2region_id(group_rule,region_hit[k].expr_id,&district_id);
|
||||
@@ -1042,7 +1042,7 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id,
|
||||
void rule_ex_data_new_cb(const uchar * key, uint size, void * data, void * user)
|
||||
{
|
||||
struct compile_ex_data_idx *ex_desc=(struct compile_ex_data_idx*)user;
|
||||
struct Maat_compile_inner_t *compile_inner=(struct Maat_compile_inner_t *)data;
|
||||
struct Maat_compile_inner *compile_inner=(struct Maat_compile_inner *)data;
|
||||
MAAT_RULE_EX_DATA ad=NULL;
|
||||
|
||||
if(compile_inner->ref_table==NULL || compile_inner->ref_table->table_id!=ex_desc->table_id || compile_inner->db_c_rule==NULL)
|
||||
@@ -1104,12 +1104,12 @@ failed:
|
||||
MAAT_RULE_EX_DATA Maat_rule_get_ex_data(Maat_feather_t feather, const struct Maat_rule_t* rule, int idx)
|
||||
{
|
||||
struct _Maat_feather_t *_feather=(struct _Maat_feather_t *)feather;
|
||||
struct Maat_compile_inner_t *compile_inner=NULL;
|
||||
struct Maat_compile_inner *compile_inner=NULL;
|
||||
const struct compile_table_desc* compile_desc=NULL;
|
||||
const struct compile_ex_data_idx* ex_desc=NULL;
|
||||
MAAT_RULE_EX_DATA ad=NULL;
|
||||
|
||||
compile_inner=(struct Maat_compile_inner_t *)HASH_fetch_by_id(_feather->scanner->compile_hash, rule->config_id);
|
||||
compile_inner=(struct Maat_compile_inner *)HASH_fetch_by_id(_feather->scanner->compile_hash, rule->config_id);
|
||||
if(compile_inner==NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -2153,11 +2153,11 @@ int Maat_read_rule(Maat_feather_t feather, const struct Maat_rule_t* rule, enum
|
||||
{
|
||||
int ret=0;
|
||||
struct _Maat_feather_t *_feather=(struct _Maat_feather_t *)feather;
|
||||
struct Maat_compile_inner_t *compile_inner=NULL;
|
||||
struct Maat_compile_inner *compile_inner=NULL;
|
||||
switch(type)
|
||||
{
|
||||
case MAAT_RULE_SERV_DEFINE:
|
||||
compile_inner=(struct Maat_compile_inner_t *)HASH_fetch_by_id(_feather->scanner->compile_hash, rule->config_id);
|
||||
compile_inner=(struct Maat_compile_inner *)HASH_fetch_by_id(_feather->scanner->compile_hash, rule->config_id);
|
||||
if(compile_inner==NULL)
|
||||
{
|
||||
ret=0;
|
||||
|
||||
@@ -836,9 +836,9 @@ int reconstruct_cmd(struct _Maat_feather_t *feather, struct _Maat_cmd_inner_t* _
|
||||
struct Maat_group_t* group_cmd=NULL;
|
||||
struct Maat_region_t* region_cmd=NULL;
|
||||
|
||||
struct Maat_compile_inner_t *compile_inner=NULL;
|
||||
struct Maat_group_inner_t* group_inner=NULL;
|
||||
struct _Maat_region_inner_t* region_inner=NULL;
|
||||
struct Maat_compile_inner *compile_inner=NULL;
|
||||
struct Maat_group_inner* group_inner=NULL;
|
||||
struct Maat_region_inner* region_inner=NULL;
|
||||
void* logger=feather->logger;
|
||||
|
||||
int config_id=cmd->compile.config_id;
|
||||
@@ -848,7 +848,7 @@ int reconstruct_cmd(struct _Maat_feather_t *feather, struct _Maat_cmd_inner_t* _
|
||||
,"MAAT not ready.");
|
||||
return -1;
|
||||
}
|
||||
compile_inner=(struct Maat_compile_inner_t *)HASH_fetch_by_id(feather->scanner->compile_hash, config_id);
|
||||
compile_inner=(struct Maat_compile_inner *)HASH_fetch_by_id(feather->scanner->compile_hash, config_id);
|
||||
//Operation on compile_inner is thread safe, no immediate memory free when delete a compile rule or a scanner.
|
||||
//In another words, if the compile_inner is accessable from compile means, its was valid in at least 10 seconds (garbage bury).
|
||||
if(compile_inner==NULL)
|
||||
@@ -864,7 +864,7 @@ int reconstruct_cmd(struct _Maat_feather_t *feather, struct _Maat_cmd_inner_t* _
|
||||
cmd->groups=(struct Maat_group_t*)calloc(sizeof(struct Maat_group_t),cmd->group_num);
|
||||
for(i=0;i<compile_inner->group_boundary;i++)
|
||||
{
|
||||
group_inner=(struct Maat_group_inner_t*)dynamic_array_read(compile_inner->groups,i);
|
||||
group_inner=(struct Maat_group_inner*)dynamic_array_read(compile_inner->groups,i);
|
||||
if(group_inner==NULL)
|
||||
{
|
||||
continue;
|
||||
@@ -880,7 +880,7 @@ int reconstruct_cmd(struct _Maat_feather_t *feather, struct _Maat_cmd_inner_t* _
|
||||
group_cmd->regions=(struct Maat_region_t*)calloc(sizeof(struct Maat_region_t),group_cmd->region_num);
|
||||
for(j=0;j<group_inner->region_boundary;j++)
|
||||
{
|
||||
region_inner=(struct _Maat_region_inner_t*)dynamic_array_read(group_inner->regions,j);
|
||||
region_inner=(struct Maat_region_inner*)dynamic_array_read(group_inner->regions,j);
|
||||
if(region_inner==NULL)
|
||||
{
|
||||
continue;
|
||||
@@ -1358,10 +1358,10 @@ int fix_table_name(_Maat_feather_t* feather,struct Maat_cmd_t* cmd)
|
||||
struct Maat_region_t* p_region=NULL;
|
||||
enum MAAT_TABLE_TYPE table_type;
|
||||
|
||||
struct Maat_compile_inner_t *compile_rule=NULL;
|
||||
struct Maat_compile_inner *compile_rule=NULL;
|
||||
if(feather->scanner!=NULL)
|
||||
{
|
||||
compile_rule=(struct Maat_compile_inner_t*)HASH_fetch_by_id(feather->scanner->compile_hash, cmd->compile.config_id);
|
||||
compile_rule=(struct Maat_compile_inner*)HASH_fetch_by_id(feather->scanner->compile_hash, cmd->compile.config_id);
|
||||
if(compile_rule!=NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(feather->logger,RLOG_LV_FATAL,maat_module
|
||||
@@ -2056,8 +2056,8 @@ int Maat_cmd_set_group(Maat_feather_t feather,int group_id, const struct Maat_re
|
||||
if(_feather->AUTO_NUMBERING_ON==1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
//struct Maat_group_inner_t* group_inner=NULL;
|
||||
}
|
||||
//struct Maat_group_inner* group_inner=NULL;
|
||||
//group_inner=(struct Maat_group_inner*)HASH_fetch_by_id(_feather->scanner->group_hash, group_id);
|
||||
//NOT implemented yet.
|
||||
assert(0);
|
||||
|
||||
@@ -506,7 +506,7 @@ int HASH_delete_by_id(MESA_htable_handle hash,int id)
|
||||
ret=MESA_htable_del(hash,(unsigned char*)&id, sizeof(id), NULL);
|
||||
return ret;
|
||||
}
|
||||
MAAT_RULE_EX_DATA rule_ex_data_new(const struct _head_Maat_rule_t * rule_head, const char* srv_def, const struct compile_ex_data_idx* ex_desc)
|
||||
MAAT_RULE_EX_DATA rule_ex_data_new(const struct _head_Maat_rule * rule_head, const char* srv_def, const struct compile_ex_data_idx* ex_desc)
|
||||
{
|
||||
MAAT_RULE_EX_DATA ad=NULL;
|
||||
struct Maat_rule_t rule;
|
||||
@@ -514,7 +514,7 @@ MAAT_RULE_EX_DATA rule_ex_data_new(const struct _head_Maat_rule_t * rule_head, c
|
||||
ex_desc->new_func(ex_desc->idx, &rule, srv_def, &ad, ex_desc->argl,ex_desc->argp);
|
||||
return ad;
|
||||
}
|
||||
void rule_ex_data_free(const struct _head_Maat_rule_t * rule_head, const char* srv_def, MAAT_RULE_EX_DATA *ad, const struct compile_ex_data_idx* ex_desc)
|
||||
void rule_ex_data_free(const struct _head_Maat_rule * rule_head, const char* srv_def, MAAT_RULE_EX_DATA *ad, const struct compile_ex_data_idx* ex_desc)
|
||||
{
|
||||
struct Maat_rule_t rule;
|
||||
fill_maat_rule(&rule, rule_head, srv_def, strlen(srv_def)+1);
|
||||
@@ -836,9 +836,9 @@ error_jump:
|
||||
map_destroy(string2int_map);
|
||||
return table_cnt;
|
||||
}
|
||||
struct Maat_group_inner_t* create_group_rule(int group_id)
|
||||
struct Maat_group_inner* create_group_rule(int group_id)
|
||||
{
|
||||
struct Maat_group_inner_t* group=(struct Maat_group_inner_t*)malloc(sizeof(struct Maat_group_inner_t));
|
||||
struct Maat_group_inner* group=(struct Maat_group_inner*)malloc(sizeof(struct Maat_group_inner));
|
||||
group->group_id=group_id;
|
||||
group->region_cnt=0;
|
||||
group->region_boundary=0;
|
||||
@@ -850,7 +850,7 @@ struct Maat_group_inner_t* create_group_rule(int group_id)
|
||||
pthread_mutex_init(&(group->mutex), NULL);
|
||||
return group;
|
||||
}
|
||||
void _destroy_group_rule(struct Maat_group_inner_t* group)
|
||||
void _destroy_group_rule(struct Maat_group_inner* group)
|
||||
{
|
||||
dynamic_array_destroy(group->regions,free);
|
||||
group->region_cnt=0;
|
||||
@@ -865,7 +865,7 @@ void _destroy_group_rule(struct Maat_group_inner_t* group)
|
||||
free(group);
|
||||
|
||||
}
|
||||
void destroy_group_rule(struct Maat_group_inner_t* group)
|
||||
void destroy_group_rule(struct Maat_group_inner* group)
|
||||
{
|
||||
|
||||
if(group->ref_cnt>0||group->region_cnt>0)
|
||||
@@ -874,15 +874,15 @@ void destroy_group_rule(struct Maat_group_inner_t* group)
|
||||
}
|
||||
_destroy_group_rule(group);
|
||||
}
|
||||
void make_group_set(struct Maat_compile_inner_t* compile_rule, struct bool_expr* a_set, unsigned char *has_not)
|
||||
void make_group_set(struct Maat_compile_inner* compile_rule, struct bool_expr* a_set, unsigned char *has_not)
|
||||
{
|
||||
int i=0,j=0;
|
||||
a_set->user_tag=compile_rule;
|
||||
struct Maat_group_inner_t*group=NULL;
|
||||
struct Maat_group_inner*group=NULL;
|
||||
assert(compile_rule->group_cnt<=MAX_ITEMS_PER_BOOL_EXPR);
|
||||
for(i=0,j=0;i<compile_rule->group_boundary&&j<MAX_ITEMS_PER_BOOL_EXPR;i++)
|
||||
{
|
||||
group=(struct Maat_group_inner_t*)dynamic_array_read(compile_rule->groups, i);
|
||||
group=(struct Maat_group_inner*)dynamic_array_read(compile_rule->groups, i);
|
||||
if(group==NULL)
|
||||
{
|
||||
continue;
|
||||
@@ -906,7 +906,7 @@ struct compile_walker
|
||||
void walk_compile_hash(const uchar * key, uint size, void * data, void * user)
|
||||
{
|
||||
struct bool_expr* one_set=NULL;
|
||||
struct Maat_compile_inner_t* compile_rule=(struct Maat_compile_inner_t*)data;
|
||||
struct Maat_compile_inner* compile_rule=(struct Maat_compile_inner*)data;
|
||||
struct compile_walker* walker=(struct compile_walker*)user;
|
||||
unsigned char has_not_flag=0;
|
||||
MESA_lqueue_head update_q=walker->update_q;
|
||||
@@ -994,9 +994,9 @@ void EMPTY_FREE(void*p)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct Maat_compile_inner_t * create_compile_rule(int compile_id)
|
||||
struct Maat_compile_inner * create_compile_rule(int compile_id)
|
||||
{
|
||||
struct Maat_compile_inner_t* p=ALLOC(struct Maat_compile_inner_t,1);
|
||||
struct Maat_compile_inner* p=ALLOC(struct Maat_compile_inner,1);
|
||||
p->compile_id=compile_id;
|
||||
p->group_cnt=0;
|
||||
p->group_boundary=1;
|
||||
@@ -1005,11 +1005,11 @@ struct Maat_compile_inner_t * create_compile_rule(int compile_id)
|
||||
pthread_rwlock_init(&(p->rwlock), NULL);
|
||||
return p;
|
||||
}
|
||||
void _destroy_compile_rule(struct Maat_compile_inner_t * compile_rule)
|
||||
void _destroy_compile_rule(struct Maat_compile_inner * compile_rule)
|
||||
{
|
||||
const struct Maat_table_desc* table=compile_rule->ref_table;
|
||||
const struct compile_table_desc* compile_desc=&(table->compile);
|
||||
struct db_compile_rule_t* db_compile_rule=compile_rule->db_c_rule;
|
||||
struct db_compile_rule* db_compile_rule=compile_rule->db_c_rule;
|
||||
int i=0;
|
||||
compile_rule->compile_id=-1;
|
||||
dynamic_array_destroy(compile_rule->groups,NULL);
|
||||
@@ -1035,14 +1035,14 @@ void _destroy_compile_rule(struct Maat_compile_inner_t * compile_rule)
|
||||
pthread_rwlock_destroy(&(compile_rule->rwlock));
|
||||
free(compile_rule);
|
||||
}
|
||||
void destroy_compile_rule(struct Maat_compile_inner_t * p)
|
||||
void destroy_compile_rule(struct Maat_compile_inner * p)
|
||||
{
|
||||
int i=0;
|
||||
UNUSED struct Maat_compile_inner_t* p_group=NULL;
|
||||
UNUSED struct Maat_compile_inner* p_group=NULL;
|
||||
assert(p->group_cnt==0);
|
||||
for(i=0;i<p->group_boundary;i++)
|
||||
{
|
||||
p_group=(struct Maat_compile_inner_t*)dynamic_array_read(p->groups,i);
|
||||
p_group=(struct Maat_compile_inner*)dynamic_array_read(p->groups,i);
|
||||
assert(p_group==NULL);
|
||||
}
|
||||
_destroy_compile_rule(p);
|
||||
@@ -1107,7 +1107,7 @@ void destroy_rs_ip_rule(scan_rule_t* p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
scan_rule_t* create_rs_intval_rule(unsigned int sub_type,struct db_intval_rule_t *intval_rule)
|
||||
scan_rule_t* create_rs_intval_rule(unsigned int sub_type,struct db_intval_rule *intval_rule)
|
||||
{
|
||||
scan_rule_t *p_rule=(scan_rule_t*)calloc(sizeof(scan_rule_t),1);
|
||||
p_rule->rule_type=RULETYPE_INT;
|
||||
@@ -1173,7 +1173,7 @@ void op_expr_add_rule(struct op_expr_t* op_expr,scan_rule_t* p_rule)
|
||||
return;
|
||||
}
|
||||
GIE_digest_t* create_digest_rule(unsigned int id, enum GIE_operation op,const char* digest,
|
||||
short cfds_lvl,struct Maat_group_inner_t* tag)
|
||||
short cfds_lvl,struct Maat_group_inner* tag)
|
||||
{
|
||||
GIE_digest_t* rule=(GIE_digest_t*)calloc(sizeof(GIE_digest_t),1);
|
||||
int digest_len=0;
|
||||
@@ -1328,6 +1328,9 @@ struct Maat_scanner_t* create_maat_scanner(unsigned int version,_Maat_feather_t
|
||||
scanner->region_hash=MESA_htable_create(&hargs, sizeof(hargs));
|
||||
MESA_htable_print_crtl(scanner->region_hash,0);
|
||||
|
||||
ret=igraph_empty(&scanner->group_graph, 0, IGRAPH_DIRECTED);
|
||||
assert(ret==IGRAPH_SUCCESS);
|
||||
|
||||
scanner->district_map=map_create();
|
||||
|
||||
scanner->version=version;
|
||||
@@ -1413,6 +1416,7 @@ void destroy_maat_scanner(struct Maat_scanner_t*scanner)
|
||||
{
|
||||
table_runtime_free(scanner->table_rt[i]);
|
||||
}
|
||||
igraph_destroy(&scanner->group_graph);
|
||||
free(scanner);
|
||||
return;
|
||||
}
|
||||
@@ -1648,13 +1652,13 @@ void digest_batch_update(GIE_handle_t* handle,MESA_lqueue_head update_q,void*log
|
||||
update_array=NULL;
|
||||
return;
|
||||
}
|
||||
struct Maat_group_inner_t* add_region_to_group(struct Maat_group_inner_t* group,int table_id,int region_id,int district_id,int expr_id,enum MAAT_TABLE_TYPE region_type)
|
||||
struct Maat_group_inner* add_region_to_group(struct Maat_group_inner* group,int table_id,int region_id,int district_id,int expr_id,enum MAAT_TABLE_TYPE region_type)
|
||||
{
|
||||
int i=0;
|
||||
struct _Maat_region_inner_t* region_rule=NULL;
|
||||
struct Maat_region_inner* region_rule=NULL;
|
||||
for(i=0;i<group->region_boundary;i++)
|
||||
{
|
||||
region_rule=(struct _Maat_region_inner_t*)dynamic_array_read(group->regions, i);
|
||||
region_rule=(struct Maat_region_inner*)dynamic_array_read(group->regions, i);
|
||||
if(region_rule==NULL)
|
||||
{
|
||||
continue;
|
||||
@@ -1666,7 +1670,7 @@ struct Maat_group_inner_t* add_region_to_group(struct Maat_group_inner_t* group,
|
||||
}
|
||||
if(i==group->region_boundary)//new region
|
||||
{
|
||||
region_rule=(struct _Maat_region_inner_t*)malloc(sizeof(struct _Maat_region_inner_t));
|
||||
region_rule=(struct Maat_region_inner*)malloc(sizeof(struct Maat_region_inner));
|
||||
region_rule->region_id=region_id;
|
||||
region_rule->expr_id_cnt=1;
|
||||
region_rule->expr_id_ub=region_rule->expr_id_lb=expr_id;
|
||||
@@ -1687,11 +1691,11 @@ struct Maat_group_inner_t* add_region_to_group(struct Maat_group_inner_t* group,
|
||||
}
|
||||
return group;
|
||||
}
|
||||
void cancel_last_region_from_group(struct Maat_group_inner_t* group,int region_id,int expr_id)
|
||||
void cancel_last_region_from_group(struct Maat_group_inner* group,int region_id,int expr_id)
|
||||
{
|
||||
struct _Maat_region_inner_t* region_rule=NULL;
|
||||
struct Maat_region_inner* region_rule=NULL;
|
||||
pthread_mutex_lock(&(group->mutex));
|
||||
region_rule=(struct _Maat_region_inner_t*)dynamic_array_read(group->regions,group->region_boundary-1);
|
||||
region_rule=(struct Maat_region_inner*)dynamic_array_read(group->regions,group->region_boundary-1);
|
||||
assert(region_rule->expr_id_ub==expr_id&®ion_rule->region_id==region_id);
|
||||
if(region_rule->expr_id_cnt==1)
|
||||
{
|
||||
@@ -1708,14 +1712,14 @@ void cancel_last_region_from_group(struct Maat_group_inner_t* group,int region_i
|
||||
pthread_mutex_unlock(&(group->mutex));
|
||||
return;
|
||||
}
|
||||
unsigned int del_region_from_group(struct Maat_group_inner_t* group,int region_id,unsigned int *output_expr_id,int output_size)
|
||||
unsigned int del_region_from_group(struct Maat_group_inner* group,int region_id,unsigned int *output_expr_id,int output_size)
|
||||
{
|
||||
int i=0,j=0;
|
||||
struct _Maat_region_inner_t* region_rule=NULL;
|
||||
struct Maat_region_inner* region_rule=NULL;
|
||||
pthread_mutex_lock(&(group->mutex));
|
||||
for(i=0;i<group->region_boundary;i++)
|
||||
{
|
||||
region_rule=(struct _Maat_region_inner_t*)dynamic_array_read(group->regions, i);
|
||||
region_rule=(struct Maat_region_inner*)dynamic_array_read(group->regions, i);
|
||||
if(region_rule==NULL)
|
||||
{
|
||||
continue;
|
||||
@@ -1740,11 +1744,11 @@ unsigned int del_region_from_group(struct Maat_group_inner_t* group,int region_i
|
||||
return j;
|
||||
}
|
||||
|
||||
int add_group_to_compile(struct Maat_compile_inner_t*a_compile_rule,struct Maat_group_inner_t* a_rule_group, int not_flag)
|
||||
int add_group_to_compile(struct Maat_compile_inner*a_compile_rule,struct Maat_group_inner* a_rule_group, int not_flag)
|
||||
{
|
||||
int i=0,ret=-1;
|
||||
int write_pos=-1;
|
||||
struct Maat_group_inner_t* p=NULL;
|
||||
struct Maat_group_inner* p=NULL;
|
||||
pthread_rwlock_wrlock(&(a_compile_rule->rwlock));
|
||||
if(a_compile_rule->db_c_rule!=NULL
|
||||
&&a_compile_rule->group_cnt>=a_compile_rule->db_c_rule->declare_grp_num
|
||||
@@ -1756,7 +1760,7 @@ int add_group_to_compile(struct Maat_compile_inner_t*a_compile_rule,struct Maat_
|
||||
|
||||
for(i=0;i<a_compile_rule->group_boundary;i++)
|
||||
{
|
||||
p=(struct Maat_group_inner_t*)dynamic_array_read(a_compile_rule->groups,i);
|
||||
p=(struct Maat_group_inner*)dynamic_array_read(a_compile_rule->groups,i);
|
||||
if(p==NULL)
|
||||
{
|
||||
write_pos=i;
|
||||
@@ -1807,7 +1811,7 @@ int add_group_to_compile(struct Maat_compile_inner_t*a_compile_rule,struct Maat_
|
||||
{
|
||||
for(i=0;i<a_compile_rule->group_boundary;i++)
|
||||
{
|
||||
p=(struct Maat_group_inner_t*)dynamic_array_read(a_compile_rule->groups,i);
|
||||
p=(struct Maat_group_inner*)dynamic_array_read(a_compile_rule->groups,i);
|
||||
if(p!=NULL)
|
||||
{
|
||||
p->compile_shortcut=NULL;
|
||||
@@ -1820,14 +1824,14 @@ error_out:
|
||||
|
||||
return ret;
|
||||
}
|
||||
struct Maat_group_inner_t* del_group_from_compile(struct Maat_compile_inner_t*a_compile_rule,int group_id)
|
||||
struct Maat_group_inner* del_group_from_compile(struct Maat_compile_inner*a_compile_rule,int group_id)
|
||||
{
|
||||
int i=0;
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
pthread_rwlock_wrlock(&(a_compile_rule->rwlock));
|
||||
for(i=0;i<MAAT_MAX_EXPR_ITEM_NUM;i++)
|
||||
{
|
||||
group_rule=(struct Maat_group_inner_t*)dynamic_array_read(a_compile_rule->groups,i);
|
||||
group_rule=(struct Maat_group_inner*)dynamic_array_read(a_compile_rule->groups,i);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
continue;
|
||||
@@ -1905,7 +1909,7 @@ int add_expr_rule(struct Maat_table_desc* table,struct db_str_rule_t* db_rule,st
|
||||
int expr_id=0,district_id=-1;
|
||||
struct expr_table_desc* expr_desc=&(table->expr);
|
||||
scan_rule_t*p_rule=NULL;
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
enum MAAT_CHARSET dst_charset=CHARSET_NONE;
|
||||
char *sub_key_array[MAAT_MAX_EXPR_ITEM_NUM];
|
||||
int key_left_offset[MAAT_MAX_EXPR_ITEM_NUM]={-1},key_right_offset[MAAT_MAX_EXPR_ITEM_NUM]={-1};
|
||||
@@ -1916,7 +1920,7 @@ int add_expr_rule(struct Maat_table_desc* table,struct db_str_rule_t* db_rule,st
|
||||
}
|
||||
int sub_expr_cnt=0;
|
||||
struct op_expr_t *op_expr=NULL;
|
||||
struct Maat_group_inner_t* u_para=NULL;
|
||||
struct Maat_group_inner* u_para=NULL;
|
||||
|
||||
if(table->table_type==TABLE_TYPE_EXPR_PLUS)
|
||||
{
|
||||
@@ -1924,7 +1928,7 @@ int add_expr_rule(struct Maat_table_desc* table,struct db_str_rule_t* db_rule,st
|
||||
str_unescape(db_rule->district);
|
||||
district_id=get_district_id(scanner, db_rule->district);
|
||||
}
|
||||
group_rule=(struct Maat_group_inner_t*)HASH_fetch_by_id(scanner->group_hash, db_rule->group_id);
|
||||
group_rule=(struct Maat_group_inner*)HASH_fetch_by_id(scanner->group_hash, db_rule->group_id);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
group_rule=create_group_rule(db_rule->group_id);
|
||||
@@ -2163,13 +2167,13 @@ int add_expr_rule(struct Maat_table_desc* table,struct db_str_rule_t* db_rule,st
|
||||
}
|
||||
int add_ip_rule(struct Maat_table_desc* table,struct db_ip_rule_t* db_ip_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
{
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
scan_rule_t* p_rule=NULL;
|
||||
struct op_expr_t* op_expr=NULL;
|
||||
struct Maat_group_inner_t* u_para=NULL;
|
||||
struct Maat_group_inner* u_para=NULL;
|
||||
int expr_id=0,district_id=-1;
|
||||
|
||||
group_rule=(struct Maat_group_inner_t*)HASH_fetch_by_id(scanner->group_hash, db_ip_rule->group_id);
|
||||
group_rule=(struct Maat_group_inner*)HASH_fetch_by_id(scanner->group_hash, db_ip_rule->group_id);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
group_rule=create_group_rule(db_ip_rule->group_id);
|
||||
@@ -2193,15 +2197,15 @@ int add_ip_rule(struct Maat_table_desc* table,struct db_ip_rule_t* db_ip_rule,st
|
||||
MESA_lqueue_join_tail(scanner->region_update_q, &op_expr, sizeof(void*));
|
||||
return 0;
|
||||
}
|
||||
int add_intval_rule(struct Maat_table_desc* table,struct db_intval_rule_t* intval_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
int add_intval_rule(struct Maat_table_desc* table,struct db_intval_rule* intval_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
{
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
scan_rule_t* p_rule=NULL;
|
||||
struct op_expr_t* op_expr=NULL;
|
||||
struct Maat_group_inner_t* u_para=NULL;
|
||||
struct Maat_group_inner* u_para=NULL;
|
||||
int expr_id=0,district_id=-1;
|
||||
|
||||
group_rule=(struct Maat_group_inner_t*)HASH_fetch_by_id(scanner->group_hash, intval_rule->group_id);
|
||||
group_rule=(struct Maat_group_inner*)HASH_fetch_by_id(scanner->group_hash, intval_rule->group_id);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
group_rule=create_group_rule(intval_rule->group_id);
|
||||
@@ -2224,15 +2228,15 @@ int add_intval_rule(struct Maat_table_desc* table,struct db_intval_rule_t* intva
|
||||
MESA_lqueue_join_tail(scanner->region_update_q, &op_expr, sizeof(void*));
|
||||
return 0;
|
||||
}
|
||||
int add_digest_rule(struct Maat_table_desc* table,struct db_digest_rule_t* db_digest_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
int add_digest_rule(struct Maat_table_desc* table,struct db_digest_rule* db_digest_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
{
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
GIE_digest_t* digest_rule=NULL;
|
||||
struct Maat_group_inner_t* u_para=NULL;
|
||||
struct Maat_group_inner* u_para=NULL;
|
||||
struct Maat_table_runtime * table_rt=scanner->table_rt[table->table_id];
|
||||
int expr_id=0,district_id=-1;
|
||||
|
||||
group_rule=(struct Maat_group_inner_t*)HASH_fetch_by_id(scanner->group_hash, db_digest_rule->group_id);
|
||||
group_rule=(struct Maat_group_inner*)HASH_fetch_by_id(scanner->group_hash, db_digest_rule->group_id);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
group_rule=create_group_rule(db_digest_rule->group_id);
|
||||
@@ -2261,10 +2265,10 @@ int del_region_rule(struct Maat_table_desc* table,int region_id,int group_id,int
|
||||
int i=0;
|
||||
unsigned int expr_id[MAAT_MAX_EXPR_ITEM_NUM*MAX_CHARSET_NUM]={0};
|
||||
int expr_num=0;
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
struct op_expr_t* op_expr=NULL;
|
||||
GIE_digest_t* digest_rule=NULL;
|
||||
group_rule=(struct Maat_group_inner_t*)HASH_fetch_by_id(maat_scanner->group_hash, group_id);
|
||||
group_rule=(struct Maat_group_inner*)HASH_fetch_by_id(maat_scanner->group_hash, group_id);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
@@ -2320,82 +2324,117 @@ int del_region_rule(struct Maat_table_desc* table,int region_id,int group_id,int
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int add_group_rule(struct Maat_table_desc* table,struct db_group_rule_t* db_group_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
int add_group_rule(struct Maat_table_desc* table, struct db_group_rule_t* db_group_rule, struct Maat_scanner_t *scanner, void* logger)
|
||||
{
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
struct Maat_compile_inner_t*compile_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL, *parent_group=NULL;
|
||||
struct Maat_compile_inner*compile_rule=NULL;
|
||||
int ret=0;
|
||||
group_rule=(struct Maat_group_inner_t*)HASH_fetch_by_id(scanner->group_hash, db_group_rule->group_id);
|
||||
group_rule=(struct Maat_group_inner*)HASH_fetch_by_id(scanner->group_hash, db_group_rule->group_id);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
group_rule=create_group_rule(db_group_rule->group_id);
|
||||
group_rule->table_id=table->table_id;
|
||||
|
||||
ret=HASH_add_by_id(scanner->group_hash, db_group_rule->group_id, group_rule);
|
||||
ret=HASH_add_by_id(scanner->group_hash, group_rule->group_id, group_rule);
|
||||
assert(ret>=0);
|
||||
}
|
||||
|
||||
compile_rule=(struct Maat_compile_inner_t*)HASH_fetch_by_id(scanner->compile_hash, db_group_rule->compile_id);
|
||||
if(db_group_rule->parent_type==PARENT_TYPE_GROUP)
|
||||
{
|
||||
parent_group=(struct Maat_group_inner*)HASH_fetch_by_id(scanner->group_hash, db_group_rule->parent_id);
|
||||
if(parent_group==NULL)
|
||||
{
|
||||
parent_group=create_group_rule(db_group_rule->parent_id);
|
||||
parent_group->table_id=table->table_id;
|
||||
ret=HASH_add_by_id(scanner->group_hash, parent_group->group_id, parent_group);
|
||||
assert(ret>=0);
|
||||
}
|
||||
group_rule->ref_cnt++;
|
||||
igraph_add_edge(&(scanner->group_graph), db_group_rule->group_id, db_group_rule->parent_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
group_rule->has_compile_neighbors=1;
|
||||
compile_rule=(struct Maat_compile_inner*)HASH_fetch_by_id(scanner->compile_hash, db_group_rule->parent_id);
|
||||
if(compile_rule==NULL)
|
||||
{
|
||||
compile_rule=create_compile_rule(db_group_rule->compile_id);
|
||||
ret=HASH_add_by_id(scanner->compile_hash, db_group_rule->compile_id, compile_rule);
|
||||
compile_rule=create_compile_rule(db_group_rule->parent_id);
|
||||
ret=HASH_add_by_id(scanner->compile_hash, db_group_rule->parent_id, compile_rule);
|
||||
assert(ret>=0);
|
||||
}
|
||||
ret=add_group_to_compile(compile_rule, group_rule, db_group_rule->not_flag);
|
||||
if(ret<0)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module,
|
||||
MESA_handle_runtime_log(logger, RLOG_LV_FATAL, maat_module,
|
||||
"update error,add group: %s %d to compile rule %d error, compile rule is full or duplicate group."
|
||||
,table->table_name[table->updating_name]
|
||||
,db_group_rule->group_id
|
||||
,db_group_rule->compile_id);
|
||||
,db_group_rule->parent_id);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
void del_group_rule(struct Maat_table_desc* table,struct db_group_rule_t* db_group_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
void del_group_rule(struct Maat_table_desc* table, struct db_group_rule_t* db_group_rule, struct Maat_scanner_t *scanner, void* logger)
|
||||
{
|
||||
struct Maat_compile_inner_t*compile_rule=NULL;
|
||||
struct Maat_group_inner_t* group_rule=NULL;
|
||||
compile_rule=(struct Maat_compile_inner_t*)HASH_fetch_by_id(scanner->compile_hash, db_group_rule->compile_id);
|
||||
struct Maat_compile_inner*compile_rule=NULL;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
igraph_es_t es;
|
||||
int ret=0;
|
||||
if(db_group_rule->parent_type==PARENT_TYPE_GROUP)
|
||||
{
|
||||
group_rule->ref_cnt--;
|
||||
igraph_es_pairs_small(&es, IGRAPH_DIRECTED, db_group_rule->group_id, db_group_rule->parent_id);
|
||||
ret=igraph_delete_edges(&scanner->group_graph, es);
|
||||
if(ret!=IGRAPH_SUCCESS)
|
||||
{
|
||||
MESA_handle_runtime_log(logger, RLOG_LV_FATAL, maat_module ,
|
||||
"update error, delete %s group %d from parent group %d error, not such relation before.",
|
||||
table->table_name[table->updating_name],
|
||||
db_group_rule->group_id,
|
||||
db_group_rule->parent_id);
|
||||
}
|
||||
igraph_es_destroy(&es);
|
||||
}
|
||||
else
|
||||
{
|
||||
compile_rule=(struct Maat_compile_inner*)HASH_fetch_by_id(scanner->compile_hash, db_group_rule->parent_id);
|
||||
if(compile_rule==NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,delete %s group rule error : compile id %d does not exisit."
|
||||
,table->table_name[table->updating_name]
|
||||
,db_group_rule->compile_id);
|
||||
MESA_handle_runtime_log(logger, RLOG_LV_FATAL, maat_module,
|
||||
"update error, delete %s group %d error : compile id %d does not exisit.",
|
||||
table->table_name[table->updating_name],
|
||||
db_group_rule->group_id,
|
||||
db_group_rule->parent_id);
|
||||
return;
|
||||
}
|
||||
group_rule=del_group_from_compile(compile_rule, db_group_rule->group_id);
|
||||
if(group_rule==NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,delete %s group rule error : group id %d not in compile id %d."
|
||||
MESA_handle_runtime_log(logger, RLOG_LV_FATAL, maat_module,
|
||||
"update error, delete %s group rule error : group id %d not in compile id %d."
|
||||
,table->table_name[table->updating_name]
|
||||
,db_group_rule->group_id
|
||||
,db_group_rule->compile_id);
|
||||
,db_group_rule->parent_id);
|
||||
return;
|
||||
}
|
||||
if(compile_rule->group_cnt==0&&compile_rule->is_valid==0)
|
||||
{
|
||||
HASH_delete_by_id(scanner->compile_hash, db_group_rule->compile_id);
|
||||
HASH_delete_by_id(scanner->compile_hash, db_group_rule->parent_id);
|
||||
garbage_bagging(GARBAGE_COMPILE_RULE, compile_rule, scanner->tomb_ref);
|
||||
}
|
||||
//Directly delete group id will not destroyp group_rule,it 'll be destroyed when delete this group's last region.
|
||||
}
|
||||
if(group_rule->ref_cnt==0&&group_rule->region_cnt==0)
|
||||
{
|
||||
//Directly delete table %s group id %d, do this when delete its last region.
|
||||
garbage_bagging(GARBAGE_GROUP_RULE, group_rule, scanner->tomb_ref);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int add_compile_rule(struct Maat_table_desc* table,struct db_compile_rule_t* db_compile_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
int add_compile_rule(struct Maat_table_desc* table,struct db_compile_rule* db_compile_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
{
|
||||
struct Maat_compile_inner_t *compile_rule=NULL;
|
||||
struct _head_Maat_rule_t *p_maat_rule_head=&(db_compile_rule->m_rule_head);
|
||||
struct Maat_compile_inner *compile_rule=NULL;
|
||||
struct _head_Maat_rule *p_maat_rule_head=&(db_compile_rule->m_rule_head);
|
||||
int i=0;
|
||||
compile_rule=(struct Maat_compile_inner_t*)HASH_fetch_by_id(scanner->compile_hash, p_maat_rule_head->config_id);
|
||||
compile_rule=(struct Maat_compile_inner*)HASH_fetch_by_id(scanner->compile_hash, p_maat_rule_head->config_id);
|
||||
if(compile_rule==NULL)
|
||||
{
|
||||
compile_rule=create_compile_rule(p_maat_rule_head->config_id);
|
||||
@@ -2422,10 +2461,10 @@ int add_compile_rule(struct Maat_table_desc* table,struct db_compile_rule_t* db_
|
||||
return 0;
|
||||
|
||||
}
|
||||
int del_compile_rule(struct Maat_table_desc* table,struct db_compile_rule_t* db_compile_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
int del_compile_rule(struct Maat_table_desc* table,struct db_compile_rule* db_compile_rule,struct Maat_scanner_t *scanner,void* logger)
|
||||
{
|
||||
struct Maat_compile_inner_t *compile_rule=NULL;
|
||||
compile_rule=(struct Maat_compile_inner_t*)HASH_fetch_by_id(scanner->compile_hash, db_compile_rule->m_rule_head.config_id);
|
||||
struct Maat_compile_inner *compile_rule=NULL;
|
||||
compile_rule=(struct Maat_compile_inner*)HASH_fetch_by_id(scanner->compile_hash, db_compile_rule->m_rule_head.config_id);
|
||||
if(compile_rule==NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
@@ -2451,11 +2490,12 @@ void update_group_rule(struct Maat_table_desc* table,const char* table_line,stru
|
||||
struct Maat_table_runtime* table_rt=scanner->table_rt[table->table_id];
|
||||
int ret=0;
|
||||
memset(&db_group_rule, 0, sizeof(db_group_rule));
|
||||
ret=sscanf(table_line,"%d\t%d\t%d\t%d", &(db_group_rule.group_id),
|
||||
&(db_group_rule.compile_id),
|
||||
ret=sscanf(table_line,"%d\t%d\t%d\t%d\t%d", &(db_group_rule.group_id),
|
||||
&(db_group_rule.parent_id),
|
||||
&(db_group_rule.is_valid),
|
||||
&(db_group_rule.not_flag));
|
||||
if(ret!=3&&ret!=4)
|
||||
&(db_group_rule.not_flag),
|
||||
&(db_group_rule.parent_type));
|
||||
if(ret!=3&&ret!=4&&ret!=5)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module ,
|
||||
"update error,invalid format of group table %s:%s",
|
||||
@@ -2467,6 +2507,14 @@ void update_group_rule(struct Maat_table_desc* table,const char* table_line,stru
|
||||
{
|
||||
db_group_rule.not_flag=0;
|
||||
}
|
||||
if(!db_group_rule.parent_type==PARENT_TYPE_GROUP && db_group_rule.not_flag)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module ,
|
||||
"update error, invalid format of group table %s:%s not operation is forbidden for non-compile parent.",
|
||||
table->table_name[table->updating_name], table_line);
|
||||
table->udpate_err_cnt++;
|
||||
return;
|
||||
}
|
||||
if(db_group_rule.is_valid==FALSE)
|
||||
{
|
||||
del_group_rule(table, &db_group_rule, scanner, logger);
|
||||
@@ -2488,7 +2536,7 @@ void update_group_rule(struct Maat_table_desc* table,const char* table_line,stru
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module ,
|
||||
"duplicate config of group table %s group_id %d compile_id %d.", table->table_name[0],
|
||||
db_group_rule.group_id,
|
||||
db_group_rule.compile_id);
|
||||
db_group_rule.parent_id);
|
||||
|
||||
}
|
||||
else
|
||||
@@ -2822,7 +2870,7 @@ error_out:
|
||||
|
||||
void update_intval_rule(struct Maat_table_desc* table,const char* table_line,struct Maat_scanner_t *scanner,void* logger,int group_mode_on)
|
||||
{
|
||||
struct db_intval_rule_t* intval_rule=ALLOC(struct db_intval_rule_t, 1);
|
||||
struct db_intval_rule* intval_rule=ALLOC(struct db_intval_rule, 1);
|
||||
struct Maat_table_runtime* table_rt=scanner->table_rt[table->table_id];
|
||||
int ret=0;
|
||||
ret=sscanf(table_line,"%d\t%d\t%u\t%u\t%d",&(intval_rule->region_id)
|
||||
@@ -2900,8 +2948,8 @@ void update_compile_rule(struct Maat_table_desc* table,const char* table_line,st
|
||||
struct compile_table_desc* compile_desc=&(table->compile);
|
||||
struct Maat_table_runtime* table_rt=scanner->table_rt[table->table_id];
|
||||
|
||||
struct db_compile_rule_t *p_compile=ALLOC(struct db_compile_rule_t, 1);
|
||||
struct _head_Maat_rule_t* p_m_rule=&(p_compile->m_rule_head);
|
||||
struct db_compile_rule *p_compile=ALLOC(struct db_compile_rule, 1);
|
||||
struct _head_Maat_rule* p_m_rule=&(p_compile->m_rule_head);
|
||||
char user_region[MAX_TABLE_LINE_SIZE]={0};
|
||||
char tag_str[MAX_TABLE_LINE_SIZE]={0};
|
||||
int ret=0;
|
||||
@@ -2984,7 +3032,7 @@ no_save:
|
||||
void update_digest_rule(struct Maat_table_desc* table,const char* table_line,struct Maat_scanner_t *scanner,void* logger,int group_mode_on)
|
||||
{
|
||||
struct Maat_table_runtime* table_rt=scanner->table_rt[table->table_id];
|
||||
struct db_digest_rule_t* digest_rule=ALLOC(struct db_digest_rule_t, 1);
|
||||
struct db_digest_rule* digest_rule=ALLOC(struct db_digest_rule, 1);
|
||||
int ret=0;
|
||||
char digest_buff[MAX_TABLE_LINE_SIZE]={'\0'};
|
||||
if(table->table_type==TABLE_TYPE_DIGEST)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "dynamic_array.h"
|
||||
#include "bool_matcher.h"
|
||||
#include "hiredis.h"
|
||||
|
||||
#include "igraph/igraph.h"
|
||||
#include "stream_fuzzy_hash.h"
|
||||
#include "gram_index_engine.h"
|
||||
#include "alignment_int64.h"
|
||||
@@ -69,14 +69,14 @@ struct db_ip_rule_t
|
||||
};
|
||||
int is_valid;
|
||||
};
|
||||
struct db_intval_rule_t
|
||||
struct db_intval_rule
|
||||
{
|
||||
int region_id;
|
||||
int group_id;
|
||||
interval_rule_t intval;
|
||||
int is_valid;
|
||||
};
|
||||
struct db_digest_rule_t
|
||||
struct db_digest_rule
|
||||
{
|
||||
int region_id;
|
||||
int group_id;
|
||||
@@ -85,7 +85,7 @@ struct db_digest_rule_t
|
||||
short confidence_degree;
|
||||
int is_valid;
|
||||
};
|
||||
struct _head_Maat_rule_t
|
||||
struct _head_Maat_rule
|
||||
{
|
||||
int config_id;
|
||||
int service_id;
|
||||
@@ -95,20 +95,23 @@ struct _head_Maat_rule_t
|
||||
char resevered;
|
||||
int serv_def_len;
|
||||
};
|
||||
struct db_compile_rule_t
|
||||
struct db_compile_rule
|
||||
{
|
||||
struct _head_Maat_rule_t m_rule_head;// fix len of Maat_rule_t
|
||||
struct _head_Maat_rule m_rule_head;// fix len of Maat_rule_t
|
||||
char* service_defined;
|
||||
long long effective_range;
|
||||
int is_valid;
|
||||
int declare_grp_num;
|
||||
};
|
||||
#define PARENT_TYPE_COMPILE 0
|
||||
#define PARENT_TYPE_GROUP 1
|
||||
struct db_group_rule_t
|
||||
{
|
||||
int group_id;
|
||||
int compile_id;
|
||||
int parent_id;
|
||||
int is_valid;
|
||||
int not_flag;
|
||||
int parent_type; //PARENT_TYPE_**, 0:compile, 1: group.
|
||||
};
|
||||
struct op_expr_t
|
||||
{
|
||||
@@ -120,7 +123,7 @@ struct op_expr_t
|
||||
int rule_type;
|
||||
};
|
||||
|
||||
struct _Maat_region_inner_t
|
||||
struct Maat_region_inner
|
||||
{
|
||||
int region_id;
|
||||
int district_id;
|
||||
@@ -130,7 +133,7 @@ struct _Maat_region_inner_t
|
||||
int expr_id_ub;
|
||||
enum MAAT_TABLE_TYPE table_type;
|
||||
};
|
||||
struct Maat_group_inner_t
|
||||
struct Maat_group_inner
|
||||
{
|
||||
int group_id;
|
||||
int table_id;
|
||||
@@ -138,14 +141,15 @@ struct Maat_group_inner_t
|
||||
int region_cnt;
|
||||
int ref_cnt;
|
||||
char* group_name;
|
||||
int has_compile_neighbors;
|
||||
dynamic_array_t *regions;
|
||||
void* compile_shortcut;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
struct Maat_compile_inner_t
|
||||
struct Maat_compile_inner
|
||||
{
|
||||
struct db_compile_rule_t *db_c_rule;
|
||||
dynamic_array_t *groups; //element is struct Maat_group_inner_t*
|
||||
struct db_compile_rule *db_c_rule;
|
||||
dynamic_array_t *groups; //element is struct Maat_group_inner*
|
||||
char not_flag[MAX_ITEMS_PER_BOOL_EXPR];
|
||||
char is_valid;
|
||||
int compile_id;//equal to db_c_rule->m_rule.config_id
|
||||
@@ -281,6 +285,8 @@ struct Maat_scanner_t
|
||||
MESA_htable_handle compile_hash;
|
||||
MESA_htable_handle district_map;
|
||||
MESA_htable_handle tmp_district_map;
|
||||
|
||||
igraph_t group_graph;
|
||||
unsigned int district_num;
|
||||
unsigned int cfg_num;
|
||||
unsigned int exprid_generator;
|
||||
@@ -412,8 +418,8 @@ struct _maat_garbage_t
|
||||
union
|
||||
{
|
||||
struct Maat_scanner_t* scanner;
|
||||
struct Maat_group_inner_t* group_rule;
|
||||
struct Maat_compile_inner_t* compile_rule;
|
||||
struct Maat_group_inner* group_rule;
|
||||
struct Maat_compile_inner* compile_rule;
|
||||
struct bool_matcher* bool_matcher;
|
||||
void * raw;
|
||||
MESA_htable_handle str2int_map;
|
||||
@@ -443,7 +449,7 @@ int parse_accept_tag(const char* value, struct rule_tag** result, void* logger);
|
||||
void garbage_bagging(enum maat_garbage_type type,void *p,MESA_lqueue_head garbage_q);
|
||||
void garbage_bagging_with_timeout(enum maat_garbage_type type,void *p, int timeout, MESA_lqueue_head garbage_q);
|
||||
void garbage_bury(MESA_lqueue_head garbage_q,void *logger);
|
||||
void make_group_set(struct Maat_compile_inner_t* compile_rule, struct bool_expr* a_set, unsigned char *has_not);
|
||||
void make_group_set(struct Maat_compile_inner* compile_rule, struct bool_expr* a_set, unsigned char *has_not);
|
||||
int read_table_description(struct Maat_table_desc** p_table_info,int num,const char* table_info_path,int max_thread_num,void* logger);
|
||||
void maat_start_cb(long long new_version,int update_type,void*u_para);
|
||||
int maat_update_cb(const char* table_name,const char* line,void *u_para);
|
||||
@@ -466,9 +472,9 @@ int get_foreign_keys_by_prefix(redisContext *ctx, struct serial_rule_t* rule_lis
|
||||
void get_foreign_conts(redisContext *ctx, struct serial_rule_t* rule_list, int rule_num, int print_fn, void *logger);
|
||||
void rewrite_table_line_with_foreign(struct serial_rule_t*p);
|
||||
|
||||
void fill_maat_rule(struct Maat_rule_t *rule, const struct _head_Maat_rule_t* rule_head, const char* srv_def, int srv_def_len);
|
||||
MAAT_RULE_EX_DATA rule_ex_data_new(const struct _head_Maat_rule_t * rule_head, const char* srv_def, const struct compile_ex_data_idx* ex_desc);
|
||||
void rule_ex_data_free(const struct _head_Maat_rule_t * rule_head, const char* srv_def, MAAT_RULE_EX_DATA *ad, const struct compile_ex_data_idx* ex_desc);
|
||||
void fill_maat_rule(struct Maat_rule_t *rule, const struct _head_Maat_rule* rule_head, const char* srv_def, int srv_def_len);
|
||||
MAAT_RULE_EX_DATA rule_ex_data_new(const struct _head_Maat_rule * rule_head, const char* srv_def, const struct compile_ex_data_idx* ex_desc);
|
||||
void rule_ex_data_free(const struct _head_Maat_rule * rule_head, const char* srv_def, MAAT_RULE_EX_DATA *ad, const struct compile_ex_data_idx* ex_desc);
|
||||
MESA_htable_handle wrap_plugin_EX_hash_new(long long estimate_size, Maat_plugin_EX_key2index_func_t * key2index);
|
||||
int plugin_EX_data_new(const struct Maat_table_desc* plugin_table, const char* line, MESA_htable_handle key2ex_hash, void *logger);
|
||||
int plugin_EX_data_free(const struct Maat_table_desc* plugin_table, const char* line, MESA_htable_handle key2ex_hash, void *logger);
|
||||
|
||||
16
vendor/CMakeLists.txt
vendored
16
vendor/CMakeLists.txt
vendored
@@ -30,3 +30,19 @@ file(MAKE_DIRECTORY ${HIREDIS_INCLUDE_DIRECTORIES})
|
||||
add_library(hiredis-vip-static STATIC IMPORTED GLOBAL)
|
||||
set_property(TARGET hiredis-vip-static PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/libhiredis_vip.a)
|
||||
set_property(TARGET hiredis-vip-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR})
|
||||
|
||||
ExternalProject_Add(igraph PREFIX igraph
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/igraph-0.7.1.tar.gz
|
||||
URL_MD5 4f6e7c16b45fce8ed423516a9786e4e8
|
||||
CONFIGURE_COMMAND ./configure --prefix=<INSTALL_DIR> --disable-shared --with-pic
|
||||
BUILD_COMMAND make
|
||||
INSTALL_COMMAND make install
|
||||
BUILD_IN_SOURCE 1)
|
||||
|
||||
ExternalProject_Get_Property(igraph INSTALL_DIR)
|
||||
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
|
||||
|
||||
add_library(igraph-static STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(igraph-static igraph)
|
||||
set_property(TARGET igraph-static PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libigraph.a)
|
||||
set_property(TARGET igraph-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
|
||||
|
||||
BIN
vendor/igraph-0.7.1.tar.gz
vendored
Normal file
BIN
vendor/igraph-0.7.1.tar.gz
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user