解决创建hash表时重复打印配置问题
This commit is contained in:
@@ -172,6 +172,18 @@ enum kni_deploy_mode{
|
||||
KNI_DEPLOY_MODE_NORMAL = 1,
|
||||
};
|
||||
|
||||
struct kni_htable_opt{
|
||||
int mho_screen_print_ctrl;
|
||||
int mho_thread_safe;
|
||||
int mho_mutex_num;
|
||||
int mho_hash_slot_size;
|
||||
int mho_hash_max_element_num;
|
||||
int mho_expire_time;
|
||||
char mho_eliminate_type[KNI_SYMBOL_MAX];
|
||||
void *free_data_cb;
|
||||
void *expire_notify_cb;
|
||||
};
|
||||
|
||||
int kni_addr_trans_v4(struct stream_tuple4_v4 *tuple4, char *output, int len);
|
||||
int kni_addr_trans_v6(struct stream_tuple4_v6 *tuple4, char *output, int len);
|
||||
uint16_t kni_ip_checksum(const void *buf, size_t hdr_len);
|
||||
@@ -186,4 +198,5 @@ char* kni_ipv4_errmsg_get(enum kni_ipv4hdr_parse_error _errno);
|
||||
char* kni_ipv6_errmsg_get(enum kni_ipv6hdr_parse_error _errno);
|
||||
char* kni_strdup(const char* s);
|
||||
|
||||
MESA_htable_handle kni_create_htable(const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger);
|
||||
MESA_htable_handle kni_create_htable(char *symbol, struct kni_htable_opt *opt, void *logger);
|
||||
void kni_get_htable_opt(struct kni_htable_opt *opt, const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger);
|
||||
@@ -261,57 +261,51 @@ static int __wrapper_MESA_htable_set_opt(MESA_htable_handle table, enum MESA_hta
|
||||
return ret;
|
||||
}
|
||||
|
||||
MESA_htable_handle kni_create_htable(const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger)
|
||||
{
|
||||
int mho_screen_print_ctrl;
|
||||
int mho_thread_safe;
|
||||
int mho_mutex_num;
|
||||
int mho_hash_slot_size;
|
||||
int mho_hash_max_element_num;
|
||||
int mho_expire_time;
|
||||
char mho_eliminate_type[KNI_SYMBOL_MAX];
|
||||
MESA_load_profile_int_def(profile, section, "mho_screen_print_ctrl", &mho_screen_print_ctrl, 1);
|
||||
MESA_load_profile_int_def(profile, section, "mho_thread_safe", &mho_thread_safe, 0);
|
||||
MESA_load_profile_int_def(profile, section, "mho_mutex_num", &mho_mutex_num, 12);
|
||||
MESA_load_profile_int_def(profile, section, "mho_hash_slot_size", &mho_hash_slot_size, 1234);
|
||||
MESA_load_profile_int_def(profile, section, "mho_hash_max_element_num", &mho_hash_max_element_num, 12345);
|
||||
MESA_load_profile_int_def(profile, section, "mho_expire_time", &mho_expire_time, 3600);
|
||||
MESA_load_profile_string_def(profile, section, "mho_eliminate_type", mho_eliminate_type, sizeof(mho_eliminate_type), "FIFO");
|
||||
void kni_get_htable_opt(struct kni_htable_opt *opt, const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger){
|
||||
MESA_load_profile_int_def(profile, section, "mho_screen_print_ctrl", &(opt->mho_screen_print_ctrl), 1);
|
||||
MESA_load_profile_int_def(profile, section, "mho_thread_safe", &(opt->mho_thread_safe), 0);
|
||||
MESA_load_profile_int_def(profile, section, "mho_mutex_num", &(opt->mho_mutex_num), 12);
|
||||
MESA_load_profile_int_def(profile, section, "mho_hash_slot_size", &(opt->mho_hash_slot_size), 1234);
|
||||
MESA_load_profile_int_def(profile, section, "mho_hash_max_element_num", &(opt->mho_hash_max_element_num), 12345);
|
||||
MESA_load_profile_int_def(profile, section, "mho_expire_time", &(opt->mho_expire_time), 0);
|
||||
MESA_load_profile_string_def(profile, section, "mho_eliminate_type", opt->mho_eliminate_type, sizeof(opt->mho_eliminate_type), "FIFO");
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n mho_screen_print_ctrl: %d\n mho_thread_safe: %d\n mho_mutex_num: %d\n"
|
||||
"mho_hash_slot_size: %d\n mho_hash_max_element_num: %d\n mho_expire_time: %d\n mho_eliminate_type: %s\n", section,
|
||||
mho_screen_print_ctrl, mho_thread_safe, mho_mutex_num, mho_hash_slot_size, mho_hash_max_element_num, mho_expire_time, mho_eliminate_type);
|
||||
opt->mho_screen_print_ctrl, opt->mho_thread_safe, opt->mho_mutex_num, opt->mho_hash_slot_size, opt->mho_hash_max_element_num,
|
||||
opt->mho_expire_time, opt->mho_eliminate_type);
|
||||
opt->free_data_cb = free_data_cb;
|
||||
opt->expire_notify_cb = expire_notify_cb;
|
||||
}
|
||||
|
||||
MESA_htable_handle kni_create_htable(char *symbol, struct kni_htable_opt *opt, void *logger){
|
||||
MESA_htable_handle htable = MESA_htable_born();
|
||||
if(htable == NULL)
|
||||
{
|
||||
if(htable == NULL){
|
||||
KNI_LOG_ERROR(logger, "MESA_htable: failed at MESA_htable_born");
|
||||
return NULL;
|
||||
}
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, mho_screen_print_ctrl, logger, section);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_THREAD_SAFE, mho_thread_safe, logger, section);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_MUTEX_NUM, mho_mutex_num, logger, section);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, mho_hash_slot_size, logger, section);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_MAX_ELEMENT_NUM, mho_hash_max_element_num, logger, section);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_EXPIRE_TIME, mho_expire_time, logger, section);
|
||||
if(strncmp(mho_eliminate_type, "LRU", KNI_SYMBOL_MAX) == 0)
|
||||
{
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_LRU, logger, section);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, opt->mho_screen_print_ctrl, logger, symbol);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_THREAD_SAFE, opt->mho_thread_safe, logger, symbol);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_MUTEX_NUM, opt->mho_mutex_num, logger, symbol);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, opt->mho_hash_slot_size, logger, symbol);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_MAX_ELEMENT_NUM, opt->mho_hash_max_element_num, logger, symbol);
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_EXPIRE_TIME, opt->mho_expire_time, logger, symbol);
|
||||
if(strncmp(opt->mho_eliminate_type, "LRU", KNI_SYMBOL_MAX) == 0){
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_LRU, logger, symbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_FIFO, logger, section);
|
||||
else{
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_FIFO, logger, symbol);
|
||||
}
|
||||
if(free_data_cb != NULL){
|
||||
if(opt->free_data_cb != NULL){
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_CBFUN_DATA_FREE,
|
||||
(void *)free_data_cb, sizeof(free_data_cb), logger, section);
|
||||
(void *)(opt->free_data_cb), sizeof(opt->free_data_cb), logger, symbol);
|
||||
}
|
||||
if(expire_notify_cb != NULL){
|
||||
if(opt->expire_notify_cb != NULL){
|
||||
__wrapper_MESA_htable_set_opt(htable, MHO_CBFUN_DATA_EXPIRE_NOTIFY,
|
||||
(void *)expire_notify_cb, sizeof(free_data_cb), logger, section);
|
||||
(void *)(opt->expire_notify_cb), sizeof(opt->expire_notify_cb), logger, symbol);
|
||||
}
|
||||
int ret = MESA_htable_mature(htable);
|
||||
if(unlikely(ret != 0))
|
||||
{
|
||||
KNI_LOG_ERROR(logger, "MESA_htable: failed at MESA_htable_mature, htable is %s", section);
|
||||
if(unlikely(ret != 0)){
|
||||
KNI_LOG_ERROR(logger, "MESA_htable: failed at MESA_htable_mature, htable is %s", symbol);
|
||||
return NULL;
|
||||
}
|
||||
return htable;
|
||||
|
||||
@@ -2298,8 +2298,10 @@ extern "C" int kni_init(){
|
||||
g_kni_handle->send_logger = send_logger;
|
||||
|
||||
//init traceid2pme_htable
|
||||
traceid2pme_htable = kni_create_htable(profile, "traceid2pme_htable", NULL,
|
||||
(void*)traceid2pme_htable_expire_notify_cb, local_logger);
|
||||
struct kni_htable_opt opt;
|
||||
memset(&opt, 0, sizeof(opt));
|
||||
kni_get_htable_opt(&opt, profile, "traceid2pme_htable", NULL, (void*)traceid2pme_htable_expire_notify_cb, local_logger);
|
||||
traceid2pme_htable = kni_create_htable("traceid2pme_htable", &opt, local_logger);
|
||||
if(traceid2pme_htable == NULL){
|
||||
KNI_LOG_ERROR(local_logger, "Failed at create traceid2pme_htable");
|
||||
goto error_out;
|
||||
@@ -2308,9 +2310,10 @@ extern "C" int kni_init(){
|
||||
|
||||
//init tuple2stream_htable
|
||||
g_kni_handle->threads_handle = ALLOC(struct per_thread_handle, g_kni_handle->thread_count);
|
||||
memset(&opt, 0, sizeof(opt));
|
||||
kni_get_htable_opt(&opt, profile, "tuple2stream_htable", (void*)tuple2stream_htable_data_free_cb, NULL, local_logger);
|
||||
for(int i = 0; i < g_kni_handle->thread_count; i++){
|
||||
MESA_htable_handle tuple2stream_htable = kni_create_htable(profile, "tuple2stream_htable",
|
||||
(void*)tuple2stream_htable_data_free_cb, NULL, local_logger);
|
||||
MESA_htable_handle tuple2stream_htable = kni_create_htable("tuple2stream_htable", &opt, local_logger);
|
||||
if(tuple2stream_htable == NULL){
|
||||
KNI_LOG_ERROR(local_logger, "Failed at kni_create_htable, table = tuple2stream_htable");
|
||||
goto error_out;
|
||||
|
||||
Reference in New Issue
Block a user