[BUGFIX]fix hit path not include super_group referenced by compile: TSG-15336
This commit is contained in:
@@ -93,12 +93,6 @@ struct compile_rule {
|
||||
char table_name[MAX_NAME_STR_LEN];
|
||||
};
|
||||
|
||||
struct group_reference {
|
||||
long long group_id;
|
||||
size_t ref_by_compile_cnt;
|
||||
UT_hash_handle hh;
|
||||
};
|
||||
|
||||
/* compile_runtime and group2compile_runtime share compile_hash_map */
|
||||
struct compile_runtime {
|
||||
struct bool_matcher *bm;
|
||||
@@ -107,9 +101,8 @@ struct compile_runtime {
|
||||
time_t version;
|
||||
struct maat_clause *clause_by_literals_hash;
|
||||
struct literal_clause *literal2clause_hash;
|
||||
struct group_reference *group_ref_hash;
|
||||
struct group2compile_runtime *ref_g2c_rt;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
struct bool_expr_match *expr_match_buff;
|
||||
@@ -583,10 +576,8 @@ void *compile_runtime_new(void *compile_schema, size_t max_thread_num,
|
||||
compile_rt->cfg_hash_tbl = rcu_hash_new(rcu_maat_compile_free, NULL);
|
||||
compile_rt->clause_by_literals_hash = NULL;
|
||||
compile_rt->literal2clause_hash = NULL;
|
||||
compile_rt->group_ref_hash = NULL;
|
||||
compile_rt->logger = logger;
|
||||
compile_rt->ref_garbage_bin = garbage_bin;
|
||||
pthread_mutex_init(&(compile_rt->mutex), NULL);
|
||||
|
||||
return compile_rt;
|
||||
}
|
||||
@@ -619,17 +610,6 @@ static void literal2clause_hash_free(struct literal_clause *hash)
|
||||
assert(hash == NULL);
|
||||
}
|
||||
|
||||
static void group_reference_hash_free(struct group_reference *group_ref_hash)
|
||||
{
|
||||
struct group_reference *group_ref = NULL, *tmp_group_ref = NULL;
|
||||
|
||||
HASH_ITER(hh, group_ref_hash, group_ref, tmp_group_ref) {
|
||||
HASH_DEL(group_ref_hash, group_ref);
|
||||
FREE(group_ref);
|
||||
}
|
||||
assert(group_ref_hash == NULL);
|
||||
}
|
||||
|
||||
void garbage_literal2clause_hash_free(void *l2c_hash, void *arg)
|
||||
{
|
||||
literal2clause_hash_free((struct literal_clause *)l2c_hash);
|
||||
@@ -663,14 +643,6 @@ void compile_runtime_free(void *compile_runtime)
|
||||
compile_rt->clause_by_literals_hash = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&(compile_rt->mutex));
|
||||
if (compile_rt->group_ref_hash != NULL) {
|
||||
group_reference_hash_free(compile_rt->group_ref_hash);
|
||||
compile_rt->group_ref_hash = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&(compile_rt->mutex));
|
||||
pthread_mutex_destroy(&(compile_rt->mutex));
|
||||
|
||||
if (compile_rt->expr_match_buff != NULL) {
|
||||
FREE(compile_rt->expr_match_buff);
|
||||
}
|
||||
@@ -1930,22 +1902,8 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group_reference *group_ref = NULL;
|
||||
if (0 == is_valid) {
|
||||
//delete
|
||||
pthread_mutex_lock(&(compile_rt->mutex));
|
||||
HASH_FIND(hh, compile_rt->group_ref_hash, (char *)&(g2c_item->group_id),
|
||||
sizeof(long long), group_ref);
|
||||
if (group_ref != NULL) {
|
||||
if (0 == group_ref->ref_by_compile_cnt) {
|
||||
HASH_DEL(compile_rt->group_ref_hash, group_ref);
|
||||
FREE(group_ref);
|
||||
} else {
|
||||
group_ref->ref_by_compile_cnt--;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&(compile_rt->mutex));
|
||||
|
||||
ret = maat_remove_group_from_compile(compile_rt->cfg_hash_tbl, g2c_item,
|
||||
compile_rt->logger);
|
||||
if (0 == ret) {
|
||||
@@ -1958,18 +1916,6 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
}
|
||||
} else {
|
||||
//add
|
||||
pthread_mutex_lock(&(compile_rt->mutex));
|
||||
HASH_FIND(hh, compile_rt->group_ref_hash, (char *)&(g2c_item->group_id),
|
||||
sizeof(long long), group_ref);
|
||||
if (NULL == group_ref) {
|
||||
group_ref = ALLOC(struct group_reference, 1);
|
||||
group_ref->group_id = g2c_item->group_id;
|
||||
HASH_ADD_KEYPTR(hh, compile_rt->group_ref_hash, (char *)&(group_ref->group_id),
|
||||
sizeof(long long), group_ref);
|
||||
}
|
||||
group_ref->ref_by_compile_cnt++;
|
||||
pthread_mutex_unlock(&(compile_rt->mutex));
|
||||
|
||||
ret = maat_add_group_to_compile(compile_rt->cfg_hash_tbl, g2c_item, compile_rt->logger);
|
||||
if (0 == ret) {
|
||||
if (g2c_item->not_flag) {
|
||||
@@ -1985,21 +1931,6 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int group_referenced_by_compile(struct compile_runtime *compile_rt, long long group_id)
|
||||
{
|
||||
struct group_reference *group_ref = NULL;
|
||||
|
||||
pthread_mutex_lock(&(compile_rt->mutex));
|
||||
HASH_FIND(hh, compile_rt->group_ref_hash, (char *)&group_id, sizeof(long long), group_ref);
|
||||
if (group_ref != NULL) {
|
||||
pthread_mutex_unlock(&(compile_rt->mutex));
|
||||
return 1;
|
||||
}
|
||||
pthread_mutex_unlock(&(compile_rt->mutex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long long group2compile_runtime_not_group_count(void *g2c_runtime)
|
||||
{
|
||||
if (NULL == g2c_runtime) {
|
||||
@@ -2290,22 +2221,17 @@ size_t maat_compile_state_get_internal_hit_paths(struct maat_compile_state *comp
|
||||
super_group_ids, MAX_SCANNER_HIT_GROUP_NUM);
|
||||
/* if super group is not referenced by compile, drop it */
|
||||
for (size_t idx = 0; idx < super_group_cnt; idx++) {
|
||||
if (0 == group_referenced_by_compile(compile_rt, super_group_ids[idx])) {
|
||||
continue;
|
||||
}
|
||||
utarray_push_back(valid_super_group_ids, &super_group_ids[idx]);
|
||||
}
|
||||
|
||||
/*
|
||||
if internal_path->group_id can be referenced directly by compile,
|
||||
internal_path->group_id can be referenced directly by compile,
|
||||
so add it to hit_path which super_group_ids is -1
|
||||
------------------------------------------------------------------------------
|
||||
NOTE: Add the hit path as long as the item is hit
|
||||
*/
|
||||
if (0 == utarray_len(valid_super_group_ids)) {
|
||||
long long super_group_id = -1;
|
||||
utarray_push_back(valid_super_group_ids, &super_group_id);
|
||||
}
|
||||
|
||||
long long *p = NULL;
|
||||
struct maat_hit_path tmp_path;
|
||||
|
||||
@@ -5506,13 +5506,20 @@ TEST_F(MaatCmdTest, HitPath) {
|
||||
struct maat_hit_path hit_path[128];
|
||||
memset(hit_path, 0, sizeof(hit_path));
|
||||
int n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
|
||||
EXPECT_EQ(n_read, 1);
|
||||
EXPECT_EQ(n_read, 2);
|
||||
|
||||
int path_idx = 0;
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item1_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group1_id);
|
||||
//EXPECT_EQ(hit_path[path_idx].top_group_id, group1_id);
|
||||
EXPECT_EQ(hit_path[path_idx].top_group_id, group11_id);
|
||||
EXPECT_EQ(hit_path[path_idx].vtable_id, http_req_table_id);
|
||||
EXPECT_EQ(hit_path[path_idx].compile_id, -1);
|
||||
|
||||
path_idx++;
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item1_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group1_id);
|
||||
EXPECT_EQ(hit_path[path_idx].top_group_id, -1);
|
||||
EXPECT_EQ(hit_path[path_idx].vtable_id, http_req_table_id);
|
||||
EXPECT_EQ(hit_path[path_idx].compile_id, -1);
|
||||
@@ -5542,7 +5549,17 @@ TEST_F(MaatCmdTest, HitPath) {
|
||||
EXPECT_EQ(hit_groups[3].vtable_id, http_req_table_id);
|
||||
|
||||
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
|
||||
EXPECT_EQ(n_read, 2);
|
||||
EXPECT_EQ(n_read, 4);
|
||||
|
||||
path_idx = 0;
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan-1);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item1_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group1_id);
|
||||
EXPECT_EQ(hit_path[path_idx].top_group_id, group11_id);
|
||||
EXPECT_EQ(hit_path[path_idx].compile_id, -1);
|
||||
|
||||
path_idx++;
|
||||
ASSERT_EQ(path_idx, 1);
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan-1);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item1_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group1_id);
|
||||
@@ -5550,7 +5567,7 @@ TEST_F(MaatCmdTest, HitPath) {
|
||||
EXPECT_EQ(hit_path[path_idx].compile_id, compile1_id);
|
||||
|
||||
path_idx++;
|
||||
ASSERT_EQ(path_idx, 1);
|
||||
ASSERT_EQ(path_idx, 2);
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item2_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group2_id);
|
||||
@@ -5558,6 +5575,14 @@ TEST_F(MaatCmdTest, HitPath) {
|
||||
EXPECT_EQ(hit_path[path_idx].vtable_id, http_res_table_id);
|
||||
EXPECT_EQ(hit_path[path_idx].compile_id, compile1_id);
|
||||
|
||||
path_idx++;
|
||||
ASSERT_EQ(path_idx, 3);
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item2_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group2_id);
|
||||
EXPECT_EQ(hit_path[path_idx].top_group_id, -1);
|
||||
EXPECT_EQ(hit_path[path_idx].vtable_id, http_res_table_id);
|
||||
EXPECT_EQ(hit_path[path_idx].compile_id, -1);
|
||||
const char* keywords1="In graph theory, a path in a graph is a finite or infinite \
|
||||
sequence of edges which joins a sequence of vertices which, by most definitions,\
|
||||
are all distinct (and since the vertices are distinct, so are the edges). ";
|
||||
@@ -5588,10 +5613,10 @@ that the edges be all directed in the same direction.";
|
||||
EXPECT_EQ(hit_groups[4].vtable_id, 0); //physical table(keywords_table) vtable_id is 0
|
||||
|
||||
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
|
||||
EXPECT_EQ(n_read, 3);
|
||||
EXPECT_EQ(n_read, 5);
|
||||
|
||||
path_idx++;
|
||||
ASSERT_EQ(path_idx, 2);
|
||||
ASSERT_EQ(path_idx, 4);
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item4_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group4_id);
|
||||
@@ -5626,10 +5651,10 @@ that the edges be all directed in the same direction.";
|
||||
EXPECT_EQ(hit_groups[5].vtable_id, 0); //physical table(keywords_table) vtable_id is 0
|
||||
|
||||
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
|
||||
EXPECT_EQ(n_read, 4);
|
||||
EXPECT_EQ(n_read, 6);
|
||||
|
||||
path_idx++;
|
||||
ASSERT_EQ(path_idx, 3);
|
||||
ASSERT_EQ(path_idx, 5);
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item3_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group3_id);
|
||||
@@ -5643,10 +5668,10 @@ that the edges be all directed in the same direction.";
|
||||
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
|
||||
|
||||
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
|
||||
EXPECT_EQ(n_read, 5);
|
||||
EXPECT_EQ(n_read, 7);
|
||||
|
||||
path_idx++;
|
||||
ASSERT_EQ(path_idx, 4);
|
||||
ASSERT_EQ(path_idx, 6);
|
||||
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
|
||||
EXPECT_EQ(hit_path[path_idx].item_id, item4_id);
|
||||
EXPECT_EQ(hit_path[path_idx].sub_group_id, group4_id);
|
||||
|
||||
Reference in New Issue
Block a user