[OPTIMIZE]reduce config memory usage
This commit is contained in:
@@ -49,8 +49,7 @@ void *compile_runtime_new(void *compile_schema, size_t max_thread_num,
|
||||
struct log_handle *logger);
|
||||
void compile_runtime_free(void *compile_runtime);
|
||||
|
||||
void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt,
|
||||
void *g2c_runtime);
|
||||
void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt);
|
||||
|
||||
int compile_runtime_update(void *compile_runtime, void *compile_schema,
|
||||
const char *table_name, const char *line,
|
||||
@@ -81,7 +80,9 @@ void compile_runtime_ex_data_iterate(struct compile_runtime *compile_rt,
|
||||
void *group2compile_runtime_new(void *g2c_schema, size_t max_thread_num,
|
||||
struct maat_garbage_bin *garbage_bin,
|
||||
struct log_handle *logger);
|
||||
|
||||
void group2compile_runtime_init(void *g2c_runtime, void *compile_runtime);
|
||||
|
||||
void group2compile_runtime_free(void *g2c_runtime);
|
||||
|
||||
int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
|
||||
@@ -17,9 +17,13 @@ extern "C"
|
||||
#endif
|
||||
|
||||
#define MAX_KEYWORDS_STR 1024
|
||||
|
||||
#define MAX_MAAT_STAT_NUM 64
|
||||
|
||||
#define MAX_NAME_STR_LEN 64
|
||||
|
||||
#define MAX_INSTANCE_NAME_LEN 15
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -36,7 +36,6 @@ extern "C"
|
||||
#include "hiredis/hiredis.h"
|
||||
|
||||
#define MAX_TABLE_NUM 1024
|
||||
#define MAX_COMPILE_TABLE_NUM 16
|
||||
|
||||
#define DISTRICT_ANY -1
|
||||
#define DISTRICT_UNKNOWN -2
|
||||
@@ -109,13 +108,13 @@ struct source_redis_ctx {
|
||||
};
|
||||
|
||||
struct maat_options {
|
||||
char instance_name[NAME_MAX];
|
||||
char inst_name[MAX_INSTANCE_NAME_LEN + 1];
|
||||
char foreign_cont_dir[NAME_MAX];
|
||||
char decrypt_algo[MAX_KEYWORDS_STR];
|
||||
char decrypt_key[MAX_KEYWORDS_STR];
|
||||
char log_path[PATH_MAX];
|
||||
int log_level;
|
||||
char stat_file[PATH_MAX];
|
||||
char stat_file[NAME_MAX];
|
||||
size_t nr_worker_thread;
|
||||
char *accept_tags;
|
||||
|
||||
@@ -194,7 +193,7 @@ enum last_scan_flag {
|
||||
};
|
||||
|
||||
struct maat_state {
|
||||
struct maat *maat_instance;
|
||||
struct maat *maat_inst;
|
||||
struct maat_compile_state *compile_state;
|
||||
int scan_cnt;
|
||||
int district_id; //-1: Any District; -2: Unkonwn District;
|
||||
|
||||
562
src/maat_api.c
562
src/maat_api.c
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,6 @@ struct bool_plugin_schema {
|
||||
struct bool_plugin_runtime {
|
||||
struct bool_matcher *matcher;
|
||||
struct ex_data_runtime *ex_data_rt;
|
||||
long long version;
|
||||
long long rule_num;
|
||||
size_t n_worker_thread;
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
@@ -493,13 +492,10 @@ int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name
|
||||
}
|
||||
|
||||
bool_plugin_rt->rule_num = rule_cnt;
|
||||
if (maat_rt_version != 0) {
|
||||
bool_plugin_rt->version = maat_rt_version;
|
||||
}
|
||||
|
||||
log_info(bool_plugin_rt->logger, MODULE_BOOL_PLUGIN,
|
||||
"table[%s] commit %zu bool_plugin rules and rebuild bool_matcher completed"
|
||||
", version:%lld", table_name, rule_cnt, bool_plugin_rt->version);
|
||||
", version:%lld", table_name, rule_cnt, maat_rt_version);
|
||||
|
||||
if (rules != NULL) {
|
||||
FREE(rules);
|
||||
|
||||
@@ -184,31 +184,31 @@ static int connect_redis_for_write(struct source_redis_ctx *redis_ctx,
|
||||
}
|
||||
}
|
||||
|
||||
redisContext *get_redis_ctx_for_write(struct maat *maat_instance)
|
||||
redisContext *get_redis_ctx_for_write(struct maat *maat_inst)
|
||||
{
|
||||
if (NULL == maat_instance->opts.redis_ctx.write_ctx) {
|
||||
int ret = connect_redis_for_write(&(maat_instance->opts.redis_ctx),
|
||||
maat_instance->logger);
|
||||
if (NULL == maat_inst->opts.redis_ctx.write_ctx) {
|
||||
int ret = connect_redis_for_write(&(maat_inst->opts.redis_ctx),
|
||||
maat_inst->logger);
|
||||
if (ret != 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return maat_instance->opts.redis_ctx.write_ctx;
|
||||
return maat_inst->opts.redis_ctx.write_ctx;
|
||||
}
|
||||
|
||||
int maat_cmd_flushDB(struct maat *maat_instance)
|
||||
int maat_cmd_flushDB(struct maat *maat_inst)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
redisContext *write_ctx = get_redis_ctx_for_write(maat_instance);
|
||||
redisContext *write_ctx = get_redis_ctx_for_write(maat_inst);
|
||||
if (NULL == write_ctx) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
ret = redis_flushDB(maat_instance->opts.redis_ctx.write_ctx,
|
||||
maat_instance->opts.redis_ctx.redis_db,
|
||||
maat_instance->logger);
|
||||
ret = redis_flushDB(maat_inst->opts.redis_ctx.write_ctx,
|
||||
maat_inst->opts.redis_ctx.redis_db,
|
||||
maat_inst->logger);
|
||||
} while(0 == ret);
|
||||
|
||||
return 0;
|
||||
@@ -317,13 +317,13 @@ int maat_cmd_wrap_redis_get_reply(redisContext *c, redisReply **reply)
|
||||
return redisGetReply(c, (void **)reply);
|
||||
}
|
||||
|
||||
int maat_cmd_set_line(struct maat *maat_instance, const struct maat_cmd_line *line_rule)
|
||||
int maat_cmd_set_line(struct maat *maat_inst, const struct maat_cmd_line *line_rule)
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
long long absolute_expire_time = 0;
|
||||
|
||||
redisContext *write_ctx = get_redis_ctx_for_write(maat_instance);
|
||||
redisContext *write_ctx = get_redis_ctx_for_write(maat_inst);
|
||||
if (NULL == write_ctx) {
|
||||
return -1;
|
||||
}
|
||||
@@ -335,18 +335,18 @@ int maat_cmd_set_line(struct maat *maat_instance, const struct maat_cmd_line *li
|
||||
|
||||
struct serial_rule *s_rule = ALLOC(struct serial_rule, 1);
|
||||
|
||||
int table_id = table_manager_get_table_id(maat_instance->tbl_mgr, line_rule->table_name);
|
||||
int table_id = table_manager_get_table_id(maat_inst->tbl_mgr, line_rule->table_name);
|
||||
if (table_id < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_COMMAND,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_COMMAND,
|
||||
"[%s:%d] Command set line id %lld failed: unknown table %s",
|
||||
__FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name);
|
||||
FREE(s_rule);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int valid_column = table_manager_get_valid_column(maat_instance->tbl_mgr, table_id);
|
||||
int valid_column = table_manager_get_valid_column(maat_inst->tbl_mgr, table_id);
|
||||
if (valid_column < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_COMMAND,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_COMMAND,
|
||||
"[%s:%d] Command set line id %lld failed: table %s is not a plugin or ip_plugin table",
|
||||
__FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name);
|
||||
FREE(s_rule);
|
||||
@@ -355,7 +355,7 @@ int maat_cmd_set_line(struct maat *maat_instance, const struct maat_cmd_line *li
|
||||
|
||||
int valid_offset = maat_cmd_get_valid_flag_offset(line_rule->table_line, valid_column);
|
||||
if (valid_offset < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_COMMAND,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_COMMAND,
|
||||
"[%s:%d] Command set line id %lld failed: table %s valid_offset error",
|
||||
__FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name);
|
||||
FREE(s_rule);
|
||||
@@ -370,14 +370,14 @@ int maat_cmd_set_line(struct maat *maat_instance, const struct maat_cmd_line *li
|
||||
maat_cmd_set_serial_rule(s_rule + i, (enum maat_operation)is_valid, line_rule->rule_id,
|
||||
line_rule->table_name, line_rule->table_line, absolute_expire_time);
|
||||
|
||||
int success_cnt = maat_cmd_write_rule(write_ctx, s_rule, 1, server_time, maat_instance->logger);
|
||||
int success_cnt = maat_cmd_write_rule(write_ctx, s_rule, 1, server_time, maat_inst->logger);
|
||||
if (success_cnt != 1) {
|
||||
ret = -1;
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ret = success_cnt;
|
||||
maat_instance->stat->line_cmd_acc_num += success_cnt;
|
||||
maat_inst->stat->line_cmd_acc_num += success_cnt;
|
||||
|
||||
error_out:
|
||||
maat_cmd_clear_rule_cache(s_rule);
|
||||
@@ -386,12 +386,12 @@ error_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int maat_cmd_set_file(struct maat *maat_instance, const char *key, const char *value,
|
||||
int maat_cmd_set_file(struct maat *maat_inst, const char *key, const char *value,
|
||||
size_t size, enum maat_operation op)
|
||||
{
|
||||
redisContext *ctx = maat_instance->opts.redis_ctx.write_ctx;
|
||||
redisContext *ctx = maat_inst->opts.redis_ctx.write_ctx;
|
||||
if (NULL == ctx) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_COMMAND,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_COMMAND,
|
||||
"[%s:%d] failed: Redis is not connected.",
|
||||
__FUNCTION__, __LINE__);
|
||||
return -1;
|
||||
@@ -411,7 +411,7 @@ int maat_cmd_set_file(struct maat *maat_instance, const char *key, const char *v
|
||||
|
||||
redisReply *reply = NULL;
|
||||
if (0 != strncmp(key, foreign_key_prefix, strlen(foreign_key_prefix))) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_COMMAND,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_COMMAND,
|
||||
"Invalid File key, prefix %s is mandatory.", foreign_key_prefix);
|
||||
return -1;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ int maat_cmd_set_file(struct maat *maat_instance, const char *key, const char *v
|
||||
}
|
||||
|
||||
if (NULL == reply || reply->type == REDIS_REPLY_NIL || reply->type == REDIS_REPLY_ERROR) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_COMMAND,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_COMMAND,
|
||||
"Set file failed, maybe Redis is busy.");
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
@@ -442,11 +442,11 @@ int maat_cmd_set_file(struct maat *maat_instance, const char *key, const char *v
|
||||
return 1;
|
||||
}
|
||||
|
||||
long long maat_cmd_incrby(struct maat *maat_instance, const char *key, int increment)
|
||||
long long maat_cmd_incrby(struct maat *maat_inst, const char *key, int increment)
|
||||
{
|
||||
long long result = 0;
|
||||
|
||||
redisContext *write_ctx = get_redis_ctx_for_write(maat_instance);
|
||||
redisContext *write_ctx = get_redis_ctx_for_write(maat_inst);
|
||||
if (NULL == write_ctx) {
|
||||
return -1;
|
||||
}
|
||||
@@ -464,26 +464,26 @@ long long maat_cmd_incrby(struct maat *maat_instance, const char *key, int incre
|
||||
return result;
|
||||
}
|
||||
|
||||
long long maat_cmd_get_config_version(struct maat *maat_instance)
|
||||
long long maat_cmd_get_config_version(struct maat *maat_inst)
|
||||
{
|
||||
long long new_version = -1;
|
||||
|
||||
if (maat_instance->new_version != INVALID_VERSION) {
|
||||
new_version = maat_instance->new_version;
|
||||
if (maat_inst->new_version != INVALID_VERSION) {
|
||||
new_version = maat_inst->new_version;
|
||||
} else {
|
||||
new_version = maat_instance->maat_version;
|
||||
new_version = maat_inst->maat_version;
|
||||
}
|
||||
|
||||
return new_version;
|
||||
}
|
||||
|
||||
int maat_cmd_config_is_updating(struct maat *maat_instance)
|
||||
int maat_cmd_config_is_updating(struct maat *maat_inst)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (0 == pthread_mutex_trylock(&(maat_instance->background_update_mutex))) {
|
||||
if (0 == pthread_mutex_trylock(&(maat_inst->background_update_mutex))) {
|
||||
ret = 0;
|
||||
pthread_mutex_unlock(&(maat_instance->background_update_mutex));
|
||||
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
|
||||
} else {
|
||||
ret = 1;
|
||||
}
|
||||
@@ -522,4 +522,4 @@ char *maat_cmd_str_escape(char *dst, int size, const char *src)
|
||||
dst[j] = '\0';
|
||||
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,12 +96,11 @@ struct compile_rule {
|
||||
/* compile_runtime and group2compile_runtime share compile_hash_map */
|
||||
struct compile_runtime {
|
||||
struct bool_matcher *bm;
|
||||
struct rcu_hash_table *cfg_hash_tbl; // <compile_id, struct maat_compile>
|
||||
struct rcu_hash_table *cfg_hash; // <compile_id, struct maat_compile>
|
||||
struct maat_runtime *ref_maat_rt;
|
||||
time_t version;
|
||||
struct maat_clause *clause_by_literals_hash;
|
||||
struct literal_clause *literal2clause_hash;
|
||||
struct group2compile_runtime *ref_g2c_rt;
|
||||
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
@@ -222,7 +221,7 @@ void maat_compile_free(struct maat_compile *compile)
|
||||
FREE(compile);
|
||||
}
|
||||
|
||||
void rcu_maat_compile_free(void *user_ctx, void *data)
|
||||
void rcu_compile_cfg_free(void *user_ctx, void *data)
|
||||
{
|
||||
struct maat_compile *compile = (struct maat_compile *)data;
|
||||
maat_compile_free(compile);
|
||||
@@ -253,7 +252,7 @@ int compile_table_set_ex_data_schema(struct compile_schema *compile_schema, int
|
||||
|
||||
void *compile_runtime_get_user_data(struct compile_runtime *compile_rt, long long compile_id)
|
||||
{
|
||||
struct maat_compile *compile = rcu_hash_find(compile_rt->cfg_hash_tbl,
|
||||
struct maat_compile *compile = rcu_hash_find(compile_rt->cfg_hash,
|
||||
(char *)&compile_id, sizeof(long long));
|
||||
void *ret = NULL;
|
||||
if (compile != NULL) {
|
||||
@@ -291,9 +290,9 @@ void compile_runtime_user_data_iterate(struct compile_runtime *compile_rt,
|
||||
void (*callback)(void *user_data, void *param, const char *table_name, int table_id),
|
||||
void *param, int table_id)
|
||||
{
|
||||
/* I'm in background_update_mutex, config update can't happen, so no need to lock cfg_hash_tbl */
|
||||
/* I'm in background_update_mutex, config update can't happen, so no need to lock cfg_hash */
|
||||
void **data_array = NULL;
|
||||
size_t data_cnt = rcu_hash_list(compile_rt->cfg_hash_tbl, &data_array);
|
||||
size_t data_cnt = rcu_hash_list(compile_rt->cfg_hash, &data_array);
|
||||
|
||||
for (size_t i = 0; i < data_cnt; i++) {
|
||||
struct maat_compile *compile = (struct maat_compile *)data_array[i];
|
||||
@@ -573,7 +572,7 @@ void *compile_runtime_new(void *compile_schema, size_t max_thread_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->cfg_hash_tbl = rcu_hash_new(rcu_maat_compile_free, NULL);
|
||||
compile_rt->cfg_hash = rcu_hash_new(rcu_compile_cfg_free, NULL);
|
||||
compile_rt->clause_by_literals_hash = NULL;
|
||||
compile_rt->literal2clause_hash = NULL;
|
||||
compile_rt->logger = logger;
|
||||
@@ -628,9 +627,9 @@ void compile_runtime_free(void *compile_runtime)
|
||||
compile_rt->bm = NULL;
|
||||
}
|
||||
|
||||
if (compile_rt->cfg_hash_tbl != NULL) {
|
||||
rcu_hash_free(compile_rt->cfg_hash_tbl);
|
||||
compile_rt->cfg_hash_tbl = NULL;
|
||||
if (compile_rt->cfg_hash != NULL) {
|
||||
rcu_hash_free(compile_rt->cfg_hash);
|
||||
compile_rt->cfg_hash = NULL;
|
||||
}
|
||||
|
||||
if (compile_rt->literal2clause_hash != NULL) {
|
||||
@@ -650,21 +649,14 @@ void compile_runtime_free(void *compile_runtime)
|
||||
FREE(compile_rt);
|
||||
}
|
||||
|
||||
void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt,
|
||||
void *g2c_runtime)
|
||||
void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt)
|
||||
{
|
||||
if (NULL == compile_runtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
|
||||
if (maat_rt != NULL) {
|
||||
compile_rt->ref_maat_rt = maat_rt;
|
||||
}
|
||||
|
||||
if (g2c_runtime != NULL) {
|
||||
compile_rt->ref_g2c_rt = g2c_runtime;
|
||||
}
|
||||
compile_rt->ref_maat_rt = maat_rt;
|
||||
}
|
||||
|
||||
void *group2compile_runtime_new(void *g2c_schema, size_t max_thread_num,
|
||||
@@ -896,22 +888,22 @@ maat_clause_hash_fetch_clause(struct compile_runtime *compile_rt,
|
||||
return clause;
|
||||
}
|
||||
|
||||
struct bool_matcher *maat_compile_bool_matcher_new(struct compile_runtime *compile_rt,
|
||||
size_t *compile_cnt)
|
||||
struct bool_matcher *
|
||||
maat_compile_bool_matcher_new(struct compile_runtime *compile_rt, size_t *compile_cnt)
|
||||
{
|
||||
if (NULL == compile_rt) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t i = 0, j = 0;
|
||||
size_t i = 0, j = 0, idx = 0;
|
||||
int has_clause_num = 0;
|
||||
const struct maat_clause *clause = NULL;
|
||||
struct maat_literal_id *literal_ids = NULL;
|
||||
|
||||
// STEP 1, update clause_id of each compile and literal
|
||||
void **data_array = NULL;
|
||||
size_t idx = 0;
|
||||
struct maat_compile *iter_compile = NULL;
|
||||
size_t rule_cnt = rcu_updating_hash_list(compile_rt->cfg_hash_tbl, &data_array);
|
||||
size_t rule_cnt = rcu_updating_hash_list(compile_rt->cfg_hash, &data_array);
|
||||
*compile_cnt = rule_cnt;
|
||||
|
||||
for (idx = 0; idx < rule_cnt; idx++) {
|
||||
@@ -924,7 +916,7 @@ struct bool_matcher *maat_compile_bool_matcher_new(struct compile_runtime *compi
|
||||
}
|
||||
|
||||
has_clause_num++;
|
||||
struct maat_literal_id *literal_ids = (struct maat_literal_id *)utarray_eltptr(clause_state->ut_literal_ids, 0);
|
||||
literal_ids = (struct maat_literal_id *)utarray_eltptr(clause_state->ut_literal_ids, 0);
|
||||
size_t n_literal_id = utarray_len(clause_state->ut_literal_ids);
|
||||
clause = maat_clause_hash_fetch_clause(compile_rt, literal_ids, n_literal_id);
|
||||
clause_state->clause_id = clause->clause_id;
|
||||
@@ -974,7 +966,8 @@ struct bool_matcher *maat_compile_bool_matcher_new(struct compile_runtime *compi
|
||||
size_t mem_size = 0;
|
||||
if (0 == expr_cnt) {
|
||||
log_error(compile_rt->logger, MODULE_COMPILE,
|
||||
"[%s:%d] No bool expression to build bool matcher.", __FUNCTION__, __LINE__);
|
||||
"[%s:%d] No bool expression to build bool matcher.",
|
||||
__FUNCTION__, __LINE__);
|
||||
FREE(bool_expr_array);
|
||||
return NULL;
|
||||
}
|
||||
@@ -985,8 +978,8 @@ struct bool_matcher *maat_compile_bool_matcher_new(struct compile_runtime *compi
|
||||
"Build bool matcher of %zu expressions with %zu bytes memory.",
|
||||
expr_cnt, mem_size);
|
||||
} else {
|
||||
log_error(compile_rt->logger, MODULE_COMPILE, "[%s:%d] Build bool matcher failed!",
|
||||
__FUNCTION__, __LINE__);
|
||||
log_error(compile_rt->logger, MODULE_COMPILE,
|
||||
"[%s:%d] Build bool matcher failed!", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
FREE(bool_expr_array);
|
||||
@@ -1019,7 +1012,8 @@ static inline int compare_hit_group(const void *pa, const void *pb)
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct literal_clause *maat_compile_build_literal2clause_hash(struct compile_runtime *compile_rt)
|
||||
struct literal_clause *
|
||||
maat_compile_build_literal2clause_hash(struct compile_runtime *compile_rt)
|
||||
{
|
||||
if (NULL == compile_rt) {
|
||||
return NULL;
|
||||
@@ -1030,7 +1024,7 @@ struct literal_clause *maat_compile_build_literal2clause_hash(struct compile_run
|
||||
struct maat_literal_id *tmp_literal_id = NULL;
|
||||
struct literal_clause *l2c_value = NULL;
|
||||
struct literal_clause *literal2clause_hash = NULL;
|
||||
size_t compile_cnt = rcu_updating_hash_list(compile_rt->cfg_hash_tbl, &data_array);
|
||||
size_t compile_cnt = rcu_updating_hash_list(compile_rt->cfg_hash, &data_array);
|
||||
|
||||
for (size_t idx = 0; idx < compile_cnt; idx++) {
|
||||
struct maat_compile *compile = (struct maat_compile *)data_array[idx];
|
||||
@@ -1216,7 +1210,8 @@ void compile_rule_free(struct compile_rule *compile_rule)
|
||||
assert(compile_rule->magic_num == COMPILE_RULE_MAGIC);
|
||||
|
||||
if (1 == schema->set_flag) {
|
||||
rule_ex_data_free(schema->table_id, compile_rule->ex_data, &(schema->ex_schema));
|
||||
rule_ex_data_free(schema->table_id, compile_rule->ex_data,
|
||||
&(schema->ex_schema));
|
||||
*compile_rule->ex_data = NULL;
|
||||
}
|
||||
|
||||
@@ -1419,8 +1414,9 @@ int maat_remove_group_from_compile(struct rcu_hash_table *hash_tbl,
|
||||
}
|
||||
} else {
|
||||
log_error(logger, MODULE_COMPILE,
|
||||
"[%s:%d] Remove group_id:%lld from compile_id:%lld failed, compile is not exisited.",
|
||||
__FUNCTION__, __LINE__, g2c_item->group_id, compile_id);
|
||||
"[%s:%d] Remove group_id:%lld from compile_id:%lld failed, "
|
||||
"compile is not exisited.", __FUNCTION__, __LINE__,
|
||||
g2c_item->group_id, compile_id);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1456,7 +1452,7 @@ void maat_compile_state_reset(struct maat_compile_state *compile_state)
|
||||
}
|
||||
|
||||
void maat_compile_state_free(struct maat_compile_state *compile_state,
|
||||
struct maat *maat_instance, int thread_id)
|
||||
struct maat *maat_inst, int thread_id)
|
||||
{
|
||||
if (NULL == compile_state) {
|
||||
return;
|
||||
@@ -1484,7 +1480,7 @@ void maat_compile_state_free(struct maat_compile_state *compile_state,
|
||||
FREE(compile_state);
|
||||
|
||||
free_bytes += sizeof(struct maat_compile_state);
|
||||
alignment_int64_array_add(maat_instance->stat->maat_state_free_bytes, thread_id, free_bytes);
|
||||
alignment_int64_array_add(maat_inst->stat->maat_state_free_bytes, thread_id, free_bytes);
|
||||
}
|
||||
|
||||
static int maat_compile_hit_path_add(UT_array *hit_paths, long long item_id,
|
||||
@@ -1602,8 +1598,8 @@ size_t compile_runtime_get_hit_paths(struct compile_runtime *compile_rt, int thr
|
||||
}
|
||||
|
||||
void maat_compile_state_update_hit_path(struct maat_compile_state *compile_state,
|
||||
long long item_id, long long group_id, int vtable_id,
|
||||
int Nth_scan, int Nth_item_result)
|
||||
long long item_id, long long group_id,
|
||||
int vtable_id, int Nth_scan, int Nth_item_result)
|
||||
{
|
||||
if (compile_state->Nth_scan != Nth_scan) {
|
||||
assert(compile_state->this_scan_hit_item_flag == 0);
|
||||
@@ -1618,16 +1614,15 @@ void maat_compile_state_update_hit_path(struct maat_compile_state *compile_state
|
||||
}
|
||||
|
||||
void maat_compile_state_update_hit_clause(struct maat_compile_state *compile_state,
|
||||
void *compile_runtime, long long group_id,
|
||||
int vtable_id)
|
||||
struct compile_runtime *compile_rt,
|
||||
long long group_id, int vtable_id)
|
||||
{
|
||||
if (NULL == compile_state || NULL == compile_runtime) {
|
||||
if (NULL == compile_state || NULL == compile_rt) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct maat_literal_id literal_id = {group_id, vtable_id};
|
||||
struct literal_clause *l2c_val = NULL;
|
||||
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
|
||||
|
||||
HASH_FIND(hh, compile_rt->literal2clause_hash, &literal_id, sizeof(literal_id), l2c_val);
|
||||
if (!l2c_val) {
|
||||
@@ -1685,7 +1680,8 @@ void *compile_runtime_get_ex_data(struct compile_runtime *compile_rt,
|
||||
}
|
||||
|
||||
struct compile_rule *compile_rule = NULL;
|
||||
compile_rule = (struct compile_rule *)compile_runtime_get_user_data(compile_rt, compile_id);
|
||||
compile_rule = (struct compile_rule *)compile_runtime_get_user_data(compile_rt,
|
||||
compile_id);
|
||||
if (NULL == compile_rule) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -1712,9 +1708,9 @@ int compile_runtime_add_compile(struct compile_runtime *compile_rt, struct compi
|
||||
struct compile_rule *compile_rule = compile_rule_new(compile_item, schema, table_name, line);
|
||||
compile_item_free(compile_item);
|
||||
|
||||
int updating_flag = rcu_hash_is_updating(compile_rt->cfg_hash_tbl);
|
||||
int updating_flag = rcu_hash_is_updating(compile_rt->cfg_hash);
|
||||
if (1 == updating_flag) {
|
||||
compile = rcu_updating_hash_find(compile_rt->cfg_hash_tbl, (char *)&compile_id,
|
||||
compile = rcu_updating_hash_find(compile_rt->cfg_hash, (char *)&compile_id,
|
||||
sizeof(long long));
|
||||
if (compile != NULL) {
|
||||
/****************************************************************
|
||||
@@ -1734,10 +1730,10 @@ int compile_runtime_add_compile(struct compile_runtime *compile_rt, struct compi
|
||||
assert(compile != NULL);
|
||||
maat_compile_set(compile, table_name, compile_rule->declared_clause_num,
|
||||
compile_rule, (void (*)(void *))compile_rule_free);
|
||||
rcu_hash_add(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long), compile);
|
||||
rcu_hash_add(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long), compile);
|
||||
}
|
||||
} else {
|
||||
compile = rcu_hash_find(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long));
|
||||
compile = rcu_hash_find(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long));
|
||||
if (compile != NULL) {
|
||||
/********************************************************************************
|
||||
compile found in effective hash(added by group2compile runtime), which means
|
||||
@@ -1752,19 +1748,19 @@ int compile_runtime_add_compile(struct compile_runtime *compile_rt, struct compi
|
||||
assert(copy_compile != NULL);
|
||||
|
||||
/* delete compile from rcu hash */
|
||||
rcu_hash_del(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long));
|
||||
rcu_hash_del(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long));
|
||||
|
||||
/* copy_compile has group2compile_table info, so set compile_table info */
|
||||
maat_compile_set(copy_compile, table_name, compile_rule->declared_clause_num,
|
||||
compile_rule, (void (*)(void *))compile_rule_free);
|
||||
/* add copy_compile to rcu hash */
|
||||
rcu_hash_add(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long), copy_compile);
|
||||
rcu_hash_add(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long), copy_compile);
|
||||
} else {
|
||||
compile = maat_compile_new(compile_rule->compile_id);
|
||||
assert(compile != NULL);
|
||||
maat_compile_set(compile, table_name, compile_rule->declared_clause_num,
|
||||
compile_rule, (void (*)(void *))compile_rule_free);
|
||||
rcu_hash_add(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long), compile);
|
||||
rcu_hash_add(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long), compile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1775,11 +1771,11 @@ void compile_runtime_del_compile(struct compile_runtime *compile_rt, long long c
|
||||
{
|
||||
struct maat_compile *compile = NULL;
|
||||
|
||||
int updating_flag = rcu_hash_is_updating(compile_rt->cfg_hash_tbl);
|
||||
int updating_flag = rcu_hash_is_updating(compile_rt->cfg_hash);
|
||||
|
||||
if (1 == updating_flag) {
|
||||
// find in updating hash
|
||||
compile = rcu_updating_hash_find(compile_rt->cfg_hash_tbl, (char *)&compile_id,
|
||||
compile = rcu_updating_hash_find(compile_rt->cfg_hash, (char *)&compile_id,
|
||||
sizeof(long long));
|
||||
if (compile != NULL) {
|
||||
/****************************************************************
|
||||
@@ -1795,12 +1791,12 @@ void compile_runtime_del_compile(struct compile_runtime *compile_rt, long long c
|
||||
}
|
||||
|
||||
if (0 == compile->actual_clause_num) {
|
||||
rcu_hash_del(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long));
|
||||
rcu_hash_del(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// find in effective hash
|
||||
compile = rcu_hash_find(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long));
|
||||
compile = rcu_hash_find(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long));
|
||||
if (compile != NULL) {
|
||||
/*******************************************************************
|
||||
compile found in effective hash, which means
|
||||
@@ -1815,12 +1811,12 @@ void compile_runtime_del_compile(struct compile_runtime *compile_rt, long long c
|
||||
assert(copy_compile != NULL);
|
||||
|
||||
/* delete compile from rcu hash */
|
||||
rcu_hash_del(compile_rt->cfg_hash_tbl, (char *)&compile_id, sizeof(long long));
|
||||
rcu_hash_del(compile_rt->cfg_hash, (char *)&compile_id, sizeof(long long));
|
||||
|
||||
if (0 == copy_compile->actual_clause_num) {
|
||||
maat_compile_free(copy_compile);
|
||||
} else {
|
||||
rcu_hash_add(compile_rt->cfg_hash_tbl, (char *)&compile_id,
|
||||
rcu_hash_add(compile_rt->cfg_hash, (char *)&compile_id,
|
||||
sizeof(long long), copy_compile);
|
||||
}
|
||||
}
|
||||
@@ -1904,7 +1900,7 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
|
||||
if (0 == is_valid) {
|
||||
//delete
|
||||
ret = maat_remove_group_from_compile(compile_rt->cfg_hash_tbl, g2c_item,
|
||||
ret = maat_remove_group_from_compile(compile_rt->cfg_hash, g2c_item,
|
||||
compile_rt->logger);
|
||||
if (0 == ret) {
|
||||
if (g2c_item->not_flag) {
|
||||
@@ -1916,7 +1912,8 @@ int group2compile_runtime_update(void *g2c_runtime, void *g2c_schema,
|
||||
}
|
||||
} else {
|
||||
//add
|
||||
ret = maat_add_group_to_compile(compile_rt->cfg_hash_tbl, g2c_item, compile_rt->logger);
|
||||
ret = maat_add_group_to_compile(compile_rt->cfg_hash, g2c_item,
|
||||
compile_rt->logger);
|
||||
if (0 == ret) {
|
||||
if (g2c_item->not_flag) {
|
||||
g2c_rt->not_flag_group++;
|
||||
@@ -1970,7 +1967,7 @@ int compile_runtime_commit(void *compile_runtime, const char *table_name,
|
||||
|
||||
struct compile_runtime *compile_rt = (struct compile_runtime *)compile_runtime;
|
||||
|
||||
int updating_flag = rcu_hash_is_updating(compile_rt->cfg_hash_tbl);
|
||||
int updating_flag = rcu_hash_is_updating(compile_rt->cfg_hash);
|
||||
if (0 == updating_flag) {
|
||||
return 0;
|
||||
}
|
||||
@@ -2003,14 +2000,14 @@ int compile_runtime_commit(void *compile_runtime, const char *table_name,
|
||||
compile_rt->bm = new_bool_matcher;
|
||||
compile_rt->literal2clause_hash = new_literal2clause;
|
||||
|
||||
rcu_hash_commit(compile_rt->cfg_hash_tbl);
|
||||
rcu_hash_commit(compile_rt->cfg_hash);
|
||||
|
||||
maat_garbage_bagging(compile_rt->ref_garbage_bin, old_bool_matcher, NULL,
|
||||
garbage_bool_matcher_free);
|
||||
maat_garbage_bagging(compile_rt->ref_garbage_bin, old_literal2clause, NULL,
|
||||
garbage_literal2clause_hash_free);
|
||||
|
||||
compile_rt->rule_num = rcu_hash_count(compile_rt->cfg_hash_tbl);
|
||||
compile_rt->rule_num = rcu_hash_count(compile_rt->cfg_hash);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -2100,10 +2097,10 @@ void maat_compile_state_update(int vtable_id, struct maat_item *hit_items,
|
||||
hit_cnt = MAX_SCANNER_HIT_GROUP_NUM;
|
||||
}
|
||||
|
||||
struct maat *maat_instance = state->maat_instance;
|
||||
struct maat *maat_inst = state->maat_inst;
|
||||
if (NULL == state->compile_state) {
|
||||
state->compile_state = maat_compile_state_new();
|
||||
alignment_int64_array_add(maat_instance->stat->maat_compile_state_cnt,
|
||||
alignment_int64_array_add(maat_inst->stat->maat_compile_state_cnt,
|
||||
state->thread_id, 1);
|
||||
}
|
||||
|
||||
@@ -2118,17 +2115,17 @@ void maat_compile_state_update(int vtable_id, struct maat_item *hit_items,
|
||||
if (state->compile_table_id > 0) {
|
||||
compile_table_id = state->compile_table_id;
|
||||
} else {
|
||||
compile_table_id = table_manager_get_default_compile_table_id(maat_instance->tbl_mgr);
|
||||
compile_table_id = table_manager_get_default_compile_table_id(maat_inst->tbl_mgr);
|
||||
}
|
||||
|
||||
void *compile_rt = table_manager_get_runtime(maat_instance->tbl_mgr,
|
||||
compile_table_id);
|
||||
struct compile_runtime *compile_rt = table_manager_get_runtime(maat_inst->tbl_mgr,
|
||||
compile_table_id);
|
||||
if (NULL == compile_rt) {
|
||||
return;
|
||||
}
|
||||
|
||||
int g2g_table_id = table_manager_get_group2group_table_id(maat_instance->tbl_mgr);
|
||||
void *g2g_rt = table_manager_get_runtime(maat_instance->tbl_mgr, g2g_table_id);
|
||||
int g2g_table_id = table_manager_get_group2group_table_id(maat_inst->tbl_mgr);
|
||||
void *g2g_rt = table_manager_get_runtime(maat_inst->tbl_mgr, g2g_table_id);
|
||||
if (NULL == g2g_rt) {
|
||||
return;
|
||||
}
|
||||
@@ -2260,4 +2257,4 @@ size_t maat_compile_state_get_internal_hit_paths(struct maat_compile_state *comp
|
||||
}
|
||||
|
||||
return hit_path_cnt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ void config_monitor_traverse(long long current_version, const char *idx_dir,
|
||||
FREE(idx_path_array);
|
||||
}
|
||||
|
||||
int load_maat_json_file(struct maat *maat_instance, const char *json_filename,
|
||||
int load_maat_json_file(struct maat *maat_inst, const char *json_filename,
|
||||
char *err_str, size_t err_str_sz)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -404,18 +404,18 @@ int load_maat_json_file(struct maat *maat_instance, const char *json_filename,
|
||||
size_t decrypted_buff_sz = 0;
|
||||
size_t uncompressed_buff_sz = 0;
|
||||
|
||||
log_info(maat_instance->logger, MODULE_CONFIG_MONITOR,
|
||||
log_info(maat_inst->logger, MODULE_CONFIG_MONITOR,
|
||||
"Maat initial with JSON file %s, formating...",
|
||||
json_filename);
|
||||
|
||||
if (strlen(maat_instance->opts.decrypt_key) && strlen(maat_instance->opts.decrypt_algo)) {
|
||||
ret = decrypt_open(json_filename, maat_instance->opts.decrypt_key,
|
||||
maat_instance->opts.decrypt_algo,
|
||||
if (strlen(maat_inst->opts.decrypt_key) && strlen(maat_inst->opts.decrypt_algo)) {
|
||||
ret = decrypt_open(json_filename, maat_inst->opts.decrypt_key,
|
||||
maat_inst->opts.decrypt_algo,
|
||||
(unsigned char **)&decrypted_buff,
|
||||
&decrypted_buff_sz,
|
||||
err_str, err_str_sz);
|
||||
if (ret < 0) {
|
||||
log_error(maat_instance->logger, MODULE_CONFIG_MONITOR,
|
||||
log_error(maat_inst->logger, MODULE_CONFIG_MONITOR,
|
||||
"[%s:%d] Decrypt Maat JSON file %s failed",
|
||||
__FUNCTION__, __LINE__, json_filename);
|
||||
return -1;
|
||||
@@ -425,12 +425,12 @@ int load_maat_json_file(struct maat *maat_instance, const char *json_filename,
|
||||
json_buff_sz = decrypted_buff_sz;
|
||||
}
|
||||
|
||||
if (maat_instance->opts.maat_json_is_gzipped) {
|
||||
if (maat_inst->opts.maat_json_is_gzipped) {
|
||||
ret = gzip_uncompress(json_buff, json_buff_sz, &uncompressed_buff,
|
||||
&uncompressed_buff_sz);
|
||||
FREE(json_buff);
|
||||
if (ret < 0) {
|
||||
log_error(maat_instance->logger, MODULE_CONFIG_MONITOR,
|
||||
log_error(maat_inst->logger, MODULE_CONFIG_MONITOR,
|
||||
"[%s:%d] Uncompress Maat JSON file %s failed",
|
||||
__FUNCTION__, __LINE__, json_filename);
|
||||
return -1;
|
||||
@@ -444,7 +444,7 @@ int load_maat_json_file(struct maat *maat_instance, const char *json_filename,
|
||||
if (NULL == json_buff) {
|
||||
ret = load_file_to_memory(json_filename, &json_buff, &json_buff_sz);
|
||||
if (ret < 0) {
|
||||
log_error(maat_instance->logger, MODULE_CONFIG_MONITOR,
|
||||
log_error(maat_inst->logger, MODULE_CONFIG_MONITOR,
|
||||
"[%s:%d] Read Maat JSON file %s failed",
|
||||
__FUNCTION__, __LINE__, json_filename);
|
||||
return -1;
|
||||
@@ -452,27 +452,27 @@ int load_maat_json_file(struct maat *maat_instance, const char *json_filename,
|
||||
}
|
||||
|
||||
ret = json2iris((const char*)json_buff, json_filename, NULL,
|
||||
maat_instance->opts.json_ctx.iris_file,
|
||||
sizeof(maat_instance->opts.json_ctx.iris_file),
|
||||
strlen(maat_instance->opts.decrypt_key) ? maat_instance->opts.decrypt_key : NULL,
|
||||
strlen(maat_instance->opts.decrypt_algo) ? maat_instance->opts.decrypt_algo : NULL,
|
||||
maat_instance->logger);
|
||||
maat_inst->opts.json_ctx.iris_file,
|
||||
sizeof(maat_inst->opts.json_ctx.iris_file),
|
||||
strlen(maat_inst->opts.decrypt_key) ? maat_inst->opts.decrypt_key : NULL,
|
||||
strlen(maat_inst->opts.decrypt_algo) ? maat_inst->opts.decrypt_algo : NULL,
|
||||
maat_inst->logger);
|
||||
FREE(json_buff);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = stat(json_filename, &fstat_buf);
|
||||
maat_instance->opts.json_ctx.last_md5_time = fstat_buf.st_ctim;
|
||||
maat_inst->opts.json_ctx.last_md5_time = fstat_buf.st_ctim;
|
||||
|
||||
md5_file(maat_instance->opts.json_ctx.json_file, maat_instance->opts.json_ctx.effective_json_md5);
|
||||
log_info(maat_instance->logger, MODULE_CONFIG_MONITOR,
|
||||
md5_file(maat_inst->opts.json_ctx.json_file, maat_inst->opts.json_ctx.effective_json_md5);
|
||||
log_info(maat_inst->logger, MODULE_CONFIG_MONITOR,
|
||||
"JSON file %s md5: %s, generate index file %s OK",
|
||||
maat_instance->opts.json_ctx.json_file,
|
||||
maat_instance->opts.json_ctx.effective_json_md5,
|
||||
maat_instance->opts.json_ctx.iris_file);
|
||||
maat_inst->opts.json_ctx.json_file,
|
||||
maat_inst->opts.json_ctx.effective_json_md5,
|
||||
maat_inst->opts.json_ctx.iris_file);
|
||||
|
||||
maat_instance->opts.input_mode = DATA_SOURCE_JSON_FILE;
|
||||
maat_inst->opts.input_mode = DATA_SOURCE_JSON_FILE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -875,7 +875,7 @@ int expr_runtime_commit(void *expr_runtime, const char *table_name,
|
||||
struct adapter_hs *old_adapter_hs = NULL;
|
||||
|
||||
if (rule_cnt > 0) {
|
||||
new_adapter_hs = adapter_hs_new(expr_rt->n_worker_thread, rules, real_rule_cnt,
|
||||
new_adapter_hs = adapter_hs_new(rules, real_rule_cnt, expr_rt->n_worker_thread,
|
||||
expr_rt->logger);
|
||||
if (NULL == new_adapter_hs) {
|
||||
log_error(expr_rt->logger, MODULE_EXPR,
|
||||
|
||||
@@ -49,7 +49,6 @@ struct flag_runtime {
|
||||
struct rcu_hash_table *item_hash; // <item_id, struct flag_item>
|
||||
|
||||
long long rule_num;
|
||||
long long version;
|
||||
size_t n_worker_thread;
|
||||
struct log_handle *logger;
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
@@ -510,11 +509,10 @@ int flag_runtime_commit(void *flag_runtime, const char *table_name,
|
||||
}
|
||||
|
||||
flag_rt->rule_num = rule_cnt;
|
||||
flag_rt->version = maat_rt_version;
|
||||
|
||||
log_info(flag_rt->logger, MODULE_FLAG,
|
||||
"table[%s] commit %zu flag rules and rebuild flag_matcher completed,"
|
||||
" version:%lld", table_name, rule_cnt, flag_rt->version);
|
||||
" version:%lld", table_name, rule_cnt, maat_rt_version);
|
||||
|
||||
if (rules != NULL) {
|
||||
FREE(rules);
|
||||
|
||||
@@ -33,7 +33,6 @@ struct fqdn_plugin_schema {
|
||||
struct fqdn_plugin_runtime {
|
||||
struct FQDN_engine *engine;
|
||||
struct ex_data_runtime *ex_data_rt;
|
||||
long long version;
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
size_t n_worker_thread;
|
||||
@@ -499,13 +498,10 @@ int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name
|
||||
}
|
||||
|
||||
fqdn_plugin_rt->rule_num = rule_cnt;
|
||||
if (maat_rt_version != 0) {
|
||||
fqdn_plugin_rt->version = maat_rt_version;
|
||||
}
|
||||
|
||||
log_info(fqdn_plugin_rt->logger, MODULE_FQDN_PLUGIN,
|
||||
"table[%s] commit %zu fqdn_plugin rules and rebuild FQDN engine completed"
|
||||
", version:%lld", table_name, rule_cnt, fqdn_plugin_rt->version);
|
||||
", version:%lld", table_name, rule_cnt, maat_rt_version);
|
||||
|
||||
if (rules != NULL) {
|
||||
FREE(rules);
|
||||
|
||||
@@ -62,7 +62,6 @@ struct maat_group_topology {
|
||||
struct group2group_runtime {
|
||||
struct maat_group_topology *group_topo;
|
||||
struct maat_group_topology *updating_group_topo;
|
||||
long long version;
|
||||
long long rule_num;
|
||||
long long excl_rule_num; //exclude g2g rule num
|
||||
long long update_err_cnt;
|
||||
@@ -774,11 +773,10 @@ int group2group_runtime_commit(void *g2g_runtime, const char *table_name,
|
||||
|
||||
maat_garbage_bagging(g2g_rt->ref_garbage_bin, old_group_topo, NULL,
|
||||
garbage_maat_group_topology_free);
|
||||
g2g_rt->version = maat_rt_version;
|
||||
|
||||
log_info(g2g_rt->logger, MODULE_GROUP,
|
||||
"table[%s] commit %zu g2g rules and rebuild super_groups completed,"
|
||||
" version:%lld", table_name, g2g_rt->rule_num, g2g_rt->version);
|
||||
" version:%lld", table_name, g2g_rt->rule_num, maat_rt_version);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ struct interval_runtime {
|
||||
struct interval_matcher *matcher;
|
||||
struct rcu_hash_table *item_hash; // <item_id, struct interval_item>
|
||||
|
||||
long long version;
|
||||
long long rule_num;
|
||||
size_t n_worker_thread;
|
||||
struct log_handle *logger;
|
||||
@@ -514,11 +513,10 @@ int interval_runtime_commit(void *interval_runtime, const char *table_name,
|
||||
}
|
||||
|
||||
interval_rt->rule_num = rule_cnt;
|
||||
interval_rt->version = maat_rt_version;
|
||||
|
||||
log_info(interval_rt->logger, MODULE_INTERVAL,
|
||||
"table[%s] commit %zu interval rules and rebuild interval_matcher "
|
||||
"completed, version:%lld", table_name, rule_cnt, interval_rt->version);
|
||||
"completed, version:%lld", table_name, rule_cnt, maat_rt_version);
|
||||
|
||||
if (rules != NULL) {
|
||||
FREE(rules);
|
||||
|
||||
@@ -69,7 +69,6 @@ struct ip_runtime {
|
||||
struct interval_matcher *intval_matcher;
|
||||
struct rcu_hash_table *item_hash; // <item_id, struct ip_item>
|
||||
|
||||
long long version;
|
||||
long long rule_num;
|
||||
long long ipv6_rule_num;
|
||||
size_t n_worker_thread;
|
||||
@@ -641,11 +640,10 @@ int ip_runtime_commit(void *ip_runtime, const char *table_name,
|
||||
}
|
||||
|
||||
ip_rt->rule_num = rule_cnt;
|
||||
ip_rt->version = maat_rt_version;
|
||||
|
||||
log_info(ip_rt->logger, MODULE_IP,
|
||||
"table[%s] commit %zu ip rules and rebuild ip_matcher completed"
|
||||
", version:%lld", table_name, rule_cnt, ip_rt->version);
|
||||
", version:%lld", table_name, rule_cnt, maat_rt_version);
|
||||
|
||||
if (rules != NULL) {
|
||||
FREE(rules);
|
||||
|
||||
@@ -37,7 +37,6 @@ struct ip_plugin_schema {
|
||||
struct ip_plugin_runtime {
|
||||
struct ip_matcher *ip_matcher;
|
||||
struct ex_data_runtime *ex_data_rt;
|
||||
long long version;
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
size_t n_worker_thread;
|
||||
@@ -539,13 +538,10 @@ int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name,
|
||||
}
|
||||
|
||||
ip_plugin_rt->rule_num = rule_cnt;
|
||||
if (maat_rt_version != 0) {
|
||||
ip_plugin_rt->version = maat_rt_version;
|
||||
}
|
||||
|
||||
log_info(ip_plugin_rt->logger, MODULE_IP_PLUGIN,
|
||||
"table[%s] commit %zu ip_plugin rules and rebuild ip_matcher "
|
||||
"completed, version:%lld", table_name, rule_cnt, ip_plugin_rt->version);
|
||||
"completed, version:%lld", table_name, rule_cnt, maat_rt_version);
|
||||
|
||||
if (rules != NULL) {
|
||||
FREE(rules);
|
||||
|
||||
@@ -33,7 +33,6 @@ struct plugin_callback_schema {
|
||||
struct plugin_runtime {
|
||||
long long acc_line_num;
|
||||
struct ex_data_runtime *ex_data_rt;
|
||||
long long version;
|
||||
long long rule_num;
|
||||
long long update_err_cnt;
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
@@ -572,13 +571,10 @@ int plugin_runtime_commit(void *plugin_runtime, const char *table_name,
|
||||
ex_data_runtime_commit(ex_data_rt);
|
||||
|
||||
plugin_rt->rule_num = ex_data_runtime_ex_container_count(ex_data_rt);
|
||||
if (maat_rt_version != 0) {
|
||||
plugin_rt->version = maat_rt_version;
|
||||
}
|
||||
|
||||
log_info(plugin_rt->logger, MODULE_PLUGIN,
|
||||
"table[%s] commit %zu plugin rules, version:%lld",
|
||||
table_name, plugin_rt->rule_num, plugin_rt->version);
|
||||
table_name, plugin_rt->rule_num, maat_rt_version);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ void _get_foregin_keys(struct serial_rule *p_rule, int *foreign_columns,
|
||||
}
|
||||
|
||||
int get_foreign_keys_define(redisContext *ctx, struct serial_rule *rule_list,
|
||||
int rule_num, struct maat *maat_instance, const char *dir)
|
||||
int rule_num, struct maat *maat_inst, const char *dir)
|
||||
{
|
||||
int rule_with_foreign_key = 0;
|
||||
|
||||
@@ -127,9 +127,9 @@ int get_foreign_keys_define(redisContext *ctx, struct serial_rule *rule_list,
|
||||
continue;
|
||||
}
|
||||
|
||||
int table_id = table_manager_get_table_id(maat_instance->tbl_mgr, rule_list[i].table_name);
|
||||
void *schema = table_manager_get_schema(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
int table_id = table_manager_get_table_id(maat_inst->tbl_mgr, rule_list[i].table_name);
|
||||
void *schema = table_manager_get_schema(maat_inst->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
|
||||
if (!schema || table_type != TABLE_TYPE_PLUGIN) {
|
||||
continue;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ int get_foreign_keys_define(redisContext *ctx, struct serial_rule *rule_list,
|
||||
continue;
|
||||
}
|
||||
|
||||
_get_foregin_keys(rule_list+i, foreign_columns, n_foreign_column, dir, maat_instance->logger);
|
||||
_get_foregin_keys(rule_list+i, foreign_columns, n_foreign_column, dir, maat_inst->logger);
|
||||
rule_with_foreign_key++;
|
||||
}
|
||||
|
||||
@@ -1380,14 +1380,14 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
int no_table_num = 0;
|
||||
int call_update_num = 0;
|
||||
int valid_column = -1;
|
||||
struct maat *maat_instance = (struct maat *)u_param;
|
||||
struct maat *maat_inst = (struct maat *)u_param;
|
||||
|
||||
//authorized to write
|
||||
if (mr_ctx->write_ctx != NULL && mr_ctx->write_ctx->err == 0) {
|
||||
//For thread safe, deliberately use redis_read_ctx but not redis_write_ctx.
|
||||
if (1 == redlock_try_lock(mr_ctx->read_ctx, mr_expire_lock, mr_expire_lock_timeout_ms)) {
|
||||
check_maat_expiration(mr_ctx->read_ctx, maat_instance->logger);
|
||||
cleanup_update_status(mr_ctx->read_ctx, maat_instance->logger);
|
||||
check_maat_expiration(mr_ctx->read_ctx, maat_inst->logger);
|
||||
cleanup_update_status(mr_ctx->read_ctx, maat_inst->logger);
|
||||
redlock_unlock(mr_ctx->read_ctx, mr_expire_lock);
|
||||
}
|
||||
}
|
||||
@@ -1402,12 +1402,12 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
redisFree(mr_ctx->read_ctx);
|
||||
mr_ctx->read_ctx = NULL;
|
||||
}
|
||||
log_info(maat_instance->logger, MODULE_REDIS_MONITOR, "Reconnecting...");
|
||||
log_info(maat_inst->logger, MODULE_REDIS_MONITOR, "Reconnecting...");
|
||||
|
||||
mr_ctx->read_ctx = maat_cmd_connect_redis(mr_ctx->redis_ip,
|
||||
mr_ctx->redis_port,
|
||||
mr_ctx->redis_db,
|
||||
maat_instance->logger);
|
||||
maat_inst->logger);
|
||||
if (NULL == mr_ctx->read_ctx) {
|
||||
return;
|
||||
} else {
|
||||
@@ -1420,11 +1420,11 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
int update_type = MAAT_UPDATE_TYPE_INC;
|
||||
|
||||
int rule_num = maat_cmd_get_rm_key_list(mr_ctx->read_ctx, version,
|
||||
maat_instance->load_specific_version,
|
||||
&new_version, maat_instance->tbl_mgr,
|
||||
maat_inst->load_specific_version,
|
||||
&new_version, maat_inst->tbl_mgr,
|
||||
&rule_list, &update_type,
|
||||
maat_instance->opts.cumulative_update_off,
|
||||
maat_instance->logger);
|
||||
maat_inst->opts.cumulative_update_off,
|
||||
maat_inst->logger);
|
||||
//redis communication error
|
||||
if (rule_num < 0) {
|
||||
redisFree(mr_ctx->read_ctx);
|
||||
@@ -1432,7 +1432,7 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
return;
|
||||
}
|
||||
|
||||
maat_instance->load_specific_version = 0;//only valid for one time.
|
||||
maat_inst->load_specific_version = 0;//only valid for one time.
|
||||
//error or nothing changed
|
||||
if (0 == rule_num && update_type == MAAT_UPDATE_TYPE_INC) {
|
||||
return;
|
||||
@@ -1440,12 +1440,12 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
|
||||
if (rule_num > 0) {
|
||||
ret = maat_cmd_get_redis_value(mr_ctx->read_ctx, rule_list, rule_num,
|
||||
0, maat_instance->logger);
|
||||
0, maat_inst->logger);
|
||||
//redis communication error
|
||||
if (ret < 0) {
|
||||
redisFree(mr_ctx->read_ctx);
|
||||
mr_ctx->read_ctx = NULL;
|
||||
log_error(maat_instance->logger, MODULE_REDIS_MONITOR,
|
||||
log_error(maat_inst->logger, MODULE_REDIS_MONITOR,
|
||||
"[%s:%d] Get Redis value failed, abandon update and close connection",
|
||||
__FUNCTION__, __LINE__);
|
||||
goto clean_up;
|
||||
@@ -1458,21 +1458,21 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
}
|
||||
|
||||
if (empty_value_num == rule_num) {
|
||||
log_info(maat_instance->logger, MODULE_REDIS_MONITOR,
|
||||
log_info(maat_inst->logger, MODULE_REDIS_MONITOR,
|
||||
"All %d rules are empty, abandon update", empty_value_num);
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
ret = get_foreign_keys_define(mr_ctx->read_ctx, rule_list, rule_num,
|
||||
maat_instance, maat_instance->opts.foreign_cont_dir);
|
||||
maat_inst, maat_inst->opts.foreign_cont_dir);
|
||||
if (ret > 0) {
|
||||
maat_cmd_get_foreign_conts(mr_ctx->read_ctx, rule_list, rule_num, 0,
|
||||
maat_instance->logger);
|
||||
maat_inst->logger);
|
||||
}
|
||||
}
|
||||
|
||||
start_fn(new_version, update_type, u_param);
|
||||
log_info(maat_instance->logger, MODULE_REDIS_MONITOR,
|
||||
log_info(maat_inst->logger, MODULE_REDIS_MONITOR,
|
||||
"Start %s update: %lld -> %lld (%d entries)",
|
||||
update_type == MAAT_UPDATE_TYPE_INC ? "INC" : "FULL",
|
||||
version, new_version, rule_num);
|
||||
@@ -1482,7 +1482,7 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
continue;
|
||||
}
|
||||
|
||||
table_id = table_manager_get_table_id(maat_instance->tbl_mgr, rule_list[i].table_name);
|
||||
table_id = table_manager_get_table_id(maat_inst->tbl_mgr, rule_list[i].table_name);
|
||||
//Unrecognized table.
|
||||
if (table_id < 0) {
|
||||
no_table_num++;
|
||||
@@ -1490,10 +1490,10 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
}
|
||||
|
||||
if (rule_list[i].op == MAAT_OP_DEL) {
|
||||
valid_column = table_manager_get_valid_column(maat_instance->tbl_mgr, table_id);
|
||||
valid_column = table_manager_get_valid_column(maat_inst->tbl_mgr, table_id);
|
||||
ret = invalidate_line(rule_list[i].table_line, valid_column);
|
||||
if (ret < 0) {
|
||||
log_error(maat_instance->logger, MODULE_REDIS_MONITOR,
|
||||
log_error(maat_inst->logger, MODULE_REDIS_MONITOR,
|
||||
"[%s:%d] Invalidate line failed, invaid format %s",
|
||||
__FUNCTION__, __LINE__, rule_list[i].table_line);
|
||||
continue;
|
||||
@@ -1511,7 +1511,7 @@ void redis_monitor_traverse(long long version, struct source_redis_ctx *mr_ctx,
|
||||
finish_fn(u_param);
|
||||
|
||||
if (call_update_num < rule_num) {
|
||||
log_error(maat_instance->logger, MODULE_REDIS_MONITOR,
|
||||
log_error(maat_inst->logger, MODULE_REDIS_MONITOR,
|
||||
"[%s:%d] Load %d entries to match engine, no table: %d, empty value: %d",
|
||||
__FUNCTION__, __LINE__, call_update_num, no_table_num, empty_value_num);
|
||||
}
|
||||
@@ -1522,4 +1522,4 @@ clean_up:
|
||||
}
|
||||
|
||||
FREE(rule_list);
|
||||
}
|
||||
}
|
||||
|
||||
323
src/maat_rule.c
323
src/maat_rule.c
@@ -32,25 +32,25 @@
|
||||
|
||||
#define MODULE_MAAT_RULE module_name_str("maat.rule")
|
||||
|
||||
struct maat_runtime* maat_runtime_create(long long version, struct maat *maat_instance)
|
||||
struct maat_runtime* maat_runtime_create(long long version, struct maat *maat_inst)
|
||||
{
|
||||
struct maat_runtime *maat_rt = ALLOC(struct maat_runtime, 1);
|
||||
|
||||
maat_rt->version = version;
|
||||
int ret = table_manager_runtime_create(maat_instance->tbl_mgr,
|
||||
maat_instance->opts.nr_worker_thread,
|
||||
maat_instance->garbage_bin);
|
||||
int ret = table_manager_runtime_create(maat_inst->tbl_mgr,
|
||||
maat_inst->opts.nr_worker_thread,
|
||||
maat_inst->garbage_bin);
|
||||
if (ret < 0) {
|
||||
FREE(maat_rt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
maat_rt->ref_tbl_mgr = maat_instance->tbl_mgr;
|
||||
maat_rt->max_table_num = table_manager_table_size(maat_instance->tbl_mgr);
|
||||
maat_rt->ref_tbl_mgr = maat_inst->tbl_mgr;
|
||||
maat_rt->max_table_num = table_manager_table_size(maat_inst->tbl_mgr);
|
||||
maat_rt->sequence_map = maat_kv_store_new();
|
||||
maat_rt->logger = maat_instance->logger;
|
||||
maat_rt->ref_garbage_bin = maat_instance->garbage_bin;
|
||||
maat_rt->ref_cnt = alignment_int64_array_alloc(maat_instance->opts.nr_worker_thread);
|
||||
maat_rt->logger = maat_inst->logger;
|
||||
maat_rt->ref_garbage_bin = maat_inst->garbage_bin;
|
||||
maat_rt->ref_cnt = alignment_int64_array_alloc(maat_inst->opts.nr_worker_thread);
|
||||
|
||||
return maat_rt;
|
||||
}
|
||||
@@ -67,30 +67,32 @@ void maat_runtime_commit(struct maat_runtime *maat_rt, int update_type,
|
||||
|
||||
void maat_start_cb(long long new_version, int update_type, void *u_param)
|
||||
{
|
||||
struct maat *maat_instance = (struct maat *)u_param;
|
||||
maat_instance->new_version = new_version;
|
||||
size_t i = 0;
|
||||
size_t max_table_cnt = table_manager_table_size(maat_instance->tbl_mgr);
|
||||
enum table_type table_type = TABLE_TYPE_INVALID;
|
||||
struct maat *maat_inst = (struct maat *)u_param;
|
||||
|
||||
size_t max_table_cnt = table_manager_table_size(maat_inst->tbl_mgr);
|
||||
maat_inst->new_version = new_version;
|
||||
|
||||
if (update_type == MAAT_UPDATE_TYPE_FULL) {
|
||||
maat_instance->creating_maat_rt = maat_runtime_create(new_version, maat_instance);
|
||||
maat_inst->creating_maat_rt = maat_runtime_create(new_version, maat_inst);
|
||||
|
||||
for (i = 0; i < max_table_cnt; i++) {
|
||||
table_type = table_manager_get_table_type(maat_instance->tbl_mgr, i);
|
||||
table_type = table_manager_get_table_type(maat_inst->tbl_mgr, i);
|
||||
if (table_type == TABLE_TYPE_COMPILE) {
|
||||
// compile runtime need a reference to maat runtime
|
||||
void *compile_rt = table_manager_get_updating_runtime(maat_instance->tbl_mgr, i);
|
||||
compile_runtime_init(compile_rt, maat_instance->creating_maat_rt, NULL);
|
||||
void *compile_rt = table_manager_get_updating_runtime(maat_inst->tbl_mgr, i);
|
||||
compile_runtime_init(compile_rt, maat_inst->creating_maat_rt);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
maat_instance->maat_version = new_version;
|
||||
maat_inst->maat_version = new_version;
|
||||
}
|
||||
|
||||
for (i = 0; i < max_table_cnt; i++) {
|
||||
table_type = table_manager_get_table_type(maat_instance->tbl_mgr, i);
|
||||
table_type = table_manager_get_table_type(maat_inst->tbl_mgr, i);
|
||||
if (table_type == TABLE_TYPE_PLUGIN) {
|
||||
void *schema = table_manager_get_schema(maat_instance->tbl_mgr, i);
|
||||
void *schema = table_manager_get_schema(maat_inst->tbl_mgr, i);
|
||||
plugin_table_all_callback_start((struct plugin_schema *)schema, update_type);
|
||||
}
|
||||
}
|
||||
@@ -102,30 +104,30 @@ int maat_update_cb(const char *table_name, const char *line, void *u_param)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct maat *maat_instance =(struct maat *)u_param;
|
||||
struct maat *maat_inst =(struct maat *)u_param;
|
||||
struct maat_runtime* maat_rt = NULL;
|
||||
int table_id = table_manager_get_table_id(maat_instance->tbl_mgr, table_name);
|
||||
int table_id = table_manager_get_table_id(maat_inst->tbl_mgr, table_name);
|
||||
if (table_id < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] update warning, unknown table name %s",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *schema = table_manager_get_schema(maat_instance->tbl_mgr, table_id);
|
||||
void *schema = table_manager_get_schema(maat_inst->tbl_mgr, table_id);
|
||||
if (NULL == schema) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] update warning, table name %s doesn't have table schema",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int update_type = MAAT_UPDATE_TYPE_INC;
|
||||
if (maat_instance->creating_maat_rt != NULL) { //Full update
|
||||
maat_rt = maat_instance->creating_maat_rt;
|
||||
if (maat_inst->creating_maat_rt != NULL) { //Full update
|
||||
maat_rt = maat_inst->creating_maat_rt;
|
||||
update_type = MAAT_UPDATE_TYPE_FULL;
|
||||
} else {
|
||||
maat_rt = maat_instance->maat_rt;
|
||||
maat_rt = maat_inst->maat_rt;
|
||||
}
|
||||
|
||||
table_manager_update_runtime(maat_rt->ref_tbl_mgr, table_name, table_id, line, update_type);
|
||||
@@ -166,107 +168,107 @@ void maat_plugin_table_all_callback_finish(struct table_manager *tbl_mgr)
|
||||
|
||||
void maat_finish_cb(void *u_param)
|
||||
{
|
||||
struct maat *maat_instance = (struct maat *)u_param;
|
||||
struct maat *maat_inst = (struct maat *)u_param;
|
||||
|
||||
maat_plugin_table_all_callback_finish(maat_instance->tbl_mgr);
|
||||
maat_plugin_table_all_callback_finish(maat_inst->tbl_mgr);
|
||||
|
||||
if (maat_instance->creating_maat_rt != NULL) {
|
||||
maat_runtime_commit(maat_instance->creating_maat_rt, MAAT_UPDATE_TYPE_FULL,
|
||||
maat_instance->creating_maat_rt->version, maat_instance->logger);
|
||||
maat_instance->creating_maat_rt->rule_num = maat_runtime_rule_num(maat_instance->creating_maat_rt);
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
if (maat_inst->creating_maat_rt != NULL) {
|
||||
maat_runtime_commit(maat_inst->creating_maat_rt, MAAT_UPDATE_TYPE_FULL,
|
||||
maat_inst->creating_maat_rt->version, maat_inst->logger);
|
||||
maat_inst->creating_maat_rt->rule_num = maat_runtime_rule_num(maat_inst->creating_maat_rt);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Full config version %llu load %d entries complete",
|
||||
maat_instance->creating_maat_rt->version,
|
||||
maat_instance->creating_maat_rt->rule_num);
|
||||
} else if (maat_instance->maat_rt != NULL) {
|
||||
maat_instance->maat_rt->version = maat_instance->maat_version;
|
||||
maat_runtime_commit(maat_instance->maat_rt, MAAT_UPDATE_TYPE_INC,
|
||||
maat_instance->maat_rt->version, maat_instance->logger);
|
||||
maat_instance->maat_rt->rule_num = maat_runtime_rule_num(maat_instance->maat_rt);
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
maat_inst->creating_maat_rt->version,
|
||||
maat_inst->creating_maat_rt->rule_num);
|
||||
} else if (maat_inst->maat_rt != NULL) {
|
||||
maat_inst->maat_rt->version = maat_inst->maat_version;
|
||||
maat_runtime_commit(maat_inst->maat_rt, MAAT_UPDATE_TYPE_INC,
|
||||
maat_inst->maat_rt->version, maat_inst->logger);
|
||||
maat_inst->maat_rt->rule_num = maat_runtime_rule_num(maat_inst->maat_rt);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Inc config version %llu load %d entries complete",
|
||||
maat_instance->maat_rt->version,
|
||||
maat_instance->maat_rt->rule_num);
|
||||
maat_inst->maat_rt->version,
|
||||
maat_inst->maat_rt->rule_num);
|
||||
} else {
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Version %d has no valid rules, plugin callback complete.",
|
||||
maat_instance->maat_version);
|
||||
maat_inst->maat_version);
|
||||
}
|
||||
|
||||
maat_instance->new_version = INVALID_VERSION;
|
||||
maat_inst->new_version = INVALID_VERSION;
|
||||
}
|
||||
|
||||
void maat_read_full_config(struct maat *maat_instance)
|
||||
void maat_read_full_config(struct maat *maat_inst)
|
||||
{
|
||||
int ret = -1;
|
||||
char err_str[NAME_MAX] = {0};
|
||||
struct source_redis_ctx *redis_ctx = NULL;
|
||||
|
||||
switch (maat_instance->opts.input_mode) {
|
||||
switch (maat_inst->opts.input_mode) {
|
||||
case DATA_SOURCE_REDIS:
|
||||
redis_ctx = &(maat_instance->opts.redis_ctx);
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
redis_ctx = &(maat_inst->opts.redis_ctx);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat initiate from Redis %s:%hu db%d",
|
||||
redis_ctx->redis_ip, redis_ctx->redis_port, redis_ctx->redis_db);
|
||||
redis_ctx->read_ctx = maat_cmd_connect_redis(redis_ctx->redis_ip,
|
||||
redis_ctx->redis_port,
|
||||
redis_ctx->redis_db,
|
||||
maat_instance->logger);
|
||||
maat_inst->logger);
|
||||
if (redis_ctx->read_ctx != NULL) {
|
||||
redis_monitor_traverse(maat_instance->maat_version, redis_ctx,
|
||||
redis_monitor_traverse(maat_inst->maat_version, redis_ctx,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_instance);
|
||||
maat_inst);
|
||||
}
|
||||
|
||||
if (NULL == maat_instance->creating_maat_rt) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
if (NULL == maat_inst->creating_maat_rt) {
|
||||
log_error(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] At initiation: NO effective rule in redis %s:%hu db%d",
|
||||
__FUNCTION__, __LINE__, redis_ctx->redis_ip, redis_ctx->redis_port,
|
||||
redis_ctx->redis_db);
|
||||
}
|
||||
break;
|
||||
case DATA_SOURCE_IRIS_FILE:
|
||||
config_monitor_traverse(maat_instance->maat_version,
|
||||
maat_instance->opts.iris_ctx.full_idx_dir,
|
||||
config_monitor_traverse(maat_inst->maat_version,
|
||||
maat_inst->opts.iris_ctx.full_idx_dir,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_instance, maat_instance->opts.decrypt_key,
|
||||
maat_instance->logger);
|
||||
if (NULL == maat_instance->creating_maat_rt) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
if (NULL == maat_inst->creating_maat_rt) {
|
||||
log_error(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] At initiation: NO effective rule in %s",
|
||||
__FUNCTION__, __LINE__, maat_instance->opts.iris_ctx.full_idx_dir);
|
||||
__FUNCTION__, __LINE__, maat_inst->opts.iris_ctx.full_idx_dir);
|
||||
}
|
||||
break;
|
||||
case DATA_SOURCE_JSON_FILE:
|
||||
ret = load_maat_json_file(maat_instance, maat_instance->opts.json_ctx.json_file,
|
||||
ret = load_maat_json_file(maat_inst, maat_inst->opts.json_ctx.json_file,
|
||||
err_str, sizeof(err_str));
|
||||
if (ret < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] Maat re-initiate with JSON file %s failed: %s",
|
||||
__FUNCTION__, __LINE__, maat_instance->opts.json_ctx.json_file, err_str);
|
||||
__FUNCTION__, __LINE__, maat_inst->opts.json_ctx.json_file, err_str);
|
||||
}
|
||||
|
||||
config_monitor_traverse(maat_instance->maat_version,
|
||||
maat_instance->opts.json_ctx.iris_file,
|
||||
config_monitor_traverse(maat_inst->maat_version,
|
||||
maat_inst->opts.json_ctx.iris_file,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_instance, maat_instance->opts.decrypt_key,
|
||||
maat_instance->logger);
|
||||
if (NULL == maat_instance->creating_maat_rt) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
if (NULL == maat_inst->creating_maat_rt) {
|
||||
log_error(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] At initiation: NO effective rule in %s",
|
||||
__FUNCTION__, __LINE__, maat_instance->opts.json_ctx.iris_file);
|
||||
__FUNCTION__, __LINE__, maat_inst->opts.json_ctx.iris_file);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
maat_instance->maat_rt = maat_instance->creating_maat_rt;
|
||||
maat_instance->creating_maat_rt = NULL;
|
||||
maat_instance->is_running = 1;
|
||||
if (maat_instance->maat_rt != NULL) {
|
||||
maat_instance->maat_version = maat_instance->maat_rt->version;
|
||||
maat_instance->last_full_version = maat_instance->maat_rt->version;
|
||||
maat_inst->maat_rt = maat_inst->creating_maat_rt;
|
||||
maat_inst->creating_maat_rt = NULL;
|
||||
maat_inst->is_running = 1;
|
||||
if (maat_inst->maat_rt != NULL) {
|
||||
maat_inst->maat_version = maat_inst->maat_rt->version;
|
||||
maat_inst->last_full_version = maat_inst->maat_rt->version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,74 +328,77 @@ void *rule_monitor_loop(void *arg)
|
||||
{
|
||||
/* Defined by prctl: The name can be up to 16 bytes long, and should
|
||||
be null terminated if it contains fewer bytes. */
|
||||
char maat_name[16] = {0};
|
||||
struct maat *maat_instance = (struct maat *)arg;
|
||||
char maat_name[MAX_INSTANCE_NAME_LEN + 1] = {0};
|
||||
struct maat *maat_inst = (struct maat *)arg;
|
||||
|
||||
if (strlen(maat_instance->opts.instance_name) > 0) {
|
||||
snprintf(maat_name, sizeof(maat_name), "MAAT_%s", maat_instance->opts.instance_name);
|
||||
if (strlen(maat_inst->opts.inst_name) > 0) {
|
||||
snprintf(maat_name, sizeof(maat_name), "%s", maat_inst->opts.inst_name);
|
||||
} else {
|
||||
snprintf(maat_name, sizeof(maat_name), "MAAT");
|
||||
snprintf(maat_name, sizeof(maat_name), "MAAT_LOOP");
|
||||
}
|
||||
|
||||
int ret = prctl(PR_SET_NAME, (unsigned long long)maat_name, NULL, NULL, NULL);
|
||||
assert(ret >= 0);
|
||||
|
||||
pthread_mutex_lock(&(maat_instance->background_update_mutex));
|
||||
pthread_mutex_lock(&(maat_inst->background_update_mutex));
|
||||
/* if deferred load on */
|
||||
if (maat_instance->opts.deferred_load_on != 0) {
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
if (maat_inst->opts.deferred_load_on != 0) {
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Deferred Loading ON, updating in %s:%d", __FUNCTION__, __LINE__);
|
||||
maat_read_full_config(maat_instance);
|
||||
maat_read_full_config(maat_inst);
|
||||
}
|
||||
pthread_mutex_unlock(&(maat_instance->background_update_mutex));
|
||||
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
|
||||
|
||||
char md5_tmp[MD5_DIGEST_LENGTH * 2 + 1] = {0};
|
||||
char err_str[NAME_MAX] = {0};
|
||||
struct stat attrib;
|
||||
while (maat_instance->is_running) {
|
||||
|
||||
while (maat_inst->is_running) {
|
||||
if (time(NULL) % 10 == 0) {
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"%s thread still alive.........", __FUNCTION__);
|
||||
}
|
||||
|
||||
usleep(maat_instance->opts.rule_update_checking_interval_ms * 1000);
|
||||
if (0 == pthread_mutex_trylock(&(maat_instance->background_update_mutex))) {
|
||||
switch (maat_instance->opts.input_mode) {
|
||||
usleep(maat_inst->opts.rule_update_checking_interval_ms * 1000);
|
||||
|
||||
if (0 == pthread_mutex_trylock(&(maat_inst->background_update_mutex))) {
|
||||
switch (maat_inst->opts.input_mode) {
|
||||
case DATA_SOURCE_REDIS:
|
||||
redis_monitor_traverse(maat_instance->maat_version,
|
||||
&(maat_instance->opts.redis_ctx),
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_instance);
|
||||
redis_monitor_traverse(maat_inst->maat_version,
|
||||
&(maat_inst->opts.redis_ctx),
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_inst);
|
||||
break;
|
||||
case DATA_SOURCE_IRIS_FILE:
|
||||
config_monitor_traverse(maat_instance->maat_version,
|
||||
maat_instance->opts.iris_ctx.inc_idx_dir,
|
||||
config_monitor_traverse(maat_inst->maat_version,
|
||||
maat_inst->opts.iris_ctx.inc_idx_dir,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_instance, maat_instance->opts.decrypt_key,
|
||||
maat_instance->logger);
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
break;
|
||||
case DATA_SOURCE_JSON_FILE:
|
||||
memset(md5_tmp, 0, sizeof(md5_tmp));
|
||||
stat(maat_instance->opts.json_ctx.json_file, &attrib);
|
||||
if (memcmp(&attrib.st_ctim, &(maat_instance->opts.json_ctx.last_md5_time), sizeof(attrib.st_ctim))) {
|
||||
maat_instance->opts.json_ctx.last_md5_time = attrib.st_ctim;
|
||||
md5_file(maat_instance->opts.json_ctx.json_file, md5_tmp);
|
||||
if (0 != strcmp(md5_tmp, maat_instance->opts.json_ctx.effective_json_md5)) {
|
||||
ret = load_maat_json_file(maat_instance, maat_instance->opts.json_ctx.json_file,
|
||||
stat(maat_inst->opts.json_ctx.json_file, &attrib);
|
||||
if (memcmp(&attrib.st_ctim, &(maat_inst->opts.json_ctx.last_md5_time),
|
||||
sizeof(attrib.st_ctim))) {
|
||||
maat_inst->opts.json_ctx.last_md5_time = attrib.st_ctim;
|
||||
md5_file(maat_inst->opts.json_ctx.json_file, md5_tmp);
|
||||
if (0 != strcmp(md5_tmp, maat_inst->opts.json_ctx.effective_json_md5)) {
|
||||
ret = load_maat_json_file(maat_inst, maat_inst->opts.json_ctx.json_file,
|
||||
err_str, sizeof(err_str));
|
||||
if (ret < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
log_error(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] Maat re-initiate with JSON file %s (md5=%s)failed: %s\n",
|
||||
__FUNCTION__, __LINE__, maat_instance->opts.json_ctx.json_file,
|
||||
__FUNCTION__, __LINE__, maat_inst->opts.json_ctx.json_file,
|
||||
md5_tmp, err_str);
|
||||
} else {
|
||||
config_monitor_traverse(0, maat_instance->opts.json_ctx.iris_file,
|
||||
config_monitor_traverse(0, maat_inst->opts.json_ctx.iris_file,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_instance, maat_instance->opts.decrypt_key,
|
||||
maat_instance->logger);
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat re-initiate with JSON file %s success, md5: %s\n",
|
||||
maat_instance->opts.json_ctx.json_file, md5_tmp);
|
||||
maat_inst->opts.json_ctx.json_file, md5_tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,77 +407,81 @@ void *rule_monitor_loop(void *arg)
|
||||
break;
|
||||
}
|
||||
|
||||
if (maat_instance->creating_maat_rt != NULL) {
|
||||
struct maat_runtime *old_maat_rt = maat_instance->maat_rt;
|
||||
maat_instance->maat_rt = maat_instance->creating_maat_rt;
|
||||
if (maat_inst->creating_maat_rt != NULL) {
|
||||
struct maat_runtime *old_maat_rt = maat_inst->maat_rt;
|
||||
maat_inst->maat_rt = maat_inst->creating_maat_rt;
|
||||
|
||||
if (old_maat_rt != NULL) {
|
||||
if (maat_instance->maat_rt->version > old_maat_rt->version) {
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
if (maat_inst->maat_rt->version > old_maat_rt->version) {
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat version updated %lld -> %lld\n",
|
||||
old_maat_rt->version, maat_instance->maat_rt->version);
|
||||
old_maat_rt->version, maat_inst->maat_rt->version);
|
||||
} else {
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat version roll back %lld -> %lld\n",
|
||||
old_maat_rt->version, maat_instance->maat_rt->version);
|
||||
old_maat_rt->version, maat_inst->maat_rt->version);
|
||||
}
|
||||
maat_garbage_bagging(maat_instance->garbage_bin, old_maat_rt, NULL,
|
||||
|
||||
maat_inst->stat->zombie_rs_stream += alignment_int64_array_sum(old_maat_rt->ref_cnt,
|
||||
maat_inst->opts.nr_worker_thread);
|
||||
maat_garbage_bagging(maat_inst->garbage_bin, old_maat_rt, NULL,
|
||||
garbage_maat_runtime_destroy);
|
||||
}
|
||||
|
||||
maat_instance->creating_maat_rt = NULL;
|
||||
maat_instance->maat_version = maat_instance->maat_rt->version;
|
||||
maat_instance->last_full_version = maat_instance->maat_rt->version;
|
||||
maat_inst->creating_maat_rt = NULL;
|
||||
maat_inst->maat_version = maat_inst->maat_rt->version;
|
||||
maat_inst->last_full_version = maat_inst->maat_rt->version;
|
||||
}
|
||||
|
||||
if (maat_instance->maat_rt != NULL) {
|
||||
time_t time_window = time(NULL) - maat_instance->maat_rt->last_update_time;
|
||||
if (maat_inst->maat_rt != NULL) {
|
||||
time_t time_window = time(NULL) - maat_inst->maat_rt->last_update_time;
|
||||
|
||||
if (time_window >= maat_instance->opts.rule_effect_interval_ms / 1000) {
|
||||
maat_runtime_commit(maat_instance->maat_rt, MAAT_UPDATE_TYPE_INC,
|
||||
maat_instance->maat_rt->version, maat_instance->logger);
|
||||
log_info(maat_instance->logger, MODULE_MAAT_RULE,
|
||||
if (time_window >= maat_inst->opts.rule_effect_interval_ms / 1000) {
|
||||
maat_runtime_commit(maat_inst->maat_rt, MAAT_UPDATE_TYPE_INC,
|
||||
maat_inst->maat_rt->version, maat_inst->logger);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Actual update config version %u, %d entries load to maat runtime.",
|
||||
maat_instance->maat_rt->version, maat_instance->maat_rt->rule_num);
|
||||
maat_inst->maat_rt->version, maat_inst->maat_rt->rule_num);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(maat_instance->background_update_mutex));
|
||||
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
|
||||
}
|
||||
maat_garbage_collect_routine(maat_instance->garbage_bin);
|
||||
if ((1 == maat_instance->opts.stat_on) && (time(NULL) % 2 == 0)) {
|
||||
maat_stat_output(maat_instance->stat, maat_instance->maat_version, maat_instance->opts.perf_on);
|
||||
|
||||
maat_garbage_collect_routine(maat_inst->garbage_bin);
|
||||
if ((1 == maat_inst->opts.stat_on) && (time(NULL) % 2 == 0)) {
|
||||
maat_stat_output(maat_inst->stat, maat_inst->maat_version, maat_inst->opts.perf_on);
|
||||
}
|
||||
}
|
||||
|
||||
maat_runtime_destroy(maat_instance->maat_rt);
|
||||
maat_garbage_bin_free(maat_instance->garbage_bin);
|
||||
table_manager_destroy(maat_instance->tbl_mgr); //table manager MUST be freed at last.
|
||||
maat_runtime_destroy(maat_inst->maat_rt);
|
||||
maat_garbage_bin_free(maat_inst->garbage_bin);
|
||||
table_manager_destroy(maat_inst->tbl_mgr); //table manager MUST be freed at last.
|
||||
|
||||
if (maat_instance->stat != NULL) {
|
||||
maat_stat_free(maat_instance->stat);
|
||||
maat_instance->stat = NULL;
|
||||
if (maat_inst->stat != NULL) {
|
||||
maat_stat_free(maat_inst->stat);
|
||||
maat_inst->stat = NULL;
|
||||
}
|
||||
|
||||
if (maat_instance->opts.input_mode == DATA_SOURCE_REDIS) {
|
||||
if (maat_instance->opts.redis_ctx.read_ctx != NULL) {
|
||||
redisFree(maat_instance->opts.redis_ctx.read_ctx);
|
||||
maat_instance->opts.redis_ctx.read_ctx = NULL;
|
||||
if (maat_inst->opts.input_mode == DATA_SOURCE_REDIS) {
|
||||
if (maat_inst->opts.redis_ctx.read_ctx != NULL) {
|
||||
redisFree(maat_inst->opts.redis_ctx.read_ctx);
|
||||
maat_inst->opts.redis_ctx.read_ctx = NULL;
|
||||
}
|
||||
|
||||
if (maat_instance->opts.redis_ctx.write_ctx != NULL) {
|
||||
redisFree(maat_instance->opts.redis_ctx.write_ctx);
|
||||
maat_instance->opts.redis_ctx.write_ctx = NULL;
|
||||
if (maat_inst->opts.redis_ctx.write_ctx != NULL) {
|
||||
redisFree(maat_inst->opts.redis_ctx.write_ctx);
|
||||
maat_inst->opts.redis_ctx.write_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (maat_instance->opts.accept_tags != NULL) {
|
||||
FREE(maat_instance->opts.accept_tags);
|
||||
maat_instance->opts.accept_tags = NULL;
|
||||
if (maat_inst->opts.accept_tags != NULL) {
|
||||
FREE(maat_inst->opts.accept_tags);
|
||||
maat_inst->opts.accept_tags = NULL;
|
||||
}
|
||||
|
||||
log_handle_destroy(maat_instance->logger);
|
||||
FREE(maat_instance);
|
||||
log_handle_destroy(maat_inst->logger);
|
||||
FREE(maat_inst);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ struct rcu_hash_table {
|
||||
struct rcu_hash_node {
|
||||
char *key;
|
||||
size_t key_len;
|
||||
void *data; //table_runtime解析成两个成员
|
||||
void *data;
|
||||
|
||||
/* htable the node belongs to */
|
||||
struct rcu_hash_table *htable;
|
||||
|
||||
Reference in New Issue
Block a user