在compile_group_relation中增加magic num,编写更为复杂的SubGroup测试用例用于调试 #15 的死锁情况。
This commit is contained in:
@@ -169,7 +169,7 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int
|
||||
unsigned char has_not_flag=0;
|
||||
struct bool_matcher* bm=feather->scanner->bool_matcher_expr_compiler;
|
||||
struct Maat_group_inner* group_rule=NULL;
|
||||
struct Maat_compile_group_relation* relation_arrary[MAX_SCANNER_HIT_NUM];
|
||||
struct Maat_compile_group_relation* relation_array[MAX_SCANNER_HIT_NUM];
|
||||
struct Maat_compile_group_relation* relation=NULL;
|
||||
|
||||
int region_pos[MAX_SCANNER_HIT_NUM];
|
||||
@@ -181,9 +181,11 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int
|
||||
{
|
||||
continue;
|
||||
}
|
||||
assert(group_rule->ref_by_children_cnt>=0);
|
||||
assert(group_rule->ref_by_parent_cnt>=0);
|
||||
if(group_rule->compile_shortcut!=NULL&&group_rule->ref_by_parent_cnt==1&&shortcut_avilable_cnt<MAX_SCANNER_HIT_NUM)
|
||||
{
|
||||
relation_arrary[shortcut_avilable_cnt]=(struct Maat_compile_group_relation*)(group_rule->compile_shortcut);
|
||||
relation_array[shortcut_avilable_cnt]=(struct Maat_compile_group_relation*)(group_rule->compile_shortcut);
|
||||
shortcut_avilable_cnt++;
|
||||
}
|
||||
for(j=0; j<group_rule->top_group_cnt; j++)
|
||||
@@ -219,21 +221,21 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int
|
||||
{
|
||||
scan_ret=bool_matcher_match(bm, thread_num,
|
||||
_mid->all_hit_group_array, _mid->all_hit_group_cnt,
|
||||
(void **)relation_arrary, MAX_SCANNER_HIT_NUM);
|
||||
(void **)relation_array, MAX_SCANNER_HIT_NUM);
|
||||
}
|
||||
if(scan_ret>1)
|
||||
{
|
||||
qsort(relation_arrary, scan_ret, sizeof(struct Maat_compile_group_relation**),
|
||||
qsort(relation_array, scan_ret, sizeof(struct Maat_compile_group_relation**),
|
||||
compare_compile_inner);
|
||||
}
|
||||
for(i=0;i<scan_ret&&result_cnt<size;i++)
|
||||
{
|
||||
relation=relation_arrary[i];
|
||||
relation=relation_array[i];
|
||||
if(relation==NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(relation->magic_num==COMPILE_RELATION_MAGIC);
|
||||
if(0==pthread_rwlock_tryrdlock(&(relation->rwlock)))
|
||||
{
|
||||
if(relation->compile)
|
||||
|
||||
@@ -1095,6 +1095,7 @@ struct Maat_compile_group_relation * create_compile_group_relation(int compile_i
|
||||
{
|
||||
int ret=0;
|
||||
struct Maat_compile_group_relation* p=ALLOC(struct Maat_compile_group_relation, 1);
|
||||
p->magic_num=COMPILE_RELATION_MAGIC;
|
||||
p->compile_id=compile_id;
|
||||
p->group_cnt=0;
|
||||
p->group_boundary=1;
|
||||
@@ -1107,6 +1108,7 @@ struct Maat_compile_group_relation * create_compile_group_relation(int compile_i
|
||||
|
||||
void _destroy_compile_group_relation(struct Maat_compile_group_relation * cg_relation)
|
||||
{
|
||||
assert(cg_relation->magic_num==COMPILE_RELATION_MAGIC);
|
||||
pthread_rwlock_wrlock(&(cg_relation->rwlock));
|
||||
cg_relation->compile_id=-1;
|
||||
dynamic_array_destroy(cg_relation->groups, NULL);
|
||||
@@ -1121,12 +1123,13 @@ void destroy_compile_group_relation(struct Maat_compile_group_relation * p, stru
|
||||
int i=0;
|
||||
UNUSED struct Maat_group_inner* p_group=NULL;
|
||||
assert(p->group_cnt==0);
|
||||
|
||||
assert(p->compile==NULL);
|
||||
for(i=0;i<p->group_boundary;i++)
|
||||
{
|
||||
p_group=(struct Maat_group_inner*)dynamic_array_read(p->groups, i);
|
||||
assert(p_group==NULL);
|
||||
}
|
||||
assert(p->magic_num==COMPILE_RELATION_MAGIC);
|
||||
HASH_delete_by_id(scanner->compile_hash, p->compile_id);
|
||||
garbage_bagging(GARBAGE_COMPILE_GOURP_RELATION, p, scanner->tomb_ref);
|
||||
}
|
||||
@@ -1927,7 +1930,6 @@ struct Maat_group_inner* del_group_from_compile(struct Maat_compile_group_relati
|
||||
}
|
||||
if(group_rule->group_id==group_id)
|
||||
{
|
||||
group_rule->ref_by_parent_cnt--;
|
||||
dynamic_array_write(relation->groups,i,NULL);
|
||||
if(relation->not_flag[i]==1)
|
||||
{
|
||||
|
||||
@@ -152,8 +152,10 @@ struct Maat_group_inner
|
||||
void* compile_shortcut;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
#define COMPILE_RELATION_MAGIC 0x1a2b3c4d
|
||||
struct Maat_compile_group_relation
|
||||
{
|
||||
long long magic_num;
|
||||
struct Maat_compile_rule *compile;
|
||||
dynamic_array_t *groups; //element is struct Maat_group_inner*
|
||||
char not_flag[MAX_ITEMS_PER_BOOL_EXPR];
|
||||
@@ -288,7 +290,7 @@ struct Maat_scanner_t
|
||||
MESA_htable_handle region_hash;
|
||||
MESA_htable_handle group_hash;
|
||||
MESA_htable_handle compile_hash;
|
||||
MESA_htable_handle compile_group_relation_hash;
|
||||
|
||||
|
||||
MESA_htable_handle district_map;
|
||||
MESA_htable_handle tmp_district_map;
|
||||
|
||||
@@ -1797,12 +1797,6 @@ TEST_F(MaatCmdTest, ReturnRuleIDWithDescendingOrder)
|
||||
TEST_F(MaatCmdTest, SubGroup)
|
||||
{
|
||||
|
||||
/* compile1->group1--group2->region1
|
||||
\
|
||||
\group3->region2
|
||||
|
||||
compile2->group1
|
||||
*/
|
||||
const char* table_name="HTTP_URL";
|
||||
const char* group_table_name="GROUP";
|
||||
const char* compile_table_name="COMPILE";
|
||||
@@ -1826,7 +1820,7 @@ TEST_F(MaatCmdTest, SubGroup)
|
||||
compile2.config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
|
||||
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile2, compile_table_name, NULL, 1);
|
||||
|
||||
|
||||
//group1->compile1
|
||||
memset(&group1, 0, sizeof(group1));
|
||||
group1.group_id=Maat_cmd_get_new_group_id(feather);
|
||||
group1.table_name=group_table_name;
|
||||
@@ -1834,9 +1828,14 @@ TEST_F(MaatCmdTest, SubGroup)
|
||||
group1.parent_type=PARENT_TYPE_COMPILE;
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group1);
|
||||
|
||||
//group1->compile2
|
||||
group1.parent_id=compile2.config_id;
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group1);
|
||||
|
||||
/*group2->group1->compile1
|
||||
\
|
||||
\__compile2
|
||||
*/
|
||||
memset(&group2, 0, sizeof(group2));
|
||||
group2.group_id=Maat_cmd_get_new_group_id(feather);
|
||||
group2.table_name=group_table_name;
|
||||
@@ -1844,6 +1843,10 @@ TEST_F(MaatCmdTest, SubGroup)
|
||||
group2.parent_type=PARENT_TYPE_GROUP;
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group2);
|
||||
|
||||
/*region1->group2->group1->compile1
|
||||
\
|
||||
\_compile2
|
||||
*/
|
||||
memset(®ion1, 0, sizeof(region1));
|
||||
region1.region_id=Maat_cmd_get_new_region_id(feather);
|
||||
region1.region_type=REGION_EXPR;
|
||||
@@ -1865,6 +1868,11 @@ TEST_F(MaatCmdTest, SubGroup)
|
||||
EXPECT_EQ(result[1].config_id, compile1.config_id);
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
|
||||
/*region1->group2->group1->compile1
|
||||
\
|
||||
\--X--compile2
|
||||
*/
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_DEL, &group1);
|
||||
sleep(1);
|
||||
ret=Maat_full_scan_string(feather, table_id, CHARSET_GBK, scan_data1, strlen(scan_data1),
|
||||
@@ -1874,15 +1882,33 @@ TEST_F(MaatCmdTest, SubGroup)
|
||||
EXPECT_EQ(result[0].config_id, compile1.config_id);
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
|
||||
/*region1->group2->group1--X--
|
||||
\
|
||||
\->compile2
|
||||
*/
|
||||
group1.parent_id=compile1.config_id;
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_DEL, &group1);
|
||||
Maat_command_raw_set_compile(feather, MAAT_OP_DEL, &compile1, compile_table_name, NULL, 1);
|
||||
group2.parent_type=PARENT_TYPE_COMPILE;
|
||||
group2.parent_id=compile2.config_id;
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group2);
|
||||
|
||||
sleep(1);
|
||||
ret=Maat_full_scan_string(feather, table_id, CHARSET_GBK, scan_data1, strlen(scan_data1),
|
||||
result, NULL, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, -2);
|
||||
EXPECT_EQ(ret, 1);
|
||||
EXPECT_EQ(result[0].config_id, compile2.config_id);
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
|
||||
/*region1->group2->group1--X--
|
||||
\
|
||||
\->compile2
|
||||
region2->group3
|
||||
*/
|
||||
|
||||
memset(&group3, 0, sizeof(group3));
|
||||
group3.group_id=Maat_cmd_get_new_group_id(feather);
|
||||
group3.parent_id=group1.group_id;
|
||||
@@ -1898,13 +1924,33 @@ TEST_F(MaatCmdTest, SubGroup)
|
||||
region2.expr_rule.expr_type=EXPR_TYPE_AND;
|
||||
Maat_command_raw_set_region(feather, MAAT_OP_ADD, ®ion2, group3.group_id);
|
||||
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group1);
|
||||
sleep(1);
|
||||
ret=Maat_full_scan_string(feather, table_id, CHARSET_GBK, scan_data2, strlen(scan_data2),
|
||||
result, NULL, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, -2);
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
/*region1->group2->group1--X--
|
||||
\
|
||||
\->compile2
|
||||
region2->group3
|
||||
*/
|
||||
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 1);
|
||||
group1.parent_id=compile1.config_id;
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group1);
|
||||
|
||||
Maat_command_raw_set_compile(feather, MAAT_OP_DEL, &compile1, compile_table_name, NULL, 1);
|
||||
group1.parent_id=compile1.config_id;
|
||||
Maat_command_raw_set_group(feather, MAAT_OP_DEL, &group1);
|
||||
|
||||
sleep(1);
|
||||
ret=Maat_full_scan_string(feather, table_id, CHARSET_GBK, scan_data1, strlen(scan_data1),
|
||||
result, NULL, 4,
|
||||
&mid, 0);
|
||||
EXPECT_EQ(ret, 1);
|
||||
EXPECT_EQ(result[0].config_id, compile1.config_id);
|
||||
EXPECT_EQ(result[0].config_id, compile2.config_id);
|
||||
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user