optimize rcu compile runtime

This commit is contained in:
liuwentan
2023-04-14 11:32:59 +08:00
parent ffc1740a00
commit 923b4c4168
8 changed files with 637 additions and 472 deletions

View File

@@ -75,10 +75,11 @@ struct maat_item {
struct compile_rule {
long long magic_num;
long long compile_id;
char table_name[NAME_MAX];
char *table_line;
size_t table_line_len;
int declared_clause_num;
struct compile_schema *ref_table;
struct compile_schema *ref_schema;
void **ex_data;
};
@@ -272,7 +273,7 @@ void *rule_monitor_loop(void *arg);
long long maat_runtime_get_sequence(struct maat_runtime *maat_rt, const char *key);
int maat_read_full_config(struct maat *maat_instance);
void maat_read_full_config(struct maat *maat_instance);
/* maat command API for internal */
redisContext *maat_cmd_connect_redis(const char *redis_ip, int redis_port,

View File

@@ -50,6 +50,8 @@ int rcu_hash_del(struct rcu_hash_table *htable, const char *key, size_t key_len)
*/
void *rcu_hash_find(struct rcu_hash_table *htable, const char *key, size_t key_len);
void *rcu_updating_hash_find(struct rcu_hash_table *htable, const char *key, size_t key_len);
/**
* @brief list all effective nodes
*
@@ -57,6 +59,8 @@ void *rcu_hash_find(struct rcu_hash_table *htable, const char *key, size_t key_l
*/
size_t rcu_hash_list(struct rcu_hash_table *htable, void ***data_array);
size_t rcu_updating_hash_list(struct rcu_hash_table *htable, void ***data_array);
size_t rcu_hash_count(struct rcu_hash_table *htable);
/**

View File

@@ -218,7 +218,7 @@ int maat_options_set_logger(struct maat_options *opts, const char *log_path, enu
return 0;
}
int maat_read_full_config(struct maat *maat_instance)
void maat_read_full_config(struct maat *maat_instance)
{
int ret = -1;
char err_str[NAME_MAX] = {0};
@@ -245,7 +245,6 @@ int maat_read_full_config(struct maat *maat_instance)
"[%s:%d] At initiation: NO effective rule in redis %s:%hu db%d",
__FUNCTION__, __LINE__, mr_ctx->redis_ip, mr_ctx->redis_port,
mr_ctx->redis_db);
return -1;
}
break;
case DATA_SOURCE_IRIS_FILE:
@@ -257,7 +256,6 @@ int maat_read_full_config(struct maat *maat_instance)
log_error(maat_instance->logger, MODULE_MAAT_API,
"[%s:%d] At initiation: NO effective rule in %s",
__FUNCTION__, __LINE__, maat_instance->iris_ctx.full_idx_dir);
return -1;
}
break;
case DATA_SOURCE_JSON_FILE:
@@ -278,7 +276,6 @@ int maat_read_full_config(struct maat *maat_instance)
log_error(maat_instance->logger, MODULE_MAAT_API,
"[%s:%d] At initiation: NO effective rule in %s",
__FUNCTION__, __LINE__, maat_instance->json_ctx.iris_file);
return -1;
}
break;
default:
@@ -292,8 +289,6 @@ int maat_read_full_config(struct maat *maat_instance)
maat_instance->maat_version = maat_instance->maat_rt->version;
maat_instance->last_full_version = maat_instance->maat_rt->version;
}
return 0;
}
struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
@@ -384,11 +379,7 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
maat_instance->g2g_table_id = table_manager_get_group2group_table_id(maat_instance->tbl_mgr);
if (0 == maat_instance->deferred_load) {
int ret = maat_read_full_config(maat_instance);
if (ret < 0) {
log_error(maat_instance->logger, MODULE_MAAT_API,
"[%s:%d] maat read full config failed", __FUNCTION__, __LINE__);
}
maat_read_full_config(maat_instance);
}
pthread_create(&(maat_instance->cfg_mon_thread), NULL, rule_monitor_loop, (void *)maat_instance);

File diff suppressed because it is too large Load Diff

View File

@@ -470,12 +470,7 @@ void *rule_monitor_loop(void *arg)
if (maat_instance->deferred_load != 0) {
log_info(maat_instance->logger, MODULE_MAAT_RULE,
"Deferred Loading ON, updating in %s:%d", __FUNCTION__, __LINE__);
ret = maat_read_full_config(maat_instance);
if (ret < 0) {
log_error(maat_instance->logger, MODULE_MAAT_RULE,
"[%s:%d] maat read full config failed",
__FUNCTION__, __LINE__);
}
maat_read_full_config(maat_instance);
}
pthread_mutex_unlock(&(maat_instance->background_update_mutex));

View File

@@ -247,6 +247,28 @@ void *rcu_hash_find(struct rcu_hash_table *htable, const char *key, size_t key_l
return NULL;
}
void *rcu_updating_hash_find(struct rcu_hash_table *htable, const char *key, size_t key_len)
{
if (NULL == htable || NULL == key || 0 == key_len) {
return NULL;
}
struct rcu_hash_node *node = NULL;
if (htable->effective_hash == 'a') {
HASH_FIND(hh_b, htable->hashmap_b, key, key_len, node);
if (node != NULL) {
return node->data;
}
} else {
HASH_FIND(hh_a, htable->hashmap_a, key, key_len, node);
if (node != NULL) {
return node->data;
}
}
return NULL;
}
size_t rcu_hash_count(struct rcu_hash_table *htable)
{
if (NULL == htable) {
@@ -329,4 +351,33 @@ size_t rcu_hash_list(struct rcu_hash_table *htable, void ***data_array)
}
return node_cnt;
}
size_t rcu_updating_hash_list(struct rcu_hash_table *htable, void ***data_array)
{
if (NULL == htable || NULL == data_array) {
return 0;
}
size_t i = 0;
size_t node_cnt = 0;
struct rcu_hash_node *node = NULL, *tmp = NULL;
if (htable->effective_hash == 'a') {
node_cnt = HASH_CNT(hh_b, htable->hashmap_b);
*data_array = ALLOC(void *, node_cnt);
HASH_ITER(hh_b, htable->hashmap_b, node, tmp) {
(*data_array)[i] = node->data;
i++;
}
} else {
node_cnt = HASH_CNT(hh_a, htable->hashmap_a);
*data_array = ALLOC(void *, node_cnt);
HASH_ITER(hh_a, htable->hashmap_a, node, tmp) {
(*data_array)[i] = node->data;
i++;
}
}
return node_cnt;
}