summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhengchao <[email protected]>2021-05-27 20:44:21 +0800
committerzhengchao <[email protected]>2021-05-27 20:44:21 +0800
commit6b9162272dbaa4a232164de19da56dd15f5bd838 (patch)
tree22b97e1acf3bd2612603dba61efd4e7f8727f2aa
parentdf4fad9e8b0ce6329dc191eb1fcdb0561c373244 (diff)
修复bug: Bool matcher重建时,maat hierarchy会重新生成clause id,会引发两种bug现象:3.1.22
1. 新生成的clause id,与扫描状态mid中缓存的clause id冲突,导致误命中。引发 TSG-6419 2. mid中已缓存了clause id,但是由于构造的bool macher使用新的clause id,导致漏命中。 修复方案: 1. 将生成clause id的哈希表保存在hierarchy中, 保证增量更新前后clause id不变化; 2. 在mid中增加时间戳作为版本号,旧版本的mid不进行bool matcher运算,以免误命中。
-rw-r--r--src/entry/Maat_hierarchy.cpp128
-rw-r--r--test/test_maatframe.cpp218
2 files changed, 141 insertions, 205 deletions
diff --git a/src/entry/Maat_hierarchy.cpp b/src/entry/Maat_hierarchy.cpp
index 7fa4f32..2a47fc8 100644
--- a/src/entry/Maat_hierarchy.cpp
+++ b/src/entry/Maat_hierarchy.cpp
@@ -83,10 +83,18 @@ static void _group_vertex_free(struct Maat_hierarchy_group* group)
free(group);
}
+struct Maat_hierarchy_clause
+{
+ long long clause_id;
+ size_t n_literal_id;
+ struct Maat_hierarchy_literal_id* literal_ids;
+ UT_hash_handle hh;
+};
struct Maat_hierarchy
{
pthread_rwlock_t rwlock;
+ time_t version;
struct bool_matcher* bm;
struct Maat_hierarchy_compile* hash_compile_by_id; //key: compile_id, value: struct Maat_hierarchy_compile*.
@@ -98,6 +106,10 @@ struct Maat_hierarchy
struct Maat_hierarchy_literal* hash_literal_by_id; //key: virtual_table<<32|group_id, aka literal_id, value: struct Maat_hierarchy_literal*.
struct Maat_hierarchy_region* hash_region_by_id; //key: region_id, value: struct Maat_hierarchy_region*.
+
+ struct Maat_hierarchy_clause* hash_dedup_clause_by_literals; //key: literal combination, value: struct Maat_hierarchy_clause*. For generating unique clause_id.
+ unsigned long long clause_id_generator; //Increasing number.
+
void (* region_user_data_free)(void *region_ud);
@@ -141,6 +153,37 @@ static inline int compare_clause_id(const void* a, const void* b)
return 1;
}
}
+
+static struct Maat_hierarchy_clause* Maat_hierarchy_clause_fetch(struct Maat_hierarchy* hier, struct Maat_hierarchy_literal_id* literal_ids, size_t n_literal_id)
+{
+ static struct Maat_hierarchy_clause* clause=NULL;
+
+ HASH_FIND(hh, hier->hash_dedup_clause_by_literals, literal_ids,
+ n_literal_id*sizeof(struct Maat_hierarchy_literal_id), clause);
+
+ if(!clause)
+ {
+ clause=ALLOC(struct Maat_hierarchy_clause, 1);
+ clause->clause_id=hier->clause_id_generator;
+ clause->n_literal_id=n_literal_id;
+ clause->literal_ids=ALLOC(struct Maat_hierarchy_literal_id, n_literal_id);
+ memcpy(clause->literal_ids, literal_ids, n_literal_id*sizeof(struct Maat_hierarchy_literal_id));
+
+ hier->clause_id_generator++;
+ HASH_ADD_KEYPTR(hh, hier->hash_dedup_clause_by_literals, literal_ids,
+ n_literal_id*sizeof(struct Maat_hierarchy_literal_id),
+ clause);
+ }
+ return clause;
+}
+static void Maat_hierarchy_clause_free(struct Maat_hierarchy* hier, struct Maat_hierarchy_clause* clause)
+{
+ HASH_DELETE(hh, hier->hash_dedup_clause_by_literals, clause);
+ free(clause->literal_ids);
+ clause->n_literal_id=0;
+ free(clause);
+ return;
+}
static struct Maat_hierarchy_literal* Maat_hierarchy_literal_new(struct Maat_hierarchy_literal** hash_table, int group_id, int vt_id)
{
struct Maat_hierarchy_literal* literal=ALLOC(struct Maat_hierarchy_literal, 1);
@@ -242,6 +285,7 @@ static struct Maat_hierarchy_compile* Maat_hierarchy_compile_new(struct Maat_hie
static void Maat_hierarchy_compile_free(struct Maat_hierarchy* hier, struct Maat_hierarchy_compile* compile)
{
int i=0;
+ struct Maat_hierarchy_clause_state* clause_state=NULL;
HASH_DEL(hier->hash_compile_by_id, compile);
if(compile->user_data && hier->compile_user_data_free)
{
@@ -249,10 +293,11 @@ static void Maat_hierarchy_compile_free(struct Maat_hierarchy* hier, struct Maat
compile->user_data=NULL;
}
for(i=0; i<MAX_ITEMS_PER_BOOL_EXPR; i++)
- {
- utarray_free(compile->clause_states[i].literal_ids);
- compile->clause_states[i].literal_ids=NULL;
- compile->clause_states[i].in_use=0;
+ {
+ clause_state=compile->clause_states+i;
+ utarray_free(clause_state->literal_ids);
+ clause_state->literal_ids=NULL;
+ clause_state->in_use=0;
}
free(compile);
}
@@ -290,13 +335,16 @@ struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logg
int ret=0;
hier->logger=mesa_handle_logger;
hier->thread_num=thread_num;
+ hier->version=time(NULL);
hier->hash_group_by_id=NULL;
hier->hash_group_by_vertex=NULL;
hier->hash_compile_by_id=NULL;
hier->hash_literal_by_id=NULL;
hier->hash_region_by_id=NULL;
-
+ hier->hash_dedup_clause_by_literals=NULL;
+ hier->clause_id_generator=0;
+
hier->expr_match_buff=ALLOC(void*, thread_num*MAX_SCANNER_HIT_NUM);
ret=igraph_empty(&hier->group_graph, 0, IGRAPH_DIRECTED);
@@ -309,6 +357,7 @@ void Maat_hierarchy_free(struct Maat_hierarchy* hier)
struct Maat_hierarchy_group* group=NULL, *tmp_group=NULL;
struct Maat_hierarchy_literal* literal=NULL, *tmp_literal=NULL;
struct Maat_hierarchy_region* region=NULL, *tmp_region=NULL;
+ struct Maat_hierarchy_clause* clause=NULL, *tmp_clause=NULL;
pthread_rwlock_wrlock(&hier->rwlock);
//Reference: https://troydhanson.github.io/uthash/userguide.html#_what_can_it_do
@@ -333,6 +382,10 @@ void Maat_hierarchy_free(struct Maat_hierarchy* hier)
Maat_hierarchy_region_free(hier, region);
}
+ HASH_ITER(hh, hier->hash_dedup_clause_by_literals, clause, tmp_clause)
+ {
+ Maat_hierarchy_clause_free(hier, clause);
+ }
//Free group as the last.
HASH_CLEAR(hh_vertex_id, hier->hash_group_by_vertex);//No need group memory clean up.
@@ -798,12 +851,7 @@ error_out:
pthread_rwlock_unlock(&hier->rwlock);
return -1;
}
-struct clause_entry
-{
- long long clause_id;
- const UT_array *literal_ids;//a reference of struct Maat_hierarchy_clause_state->literal_ids
- UT_hash_handle hh;
-};
+
static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierarchy* hier)
{
struct bool_matcher* bm=NULL;
@@ -812,10 +860,10 @@ static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierar
struct Maat_hierarchy_compile* compile=NULL, *tmp_compile=NULL;
struct Maat_hierarchy_clause_state* clause_state=NULL;
+ struct Maat_hierarchy_clause* clause=NULL;
size_t i=0, j=0;
int has_clause_num=0;
compile_num=HASH_COUNT(hier->hash_compile_by_id);
- size_t all_clause_num=compile_num*MAX_ITEMS_PER_BOOL_EXPR;
if(compile_num==0)
{
@@ -824,12 +872,9 @@ static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierar
return NULL;
}
- //STEP 1, create a clause hash by literals it contains
- unsigned long long clause_id_generator=0;
+ //STEP 1, update clause_id of each compile and literal
struct Maat_hierarchy_literal_id* literal_ids=NULL;
size_t n_literal_id=0;
- struct clause_entry* clause_entry_array=ALLOC(struct clause_entry, all_clause_num);
- struct clause_entry* clause_dedup_hash=NULL, *clause_entry=NULL, *tmp_clause_entry=NULL;
HASH_ITER(hh, hier->hash_compile_by_id, compile, tmp_compile)
{
has_clause_num=0;
@@ -844,41 +889,13 @@ static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierar
has_clause_num++;
literal_ids=(struct Maat_hierarchy_literal_id*)utarray_eltptr(clause_state->literal_ids, 0);
n_literal_id=utarray_len(clause_state->literal_ids);
- HASH_FIND(hh, clause_dedup_hash, literal_ids,
- n_literal_id*sizeof(struct Maat_hierarchy_literal_id), clause_entry);
- if(!clause_entry)
- {
- clause_entry_array[clause_id_generator].clause_id=clause_id_generator;
- clause_entry_array[clause_id_generator].literal_ids=clause_state->literal_ids;
- HASH_ADD_KEYPTR(hh, clause_dedup_hash, literal_ids,
- n_literal_id*sizeof(struct Maat_hierarchy_literal_id),
- clause_entry_array+clause_id_generator);
- clause_id_generator++;
- }
+ clause=Maat_hierarchy_clause_fetch(hier, literal_ids, n_literal_id);
+ clause_state->clause_id=clause->clause_id;
}
assert(has_clause_num==compile->actual_clause_num);
}
- //STEP 2, update clause_id of each compile and literal
- HASH_ITER(hh, hier->hash_compile_by_id, compile, tmp_compile)
- {
- for(i=0; i<MAX_ITEMS_PER_BOOL_EXPR; i++)
- {
- clause_state=compile->clause_states+i;
- if(!clause_state->in_use)
- {
- continue;
- }
- literal_ids=(struct Maat_hierarchy_literal_id*)utarray_eltptr(clause_state->literal_ids, 0);
- n_literal_id=utarray_len(clause_state->literal_ids);
- HASH_FIND(hh, clause_dedup_hash, literal_ids,
- n_literal_id*sizeof(struct Maat_hierarchy_literal_id), clause_entry);
- assert(clause_entry);
- clause_state->clause_id=clause_entry->clause_id;
- }
- }
-
- //STEP 3, serial compile clause states to a bool expression array.
+ //STEP 2, serial compile clause states to a bool expression array.
compile_num=HASH_COUNT(hier->hash_compile_by_id);
bool_expr_array=ALLOC(struct bool_expr, compile_num);
HASH_ITER(hh, hier->hash_compile_by_id, compile, tmp_compile)
@@ -905,7 +922,7 @@ static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierar
}
}
- //STEP 4, build the bool matcher.
+ //STEP 3, build the bool matcher.
size_t mem_size=0;
if(expr_cnt==0)
{
@@ -917,9 +934,8 @@ static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierar
if(bm!=NULL)
{
MESA_handle_runtime_log(hier->logger, RLOG_LV_INFO, module_maat_hierarchy,
- "Build bool matcher of %zu expressions and %llu clauses, use %zu bytes memory.",
+ "Build bool matcher of %zu expressions with %zu bytes memory.",
expr_cnt,
- HASH_COUNT(clause_dedup_hash),
mem_size);
}
else
@@ -928,14 +944,8 @@ static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierar
"Build bool matcher failed!");
}
- //STEP 5, release resources
- HASH_ITER(hh, clause_dedup_hash, clause_entry, tmp_clause_entry)
- {
- HASH_DELETE(hh, clause_dedup_hash, clause_entry);
- }
error_out:
- free(clause_entry_array);
- clause_entry_array=NULL;
+
free(bool_expr_array);
bool_expr_array=NULL;
@@ -1109,6 +1119,7 @@ struct Maat_hierarchy_compile_mid
{
int thread_num;
int Nth_scan;
+ time_t hier_ver;
size_t this_scan_region_hit_cnt;
int not_clause_hitted_flag;
size_t hit_path_cnt;
@@ -1122,6 +1133,7 @@ struct Maat_hierarchy_compile_mid* Maat_hierarchy_compile_mid_new(struct Maat_hi
struct Maat_hierarchy_compile_mid* mid=ALLOC(struct Maat_hierarchy_compile_mid, 1);
TAILQ_INIT(&mid->hit_path_qhead);
mid->thread_num=thread_num;
+ mid->hier_ver=hier->version;
utarray_new(mid->_all_hit_clause_array, &ut_clause_id_icd);
return mid;
}
@@ -1341,7 +1353,7 @@ int Maat_hierarchy_region_compile(struct Maat_hierarchy* hier, struct Maat_hiera
size_t r_in_c_cnt=0, this_scan_region_hits=mid->this_scan_region_hit_cnt;
size_t ud_result_cnt=0;
- if(!hier->bm)
+ if(!hier->bm||0==utarray_len(mid->_all_hit_clause_array)||hier->version!=mid->hier_ver)
{
mid->this_scan_region_hit_cnt=0;
return 0;
diff --git a/test/test_maatframe.cpp b/test/test_maatframe.cpp
index 1764f91..c2f5842 100644
--- a/test/test_maatframe.cpp
+++ b/test/test_maatframe.cpp
@@ -3965,7 +3965,7 @@ that the edges be all directed in the same direction.";
}
#define ScanStatusCompileUpdate_MissMatch
-TEST_F(MaatCmdTest, MissMatchAfterCompileUpdate_TSG6419)
+TEST_F(MaatCmdTest, SameScanStatusWhenClauseUpdate_TSG6419)
{
Maat_feather_t feather=MaatCmdTest::_shared_feather;
@@ -3973,139 +3973,59 @@ TEST_F(MaatCmdTest, MissMatchAfterCompileUpdate_TSG6419)
const char* compile_table_name="COMPILE";
const char* ip_table_name="IP_PLUS_CONFIG", *app_id_table_name="APP_ID";
- struct Maat_rule_t compile1, compile2;
- struct Maat_cmd_group2compile group1, group2, group3, group4;
- struct Maat_cmd_region region1, region2, region3;
- struct Maat_cmd_region region4, region5, region6;
+ struct Maat_rule_t compile1;
+ struct Maat_cmd_group2compile group11, group21, group22;
+ struct Maat_cmd_region region11, region21, region22;
- //---------------Start Compile1 Initialization----------------------------
memset(&compile1, 0, sizeof(compile1));
compile1.config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 2, 0, 0);
- //group1->compile1
- // /
- //group2--/
-
- memset(&group1, 0, sizeof(group1));
- group1.group_id=Maat_command_get_new_group_id(feather);
- group1.table_name=g2c_tn;
- group1.compile_id=compile1.config_id;
- group1.clause_index=0;
- Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group1);
-
- memset(&group2, 0, sizeof(group2));
- group2.group_id=Maat_command_get_new_group_id(feather);
- group2.table_name=g2c_tn;
- group2.compile_id=compile1.config_id;
- group2.clause_index=1;
- Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group2);
-
- //region1->group1->compile1
- // /
- // group2--/
-
- memset(&region1, 0, sizeof(region1));
- region1.region_id=Maat_command_get_new_region_id(feather);
- region1.region_type=REGION_IP_PLUS;
- region1.table_name=ip_table_name;
- region1.ip_plus_rule.addr_type=ADDR_TYPE_IPv4;
- region1.ip_plus_rule.saddr_format="range";
- region1.ip_plus_rule.src_ip1="192.168.2.1";
- region1.ip_plus_rule.src_ip2="192.168.2.4";
- region1.ip_plus_rule.sport_format="range";
- region1.ip_plus_rule.src_port1=region1.ip_plus_rule.src_port2=0;
-
- region1.ip_plus_rule.daddr_format="mask";
- region1.ip_plus_rule.dst_ip1="0.0.0.0";
- region1.ip_plus_rule.dst_ip2="255.255.255.255";
- region1.ip_plus_rule.dport_format="range";
- region1.ip_plus_rule.dst_port1=region1.ip_plus_rule.dst_port2=0;
-
- Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region1, group1.group_id);
+ //region11->group11--clause0-->compile1
+ // /
+ //region21->group21--clause1--/
- //region1->group1->compile1
- // /
- //region2->group2--/
-
- region2.region_id=Maat_command_get_new_region_id(feather);
- region2.region_type=REGION_INTERVAL;
- region2.table_name=app_id_table_name;
- region2.interval_rule.up_boundary=region2.interval_rule.low_boundary=31;
- Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region2, group2.group_id);
-
- //---------------End Compile1 Initialization----------------------------
-
-
- //---------------Start Compile2 Initialization----------------------------
-
- memset(&compile2, 0, sizeof(compile2));
- 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, 2, 0, 0);
+ memset(&group11, 0, sizeof(group11));
+ group11.group_id=Maat_command_get_new_group_id(feather);
+ group11.table_name=g2c_tn;
+ group11.compile_id=compile1.config_id;
+ group11.clause_index=1;
+ Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group11);
-
- //group3->compile2
- // /
- //group4--/
+ memset(&region11, 0, sizeof(region11));
+ region11.region_id=Maat_command_get_new_region_id(feather);
+ region11.region_type=REGION_IP_PLUS;
+ region11.table_name=ip_table_name;
+ region11.ip_plus_rule.addr_type=ADDR_TYPE_IPv4;
+ region11.ip_plus_rule.saddr_format="range";
+ region11.ip_plus_rule.src_ip1="192.168.2.1";
+ region11.ip_plus_rule.src_ip2="192.168.2.4";
+ region11.ip_plus_rule.sport_format="range";
+ region11.ip_plus_rule.src_port1=region11.ip_plus_rule.src_port2=0;
- memset(&group3, 0, sizeof(group1));
- group3.group_id=Maat_command_get_new_group_id(feather);
- group3.table_name=g2c_tn;
- group3.compile_id=compile2.config_id;
- group3.clause_index=0;
- Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group3);
+ region11.ip_plus_rule.daddr_format="mask";
+ region11.ip_plus_rule.dst_ip1="0.0.0.0";
+ region11.ip_plus_rule.dst_ip2="255.255.255.255";
+ region11.ip_plus_rule.dport_format="range";
+ region11.ip_plus_rule.dst_port1=region11.ip_plus_rule.dst_port2=0;
+ Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region11, group11.group_id);
- memset(&group4, 0, sizeof(group4));
- group4.group_id=Maat_command_get_new_group_id(feather);
- group4.table_name=g2c_tn;
- group4.compile_id=compile2.config_id;
- group4.clause_index=1;
- Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group4);
- //region4->group3->compile2
- // /
- // group4--/
-
- memset(&region4, 0, sizeof(region1));
- region4.region_id=Maat_command_get_new_region_id(feather);
- region4.region_type=REGION_IP_PLUS;
- region4.table_name=ip_table_name;
- region4.ip_plus_rule.addr_type=ADDR_TYPE_IPv4;
- region4.ip_plus_rule.saddr_format="range";
- region4.ip_plus_rule.src_ip1="10.100.2.1";
- region4.ip_plus_rule.src_ip2="10.100.2.254";
- region4.ip_plus_rule.sport_format="range";
- region4.ip_plus_rule.src_port1=region1.ip_plus_rule.src_port2=0;
-
- region4.ip_plus_rule.daddr_format="mask";
- region4.ip_plus_rule.dst_ip1="0.0.0.0";
- region4.ip_plus_rule.dst_ip2="255.255.255.255";
- region4.ip_plus_rule.dport_format="range";
- region4.ip_plus_rule.dst_port1=region4.ip_plus_rule.dst_port2=0;
-
- Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region4, group3.group_id);
-
-
- //region4->group3->compile2
- // /
- //region5->group4--/
- // /
- //region6---/
- region5.region_id=Maat_command_get_new_region_id(feather);
- region5.region_type=REGION_INTERVAL;
- region5.table_name=app_id_table_name;
- region5.interval_rule.up_boundary=region5.interval_rule.low_boundary=31;
- Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region5, group4.group_id);
-
- region6.region_id=Maat_command_get_new_region_id(feather);
- region6.region_type=REGION_INTERVAL;
- region6.table_name=app_id_table_name;
- region6.interval_rule.up_boundary=region6.interval_rule.low_boundary=32;
- Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region6, group4.group_id);
+ memset(&group21, 0, sizeof(group21));
+ group21.group_id=Maat_command_get_new_group_id(feather);
+ group21.table_name=g2c_tn;
+ group21.compile_id=compile1.config_id;
+ group21.clause_index=2;
+ Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group21);
+ region21.region_id=Maat_command_get_new_region_id(feather);
+ region21.region_type=REGION_INTERVAL;
+ region21.table_name=app_id_table_name;
+ region21.interval_rule.up_boundary=region21.interval_rule.low_boundary=31;
+ Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region21, group21.group_id);
sleep(1);
@@ -4114,40 +4034,44 @@ TEST_F(MaatCmdTest, MissMatchAfterCompileUpdate_TSG6419)
scan_status_t mid=NULL;
struct ipaddr ipv4_addr;
struct stream_tuple4_v4 v4_addr;
- ipv4_addr_set(&ipv4_addr, &v4_addr, "192.168.2.5", 50001, "10.0.6.201", 80);
+ ipv4_addr_set(&ipv4_addr, &v4_addr, "192.168.2.2", 50001, "10.0.6.201", 80);
- int scan_app_id=31;
-
+ int scan_app_id=32;
+ memset(result, 0, sizeof(result));
table_id=Maat_table_register(feather, ip_table_name);
ret=Maat_scan_proto_addr(feather,table_id, &ipv4_addr, 6, result, 4, &mid,0);
- EXPECT_EQ(ret, 0);
+ EXPECT_EQ(ret, -2);
table_id=Maat_table_register(feather, app_id_table_name);
ret=Maat_scan_intval(feather, table_id, scan_app_id, result, 4, &mid, 0);
- EXPECT_EQ(ret, -2);
+ EXPECT_EQ(ret, 0);
- // region1->group1->compile1
- // /
- // region2->group2--/
- // /
- //region3(new)--/
+ //region11->group11--clause1-->compile1
+ // /
+ //region21->group21--clause2--/
+ // /
+ //region22->group22---/
- region3.region_id=Maat_command_get_new_region_id(feather);
- region3.region_type=REGION_INTERVAL;
- region3.table_name=app_id_table_name;
- region3.interval_rule.up_boundary=region3.interval_rule.low_boundary=32;
- Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region3, group2.group_id);
+ memset(&group22, 0, sizeof(group22));
+ group22.group_id=Maat_command_get_new_group_id(feather);
+ group22.table_name=g2c_tn;
+ group22.compile_id=compile1.config_id;
+ group22.clause_index=2;
+ Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group22);
+ region22.region_id=Maat_command_get_new_region_id(feather);
+ region22.region_type=REGION_INTERVAL;
+ region22.table_name=app_id_table_name;
+ region22.interval_rule.up_boundary=region22.interval_rule.low_boundary=32;
+ Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region22, group22.group_id);
+
sleep(1);
- table_id=Maat_table_register(feather, ip_table_name);
- ret=Maat_scan_proto_addr(feather, table_id, &ipv4_addr, 6, result, 4, &mid,0);
- EXPECT_EQ(ret, 0);
-
table_id=Maat_table_register(feather, app_id_table_name);
ret=Maat_scan_intval(feather, table_id, scan_app_id, result, 4, &mid, 0);
- EXPECT_EQ(ret, -2);
+ EXPECT_EQ(ret, 1);
+ EXPECT_EQ(result[0].config_id, compile1.config_id);
Maat_clean_status(&mid);
@@ -4236,20 +4160,19 @@ TEST_F(MaatCmdTest, UpdateDeadLockDetection)
//DON'T DO THIS!!!
//Roll back version, trigger full udpate.
+ //This operation generates some FATAL logs in test_maat_redis.log.yyyy-mm-dd.
Maat_cmd_incrby(feather, "MAAT_VERSION", -100);
//Wating for scanner garbage collect expiration.
sleep(10);
-
+
+ memset(result, 0, sizeof(result));
ret=Maat_full_scan_string(feather, table_id, CHARSET_GBK, scan_data2, strlen(scan_data2),
result, NULL, 4, &mid, 0);
- EXPECT_EQ(ret, 1);
- EXPECT_EQ(result[0].config_id, compile2.config_id);
+ EXPECT_EQ(ret, -2); //After full update, clause ids are re-orgnized, therefore mid are not compatible to the new scanner (hierarchy).
Maat_clean_status(&mid);
- Maat_cmd_incrby(feather, "MAAT_VERSION", 100);
-
return;
}
@@ -4310,7 +4233,9 @@ TEST_F(MaatCmdTest, StreamScanSegfaultWhenVersionRollBack_TSG6324)
EXPECT_EQ(result[0].config_id, compile1.config_id);
//DON'T DO THIS!!!
- //Roll back version, trigger full udpate.
+ //Roll back version, trigger full udpate.
+ //This operation generates FATAL logs in test_maat_redis.log.yyyy-mm-dd.
+ //For example: Add group 22 vt_id 0 to clause 2 of compile 979 failed, group is already exisited
Maat_cmd_incrby(feather, "MAAT_VERSION", -100);
//Wating for scanner garbage collect expiration.
@@ -4323,7 +4248,6 @@ TEST_F(MaatCmdTest, StreamScanSegfaultWhenVersionRollBack_TSG6324)
Maat_stream_scan_string_end(&sp);
Maat_clean_status(&mid);
- Maat_cmd_incrby(feather, "MAAT_VERSION", 100);
}