summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhengchao <[email protected]>2021-07-20 20:55:52 +0800
committerzhengchao <[email protected]>2021-07-20 20:55:52 +0800
commit72ffbd98096488bdf53e3e88080ff2b1878faaaf (patch)
tree7b23c49483a66c4725edb9a2981fde1d3915c8e3
parent524edff8bee015e9c1faad359d1a24749a286aa3 (diff)
修复bug:上一版本引入,region更新不能反映到compile命中;v3.4.1
改善Maat_hierarchy_compile_mid_udpate的处理性能。
-rw-r--r--src/entry/Maat_hierarchy.cpp15
-rw-r--r--src/entry/Maat_rule.cpp29
-rw-r--r--test/test_maatframe.cpp18
3 files changed, 32 insertions, 30 deletions
diff --git a/src/entry/Maat_hierarchy.cpp b/src/entry/Maat_hierarchy.cpp
index 7732a49..653fa59 100644
--- a/src/entry/Maat_hierarchy.cpp
+++ b/src/entry/Maat_hierarchy.cpp
@@ -1225,6 +1225,7 @@ struct Maat_hierarchy_compile_mid
time_t hier_ver;
size_t this_scan_region_hit_cnt;
int not_clause_hitted_flag;
+ int is_no_count_scan;
size_t hit_path_cnt;
UT_array* _internal_hit_paths;
@@ -1395,6 +1396,7 @@ void Maat_hierarchy_compile_mid_udpate(struct Maat_hierarchy* hier, struct Maat_
mid->Nth_scan=Nth_scan;
utarray_clear(mid->this_scan_hit_clause_ids);
}
+
int ret=0;
ret=Maat_hierarchy_hit_path_add(mid->_internal_hit_paths, region_id, virtual_table_id, Nth_scan, Nth_region_result);
if(!ret)
@@ -1414,6 +1416,7 @@ void Maat_hierarchy_compile_mid_udpate(struct Maat_hierarchy* hier, struct Maat_
{
return;
}
+ size_t new_clause_idx=utarray_len(mid->this_scan_hit_clause_ids);
for(i=0; i<utarray_len(r2c_val->clause_ids); i++)
{
clause_id=(unsigned long long*)utarray_eltptr(r2c_val->clause_ids, i);
@@ -1421,10 +1424,18 @@ void Maat_hierarchy_compile_mid_udpate(struct Maat_hierarchy* hier, struct Maat_
{
continue;
}
- utarray_push_back(mid->_all_hit_clause_array, clause_id);
- utarray_sort(mid->_all_hit_clause_array, compare_clause_id);
utarray_push_back(mid->this_scan_hit_clause_ids, clause_id);
}
+ if(utarray_len(mid->this_scan_hit_clause_ids)-new_clause_idx)
+ {
+ utarray_reserve(mid->_all_hit_clause_array, utarray_len(mid->this_scan_hit_clause_ids)-new_clause_idx);
+ for(i=new_clause_idx; i<utarray_len(mid->this_scan_hit_clause_ids); i++)
+ {
+ clause_id=(unsigned long long *)utarray_eltptr(mid->this_scan_hit_clause_ids, i);
+ utarray_push_back(mid->_all_hit_clause_array, clause_id);
+ }
+ utarray_sort(mid->_all_hit_clause_array, compare_clause_id);
+ }
return;
}
static int Maat_hierarchy_compile_has_clause(struct Maat_hierarchy_compile* compile, unsigned long long clause_id)
diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp
index 1e76572..04cbb9d 100644
--- a/src/entry/Maat_rule.cpp
+++ b/src/entry/Maat_rule.cpp
@@ -2328,23 +2328,22 @@ void do_scanner_update(struct Maat_scanner* scanner, int scan_thread_num, void*
int i=0, ret=0;
struct ip_matcher* old_ip_matcher=NULL;
struct FQDN_engine* old_fqdn_engine=NULL;
- if(scanner->to_update_compile_cnt+scanner->to_update_group_cnt>0)
+
+ ret=Maat_hierarchy_rebuild(scanner->hier);
+ if(ret!=0)
{
- ret=Maat_hierarchy_rebuild(scanner->hier);
- if(ret!=0)
- {
- MESA_handle_runtime_log(logger, RLOG_LV_FATAL, maat_module ,
- "Version %d hierarchy rebuild failed.",
- scanner->version);
- }
- else
- {
- MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module ,
- "Version %d hierarchy rebuild success, dedup string rule %lu.",
- scanner->version,
- scanner->dedup_expr_num);
- }
+ MESA_handle_runtime_log(logger, RLOG_LV_FATAL, maat_module ,
+ "Version %d hierarchy rebuild failed.",
+ scanner->version);
+ }
+ else
+ {
+ MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module ,
+ "Version %d hierarchy rebuild success, dedup string rule %lu.",
+ scanner->version,
+ scanner->dedup_expr_num);
}
+
scanner->dedup_expr_num=0;
rulescan_batch_update(scanner->region,
scanner->region_update_q,
diff --git a/test/test_maatframe.cpp b/test/test_maatframe.cpp
index 45e5f43..47d763b 100644
--- a/test/test_maatframe.cpp
+++ b/test/test_maatframe.cpp
@@ -4093,7 +4093,7 @@ TEST_F(MaatCmdTest, ScanStatusSetNoCount)
const char* ip_table_name="IP_PLUS_CONFIG", *app_id_table_name="APP_ID";
struct Maat_rule_t compile1;
- struct Maat_cmd_group2compile group11, group21, group22;
+ struct Maat_cmd_group2compile group11, group21;
struct Maat_cmd_region region11, region21, region22;
@@ -4169,22 +4169,14 @@ TEST_F(MaatCmdTest, ScanStatusSetNoCount)
//region11->group11--clause1-->compile1
// /
//region21->group21--clause2---/
- // /
- //region22->group22-/
-
-
- 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->/
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=42;
- Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region22, group22.group_id);
+ region22.interval_rule.up_boundary=region22.interval_rule.low_boundary=scan_app_id;
+ Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region22, group21.group_id);
sleep(1);