From 4d17254a7e9cc0ee4c0420c89a748852c34daca8 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Fri, 21 Oct 2016 16:42:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=85=E9=A1=BB=E9=80=82=E9=85=8DRuleScan=20?= =?UTF-8?q?2016=5F10=5F21=E4=BB=A5=E4=B8=8A=E7=89=88=E6=9C=AC=E3=80=82=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=9C=A8=E9=94=80=E6=AF=81rulescan=E5=8F=A5?= =?UTF-8?q?=E6=9F=84=E5=90=8E=EF=BC=8C=E5=9C=A8rulescan=5Fendstream?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E6=AE=B5=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entry/Maat_api.cpp | 9 +++++++-- src/entry/Maat_rule.cpp | 4 ++-- src/entry/Maat_rule_internal.h | 1 + src/entry/Maat_stat.cpp | 6 +++++- src/inc_internal/rulescan.h | 15 +++++++++++++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp index 9bf65e6..86760c0 100644 --- a/src/entry/Maat_api.cpp +++ b/src/entry/Maat_api.cpp @@ -1297,9 +1297,14 @@ void Maat_stream_scan_string_end(stream_para_t* stream_para) if(sp->version==sp->feather->maat_version) { DEC_SCANNER_REF(scanner, sp->thread_num); - } + rulescan_endstream(sp->rs_stream_para); - rulescan_endstream(sp->rs_stream_para); + } + else + { + rulescan_endstream_simple(sp->rs_stream_para); + sp->feather->zombie_rs_stream--; + } } if(sp->last_cache!=NULL) diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index 2443dc4..da2c0f9 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -26,7 +26,7 @@ #include "mesa_fuzzy.h" #include "great_index_engine.h" -int MAAT_FRAME_VERSION_1_8_20161008=1; +int MAAT_FRAME_VERSION_1_8_20161021_zombie_stream=1; const char *maat_module="MAAT Frame"; const char* CHARSET_STRING[]={"NONE","gbk","big5","unicode","utf8","bin", @@ -2484,7 +2484,6 @@ void garbage_bury(MESA_lqueue_head garbage_q,void *logger) break; case GARBAGE_SCANNER: ref_cnt=aligment_int64_array_sum(bag->scanner->ref_cnt,bag->scanner->max_thread_num); - if(ref_cnt==0) { MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module, @@ -2795,6 +2794,7 @@ void *thread_rule_monitor(void *arg) { assert(feather->scanner->version>old_scanner->version); assert(old_scanner->tomb_ref==feather->garbage_q); + feather->zombie_rs_stream+=aligment_int64_array_sum(old_scanner->ref_cnt,old_scanner->max_thread_num); garbage_bagging(GARBAGE_SCANNER, old_scanner, feather->garbage_q); } feather->update_tmp_scanner=NULL; diff --git a/src/entry/Maat_rule_internal.h b/src/entry/Maat_rule_internal.h index 051b73e..ad4031a 100644 --- a/src/entry/Maat_rule_internal.h +++ b/src/entry/Maat_rule_internal.h @@ -365,6 +365,7 @@ struct _Maat_feather_t long long update_err_cnt;//sum of the same name variable in each table long long iconv_err_cnt;//sum of the same name variable in each table long long scan_err_cnt; + long long zombie_rs_stream; }; struct _maat_garbage_t { diff --git a/src/entry/Maat_stat.cpp b/src/entry/Maat_stat.cpp index cc57a68..6a9b0e8 100644 --- a/src/entry/Maat_stat.cpp +++ b/src/entry/Maat_stat.cpp @@ -13,7 +13,8 @@ enum MAAT_FS_STATUS{ STATUS_TOTAL_SCAN_CNT, STATUS_UPDATE_ERR_CNT, STATUS_ICONV_ERR_CNT, - STATUS_SCAN_ERR_CNT + STATUS_SCAN_ERR_CNT, + STATUS_ZOMBIE_RS_STREAM }; enum MAAT_FS_COLUMN @@ -52,6 +53,8 @@ void maat_stat_init(struct _Maat_feather_t* feather) feather->fs_status_id[STATUS_UPDATE_ERR_CNT]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"update_error"); feather->fs_status_id[STATUS_ICONV_ERR_CNT]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"iconv_error"); feather->fs_status_id[STATUS_SCAN_ERR_CNT]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"scan_error"); + feather->fs_status_id[STATUS_ZOMBIE_RS_STREAM]=FS_register(feather->stat_handle, FS_STYLE_STATUS, FS_CALC_CURRENT,"zombie_stream"); + feather->fs_column_id[COLUMN_TABLE_RULE_NUM]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"rule"); feather->fs_column_id[COLUMN_TABLE_REGEX_NUM]=FS_register(feather->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"regex"); @@ -277,6 +280,7 @@ void maat_stat_output(struct _Maat_feather_t* feather) FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_UPDATE_ERR_CNT], 0,FS_OP_SET,feather->update_err_cnt); FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_ICONV_ERR_CNT], 0,FS_OP_SET,feather->iconv_err_cnt); FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_SCAN_ERR_CNT], 0,FS_OP_SET,feather->scan_err_cnt); + FS_operate(feather->stat_handle, feather->fs_status_id[STATUS_ZOMBIE_RS_STREAM], 0,FS_OP_SET,feather->zombie_rs_stream); FS_passive_output(feather->stat_handle); return; diff --git a/src/inc_internal/rulescan.h b/src/inc_internal/rulescan.h index c2f66b1..f7a9a42 100644 --- a/src/inc_internal/rulescan.h +++ b/src/inc_internal/rulescan.h @@ -188,7 +188,7 @@ extern "C" unsigned int length[MAX_MATCH_POS_NUM]; /* 该规则所有命中结果的长度;如果该命中结果是在以前的数据包中命中的,则设置对应的length=0, 对于整数区间与IP类,长度置为0*/ }rule_result_t; - /* 布尔表达式的扫描结果类型 */ + /* 布尔表达式的扫描结果类型,quick模式下只有expr_id以及tag两项有效 */ typedef struct _scan_result_t { unsigned int expr_id; /* 与表达式的ID */ @@ -280,7 +280,8 @@ extern "C" int rulescan_computeresult(void * stream_param, scan_result_t * presults, unsigned int size); /* - 功能:结束流式扫描,释放流参数。 + 功能:结束流式扫描,释放流参数。正常流程情况下调用该接口释放流参数,正常流程指在结束流扫描之前还没有调用 + rulescan_destroy销毁rulescan句柄。 参数: stream_param [in]: 流参数指针。 返回值: @@ -288,6 +289,16 @@ extern "C" */ void rulescan_endstream(void * stream_param); + /* + 功能:结束流式扫描,释放流参数。对于先调用rulescan_destroy销毁了rulescan句柄之后再结束流扫描的情况, + 需要调用rulescan_endstream_simple来释放流参数,仅限于这种情况下才调用该接口。 + 参数: + stream_param [in]: 流参数指针。 + 返回值: + 无。 + */ + void rulescan_endstream_simple(void * stream_param); + /* 功能:非流式扫描接口,扫描结束后返回所有命中结果。 参数: