compile/plugin ex_schema support input param table_name

This commit is contained in:
liuwentan
2023-03-29 22:25:14 +08:00
parent 658625fde3
commit 10571d3de4
34 changed files with 369 additions and 242 deletions

View File

@@ -91,8 +91,8 @@ typedef void maat_start_callback_t(int update_type, void *u_param);
typedef void maat_update_callback_t(int table_id, const char *table_line, void *u_para); typedef void maat_update_callback_t(int table_id, const char *table_line, void *u_para);
typedef void maat_finish_callback_t(void *u_para); typedef void maat_finish_callback_t(void *u_para);
typedef void maat_ex_new_func_t(int table_id, const char *key, const char *table_line, typedef void maat_ex_new_func_t(const char *table_name, int table_id, const char *key,
void **ad, long argl, void *argp); const char *table_line, void **ad, long argl, void *argp);
typedef void maat_ex_free_func_t(int table_id, void **ad, long argl, void *argp); typedef void maat_ex_free_func_t(int table_id, void **ad, long argl, void *argp);
typedef void maat_ex_dup_func_t(int table_id, void **to, void **from, long argl, void *argp); typedef void maat_ex_dup_func_t(int table_id, void **to, void **from, long argl, void *argp);
@@ -136,7 +136,7 @@ int maat_table_callback_register(struct maat *instance, int table_id,
void *u_para); void *u_para);
/* maat plugin table API */ /* maat plugin table API */
int maat_plugin_table_ex_schema_register(struct maat *instance, int table_id, int maat_plugin_table_ex_schema_register(struct maat *instance, const char *table_name,
maat_ex_new_func_t *new_func, maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func, maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func, maat_ex_dup_func_t *dup_func,

View File

@@ -44,7 +44,7 @@ void *bool_plugin_runtime_new(void *bool_plugin_schema, int max_thread_num,
void bool_plugin_runtime_free(void *bool_plugin_runtime); void bool_plugin_runtime_free(void *bool_plugin_runtime);
int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_schema, int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_schema,
const char *line, int valid_column); const char *table_name, const char *line, int valid_column);
int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name); int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name);
struct ex_data_runtime *bool_plugin_runtime_get_ex_data_rt(void *bool_plugin_runtime); struct ex_data_runtime *bool_plugin_runtime_get_ex_data_rt(void *bool_plugin_runtime);

View File

@@ -53,7 +53,7 @@ void compile_runtime_free(void *compile_runtime);
void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt); void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt);
int compile_runtime_update(void *compile_runtime, void *compile_schema, int compile_runtime_update(void *compile_runtime, void *compile_schema,
const char *line, int valid_column); const char *table_name, const char *line, int valid_column);
int compile_runtime_commit(void *compile_runtime, const char *table_name); int compile_runtime_commit(void *compile_runtime, const char *table_name);
int compile_runtime_match(struct compile_runtime *compile_rt, long long *compile_ids, int compile_runtime_match(struct compile_runtime *compile_rt, long long *compile_ids,
@@ -78,7 +78,8 @@ void group2compile_runtime_init(void *g2c_runtime, void *compile_runtime, void *
void group2compile_runtime_free(void *g2c_runtime); void group2compile_runtime_free(void *g2c_runtime);
int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema, int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
const char *line, int valid_column); const char *table_name, const char *line,
int valid_column);
/* maat compile state API */ /* maat compile state API */
struct maat_compile_state; struct maat_compile_state;

View File

@@ -77,8 +77,8 @@ void ex_container_free(void *ctx, void *data);
/* ex_data_runtime ex data API */ /* ex_data_runtime ex data API */
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
struct ex_data_schema *ex_schema, struct ex_data_schema *ex_schema,
const char *row, const char *key, const char *table_name, const char *row,
size_t key_len); const char *key, size_t key_len);
int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt, int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt,
const char *key, size_t key_len, const char *key, size_t key_len,

View File

@@ -33,7 +33,8 @@ void *expr_runtime_new(void *expr_schema, int max_thread_num,
void expr_runtime_free(void *expr_runtime); void expr_runtime_free(void *expr_runtime);
int expr_runtime_update(void *expr_runtime, void *expr_schema, int expr_runtime_update(void *expr_runtime, void *expr_schema,
const char *line, int valid_column); const char *table_name, const char *line,
int valid_column);
int expr_runtime_commit(void *expr_runtime, const char *table_name); int expr_runtime_commit(void *expr_runtime, const char *table_name);
/* expr runtime scan API */ /* expr runtime scan API */

View File

@@ -35,7 +35,8 @@ void *flag_runtime_new(void *flag_schema, int max_thread_num,
void flag_runtime_free(void *flag_runtime); void flag_runtime_free(void *flag_runtime);
int flag_runtime_update(void *flag_runtime, void *flag_schema, int flag_runtime_update(void *flag_runtime, void *flag_schema,
const char *line, int valid_column); const char *table_name, const char *line,
int valid_column);
int flag_runtime_commit(void *flag_runtime, const char *table_name); int flag_runtime_commit(void *flag_runtime, const char *table_name);
/* flag runtime scan API */ /* flag runtime scan API */

View File

@@ -33,7 +33,8 @@ void *fqdn_runtime_new(void *fqdn_schema, int max_thread_num,
void fqdn_runtime_free(void *fqdn_runtime); void fqdn_runtime_free(void *fqdn_runtime);
int fqdn_runtime_update(void *fqdn_runtime, void *fqdn_schema, int fqdn_runtime_update(void *fqdn_runtime, void *fqdn_schema,
const char *line, int valid_column); const char *table_name, const char *line,
int valid_column);
int fqdn_runtime_commit(void *fqdn_runtime, const char *table_name); int fqdn_runtime_commit(void *fqdn_runtime, const char *table_name);
struct ex_data_runtime *fqdn_runtime_get_ex_data_rt(struct fqdn_runtime *fqdn_rt); struct ex_data_runtime *fqdn_runtime_get_ex_data_rt(struct fqdn_runtime *fqdn_rt);

View File

@@ -44,7 +44,7 @@ void *fqdn_plugin_runtime_new(void *fqdn_plugin_schema, int max_thread_num,
void fqdn_plugin_runtime_free(void *fqdn_plugin_runtime); void fqdn_plugin_runtime_free(void *fqdn_plugin_runtime);
int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_schema, int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_schema,
const char *line, int valid_column); const char *table_name, const char *line, int valid_column);
int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name); int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name);
struct ex_data_runtime *fqdn_plugin_runtime_get_ex_data_rt(void *fqdn_plugin_runtime); struct ex_data_runtime *fqdn_plugin_runtime_get_ex_data_rt(void *fqdn_plugin_runtime);

View File

@@ -24,8 +24,8 @@ struct maat_garbage_bin *maat_garbage_bin_new(int default_timeout);
void maat_garbage_bin_free(struct maat_garbage_bin *bin); void maat_garbage_bin_free(struct maat_garbage_bin *bin);
void maat_garbage_bagging(struct maat_garbage_bin* bin, void* garbage, void maat_garbage_bagging(struct maat_garbage_bin *bin, void *garbage, void *arg,
void (* func)(void *)); void (* func)(void *, void *));
void maat_garbage_collect_routine(struct maat_garbage_bin *bin); void maat_garbage_collect_routine(struct maat_garbage_bin *bin);

View File

@@ -47,7 +47,8 @@ int group2group_runtime_get_top_groups(void *g2g_runtime, long long *group_ids,
size_t n_group_ids, long long *top_group_ids); size_t n_group_ids, long long *top_group_ids);
int group2group_runtime_update(void *g2g_runtime, void *g2g_schema, int group2group_runtime_update(void *g2g_runtime, void *g2g_schema,
const char *line, int valid_column); const char *table_name, const char *line,
int valid_column);
int group2group_runtime_commit(void *g2g_runtime, const char *table_name); int group2group_runtime_commit(void *g2g_runtime, const char *table_name);
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -34,7 +34,7 @@ void *interval_runtime_new(void *interval_schema, int max_thread_num,
void interval_runtime_free(void *interval_runtime); void interval_runtime_free(void *interval_runtime);
int interval_runtime_update(void *interval_runtime, void *interval_schema, int interval_runtime_update(void *interval_runtime, void *interval_schema,
const char *line, int valid_column); const char *table_name,const char *line, int valid_column);
int interval_runtime_commit(void *interval_runtime, const char *table_name); int interval_runtime_commit(void *interval_runtime, const char *table_name);
/* interval runtime scan API */ /* interval runtime scan API */

View File

@@ -32,7 +32,8 @@ void *ip_runtime_new(void *ip_schema, int max_thread_num,
void ip_runtime_free(void *ip_runtime); void ip_runtime_free(void *ip_runtime);
int ip_runtime_update(void *ip_runtime, void *ip_schema, int ip_runtime_update(void *ip_runtime, void *ip_schema,
const char *line, int valid_column); const char *table_name, const char *line,
int valid_column);
int ip_runtime_commit(void *ip_runtime, const char *table_name); int ip_runtime_commit(void *ip_runtime, const char *table_name);
/* ip runtime scan API */ /* ip runtime scan API */

View File

@@ -44,7 +44,7 @@ void *ip_plugin_runtime_new(void *ip_plugin_schema, int max_thread_num,
void ip_plugin_runtime_free(void *ip_plugin_runtime); void ip_plugin_runtime_free(void *ip_plugin_runtime);
int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema, int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema,
const char *line, int valid_column); const char *table_name, const char *line, int valid_column);
int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name); int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name);
struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime); struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime);

View File

@@ -55,7 +55,8 @@ void *plugin_runtime_new(void *plugin_schema, int max_thread_num,
void plugin_runtime_free(void *plugin_runtime); void plugin_runtime_free(void *plugin_runtime);
int plugin_runtime_update(void *plugin_runtime, void *plugin_schema, int plugin_runtime_update(void *plugin_runtime, void *plugin_schema,
const char *line, int valid_column); const char *table_name, const char *line,
int valid_column);
int plugin_runtime_commit(void *plugin_runtime, const char *table_name); int plugin_runtime_commit(void *plugin_runtime, const char *table_name);
struct ex_data_runtime *plugin_runtime_get_ex_data_rt(void *plugin_runtime); struct ex_data_runtime *plugin_runtime_get_ex_data_rt(void *plugin_runtime);

View File

@@ -315,6 +315,10 @@ void maat_cmd_set_serial_rule(struct serial_rule *rule, enum maat_operation op,
long long rule_id, const char *table_name, long long rule_id, const char *table_name,
const char *line, long long timeout); const char *line, long long timeout);
void garbage_ip_matcher_free(void *ip_matcher, void *arg);
void garbage_interval_matcher_free(void *ip_matcher, void *arg);
void garbage_bool_matcher_free(void *bool_matcher, void *arg);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -73,7 +73,7 @@ long long table_manager_get_district_id(struct table_manager *tbl_mgr, const cha
void *table_manager_get_schema(struct table_manager *tbl_mgr, int table_id); void *table_manager_get_schema(struct table_manager *tbl_mgr, int table_id);
void *table_manager_get_runtime(struct table_manager *tbl_mgr, int table_id); void *table_manager_get_runtime(struct table_manager *tbl_mgr, int table_id);
int table_manager_update_runtime(struct table_manager *tbl_mgr, int table_id, const char *line); int table_manager_update_runtime(struct table_manager *tbl_mgr, const char *table_name, int table_id, const char *line);
void table_manager_commit_runtime(struct table_manager *tbl_mgr, int table_id); void table_manager_commit_runtime(struct table_manager *tbl_mgr, int table_id);
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -44,6 +44,7 @@
struct maat_stream { struct maat_stream {
struct maat *ref_maat_instance; struct maat *ref_maat_instance;
struct adapter_hs_stream *s_handle; //each physical table open one stream struct adapter_hs_stream *s_handle; //each physical table open one stream
int last_full_version;
int thread_id; int thread_id;
int vtable_id; int vtable_id;
int physical_table_id; int physical_table_id;
@@ -595,8 +596,8 @@ int generic_plugin_table_set_ex_schema(struct table_manager *tbl_mgr, int table_
return 0; return 0;
} }
void generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema, int table_id, void generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema, const char *table_name,
enum table_type table_type, int valid_column) int table_id, enum table_type table_type, int valid_column)
{ {
if (NULL == runtime || NULL == schema || valid_column < 0) { if (NULL == runtime || NULL == schema || valid_column < 0) {
return; return;
@@ -636,16 +637,16 @@ void generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema, int ta
const char *row = ex_data_runtime_cached_row_get(ex_data_rt, i); const char *row = ex_data_runtime_cached_row_get(ex_data_rt, i);
switch (table_type) { switch (table_type) {
case TABLE_TYPE_PLUGIN: case TABLE_TYPE_PLUGIN:
plugin_runtime_update(runtime, schema, row, valid_column); plugin_runtime_update(runtime, schema, table_name, row, valid_column);
break; break;
case TABLE_TYPE_IP_PLUGIN: case TABLE_TYPE_IP_PLUGIN:
ip_plugin_runtime_update(runtime, schema, row, valid_column); ip_plugin_runtime_update(runtime, schema, table_name, row, valid_column);
break; break;
case TABLE_TYPE_FQDN_PLUGIN: case TABLE_TYPE_FQDN_PLUGIN:
fqdn_plugin_runtime_update(runtime, schema, row, valid_column); fqdn_plugin_runtime_update(runtime, schema, table_name, row, valid_column);
break; break;
case TABLE_TYPE_BOOL_PLUGIN: case TABLE_TYPE_BOOL_PLUGIN:
bool_plugin_runtime_update(runtime, schema, row, valid_column); bool_plugin_runtime_update(runtime, schema, table_name, row, valid_column);
break; break;
default: default:
break; break;
@@ -655,23 +656,24 @@ void generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema, int ta
switch (table_type) { switch (table_type) {
case TABLE_TYPE_PLUGIN: case TABLE_TYPE_PLUGIN:
plugin_runtime_commit(runtime, "unknown"); plugin_runtime_commit(runtime, table_name);
break; break;
case TABLE_TYPE_IP_PLUGIN: case TABLE_TYPE_IP_PLUGIN:
ip_plugin_runtime_commit(runtime, "unknown"); ip_plugin_runtime_commit(runtime, table_name);
break; break;
case TABLE_TYPE_FQDN_PLUGIN: case TABLE_TYPE_FQDN_PLUGIN:
fqdn_plugin_runtime_commit(runtime, "unknown"); fqdn_plugin_runtime_commit(runtime, table_name);
break; break;
case TABLE_TYPE_BOOL_PLUGIN: case TABLE_TYPE_BOOL_PLUGIN:
bool_plugin_runtime_commit(runtime, "unknown"); bool_plugin_runtime_commit(runtime, table_name);
break; break;
default: default:
break; break;
} }
} }
int generic_plugin_table_ex_schema_register(struct maat *maat_instance, int table_id, int generic_plugin_table_ex_schema_register(struct maat *maat_instance,
const char *table_name, int table_id,
maat_ex_new_func_t *new_func, maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func, maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func, maat_ex_dup_func_t *dup_func,
@@ -697,22 +699,29 @@ int generic_plugin_table_ex_schema_register(struct maat *maat_instance, int tabl
return -1; return -1;
} }
generic_plugin_runtime_commit_ex_schema(runtime, schema, table_id, table_type, valid_column); generic_plugin_runtime_commit_ex_schema(runtime, schema, table_name, table_id,
table_type, valid_column);
} }
return 0; return 0;
} }
int maat_plugin_table_ex_schema_register(struct maat *maat_instance, int table_id, int maat_plugin_table_ex_schema_register(struct maat *maat_instance,
const char *table_name,
maat_ex_new_func_t *new_func, maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func, maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func, maat_ex_dup_func_t *dup_func,
long argl, void *argp) long argl, void *argp)
{ {
if (NULL == maat_instance || table_id < 0 || table_id >= MAX_TABLE_NUM) { if (NULL == maat_instance || NULL == table_name) {
log_error(maat_instance->logger, MODULE_MAAT_API, log_error(maat_instance->logger, MODULE_MAAT_API,
"[%s:%d] table(table_id:%d) input parameter is invalid.", "[%s:%d] [table:%s] ex_schema register input parameter is invalid.",
__FUNCTION__, __LINE__, table_id); __FUNCTION__, __LINE__, table_name);
return -1;
}
int table_id = maat_get_table_id(maat_instance, table_name);
if (table_id < 0) {
return -1; return -1;
} }
@@ -725,7 +734,7 @@ int maat_plugin_table_ex_schema_register(struct maat *maat_instance, int table_i
new_func, free_func, dup_func, new_func, free_func, dup_func,
argl, argp); argl, argp);
} else { } else {
ret = generic_plugin_table_ex_schema_register(maat_instance, table_id, ret = generic_plugin_table_ex_schema_register(maat_instance, table_name, table_id,
new_func, free_func, dup_func, new_func, free_func, dup_func,
argl, argp); argl, argp);
} }
@@ -1564,6 +1573,7 @@ struct maat_stream *maat_stream_new(struct maat *maat_instance, int table_id,
struct maat_stream *stream = ALLOC(struct maat_stream, 1); struct maat_stream *stream = ALLOC(struct maat_stream, 1);
stream->ref_maat_instance = maat_instance; stream->ref_maat_instance = maat_instance;
stream->last_full_version = maat_instance->last_full_version;
stream->thread_id = state->thread_id; stream->thread_id = state->thread_id;
stream->logger = maat_instance->logger; stream->logger = maat_instance->logger;
@@ -1614,17 +1624,7 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
state->scan_cnt++; state->scan_cnt++;
int valid_table_id = -1; if (maat_stream->last_full_version != maat_stream->ref_maat_instance->last_full_version) {
if (maat_stream->vtable_id != 0) {
valid_table_id = maat_stream->vtable_id;
} else {
valid_table_id = maat_stream->physical_table_id;
}
if (NULL == maat_stream->ref_maat_instance->maat_rt) {
log_error(maat_stream->logger, MODULE_MAAT_API,
"[%s:%d] table(table_id:%d) thread_id:%d maat_scan_stream error because of maat_runtime is NULL",
__FUNCTION__, __LINE__, valid_table_id, maat_stream->thread_id);
return MAAT_SCAN_OK; return MAAT_SCAN_OK;
} }

View File

@@ -217,8 +217,8 @@ void bool_plugin_runtime_free(void *bool_plugin_runtime)
} }
int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt, int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
struct ex_data_schema *ex_schema, const char *row, struct ex_data_schema *ex_schema, const char *table_name,
const char *key, size_t key_len, const char *row, const char *key, size_t key_len,
struct bool_expr *expr, int is_valid) struct bool_expr *expr, int is_valid)
{ {
int ret = -1; int ret = -1;
@@ -232,7 +232,7 @@ int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
} }
} else { } else {
// add // add
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row, key, key_len); void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, table_name, row, key, key_len);
struct ex_container *ex_container = ex_container_new(ex_data, (void *)expr); struct ex_container *ex_container = ex_container_new(ex_data, (void *)expr);
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container); ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
if (ret < 0) { if (ret < 0) {
@@ -286,7 +286,7 @@ int bool_plugin_accept_tag_match(struct bool_plugin_schema *schema, const char *
struct bool_expr * struct bool_expr *
bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema, bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
struct log_handle *logger) const char *table_name, struct log_handle *logger)
{ {
int ret = bool_plugin_accept_tag_match(schema, line, logger); int ret = bool_plugin_accept_tag_match(schema, line, logger);
if (ret == TAG_MATCH_UNMATCHED) { if (ret == TAG_MATCH_UNMATCHED) {
@@ -304,8 +304,8 @@ bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len); ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_BOOL_PLUGIN, log_error(logger, MODULE_BOOL_PLUGIN,
"[%s:%d] bool_plugin table(table_id:%d) line:%s has no item_id column", "[%s:%d] bool_plugin table:%s line:%s has no item_id column",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
bool_expr->expr_id = atoll(line + column_offset); bool_expr->expr_id = atoll(line + column_offset);
@@ -313,8 +313,8 @@ bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
ret = get_column_pos(line, schema->bool_expr_column, &column_offset, &column_len); ret = get_column_pos(line, schema->bool_expr_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_BOOL_PLUGIN, log_error(logger, MODULE_BOOL_PLUGIN,
"[%s:%d] bool_plugin table(table_id:%d) line:%s has no bool_expr column", "[%s:%d] bool_plugin table:%s line:%s has no bool_expr column",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
@@ -329,8 +329,8 @@ bool_plugin_expr_new(const char *line, struct bool_plugin_schema *schema,
n_item++; n_item++;
if (ret != 1 || n_item > MAX_ITEMS_PER_BOOL_EXPR) { if (ret != 1 || n_item > MAX_ITEMS_PER_BOOL_EXPR) {
log_error(logger, MODULE_BOOL_PLUGIN, log_error(logger, MODULE_BOOL_PLUGIN,
"[%s:%d] bool_plugin table(table_id:%d) invalid format of bool_expr column, line:%s", "[%s:%d] bool_plugin table:%s line:%s has invalid format of bool_expr column",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
} }
@@ -355,7 +355,7 @@ void bool_plugin_expr_free(struct bool_expr *expr)
} }
int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_schema, int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_schema,
const char *line, int valid_column) const char *table_name, const char *line, int valid_column)
{ {
if (NULL == bool_plugin_runtime || NULL == bool_plugin_schema || if (NULL == bool_plugin_runtime || NULL == bool_plugin_schema ||
NULL == line) { NULL == line) {
@@ -381,7 +381,7 @@ int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_sche
if (ex_schema != NULL) { if (ex_schema != NULL) {
if (1 == is_valid) { if (1 == is_valid) {
// add // add
bool_expr = bool_plugin_expr_new(line, schema, bool_plugin_rt->logger); bool_expr = bool_plugin_expr_new(line, schema, table_name, bool_plugin_rt->logger);
if (NULL == bool_expr) { if (NULL == bool_expr) {
return -1; return -1;
} }
@@ -389,8 +389,8 @@ int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_sche
const char *key = line + item_id_offset; const char *key = line + item_id_offset;
size_t key_len = item_id_len; size_t key_len = item_id_len;
ret = bool_plugin_runtime_update_row(bool_plugin_rt, ex_schema, line, key, key_len, ret = bool_plugin_runtime_update_row(bool_plugin_rt, ex_schema, table_name, line, key, key_len,
bool_expr, is_valid); bool_expr, is_valid);
if (ret < 0) { if (ret < 0) {
if (bool_expr != NULL) { if (bool_expr != NULL) {
bool_plugin_expr_free(bool_expr); bool_plugin_expr_free(bool_expr);
@@ -406,6 +406,12 @@ int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_sche
return 0; return 0;
} }
void garbage_bool_matcher_free(void *matcher, void *arg)
{
struct bool_matcher *bm = (struct bool_matcher *)matcher;
bool_matcher_free(bm);
}
int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name) int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name)
{ {
if (NULL == bool_plugin_runtime) { if (NULL == bool_plugin_runtime) {
@@ -459,8 +465,8 @@ int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name
old_bool_matcher = bool_plugin_rt->matcher; old_bool_matcher = bool_plugin_rt->matcher;
bool_plugin_rt->matcher = new_bool_matcher; bool_plugin_rt->matcher = new_bool_matcher;
if (old_bool_matcher != NULL) { if (old_bool_matcher != NULL) {
maat_garbage_bagging(bool_plugin_rt->ref_garbage_bin, old_bool_matcher, maat_garbage_bagging(bool_plugin_rt->ref_garbage_bin, old_bool_matcher, NULL,
(void (*)(void*))bool_matcher_free); garbage_bool_matcher_free);
} }
bool_plugin_rt->rule_num = rule_cnt; bool_plugin_rt->rule_num = rule_cnt;

View File

@@ -34,6 +34,7 @@ struct compile_schema {
int evaluation_order_column; int evaluation_order_column;
struct ex_data_schema *ex_schema; struct ex_data_schema *ex_schema;
int table_id; //ugly int table_id; //ugly
char table_name[NAME_MAX];
struct table_manager *ref_tbl_mgr; struct table_manager *ref_tbl_mgr;
unsigned long long update_err_cnt; unsigned long long update_err_cnt;
@@ -71,6 +72,7 @@ struct compile_runtime {
struct bool_matcher *bm; struct bool_matcher *bm;
struct maat_compile *compile_hash; // <compile_id, struct maat_compile> struct maat_compile *compile_hash; // <compile_id, struct maat_compile>
struct maat_runtime *ref_maat_rt; struct maat_runtime *ref_maat_rt;
time_t version;
uint32_t rule_num; uint32_t rule_num;
struct maat_clause *clause_by_literals_hash; struct maat_clause *clause_by_literals_hash;
pthread_rwlock_t rwlock; /* TODO: replaced with mutex? */ pthread_rwlock_t rwlock; /* TODO: replaced with mutex? */
@@ -116,6 +118,7 @@ struct compile_sort_para {
struct maat_compile { struct maat_compile {
unsigned int magic; unsigned int magic;
long long compile_id; long long compile_id;
char table_name[NAME_MAX];
int actual_clause_num; int actual_clause_num;
int declared_clause_num; int declared_clause_num;
int not_clause_cnt; int not_clause_cnt;
@@ -136,6 +139,7 @@ struct maat_internal_hit_path {
struct maat_compile_state { struct maat_compile_state {
int thread_id; int thread_id;
int Nth_scan; int Nth_scan;
time_t compile_rt_version;
size_t this_scan_hit_item_cnt; size_t this_scan_hit_item_cnt;
int not_clause_hitted_flag; int not_clause_hitted_flag;
int is_no_count_scan; int is_no_count_scan;
@@ -189,12 +193,13 @@ void *compile_runtime_get_user_data(struct compile_runtime *compile_rt, long lon
return ret; return ret;
} }
void *rule_ex_data_new(int table_id, const char *table_line, void *rule_ex_data_new(const char *table_name, int table_id, const char *table_line,
const struct ex_data_schema *ex_schema) const struct ex_data_schema *ex_schema)
{ {
void *ex_data = NULL; void *ex_data = NULL;
ex_schema->new_func(table_id, NULL, table_line, &ex_data, ex_schema->argl, ex_schema->argp); ex_schema->new_func(table_name, table_id, NULL, table_line, &ex_data,
ex_schema->argl, ex_schema->argp);
return ex_data; return ex_data;
} }
@@ -204,7 +209,7 @@ void rule_ex_data_free(int table_id, void **ex_data, const struct ex_data_schema
ex_schema->free_func(table_id, ex_data, ex_schema->argl, ex_schema->argp); ex_schema->free_func(table_id, ex_data, ex_schema->argl, ex_schema->argp);
} }
void rule_ex_data_new_cb(void *user_data, void *param, int table_id) void rule_ex_data_new_cb(void *user_data, void *param, const char *table_name, int table_id)
{ {
struct ex_data_schema *ex_schema = (struct ex_data_schema *)param; struct ex_data_schema *ex_schema = (struct ex_data_schema *)param;
struct compile_rule *compile = (struct compile_rule *)user_data; struct compile_rule *compile = (struct compile_rule *)user_data;
@@ -214,12 +219,12 @@ void rule_ex_data_new_cb(void *user_data, void *param, int table_id)
// return; // return;
// } // }
void *ad = rule_ex_data_new(table_id, compile->table_line, ex_schema); void *ad = rule_ex_data_new(table_name, table_id, compile->table_line, ex_schema);
*compile->ex_data = ad; *compile->ex_data = ad;
} }
void compile_runtime_user_data_iterate(struct compile_runtime *compile_rt, void compile_runtime_user_data_iterate(struct compile_runtime *compile_rt,
void (*callback)(void *user_data, void *param, int table_id), void (*callback)(void *user_data, void *param, const char *table_name, int table_id),
void *param, int table_id) void *param, int table_id)
{ {
struct maat_compile *compile = NULL, *tmp_compile = NULL; struct maat_compile *compile = NULL, *tmp_compile = NULL;
@@ -227,7 +232,7 @@ void compile_runtime_user_data_iterate(struct compile_runtime *compile_rt,
pthread_rwlock_rdlock(&compile_rt->rwlock); pthread_rwlock_rdlock(&compile_rt->rwlock);
HASH_ITER(hh, compile_rt->compile_hash, compile, tmp_compile) { HASH_ITER(hh, compile_rt->compile_hash, compile, tmp_compile) {
if (compile->user_data) { if (compile->user_data) {
callback(compile->user_data, param, table_id); callback(compile->user_data, param, compile->table_name, table_id);
} }
} }
pthread_rwlock_unlock(&compile_rt->rwlock); pthread_rwlock_unlock(&compile_rt->rwlock);
@@ -499,6 +504,7 @@ void *compile_runtime_new(void *compile_schema, int max_thread_num,
struct compile_runtime *compile_rt = ALLOC(struct compile_runtime, 1); struct compile_runtime *compile_rt = ALLOC(struct compile_runtime, 1);
compile_rt->expr_match_buff = ALLOC(struct bool_expr_match, max_thread_num * MAX_SCANNER_HIT_COMPILE_NUM); compile_rt->expr_match_buff = ALLOC(struct bool_expr_match, max_thread_num * MAX_SCANNER_HIT_COMPILE_NUM);
compile_rt->version = time(NULL);
compile_rt->clause_by_literals_hash = NULL; compile_rt->clause_by_literals_hash = NULL;
compile_rt->logger = logger; compile_rt->logger = logger;
compile_rt->ref_garbage_bin = garbage_bin; compile_rt->ref_garbage_bin = garbage_bin;
@@ -645,7 +651,7 @@ int is_valid_table_name(const char *str)
struct group2compile_item * struct group2compile_item *
group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema, group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema,
struct log_handle *logger) const char *table_name, struct log_handle *logger)
{ {
size_t column_offset = 0; size_t column_offset = 0;
size_t column_len = 0; size_t column_len = 0;
@@ -655,8 +661,8 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
int ret = get_column_pos(line, g2c_schema->group_id_column, &column_offset, &column_len); int ret = get_column_pos(line, g2c_schema->group_id_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_COMPILE, log_error(logger, MODULE_COMPILE,
"[%s:%d] group2compile table(table_id:%d) line:%s has no group_id", "[%s:%d] group2compile table:%s line:%s has no group_id",
__FUNCTION__, __LINE__, g2c_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
g2c_item->group_id = atoll(line + column_offset); g2c_item->group_id = atoll(line + column_offset);
@@ -664,8 +670,8 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
ret = get_column_pos(line, g2c_schema->compile_id_column, &column_offset, &column_len); ret = get_column_pos(line, g2c_schema->compile_id_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_COMPILE, log_error(logger, MODULE_COMPILE,
"[%s:%d] group2compile table(table_id:%d) line:%s has no compile_id", "[%s:%d] group2compile table:%s line:%s has no compile_id",
__FUNCTION__, __LINE__, g2c_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
g2c_item->compile_id = atoll(line + column_offset); g2c_item->compile_id = atoll(line + column_offset);
@@ -673,8 +679,8 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
ret = get_column_pos(line, g2c_schema->not_flag_column, &column_offset, &column_len); ret = get_column_pos(line, g2c_schema->not_flag_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_COMPILE, log_error(logger, MODULE_COMPILE,
"[%s:%d] group2compile table(table_id:%d) line:%s has no NOT_flag", "[%s:%d] group2compile table:%s line:%s has no NOT_flag",
__FUNCTION__, __LINE__, g2c_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
g2c_item->not_flag = atoi(line + column_offset); g2c_item->not_flag = atoi(line + column_offset);
@@ -682,15 +688,15 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
ret = get_column_pos(line, g2c_schema->vtable_name_column, &column_offset, &column_len); ret = get_column_pos(line, g2c_schema->vtable_name_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_COMPILE, log_error(logger, MODULE_COMPILE,
"[%s:%d] group2compile table(table_id:%d) line:%s has no virtual_table_name", "[%s:%d] group2compile table:%s line:%s has no virtual_table_name",
__FUNCTION__, __LINE__, g2c_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
if (column_len > NAME_MAX) { if (column_len > NAME_MAX) {
log_error(logger, MODULE_COMPILE, log_error(logger, MODULE_COMPILE,
"[%s:%d] group2compile table(table_id:%d) line:%s virtual_table_name length too long", "[%s:%d] group2compile table:%s line:%s virtual_table_name length too long",
__FUNCTION__, __LINE__, g2c_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
@@ -700,8 +706,8 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
g2c_item->vtable_id = table_manager_get_table_id(g2c_schema->ref_tbl_mgr, vtable_name); g2c_item->vtable_id = table_manager_get_table_id(g2c_schema->ref_tbl_mgr, vtable_name);
if (g2c_item->vtable_id < 0) { if (g2c_item->vtable_id < 0) {
log_error(logger, MODULE_COMPILE, log_error(logger, MODULE_COMPILE,
"[%s:%d] group2compile table(table_id:%d) line:%s unknown virtual table:%s", "[%s:%d] group2compile table:%s line:%s unknown virtual table:%s",
__FUNCTION__, __LINE__, g2c_schema->table_id, line, vtable_name); __FUNCTION__, __LINE__, table_name, line, vtable_name);
goto error; goto error;
} }
} }
@@ -709,8 +715,8 @@ group2compile_item_new(const char *line, struct group2compile_schema *g2c_schema
ret = get_column_pos(line, g2c_schema->clause_index_column, &column_offset, &column_len); ret = get_column_pos(line, g2c_schema->clause_index_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_COMPILE, log_error(logger, MODULE_COMPILE,
"[%s:%d] group2compile table(table_id:%d) line:%s has no clause_index", "[%s:%d] group2compile table:%s line:%s has no clause_index",
__FUNCTION__, __LINE__, g2c_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
@@ -748,13 +754,16 @@ struct maat_compile *maat_compile_new(long long compile_id)
return compile; return compile;
} }
int maat_compile_set(struct maat_compile *compile, int declared_clause_num, int maat_compile_set(struct maat_compile *compile, const char *table_name,
void *user_data, void (*user_data_free)(void *)) int declared_clause_num, void *user_data,
void (*user_data_free)(void *))
{ {
if (user_data != NULL && NULL == user_data_free) { if (user_data != NULL && NULL == user_data_free) {
return -1; return -1;
} }
memset(compile->table_name, 0, sizeof(compile->table_name));
memcpy(compile->table_name, table_name, sizeof(compile->table_name));
compile->declared_clause_num = declared_clause_num; compile->declared_clause_num = declared_clause_num;
compile->user_data = user_data; compile->user_data = user_data;
compile->user_data_free = user_data_free; compile->user_data_free = user_data_free;
@@ -784,8 +793,14 @@ int maat_compile_hash_add(struct maat_compile **compile_hash, long long compile_
return ret; return ret;
} }
void garbage_maat_compile_free(void *maat_compile, void *arg)
{
struct maat_compile *compile = (struct maat_compile *)maat_compile;
maat_compile_free(compile);
}
void maat_compile_hash_set(struct maat_compile **compile_hash, long long compile_id, void maat_compile_hash_set(struct maat_compile **compile_hash, long long compile_id,
struct maat_compile *compile) const char *table_name, struct maat_compile *compile)
{ {
struct maat_compile *tmp_compile = NULL; struct maat_compile *tmp_compile = NULL;
@@ -793,7 +808,7 @@ void maat_compile_hash_set(struct maat_compile **compile_hash, long long compile
assert(tmp_compile != NULL); assert(tmp_compile != NULL);
assert(tmp_compile->user_data == NULL); assert(tmp_compile->user_data == NULL);
maat_compile_set(tmp_compile, compile->declared_clause_num, maat_compile_set(tmp_compile, table_name, compile->declared_clause_num,
compile->user_data, compile->user_data_free); compile->user_data, compile->user_data_free);
} }
@@ -808,7 +823,7 @@ int maat_compile_hash_remove(struct maat_compile **compile_hash, struct maat_com
if (0 == compile->actual_clause_num) { if (0 == compile->actual_clause_num) {
HASH_DEL(*compile_hash, compile); HASH_DEL(*compile_hash, compile);
maat_garbage_bagging(garbage_bin, compile, (void (*)(void *))maat_compile_free); maat_garbage_bagging(garbage_bin, compile, NULL, garbage_maat_compile_free);
} }
//TODO:mytest need to delete //TODO:mytest need to delete
@@ -1033,11 +1048,6 @@ error:
return bm; return bm;
} }
void maat_compile_bool_matcher_free(struct bool_matcher *bm)
{
bool_matcher_free(bm);
}
static int maat_compile_has_clause(struct maat_compile *compile, long long clause_id) static int maat_compile_has_clause(struct maat_compile *compile, long long clause_id)
{ {
struct maat_clause_state *clause_state = NULL; struct maat_clause_state *clause_state = NULL;
@@ -1083,6 +1093,16 @@ size_t maat_compile_bool_matcher_match(struct compile_runtime *compile_rt, int i
struct bool_expr_match *expr_match = compile_rt->expr_match_buff + compile_state->thread_id * MAX_SCANNER_HIT_COMPILE_NUM; struct bool_expr_match *expr_match = compile_rt->expr_match_buff + compile_state->thread_id * MAX_SCANNER_HIT_COMPILE_NUM;
assert(compile_state->thread_id >= 0); assert(compile_state->thread_id >= 0);
if (0 == compile_state->compile_rt_version) {
compile_state->compile_rt_version = compile_rt->version;
}
if (NULL == compile_rt->bm || 0 == utarray_len(compile_state->all_hit_clauses)
|| compile_state->compile_rt_version != compile_rt->version) {
compile_state->this_scan_hit_item_cnt = 0;
return 0;
}
//TODO:mytest need to delete //TODO:mytest need to delete
#if 0 #if 0
unsigned long long *p = utarray_eltptr(compile_state->all_hit_clauses, 0); unsigned long long *p = utarray_eltptr(compile_state->all_hit_clauses, 0);
@@ -1181,7 +1201,7 @@ int maat_remove_group_from_compile(struct maat_compile **compile_hash,
if (0 == compile->actual_clause_num && NULL == compile->user_data) { if (0 == compile->actual_clause_num && NULL == compile->user_data) {
HASH_DEL(*compile_hash, compile); HASH_DEL(*compile_hash, compile);
maat_garbage_bagging(garbage_bin, compile, (void (*)(void*))maat_compile_free); maat_garbage_bagging(garbage_bin, compile, NULL, garbage_maat_compile_free);
} }
return 0; return 0;
@@ -1223,6 +1243,7 @@ void maat_compile_state_reset(struct maat_compile_state *compile_state)
} }
compile_state->Nth_scan = 0; compile_state->Nth_scan = 0;
compile_state->compile_rt_version = 0;
compile_state->this_scan_hit_item_cnt = 0; compile_state->this_scan_hit_item_cnt = 0;
compile_state->not_clause_hitted_flag = 0; compile_state->not_clause_hitted_flag = 0;
compile_state->is_no_count_scan = 0; compile_state->is_no_count_scan = 0;
@@ -1311,6 +1332,10 @@ size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt,
struct bool_expr_match *expr_match = compile_rt->expr_match_buff + compile_state->thread_id * MAX_SCANNER_HIT_COMPILE_NUM; struct bool_expr_match *expr_match = compile_rt->expr_match_buff + compile_state->thread_id * MAX_SCANNER_HIT_COMPILE_NUM;
assert(compile_state->thread_id >= 0); assert(compile_state->thread_id >= 0);
if (compile_state->compile_rt_version != compile_rt->version) {
return 0;
}
pthread_rwlock_rdlock(&compile_rt->rwlock); pthread_rwlock_rdlock(&compile_rt->rwlock);
int bool_match_ret = bool_matcher_match(compile_rt->bm, int bool_match_ret = bool_matcher_match(compile_rt->bm,
(unsigned long long *)utarray_eltptr(compile_state->all_hit_clauses, 0), (unsigned long long *)utarray_eltptr(compile_state->all_hit_clauses, 0),
@@ -1436,6 +1461,7 @@ int maat_compile_state_has_NOT_clause(struct maat_compile_state *compile_state)
void compile_item_to_compile_rule(struct compile_item *compile_item, void compile_item_to_compile_rule(struct compile_item *compile_item,
struct compile_schema *compile_schema, struct compile_schema *compile_schema,
struct compile_rule *compile_rule, struct compile_rule *compile_rule,
const char *table_name,
const char *table_line) const char *table_line)
{ {
compile_rule->magic_num = COMPILE_RULE_MAGIC; compile_rule->magic_num = COMPILE_RULE_MAGIC;
@@ -1448,8 +1474,9 @@ void compile_item_to_compile_rule(struct compile_item *compile_item,
compile_rule->evaluation_order = compile_item->evaluation_order; compile_rule->evaluation_order = compile_item->evaluation_order;
if (compile_schema->ex_schema != NULL) { if (compile_schema->ex_schema != NULL) {
*(compile_rule->ex_data) = rule_ex_data_new(compile_schema->table_id, compile_rule->table_line, *(compile_rule->ex_data) = rule_ex_data_new(table_name, compile_schema->table_id,
compile_schema->ex_schema); compile_rule->table_line,
compile_schema->ex_schema);
} }
compile_rule->compile_id = compile_item->compile_id; compile_rule->compile_id = compile_item->compile_id;
@@ -1507,7 +1534,8 @@ void *compile_runtime_get_ex_data(struct compile_runtime *compile_rt,
} }
int compile_runtime_update(void *compile_runtime, void *compile_schema, int compile_runtime_update(void *compile_runtime, void *compile_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == compile_runtime || NULL == compile_schema || if (NULL == compile_runtime || NULL == compile_schema ||
NULL == line) { NULL == line) {
@@ -1543,8 +1571,8 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
pthread_rwlock_unlock(&compile_rt->rwlock); pthread_rwlock_unlock(&compile_rt->rwlock);
if (ret < 0) { if (ret < 0) {
log_error(compile_rt->logger, MODULE_COMPILE, log_error(compile_rt->logger, MODULE_COMPILE,
"[%s:%d] remove compile table(table_id:%d) compile(compile_id:%lld) from compile_hash failed", "[%s:%d] remove compile table:%s compile(compile_id:%lld) from compile_hash failed",
__FUNCTION__, __LINE__, schema->table_id, compile_id); __FUNCTION__, __LINE__, table_name, compile_id);
return -1; return -1;
} }
} else { } else {
@@ -1558,7 +1586,7 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
} }
struct compile_rule *compile_rule = ALLOC(struct compile_rule, 1); struct compile_rule *compile_rule = ALLOC(struct compile_rule, 1);
compile_item_to_compile_rule(compile_item, schema, compile_rule, line); compile_item_to_compile_rule(compile_item, schema, compile_rule, table_name, line);
compile_item_free(compile_item); compile_item_free(compile_item);
compile_item = NULL; compile_item = NULL;
@@ -1567,16 +1595,16 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
destroy_compile_rule(compile_rule); destroy_compile_rule(compile_rule);
pthread_rwlock_unlock(&compile_rt->rwlock); pthread_rwlock_unlock(&compile_rt->rwlock);
log_error(compile_rt->logger, MODULE_COMPILE, log_error(compile_rt->logger, MODULE_COMPILE,
"[%s:%d] maat_compile_new failed, compile_table(table_id:%d) compile_id:%d", "[%s:%d] maat_compile_new failed, compile_table:%s compile_id:%d",
__FUNCTION__, __LINE__, schema->table_id, compile_item->compile_id); __FUNCTION__, __LINE__, table_name, compile_item->compile_id);
return -1; return -1;
} }
maat_compile_set(compile, compile_rule->declared_clause_num, compile_rule, maat_compile_set(compile, table_name, compile_rule->declared_clause_num, compile_rule,
(void (*)(void *))destroy_compile_rule); (void (*)(void *))destroy_compile_rule);
struct maat_compile *tmp_compile = maat_compile_hash_find(&(compile_rt->compile_hash), compile_id); struct maat_compile *tmp_compile = maat_compile_hash_find(&(compile_rt->compile_hash), compile_id);
if (tmp_compile != NULL) { if (tmp_compile != NULL) {
maat_compile_hash_set(&(compile_rt->compile_hash), compile_id, compile); maat_compile_hash_set(&(compile_rt->compile_hash), compile_id, table_name, compile);
} else { } else {
maat_compile_hash_add(&(compile_rt->compile_hash), compile_id, compile); maat_compile_hash_add(&(compile_rt->compile_hash), compile_id, compile);
} }
@@ -1590,7 +1618,8 @@ int compile_runtime_update(void *compile_runtime, void *compile_schema,
} }
int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema, int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == g2c_runtime || NULL == g2c_schema || NULL == line) { if (NULL == g2c_runtime || NULL == g2c_schema || NULL == line) {
return -1; return -1;
@@ -1606,7 +1635,8 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
} }
int ret = -1; int ret = -1;
struct group2compile_item *g2c_item = group2compile_item_new(line, schema, compile_rt->logger); struct group2compile_item *g2c_item = group2compile_item_new(line, schema, table_name,
compile_rt->logger);
if (NULL == g2c_item) { if (NULL == g2c_item) {
return -1; return -1;
} }
@@ -1691,8 +1721,8 @@ int compile_runtime_commit(void *compile_runtime, const char *table_name)
compile_rt->bm = new_bool_matcher; compile_rt->bm = new_bool_matcher;
pthread_rwlock_unlock(&compile_rt->rwlock); pthread_rwlock_unlock(&compile_rt->rwlock);
maat_garbage_bagging(compile_rt->ref_garbage_bin, old_bool_matcher, maat_garbage_bagging(compile_rt->ref_garbage_bin, old_bool_matcher, NULL,
(void (*)(void*))maat_compile_bool_matcher_free); garbage_bool_matcher_free);
compile_rt->rule_num = compile_cnt; compile_rt->rule_num = compile_cnt;

View File

@@ -179,12 +179,13 @@ ex_data_runtime_get_ex_container_schema(struct ex_data_runtime *ex_data_rt)
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
struct ex_data_schema *ex_schema, struct ex_data_schema *ex_schema,
const char *table_name,
const char *row, const char *key, const char *row, const char *key,
size_t key_len) size_t key_len)
{ {
void *ex_data = NULL; void *ex_data = NULL;
ex_schema->new_func(ex_data_rt->table_id, key, row, &ex_data, ex_schema->new_func(table_name, ex_data_rt->table_id, key, row, &ex_data,
ex_schema->argl, ex_schema->argp); ex_schema->argl, ex_schema->argp);
return ex_data; return ex_data;
} }

View File

@@ -691,7 +691,8 @@ error:
} }
int expr_runtime_update(void *expr_runtime, void *expr_schema, int expr_runtime_update(void *expr_runtime, void *expr_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == expr_runtime || NULL == expr_schema || if (NULL == expr_runtime || NULL == expr_schema ||
NULL == line) { NULL == line) {
@@ -729,8 +730,8 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
ret = rcu_hash_add(expr_rt->item_htable, (char *)&item_id, sizeof(item_id), item); ret = rcu_hash_add(expr_rt->item_htable, (char *)&item_id, sizeof(item_id), item);
if (ret < 0) { if (ret < 0) {
log_error(expr_rt->logger, MODULE_EXPR, log_error(expr_rt->logger, MODULE_EXPR,
"[%s:%d] expr runtime add item(item_id:%lld) to item_htable failed", "[%s:%d] [table:%s] expr runtime add item(item_id:%lld) failed",
__FUNCTION__, __LINE__, item_id); __FUNCTION__, __LINE__, table_name, item_id);
expr_item_free(expr_item); expr_item_free(expr_item);
maat_item_free(item); maat_item_free(item);
return -1; return -1;
@@ -740,8 +741,8 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
expr_item_free(expr_item); expr_item_free(expr_item);
if (NULL == expr_rule) { if (NULL == expr_rule) {
log_error(expr_rt->logger, MODULE_EXPR, log_error(expr_rt->logger, MODULE_EXPR,
"[%s:%d] transform expr table(table_id:%d) item(item_id:%lld) to expr_rule failed", "[%s:%d] [table:%s] transform expr_item(item_id:%lld) to expr_rule failed",
__FUNCTION__, __LINE__, schema->table_id, item_id); __FUNCTION__, __LINE__, table_name, item_id);
return -1; return -1;
} }
} }
@@ -759,6 +760,12 @@ int expr_runtime_update(void *expr_runtime, void *expr_schema,
return 0; return 0;
} }
void garbage_adapter_hs_free(void *adapter_hs, void *arg)
{
struct adapter_hs *hs = (struct adapter_hs *)adapter_hs;
adapter_hs_free(hs);
}
int expr_runtime_commit(void *expr_runtime, const char *table_name) int expr_runtime_commit(void *expr_runtime, const char *table_name)
{ {
if (NULL == expr_runtime) { if (NULL == expr_runtime) {
@@ -806,8 +813,7 @@ int expr_runtime_commit(void *expr_runtime, const char *table_name)
old_adapter_hs = expr_rt->hs; old_adapter_hs = expr_rt->hs;
expr_rt->hs = new_adapter_hs; expr_rt->hs = new_adapter_hs;
if (old_adapter_hs != NULL) { if (old_adapter_hs != NULL) {
maat_garbage_bagging(expr_rt->ref_garbage_bin, old_adapter_hs, maat_garbage_bagging(expr_rt->ref_garbage_bin, old_adapter_hs, NULL, garbage_adapter_hs_free);
(void (*)(void*))adapter_hs_free);
} }
rcu_hash_commit(expr_rt->item_htable); rcu_hash_commit(expr_rt->item_htable);
expr_rt->rule_num = rule_cnt; expr_rt->rule_num = rule_cnt;

View File

@@ -335,7 +335,8 @@ void flag_rule_free(struct flag_rule *rule)
} }
int flag_runtime_update(void *flag_runtime, void *flag_schema, int flag_runtime_update(void *flag_runtime, void *flag_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == flag_runtime || NULL == flag_schema || if (NULL == flag_runtime || NULL == flag_schema ||
NULL == line) { NULL == line) {
@@ -372,8 +373,8 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema,
ret = rcu_hash_add(flag_rt->item_htable, (char *)&(item_id), sizeof(item_id), item); ret = rcu_hash_add(flag_rt->item_htable, (char *)&(item_id), sizeof(item_id), item);
if (ret < 0) { if (ret < 0) {
log_error(flag_rt->logger, MODULE_FLAG, log_error(flag_rt->logger, MODULE_FLAG,
"[%s:%d] flag runtime add item(item_id:%lld) to item_htable failed", "[%s:%d] [table:%s] flag runtime add item(item_id:%lld) failed",
__FUNCTION__, __LINE__, item_id); __FUNCTION__, __LINE__, table_name, item_id);
flag_item_free(flag_item); flag_item_free(flag_item);
maat_item_free(item); maat_item_free(item);
return -1; return -1;
@@ -383,8 +384,8 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema,
flag_item_free(flag_item); flag_item_free(flag_item);
if (NULL == flag_rule) { if (NULL == flag_rule) {
log_error(flag_rt->logger, MODULE_FLAG, log_error(flag_rt->logger, MODULE_FLAG,
"[%s:%d] transform flag table(table_id:%d) item(item_id:%lld) to flag_rule failed", "[%s:%d] [table:%s] transform flag_item(item_id:%lld) to flag_rule failed",
__FUNCTION__, __LINE__, schema->table_id, item_id); __FUNCTION__, __LINE__, table_name, item_id);
return -1; return -1;
} }
} }
@@ -402,6 +403,12 @@ int flag_runtime_update(void *flag_runtime, void *flag_schema,
return 0; return 0;
} }
void garbage_flag_matcher_free(void *flag_matcher, void *arg)
{
struct flag_matcher *matcher = (struct flag_matcher *)flag_matcher;
flag_matcher_free(matcher);
}
int flag_runtime_commit(void *flag_runtime, const char *table_name) int flag_runtime_commit(void *flag_runtime, const char *table_name)
{ {
if (NULL == flag_runtime) { if (NULL == flag_runtime) {
@@ -448,8 +455,8 @@ int flag_runtime_commit(void *flag_runtime, const char *table_name)
old_flag_matcher = flag_rt->matcher; old_flag_matcher = flag_rt->matcher;
flag_rt->matcher = new_flag_matcher; flag_rt->matcher = new_flag_matcher;
if (old_flag_matcher != NULL) { if (old_flag_matcher != NULL) {
maat_garbage_bagging(flag_rt->ref_garbage_bin, old_flag_matcher, maat_garbage_bagging(flag_rt->ref_garbage_bin, old_flag_matcher, NULL,
(void (*)(void*))flag_matcher_free); garbage_flag_matcher_free);
} }
rcu_hash_commit(flag_rt->item_htable); rcu_hash_commit(flag_rt->item_htable);
flag_rt->rule_num = rule_cnt; flag_rt->rule_num = rule_cnt;

View File

@@ -61,7 +61,8 @@ void fqdn_runtime_free(void *fqdn_runtime)
} }
int fqdn_runtime_update(void *fqdn_runtime, void *fqdn_schema, int fqdn_runtime_update(void *fqdn_runtime, void *fqdn_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
return 0; return 0;
} }

View File

@@ -243,7 +243,7 @@ int fqdn_plugin_accept_tag_match(struct fqdn_plugin_schema *schema, const char *
struct FQDN_rule * struct FQDN_rule *
fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema, fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
struct log_handle *logger) const char *table_name, struct log_handle *logger)
{ {
int ret = fqdn_plugin_accept_tag_match(schema, line, logger); int ret = fqdn_plugin_accept_tag_match(schema, line, logger);
if (ret == TAG_MATCH_UNMATCHED) { if (ret == TAG_MATCH_UNMATCHED) {
@@ -259,8 +259,8 @@ fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len); ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_FQDN_PLUGIN, log_error(logger, MODULE_FQDN_PLUGIN,
"[%s:%d] fqdn_plugin table(table_id:%d) line:%s has no item_id column", "[%s:%d] fqdn_plugin table:%s line:%s has no item_id column",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
fqdn_plugin_rule->id = atoi(line + column_offset); fqdn_plugin_rule->id = atoi(line + column_offset);
@@ -268,8 +268,8 @@ fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
ret = get_column_pos(line, schema->suffix_flag_column, &column_offset, &column_len); ret = get_column_pos(line, schema->suffix_flag_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_FQDN_PLUGIN, log_error(logger, MODULE_FQDN_PLUGIN,
"[%s:%d] fqdn_plugin table(table_id:%d) line:%s has no suffix_match_method column", "[%s:%d] fqdn_plugin table:%s line:%s has no suffix_match_method column",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
fqdn_plugin_rule->is_suffix_match = atoi(line + column_offset); fqdn_plugin_rule->is_suffix_match = atoi(line + column_offset);
@@ -277,8 +277,8 @@ fqdn_plugin_rule_new(const char *line, struct fqdn_plugin_schema *schema,
ret = get_column_pos(line, schema->fqdn_column, &column_offset, &column_len); ret = get_column_pos(line, schema->fqdn_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_FQDN_PLUGIN, log_error(logger, MODULE_FQDN_PLUGIN,
"[%s:%d] fqdn_plugin table(table_id:%d) line:%s has no fqdn column", "[%s:%d] fqdn_plugin table:%s line:%s has no fqdn column",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
@@ -314,8 +314,8 @@ void fqdn_plugin_rule_free(struct FQDN_rule *rule)
} }
int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt, int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt,
struct ex_data_schema *ex_schema, const char *row, struct ex_data_schema *ex_schema, const char *table_name,
const char *key, size_t key_len, const char *row, const char *key, size_t key_len,
struct FQDN_rule *fqdn_plugin_rule, int is_valid) struct FQDN_rule *fqdn_plugin_rule, int is_valid)
{ {
int ret = -1; int ret = -1;
@@ -329,7 +329,7 @@ int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt,
} }
} else { } else {
// add // add
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row, key, key_len); void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, table_name, row, key, key_len);
struct ex_container *ex_container = ex_container_new(ex_data, (void *)fqdn_plugin_rule); struct ex_container *ex_container = ex_container_new(ex_data, (void *)fqdn_plugin_rule);
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container); ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
if (ret < 0) { if (ret < 0) {
@@ -341,7 +341,7 @@ int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt,
} }
int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_schema, int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_schema,
const char *line, int valid_column) const char *table_name, const char *line, int valid_column)
{ {
if (NULL == fqdn_plugin_runtime || NULL == fqdn_plugin_schema || if (NULL == fqdn_plugin_runtime || NULL == fqdn_plugin_schema ||
NULL == line) { NULL == line) {
@@ -367,7 +367,7 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
if (ex_schema != NULL) { if (ex_schema != NULL) {
if (1 == is_valid) { if (1 == is_valid) {
// add // add
fqdn_plugin_rule = fqdn_plugin_rule_new(line, schema, fqdn_plugin_rt->logger); fqdn_plugin_rule = fqdn_plugin_rule_new(line, schema, table_name, fqdn_plugin_rt->logger);
if (NULL == fqdn_plugin_rule) { if (NULL == fqdn_plugin_rule) {
return -1; return -1;
} }
@@ -375,7 +375,7 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
const char *key = line + item_id_offset; const char *key = line + item_id_offset;
size_t key_len = item_id_len; size_t key_len = item_id_len;
ret = fqdn_plugin_runtime_update_row(fqdn_plugin_rt, ex_schema, line, key, key_len, ret = fqdn_plugin_runtime_update_row(fqdn_plugin_rt, ex_schema, table_name, line, key, key_len,
fqdn_plugin_rule, is_valid); fqdn_plugin_rule, is_valid);
if (ret < 0) { if (ret < 0) {
if (fqdn_plugin_rule != NULL) { if (fqdn_plugin_rule != NULL) {
@@ -392,6 +392,12 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
return 0; return 0;
} }
void garbage_fqdn_engine_free(void *fqdn_engine, void *arg)
{
struct FQDN_engine *engine = (struct FQDN_engine *)fqdn_engine;
FQDN_engine_free(engine);
}
int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name) int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name)
{ {
if (NULL == fqdn_plugin_runtime) { if (NULL == fqdn_plugin_runtime) {
@@ -444,8 +450,8 @@ int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name
old_fqdn_engine = fqdn_plugin_rt->engine; old_fqdn_engine = fqdn_plugin_rt->engine;
fqdn_plugin_rt->engine = new_fqdn_engine; fqdn_plugin_rt->engine = new_fqdn_engine;
if (old_fqdn_engine != NULL) { if (old_fqdn_engine != NULL) {
maat_garbage_bagging(fqdn_plugin_rt->ref_garbage_bin, old_fqdn_engine, maat_garbage_bagging(fqdn_plugin_rt->ref_garbage_bin, old_fqdn_engine, NULL,
(void (*)(void*))FQDN_engine_free); garbage_fqdn_engine_free);
} }
fqdn_plugin_rt->rule_num = rule_cnt; fqdn_plugin_rt->rule_num = rule_cnt;

View File

@@ -20,7 +20,8 @@ struct maat_garbage_bag {
int timeout; int timeout;
int ok_times; int ok_times;
void *garbage; void *garbage;
void (* garbage_free)(void *garbage); void *arg;
void (* garbage_free)(void *garbage, void *arg);
TAILQ_ENTRY(maat_garbage_bag) entries; TAILQ_ENTRY(maat_garbage_bag) entries;
}; };
TAILQ_HEAD(maat_garbage_q, maat_garbage_bag); TAILQ_HEAD(maat_garbage_q, maat_garbage_bag);
@@ -46,7 +47,10 @@ void maat_garbage_bin_free(struct maat_garbage_bin* bin)
struct maat_garbage_bag *p = NULL; struct maat_garbage_bag *p = NULL;
while ((p = TAILQ_FIRST(&bin->garbage_q)) != NULL) { while ((p = TAILQ_FIRST(&bin->garbage_q)) != NULL) {
p->garbage_free(p->garbage); p->garbage_free(p->garbage, p->arg);
if (p->arg != NULL) {
FREE(p->arg);
}
TAILQ_REMOVE(&bin->garbage_q, p, entries); TAILQ_REMOVE(&bin->garbage_q, p, entries);
FREE(p); FREE(p);
bin->bag_cnt--; bin->bag_cnt--;
@@ -60,8 +64,8 @@ size_t maat_garbage_bin_get_size(struct maat_garbage_bin* bin)
return bin->bag_cnt; return bin->bag_cnt;
} }
void maat_garbage_bagging(struct maat_garbage_bin* bin, void* garbage, void maat_garbage_bagging(struct maat_garbage_bin* bin, void* garbage, void *arg,
void (* func)(void *)) void (* func)(void *, void *))
{ {
struct maat_garbage_bag *bag = ALLOC(struct maat_garbage_bag, 1); struct maat_garbage_bag *bag = ALLOC(struct maat_garbage_bag, 1);
@@ -81,7 +85,10 @@ void maat_garbage_collect_routine(struct maat_garbage_bin* bin)
for (p = TAILQ_FIRST(&bin->garbage_q); p != NULL; p = tmp) { for (p = TAILQ_FIRST(&bin->garbage_q); p != NULL; p = tmp) {
tmp = TAILQ_NEXT(p, entries); tmp = TAILQ_NEXT(p, entries);
if ((now - p->create_time) > p->timeout || p->timeout == 0) { if ((now - p->create_time) > p->timeout || p->timeout == 0) {
p->garbage_free(p->garbage); p->garbage_free(p->garbage, p->arg);
if (p->arg != NULL) {
FREE(p->arg);
}
TAILQ_REMOVE(&bin->garbage_q, p, entries); TAILQ_REMOVE(&bin->garbage_q, p, entries);
FREE(p); FREE(p);
n_clollected++; n_clollected++;
@@ -97,7 +104,10 @@ void maat_garbage_collect_by_force(struct maat_garbage_bin* bin)
{ {
struct maat_garbage_bag *p = NULL; struct maat_garbage_bag *p = NULL;
while ((p = TAILQ_FIRST(&bin->garbage_q)) != NULL) { while ((p = TAILQ_FIRST(&bin->garbage_q)) != NULL) {
p->garbage_free(p->garbage); p->garbage_free(p->garbage, p->arg);
if (p->arg != NULL) {
FREE(p->arg);
}
TAILQ_REMOVE(&bin->garbage_q, p, entries); TAILQ_REMOVE(&bin->garbage_q, p, entries);
FREE(p); FREE(p);
bin->bag_cnt--; bin->bag_cnt--;

View File

@@ -202,7 +202,7 @@ void maat_group_ref_dec(struct maat_group *group)
struct group2group_item * struct group2group_item *
group2group_item_new(const char *line, struct group2group_schema *g2g_schema, group2group_item_new(const char *line, struct group2group_schema *g2g_schema,
struct log_handle *logger) const char *table_name, struct log_handle *logger)
{ {
size_t column_offset = 0; size_t column_offset = 0;
size_t column_len = 0; size_t column_len = 0;
@@ -211,8 +211,8 @@ group2group_item_new(const char *line, struct group2group_schema *g2g_schema,
int ret = get_column_pos(line, g2g_schema->group_id_column, &column_offset, &column_len); int ret = get_column_pos(line, g2g_schema->group_id_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_GROUP, log_error(logger, MODULE_GROUP,
"[%s:%d] group2group table(table_id:%d) line:%s has no group_id", "[%s:%d] group2group table:%s line:%s has no group_id",
__FUNCTION__, __LINE__, g2g_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
g2g_item->group_id = atoll(line + column_offset); g2g_item->group_id = atoll(line + column_offset);
@@ -221,8 +221,8 @@ group2group_item_new(const char *line, struct group2group_schema *g2g_schema,
&column_offset, &column_len); &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_GROUP, log_error(logger, MODULE_GROUP,
"[%s:%d] group2group table(table_id:%d) line:%s has no super_group_id", "[%s:%d] group2group table:%s line:%s has no super_group_id",
__FUNCTION__, __LINE__, g2g_schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
g2g_item->super_group_id = atoll(line + column_offset); g2g_item->super_group_id = atoll(line + column_offset);
@@ -579,7 +579,8 @@ int group2group_runtime_build_top_groups(void *g2g_runtime)
} }
int group2group_runtime_update(void *g2g_runtime, void *g2g_schema, int group2group_runtime_update(void *g2g_runtime, void *g2g_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == g2g_runtime || NULL == g2g_schema || if (NULL == g2g_runtime || NULL == g2g_schema ||
NULL == line) { NULL == line) {
@@ -594,7 +595,8 @@ int group2group_runtime_update(void *g2g_runtime, void *g2g_schema,
return -1; return -1;
} }
struct group2group_item *g2g_item = group2group_item_new(line, schema, g2g_rt->logger); struct group2group_item *g2g_item = group2group_item_new(line, schema, table_name,
g2g_rt->logger);
if (NULL == g2g_item) { if (NULL == g2g_item) {
return -1; return -1;
} }

View File

@@ -331,7 +331,8 @@ int interval_runtime_update_row(struct interval_runtime *interval_rt, char *key,
} }
int interval_runtime_update(void *interval_runtime, void *interval_schema, int interval_runtime_update(void *interval_runtime, void *interval_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == interval_runtime || NULL == interval_schema || if (NULL == interval_runtime || NULL == interval_schema ||
NULL == line) { NULL == line) {
@@ -368,8 +369,8 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
ret = rcu_hash_add(interval_rt->item_htable, (char *)&(item_id), sizeof(item_id), item); ret = rcu_hash_add(interval_rt->item_htable, (char *)&(item_id), sizeof(item_id), item);
if (ret < 0) { if (ret < 0) {
log_error(interval_rt->logger, MODULE_INTERVAL, log_error(interval_rt->logger, MODULE_INTERVAL,
"[%s:%d] interval runtime add item(item_id:%lld) to item_htable failed", "[%s:%d] [table:%s] interval runtime add item(item_id:%lld) failed",
__FUNCTION__, __LINE__, item_id); __FUNCTION__, __LINE__, table_name, item_id);
interval_item_free(interval_item); interval_item_free(interval_item);
maat_item_free(item); maat_item_free(item);
return -1; return -1;
@@ -379,8 +380,8 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
interval_item_free(interval_item); interval_item_free(interval_item);
if (NULL == interval_rule) { if (NULL == interval_rule) {
log_error(interval_rt->logger, MODULE_INTERVAL, log_error(interval_rt->logger, MODULE_INTERVAL,
"[%s:%d] transform interval table(table_id:%d) item(item_id:%lld) to interval_rule failed", "[%s:%d] [table:%s] transform interval_item(item_id:%lld) to interval_rule failed",
__FUNCTION__, __LINE__, schema->table_id, item_id); __FUNCTION__, __LINE__, table_name, item_id);
return -1; return -1;
} }
} }
@@ -398,6 +399,12 @@ int interval_runtime_update(void *interval_runtime, void *interval_schema,
return 0; return 0;
} }
void garbage_interval_matcher_free(void *interval_matcher, void *arg)
{
struct interval_matcher *matcher = (struct interval_matcher *)interval_matcher;
interval_matcher_free(matcher);
}
int interval_runtime_commit(void *interval_runtime, const char *table_name) int interval_runtime_commit(void *interval_runtime, const char *table_name)
{ {
if (NULL == interval_runtime) { if (NULL == interval_runtime) {
@@ -444,8 +451,8 @@ int interval_runtime_commit(void *interval_runtime, const char *table_name)
old_interval_matcher = interval_rt->matcher; old_interval_matcher = interval_rt->matcher;
interval_rt->matcher = new_interval_matcher; interval_rt->matcher = new_interval_matcher;
if (old_interval_matcher != NULL) { if (old_interval_matcher != NULL) {
maat_garbage_bagging(interval_rt->ref_garbage_bin, old_interval_matcher, maat_garbage_bagging(interval_rt->ref_garbage_bin, old_interval_matcher, NULL,
(void (*)(void*))interval_matcher_free); garbage_interval_matcher_free);
} }
rcu_hash_commit(interval_rt->item_htable); rcu_hash_commit(interval_rt->item_htable);
interval_rt->rule_num = rule_cnt; interval_rt->rule_num = rule_cnt;

View File

@@ -472,7 +472,8 @@ int ip_runtime_update_row(struct ip_runtime *ip_rt, char *key, size_t key_len,
} }
int ip_runtime_update(void *ip_runtime, void *ip_schema, int ip_runtime_update(void *ip_runtime, void *ip_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == ip_runtime || NULL == ip_schema || NULL == line) { if (NULL == ip_runtime || NULL == ip_schema || NULL == line) {
return -1; return -1;
@@ -507,8 +508,8 @@ int ip_runtime_update(void *ip_runtime, void *ip_schema,
ret = rcu_hash_add(ip_rt->item_htable, (char *)&(item_id), sizeof(item_id), item); ret = rcu_hash_add(ip_rt->item_htable, (char *)&(item_id), sizeof(item_id), item);
if (ret < 0) { if (ret < 0) {
log_error(ip_rt->logger, MODULE_IP, log_error(ip_rt->logger, MODULE_IP,
"[%s:%d] ip runtime add item(item_id:%lld) to item_htable failed", "[%s:%d] [table:%s] ip runtime add item(item_id:%lld) failed",
__FUNCTION__, __LINE__, item_id); __FUNCTION__, __LINE__, table_name, item_id);
ip_item_free(ip_item); ip_item_free(ip_item);
maat_item_free(item); maat_item_free(item);
return -1; return -1;
@@ -528,6 +529,12 @@ int ip_runtime_update(void *ip_runtime, void *ip_schema,
return 0; return 0;
} }
void garbage_ip_matcher_free(void *ip_matcher, void *arg)
{
struct ip_matcher *matcher = (struct ip_matcher *)ip_matcher;
ip_matcher_free(matcher);
}
int ip_runtime_commit(void *ip_runtime, const char *table_name) int ip_runtime_commit(void *ip_runtime, const char *table_name)
{ {
if (NULL == ip_runtime) { if (NULL == ip_runtime) {
@@ -589,15 +596,15 @@ int ip_runtime_commit(void *ip_runtime, const char *table_name)
old_ip_matcher = ip_rt->ip_matcher; old_ip_matcher = ip_rt->ip_matcher;
ip_rt->ip_matcher = new_ip_matcher; ip_rt->ip_matcher = new_ip_matcher;
if (old_ip_matcher != NULL) { if (old_ip_matcher != NULL) {
maat_garbage_bagging(ip_rt->ref_garbage_bin, old_ip_matcher, maat_garbage_bagging(ip_rt->ref_garbage_bin, old_ip_matcher, NULL,
(void (*)(void *))ip_matcher_free); garbage_ip_matcher_free);
} }
old_intval_matcher = ip_rt->intval_matcher; old_intval_matcher = ip_rt->intval_matcher;
ip_rt->intval_matcher = new_intval_matcher; ip_rt->intval_matcher = new_intval_matcher;
if (old_intval_matcher != NULL) { if (old_intval_matcher != NULL) {
maat_garbage_bagging(ip_rt->ref_garbage_bin, old_intval_matcher, maat_garbage_bagging(ip_rt->ref_garbage_bin, old_intval_matcher, NULL,
(void (*)(void *))interval_matcher_free); garbage_interval_matcher_free);
} }
rcu_hash_commit(ip_rt->item_htable); rcu_hash_commit(ip_rt->item_htable);

View File

@@ -185,7 +185,7 @@ int ip_plugin_accept_tag_match(struct ip_plugin_schema *schema, const char *line
struct ip_rule * struct ip_rule *
ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema, ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
struct log_handle *logger) const char *table_name, struct log_handle *logger)
{ {
int ret = ip_plugin_accept_tag_match(schema, line, logger); int ret = ip_plugin_accept_tag_match(schema, line, logger);
if (ret == TAG_MATCH_UNMATCHED) { if (ret == TAG_MATCH_UNMATCHED) {
@@ -202,8 +202,8 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len); ret = get_column_pos(line, schema->item_id_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_IP_PLUGIN, log_error(logger, MODULE_IP_PLUGIN,
"[%s:%d] ip plugin table(table_id:%d) line:%s has no item_id", "[%s:%d] ip plugin table:%s line:%s has no item_id",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
ip_plugin_rule->rule_id = atoll(line + column_offset); ip_plugin_rule->rule_id = atoll(line + column_offset);
@@ -211,15 +211,15 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
ret = get_column_pos(line, schema->ip_type_column, &column_offset, &column_len); ret = get_column_pos(line, schema->ip_type_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_IP_PLUGIN, log_error(logger, MODULE_IP_PLUGIN,
"[%s:%d] ip plugin table(table_id:%d) line:%s has no ip_type", "[%s:%d] ip plugin table:%s line:%s has no ip_type",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
ip_plugin_rule->type = atoi(line + column_offset); ip_plugin_rule->type = atoi(line + column_offset);
if (ip_plugin_rule->type != IPv4 && ip_plugin_rule->type != IPv6) { if (ip_plugin_rule->type != IPv4 && ip_plugin_rule->type != IPv6) {
log_error(logger, MODULE_IP_PLUGIN, log_error(logger, MODULE_IP_PLUGIN,
"[%s:%d] ip_plugin table(table_id:%d) line:%s ip_type[%d] invalid", "[%s:%d] ip_plugin table:%s line:%s ip_type[%d] invalid",
__FUNCTION__, __LINE__, schema->table_id, line, ip_plugin_rule->type); __FUNCTION__, __LINE__, table_name, line, ip_plugin_rule->type);
goto error; goto error;
} }
@@ -247,8 +247,8 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
ret = get_column_pos(line, schema->start_ip_column, &column_offset, &column_len); ret = get_column_pos(line, schema->start_ip_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_IP_PLUGIN, log_error(logger, MODULE_IP_PLUGIN,
"[%s:%d] ip_plugin table(table_id:%d) line:%s has no start_ip", "[%s:%d] ip_plugin table:%s line:%s has no start_ip",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
strncpy(start_ip_str, line + column_offset, column_len); strncpy(start_ip_str, line + column_offset, column_len);
@@ -256,8 +256,8 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
ret = get_column_pos(line, schema->end_ip_column, &column_offset, &column_len); ret = get_column_pos(line, schema->end_ip_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_IP_PLUGIN, log_error(logger, MODULE_IP_PLUGIN,
"[%s:%d] ip_plugin table(table_id:%d) line:%s has no end_ip", "[%s:%d] ip_plugin table:%s line:%s has no end_ip",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
strncpy(end_ip_str, line + column_offset, column_len); strncpy(end_ip_str, line + column_offset, column_len);
@@ -269,8 +269,8 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
&ip_plugin_rule->ipv4_rule.end_ip); &ip_plugin_rule->ipv4_rule.end_ip);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_IP_PLUGIN, log_error(logger, MODULE_IP_PLUGIN,
"[%s:%d] ip_plugin table(table_id:%d) line:%s ip_format2range(ip4) failed", "[%s:%d] ip_plugin table:%s line:%s ip_format2range(ip4) failed",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
} else { } else {
@@ -281,8 +281,8 @@ ip_plugin_rule_new(const char *line, struct ip_plugin_schema *schema,
ip_plugin_rule->ipv6_rule.end_ip); ip_plugin_rule->ipv6_rule.end_ip);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_IP_PLUGIN, log_error(logger, MODULE_IP_PLUGIN,
"[%s:%d] ip_plugin table(table_id:%d) line:%s ip_format2range(ip6) failed", "[%s:%d] ip_plugin table:%s line:%s ip_format2range(ip6) failed",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
goto error; goto error;
} }
} }
@@ -311,8 +311,8 @@ void ip_plugin_table_set_ex_data_schema(void *ip_plugin_schema,
} }
int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt, int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt,
struct ex_data_schema *ex_schema, const char *row, struct ex_data_schema *ex_schema, const char *table_name,
const char *key, size_t key_len, const char *row, const char *key, size_t key_len,
struct ip_rule *ip_plugin_rule, int is_valid) struct ip_rule *ip_plugin_rule, int is_valid)
{ {
int ret = -1; int ret = -1;
@@ -329,7 +329,7 @@ int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt,
} }
} else { } else {
// add // add
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row, key, key_len); void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, table_name, row, key, key_len);
struct ex_container *ex_container = ex_container_new(ex_data, (void *)ip_plugin_rule); struct ex_container *ex_container = ex_container_new(ex_data, (void *)ip_plugin_rule);
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container); ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
if (ret < 0) { if (ret < 0) {
@@ -380,7 +380,8 @@ void ip_plugin_runtime_free(void *ip_plugin_runtime)
} }
int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema, int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == ip_plugin_runtime || NULL == ip_plugin_schema || if (NULL == ip_plugin_runtime || NULL == ip_plugin_schema ||
NULL == line) { NULL == line) {
@@ -406,7 +407,7 @@ int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema,
if (ex_schema != NULL) { if (ex_schema != NULL) {
if (1 == is_valid) { if (1 == is_valid) {
// add // add
ip_plugin_rule = ip_plugin_rule_new(line, schema, ip_plugin_rt->logger); ip_plugin_rule = ip_plugin_rule_new(line, schema, table_name, ip_plugin_rt->logger);
if (NULL == ip_plugin_rule) { if (NULL == ip_plugin_rule) {
return -1; return -1;
} }
@@ -414,8 +415,8 @@ int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema,
const char *key = line + item_id_offset; const char *key = line + item_id_offset;
size_t key_len = item_id_len; size_t key_len = item_id_len;
ret = ip_plugin_runtime_update_row(ip_plugin_rt, ex_schema, line, key, key_len, ret = ip_plugin_runtime_update_row(ip_plugin_rt, ex_schema, table_name, line, key, key_len,
ip_plugin_rule, is_valid); ip_plugin_rule, is_valid);
if (ret < 0) { if (ret < 0) {
if (ip_plugin_rule != NULL) { if (ip_plugin_rule != NULL) {
ip_plugin_rule_free(ip_plugin_rule); ip_plugin_rule_free(ip_plugin_rule);
@@ -484,8 +485,8 @@ int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name)
old_ip_matcher = ip_plugin_rt->ip_matcher; old_ip_matcher = ip_plugin_rt->ip_matcher;
ip_plugin_rt->ip_matcher = new_ip_matcher; ip_plugin_rt->ip_matcher = new_ip_matcher;
if (old_ip_matcher != NULL) { if (old_ip_matcher != NULL) {
maat_garbage_bagging(ip_plugin_rt->ref_garbage_bin, old_ip_matcher, maat_garbage_bagging(ip_plugin_rt->ref_garbage_bin, old_ip_matcher, NULL,
(void (*)(void*))ip_matcher_free); garbage_ip_matcher_free);
} }
ip_plugin_rt->rule_num = rule_cnt; ip_plugin_rt->rule_num = rule_cnt;

View File

@@ -291,8 +291,8 @@ void plugin_runtime_free(void *plugin_runtime)
int plugin_runtime_update_row(struct plugin_runtime *plugin_rt, int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
struct plugin_schema *plugin_schema, struct plugin_schema *plugin_schema,
const char *row, const char *key, const char *table_name, const char *row,
size_t key_len, int is_valid) const char *key, size_t key_len, int is_valid)
{ {
int ret = -1; int ret = -1;
struct ex_data_schema *ex_schema = plugin_schema->ex_schema; struct ex_data_schema *ex_schema = plugin_schema->ex_schema;
@@ -307,7 +307,8 @@ int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
} }
} else { } else {
// add // add
void *ex_data = ex_data_runtime_row2ex_data(plugin_rt->ex_data_rt, ex_schema, row, key, key_len); void *ex_data = ex_data_runtime_row2ex_data(plugin_rt->ex_data_rt, ex_schema,
table_name, row, key, key_len);
struct ex_container *ex_container = ex_container_new(ex_data, NULL); struct ex_container *ex_container = ex_container_new(ex_data, NULL);
ret = ex_data_runtime_add_ex_container(plugin_rt->ex_data_rt, key, key_len, ex_container); ret = ex_data_runtime_add_ex_container(plugin_rt->ex_data_rt, key, key_len, ex_container);
if (ret < 0) { if (ret < 0) {
@@ -332,8 +333,8 @@ int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
return 0; return 0;
} }
int plugin_accept_tag_match(struct plugin_schema *schema, const char *line, int plugin_accept_tag_match(struct plugin_schema *schema, const char *table_name,
struct log_handle *logger) const char *line, struct log_handle *logger)
{ {
size_t column_offset = 0; size_t column_offset = 0;
size_t column_len = 0; size_t column_len = 0;
@@ -343,8 +344,8 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *line,
int ret = get_column_pos(line, schema->rule_tag_column, &column_offset, &column_len); int ret = get_column_pos(line, schema->rule_tag_column, &column_offset, &column_len);
if (ret < 0) { if (ret < 0) {
log_error(logger, MODULE_PLUGIN, log_error(logger, MODULE_PLUGIN,
"[%s:%d] plugin table(table_id:%d) has no rule_tag, line:%s", "[%s:%d] plugin table:%s has no rule_tag, line:%s",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
schema->update_err_cnt++; schema->update_err_cnt++;
return TAG_MATCH_ERR; return TAG_MATCH_ERR;
} }
@@ -356,8 +357,8 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *line,
FREE(tag_str); FREE(tag_str);
if (TAG_MATCH_ERR == ret) { if (TAG_MATCH_ERR == ret) {
log_error(logger, MODULE_PLUGIN, log_error(logger, MODULE_PLUGIN,
"[%s:%d] plugin table(table_id:%d) has invalid tag format, line:%s", "[%s:%d] plugin table:%s has invalid tag format, line:%s",
__FUNCTION__, __LINE__, schema->table_id, line); __FUNCTION__, __LINE__, table_name, line);
schema->update_err_cnt++; schema->update_err_cnt++;
return TAG_MATCH_ERR; return TAG_MATCH_ERR;
} }
@@ -373,7 +374,8 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *line,
} }
int plugin_runtime_update(void *plugin_runtime, void *plugin_schema, int plugin_runtime_update(void *plugin_runtime, void *plugin_schema,
const char *line, int valid_column) const char *table_name, const char *line,
int valid_column)
{ {
if (NULL == plugin_runtime || NULL == plugin_schema || if (NULL == plugin_runtime || NULL == plugin_schema ||
NULL == line) { NULL == line) {
@@ -387,7 +389,7 @@ int plugin_runtime_update(void *plugin_runtime, void *plugin_schema,
return -1; return -1;
} }
int ret = plugin_accept_tag_match(schema, line, plugin_rt->logger); int ret = plugin_accept_tag_match(schema, table_name, line, plugin_rt->logger);
if (ret == TAG_MATCH_UNMATCHED) { if (ret == TAG_MATCH_UNMATCHED) {
return -1; return -1;
} }
@@ -406,7 +408,8 @@ int plugin_runtime_update(void *plugin_runtime, void *plugin_schema,
key_len = sizeof(long long); key_len = sizeof(long long);
} }
ret = plugin_runtime_update_row(plugin_rt, schema, line, key, key_len, is_valid); ret = plugin_runtime_update_row(plugin_rt, schema, table_name, line,
key, key_len, is_valid);
if (ret < 0) { if (ret < 0) {
schema->update_err_cnt++; schema->update_err_cnt++;
return -1; return -1;

View File

@@ -310,6 +310,12 @@ void maat_runtime_destroy(struct maat_runtime *maat_rt)
FREE(maat_rt); FREE(maat_rt);
} }
void garbage_maat_runtime_destroy(void *maat_runtime, void *arg)
{
struct maat_runtime *maat_rt = (struct maat_runtime *)maat_runtime;
maat_runtime_destroy(maat_rt);
}
void maat_start_cb(long long new_version, int update_type, void *u_param) void maat_start_cb(long long new_version, int update_type, void *u_param)
{ {
struct maat *maat_instance = (struct maat *)u_param; struct maat *maat_instance = (struct maat *)u_param;
@@ -376,7 +382,7 @@ int maat_update_cb(const char *table_name, const char *line, void *u_param)
maat_rt = maat_instance->maat_rt; maat_rt = maat_instance->maat_rt;
} }
table_manager_update_runtime(maat_rt->ref_tbl_mgr, table_id, line); table_manager_update_runtime(maat_rt->ref_tbl_mgr, table_name, table_id, line);
return 0; return 0;
} }
@@ -530,8 +536,8 @@ void *rule_monitor_loop(void *arg)
"Maat version roll back %lld -> %lld\n", "Maat version roll back %lld -> %lld\n",
old_maat_rt->version, maat_instance->maat_rt->version); old_maat_rt->version, maat_instance->maat_rt->version);
} }
maat_garbage_bagging(maat_instance->garbage_bin, old_maat_rt, maat_garbage_bagging(maat_instance->garbage_bin, old_maat_rt, NULL,
(void (*)(void*))maat_runtime_destroy); garbage_maat_runtime_destroy);
} }
maat_instance->creating_maat_rt = NULL; maat_instance->creating_maat_rt = NULL;

View File

@@ -64,15 +64,17 @@ struct table_manager {
struct table_operations { struct table_operations {
enum table_type type; enum table_type type;
void *(*new_schema)(cJSON *json, struct table_manager *tbl_mgr, const char *table_name, void *(*new_schema)(cJSON *json, struct table_manager *tbl_mgr,
struct log_handle *logger); const char *table_name, struct log_handle *logger);
void (*free_schema)(void *schema); void (*free_schema)(void *schema);
void *(*new_runtime)(void *schema, int max_thread_num, struct maat_garbage_bin *garbage_bin, void *(*new_runtime)(void *schema, int max_thread_num,
struct maat_garbage_bin *garbage_bin,
struct log_handle *logger); struct log_handle *logger);
void (*free_runtime)(void *runtime); void (*free_runtime)(void *runtime);
int (*update_runtime)(void *runtime, void *schema, const char *line, int valid_column); int (*update_runtime)(void *runtime, void *schema, const char *table_name,
const char *line, int valid_column);
int (*commit_runtime)(void *runtime, const char *table_name); int (*commit_runtime)(void *runtime, const char *table_name);
}; };
@@ -559,6 +561,12 @@ void *maat_table_runtime_new(void *schema, enum table_type table_type,
return runtime; return runtime;
} }
void garbage_maat_table_runtime_free(void *runtime, void *arg)
{
enum table_type type = *(enum table_type *)arg;
maat_table_runtime_free(runtime, type);
}
int table_manager_runtime_create(struct table_manager *tbl_mgr, int max_thread_num, int table_manager_runtime_create(struct table_manager *tbl_mgr, int max_thread_num,
struct maat_garbage_bin *garbage_bin) struct maat_garbage_bin *garbage_bin)
{ {
@@ -578,7 +586,13 @@ int table_manager_runtime_create(struct table_manager *tbl_mgr, int max_thread_n
} }
table_type = table_manager_get_table_type(tbl_mgr, i); table_type = table_manager_get_table_type(tbl_mgr, i);
assert(NULL == tbl_mgr->tbl[i]->runtime); void *runtime = table_manager_get_runtime(tbl_mgr, i);
if (runtime != NULL) {
enum table_type *arg = ALLOC(enum table_type, 1);
*arg = table_type;
maat_garbage_bagging(garbage_bin, runtime, arg, garbage_maat_table_runtime_free);
}
tbl_mgr->tbl[i]->runtime = maat_table_runtime_new(schema, table_type, max_thread_num, tbl_mgr->tbl[i]->runtime = maat_table_runtime_new(schema, table_type, max_thread_num,
garbage_bin, tbl_mgr->logger); garbage_bin, tbl_mgr->logger);
} }
@@ -790,8 +804,14 @@ void *table_manager_get_runtime(struct table_manager *tbl_mgr, int table_id)
return tbl_mgr->tbl[table_id]->runtime; return tbl_mgr->tbl[table_id]->runtime;
} }
int table_manager_update_runtime(struct table_manager *tbl_mgr, int table_id, void garbage_maat_kv_store_free(void *maat_kv_store, void *arg)
const char *line) {
struct maat_kv_store *kv_store = (struct maat_kv_store *)maat_kv_store;
maat_kv_store_free(kv_store);
}
int table_manager_update_runtime(struct table_manager *tbl_mgr, const char *table_name,
int table_id, const char *line)
{ {
void *schema = table_manager_get_schema(tbl_mgr, table_id); void *schema = table_manager_get_schema(tbl_mgr, table_id);
if (NULL == schema) { if (NULL == schema) {
@@ -817,13 +837,14 @@ int table_manager_update_runtime(struct table_manager *tbl_mgr, int table_id,
return -1; return -1;
} }
int ret = table_ops[table_type].update_runtime(runtime, schema, line, valid_column); int ret = table_ops[table_type].update_runtime(runtime, schema, table_name,
line, valid_column);
if (tbl_mgr->tmp_district_map != NULL) { if (tbl_mgr->tmp_district_map != NULL) {
struct maat_kv_store *tmp_map = tbl_mgr->district_map; struct maat_kv_store *tmp_map = tbl_mgr->district_map;
tbl_mgr->district_map = tbl_mgr->tmp_district_map; tbl_mgr->district_map = tbl_mgr->tmp_district_map;
tbl_mgr->tmp_district_map = NULL; tbl_mgr->tmp_district_map = NULL;
maat_garbage_bagging(tbl_mgr->ref_garbage_bin, tmp_map, (void (*)(void *))maat_kv_store_free); maat_garbage_bagging(tbl_mgr->ref_garbage_bin, tmp_map, NULL, garbage_maat_kv_store_free);
} }
return ret; return ret;

View File

@@ -21,8 +21,8 @@ struct user_info {
int ref_cnt; int ref_cnt;
}; };
void ex_data_new_cb(int table_id, const char *key, const char *table_line, void ex_data_new_cb(const char *table_name, int table_id, const char *key, const char *table_line,
void **ad, long argl, void *argp) void **ad, long argl, void *argp)
{ {
int *counter = (int *)argp; int *counter = (int *)argp;
struct user_info *u = ALLOC(struct user_info, 1); struct user_info *u = ALLOC(struct user_info, 1);
@@ -64,7 +64,7 @@ TEST(EXDataRuntime, Update) {
const char *row1 = "1\t192.168.0.1\tmahuateng\t1\t0"; const char *row1 = "1\t192.168.0.1\tmahuateng\t1\t0";
const char *key1 = "192.168.0.1"; const char *key1 = "192.168.0.1";
size_t key1_len = strlen(key1); size_t key1_len = strlen(key1);
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row1, key1, key1_len); void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, table_name, row1, key1, key1_len);
EXPECT_EQ(ex_data_counter, 1); EXPECT_EQ(ex_data_counter, 1);
struct ex_container *ex_container = ex_container_new(ex_data, NULL); struct ex_container *ex_container = ex_container_new(ex_data, NULL);
@@ -74,7 +74,7 @@ TEST(EXDataRuntime, Update) {
const char *row2 = "2\t192.168.0.2\tliyanhong\t1\t0"; const char *row2 = "2\t192.168.0.2\tliyanhong\t1\t0";
const char *key2 = "192.168.0.2"; const char *key2 = "192.168.0.2";
size_t key2_len = strlen(key2); size_t key2_len = strlen(key2);
ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row2, key2, key2_len); ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, table_name, row2, key2, key2_len);
ex_container = ex_container_new(ex_data, NULL); ex_container = ex_container_new(ex_data, NULL);
ret = ex_data_runtime_add_ex_container(ex_data_rt, key2, key2_len, ex_container); ret = ex_data_runtime_add_ex_container(ex_data_rt, key2, key2_len, ex_container);
EXPECT_EQ(ret, 0); EXPECT_EQ(ret, 0);

View File

@@ -1884,8 +1884,8 @@ struct plugin_ud {
int ref_cnt; int ref_cnt;
}; };
void plugin_EX_new_cb(int table_id, const char *key, const char *table_line, void plugin_EX_new_cb(const char *table_name, int table_id, const char *key,
void **ad, long argl, void *argp) const char *table_line, void **ad, long argl, void *argp)
{ {
int *counter = (int *)argp; int *counter = (int *)argp;
int valid = 0, tag = 0; int valid = 0, tag = 0;
@@ -1922,7 +1922,7 @@ TEST_F(PluginTable, EX_DATA) {
ASSERT_GT(table_id, 0); ASSERT_GT(table_id, 0);
int plugin_ex_data_counter = 0; int plugin_ex_data_counter = 0;
int ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, int ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
plugin_EX_new_cb, plugin_EX_new_cb,
plugin_EX_free_cb, plugin_EX_free_cb,
plugin_EX_dup_cb, plugin_EX_dup_cb,
@@ -1954,7 +1954,7 @@ TEST_F(PluginTable, KEY_TYPE) {
ASSERT_GT(table_id, 0); ASSERT_GT(table_id, 0);
int plugin_ex_data_counter = 0; int plugin_ex_data_counter = 0;
int ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, int ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
plugin_EX_new_cb, plugin_EX_new_cb,
plugin_EX_free_cb, plugin_EX_free_cb,
plugin_EX_dup_cb, plugin_EX_dup_cb,
@@ -2025,8 +2025,8 @@ struct ip_plugin_ud {
char *buffer; char *buffer;
int ref_cnt; int ref_cnt;
}; };
void ip_plugin_ex_new_cb(int table_id, const char *key, const char *table_line, void ip_plugin_ex_new_cb(const char *table_name, int table_id, const char *key,
void **ad, long argl, void *argp) const char *table_line, void **ad, long argl, void *argp)
{ {
int *counter = (int *)argp; int *counter = (int *)argp;
size_t column_offset=0, column_len=0; size_t column_offset=0, column_len=0;
@@ -2072,7 +2072,7 @@ TEST_F(IPPluginTable, EX_DATA) {
int table_id = maat_get_table_id(maat_instance, table_name); int table_id = maat_get_table_id(maat_instance, table_name);
ASSERT_GT(table_id, 0); ASSERT_GT(table_id, 0);
int ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, int ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
ip_plugin_ex_new_cb, ip_plugin_ex_new_cb,
ip_plugin_ex_free_cb, ip_plugin_ex_free_cb,
ip_plugin_ex_dup_cb, ip_plugin_ex_dup_cb,
@@ -2169,7 +2169,8 @@ struct fqdn_plugin_ud
int ref_cnt; int ref_cnt;
}; };
void fqdn_plugin_ex_new_cb(int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) void fqdn_plugin_ex_new_cb(const char *table_name, int table_id, const char *key,
const char *table_line, void **ad, long argl, void *argp)
{ {
int *counter = (int *)argp; int *counter = (int *)argp;
size_t column_offset = 0, column_len = 0; size_t column_offset = 0, column_len = 0;
@@ -2212,7 +2213,7 @@ TEST_F(FQDNPluginTable, EX_DATA) {
ASSERT_GT(table_id, 0); ASSERT_GT(table_id, 0);
int fqdn_plugin_ex_data_counter = 0; int fqdn_plugin_ex_data_counter = 0;
int ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, int ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
fqdn_plugin_ex_new_cb, fqdn_plugin_ex_new_cb,
fqdn_plugin_ex_free_cb, fqdn_plugin_ex_free_cb,
fqdn_plugin_ex_dup_cb, fqdn_plugin_ex_dup_cb,
@@ -2249,7 +2250,8 @@ struct bool_plugin_ud {
char *name; char *name;
int ref_cnt; int ref_cnt;
}; };
void bool_plugin_ex_new_cb(int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) void bool_plugin_ex_new_cb(const char *table_name, int table_id, const char *key,
const char *table_line, void **ad, long argl, void *argp)
{ {
int *counter=(int *)argp; int *counter=(int *)argp;
size_t column_offset=0, column_len=0; size_t column_offset=0, column_len=0;
@@ -2335,7 +2337,7 @@ TEST_F(BoolPluginTable, EX_DATA) {
int table_id = maat_get_table_id(maat_instance, table_name); int table_id = maat_get_table_id(maat_instance, table_name);
ASSERT_GT(table_id, 0); ASSERT_GT(table_id, 0);
int ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, int ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
bool_plugin_ex_new_cb, bool_plugin_ex_new_cb,
bool_plugin_ex_free_cb, bool_plugin_ex_free_cb,
bool_plugin_ex_dup_cb, bool_plugin_ex_dup_cb,
@@ -2485,13 +2487,13 @@ struct rule_ex_param {
pthread_mutex_t lock; pthread_mutex_t lock;
}; };
void compile_ex_param_new(int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) void compile_ex_param_new(const char *table_name, int table_id, const char *key,
const char *table_line, void **ad, long argl, void *argp)
{ {
int *counter = (int *)argp; int *counter = (int *)argp;
*ad = NULL; *ad = NULL;
struct rule_ex_param *param = (struct rule_ex_param *)calloc(sizeof(struct rule_ex_param), 1); struct rule_ex_param *param = (struct rule_ex_param *)calloc(sizeof(struct rule_ex_param), 1);
param->ref_cnt = 1; param->ref_cnt = 1;
pthread_mutex_init(&(param->lock), NULL); pthread_mutex_init(&(param->lock), NULL);
@@ -2746,7 +2748,7 @@ TEST_F(Policy, CompileEXData) {
int compile_table_id = maat_get_table_id(maat_instance, compile_table_name); int compile_table_id = maat_get_table_id(maat_instance, compile_table_name);
int ex_data_counter = 0; int ex_data_counter = 0;
int ret = maat_plugin_table_ex_schema_register(maat_instance, compile_table_id, int ret = maat_plugin_table_ex_schema_register(maat_instance, compile_table_name,
compile_ex_param_new, compile_ex_param_new,
compile_ex_param_free, compile_ex_param_free,
compile_ex_param_dup, compile_ex_param_dup,
@@ -3822,8 +3824,8 @@ struct user_info {
int id; int id;
int ref_cnt; int ref_cnt;
}; };
void plugin_ex_new_cb(int table_id, const char *key, const char *table_line, void plugin_ex_new_cb(const char *table_name, int table_id, const char *key,
void **ad, long argl, void *argp) const char *table_line, void **ad, long argl, void *argp)
{ {
int *counter = (int *)argp; int *counter = (int *)argp;
struct user_info *u = ALLOC(struct user_info, 1); struct user_info *u = ALLOC(struct user_info, 1);
@@ -3886,7 +3888,7 @@ TEST_F(MaatCmdTest, PluginEXData) {
sleep(WAIT_FOR_EFFECTIVE_S * 2); sleep(WAIT_FOR_EFFECTIVE_S * 2);
int ex_data_counter = 0; int ex_data_counter = 0;
ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
plugin_ex_new_cb, plugin_ex_new_cb,
plugin_ex_free_cb, plugin_ex_free_cb,
plugin_ex_dup_cb, plugin_ex_dup_cb,
@@ -3956,7 +3958,7 @@ TEST_F(MaatCmdTest, UpdateIPPlugin) {
sleep(WAIT_FOR_EFFECTIVE_S); sleep(WAIT_FOR_EFFECTIVE_S);
int ex_data_counter = 0; int ex_data_counter = 0;
ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
ip_plugin_ex_new_cb, ip_plugin_ex_new_cb,
ip_plugin_ex_free_cb, ip_plugin_ex_free_cb,
ip_plugin_ex_dup_cb, ip_plugin_ex_dup_cb,
@@ -4048,7 +4050,7 @@ TEST_F(MaatCmdTest, UpdateFQDNPlugin) {
sleep(WAIT_FOR_EFFECTIVE_S * 2); sleep(WAIT_FOR_EFFECTIVE_S * 2);
int ex_data_counter = 0; int ex_data_counter = 0;
ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
fqdn_plugin_ex_new_cb, fqdn_plugin_ex_new_cb,
fqdn_plugin_ex_free_cb, fqdn_plugin_ex_free_cb,
fqdn_plugin_ex_dup_cb, fqdn_plugin_ex_dup_cb,
@@ -4127,7 +4129,7 @@ TEST_F(MaatCmdTest, UpdateBoolPlugin) {
sleep(WAIT_FOR_EFFECTIVE_S); sleep(WAIT_FOR_EFFECTIVE_S);
int ex_data_counter = 0; int ex_data_counter = 0;
ret = maat_plugin_table_ex_schema_register(maat_instance, table_id, ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
bool_plugin_ex_new_cb, bool_plugin_ex_new_cb,
bool_plugin_ex_free_cb, bool_plugin_ex_free_cb,
bool_plugin_ex_dup_cb, bool_plugin_ex_dup_cb,
@@ -4760,7 +4762,7 @@ TEST_F(MaatCmdTest, CompileDelete_TSG6548) {
maat_state_free(state); maat_state_free(state);
} }
#if 0 #if 1
TEST_F(MaatCmdTest, UpdateDeadLockDetection) { TEST_F(MaatCmdTest, UpdateDeadLockDetection) {
const char* g2c_table_name = "GROUP2COMPILE"; const char* g2c_table_name = "GROUP2COMPILE";
const char* compile_table_name = "COMPILE"; const char* compile_table_name = "COMPILE";