未完成:支持异步加载。

This commit is contained in:
zhengchao
2017-08-21 13:59:49 +08:00
parent 733bf35a30
commit 64a9284430
5 changed files with 50 additions and 21 deletions

View File

@@ -150,7 +150,8 @@ enum MAAT_INIT_OPT
MAAT_OPT_REDIS_IP, //VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. No DEFAULT.
MAAT_OPT_REDIS_PORT, //VALUE is a unsigned short, host order, SIZE= sizeof(unsigned short). No DEFAULT.
MAAT_OPT_REDIS_INDEX, //VALUE is interger *, 0~15, SIZE=sizeof(int). DEFAULT: 0.
MAAT_OPT_CMD_AUTO_NUMBERING //VALUE is interger *, 1 or 0, SIZE=sizeof(int). DEFAULT: 1.
MAAT_OPT_CMD_AUTO_NUMBERING, //VALUE is interger *, 1 or 0, SIZE=sizeof(int). DEFAULT: 1.
MAAT_OPT_DEFERRED_INIT //VALUE is NULL,SIZE is 0. Default: Deffered initialization OFF.
};
//return -1 if failed, return 0 on success;
int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const void* value,int size);

View File

@@ -605,16 +605,17 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo
}
_feather->AUTO_NUMBERING_ON=*((int*)value);
break;
case MAAT_OPT_DEFERRED_INIT:
_feather->DEFERRED_INIT_ON=1;
break;
default:
return -1;
}
return 0;
}
int Maat_initiate_feather(Maat_feather_t feather)
void maat_read_full_config(_Maat_feather_t* _feather)
{
_Maat_feather_t* _feather=(_Maat_feather_t*)feather;
redisReply* reply=NULL;
if(strlen(_feather->redis_ip)>0&&_feather->redis_port!=0)
{
_feather->REDIS_MODE_ON=1;
@@ -652,7 +653,7 @@ int Maat_initiate_feather(Maat_feather_t feather)
MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_module ,
"At initiation: NO FULL_CFG_DIR or JSON_FILE_PATH. ");
return -1;
return;
}
config_monitor_traverse(_feather->maat_version,
_feather->full_dir,
@@ -687,6 +688,15 @@ int Maat_initiate_feather(Maat_feather_t feather)
_feather->maat_version=_feather->scanner->version;
_feather->last_full_version=_feather->scanner->version;
}
return;
}
int Maat_initiate_feather(Maat_feather_t feather)
{
_Maat_feather_t* _feather=(_Maat_feather_t*)feather;
if(_feather->DEFERRED_INIT_ON==0)
{
maat_read_full_config(_feather);
}
if(strlen(_feather->stat_file)==0)
{
if(_feather->stat_on==1)

View File

@@ -28,7 +28,7 @@
#include "stream_fuzzy_hash.h"
#include "gram_index_engine.h"
int MAAT_FRAME_VERSION_2_0_20170816=1;
int MAAT_FRAME_VERSION_2_0_20170821=1;
const char *maat_module="MAAT Frame";
const char* CHARSET_STRING[]={"NONE","gbk","big5","unicode","utf8","bin",
@@ -3168,6 +3168,10 @@ void *thread_rule_monitor(void *arg)
//pthread_setname_np are introduced in glibc2.12
//ret=pthread_setname_np(pthread_self(),maat_name);
assert(ret>=0);
if(feather->DEFERRED_INIT_ON!=0)
{
maat_read_full_config(feather);
}
while(feather->still_working)
{
usleep(feather->scan_interval_ms*1000);

View File

@@ -355,6 +355,7 @@ struct _Maat_feather_t
struct _Maat_scanner_t *update_tmp_scanner;
MESA_lqueue_head garbage_q;
int table_cnt;
int DEFERRED_INIT_ON;
int GROUP_MODE_ON;
int REDIS_MODE_ON;
int still_working;
@@ -448,6 +449,7 @@ inline void ipv6_ntoh(unsigned int *v6_addr)
void * HASH_fetch_by_id(MESA_htable_handle hash,int id);
int HASH_add_by_id(MESA_htable_handle hash,int id,void*data);
int HASH_delete_by_id(MESA_htable_handle hash,int id);
void maat_read_full_config(_Maat_feather_t* _feather);
void maat_stat_init(struct _Maat_feather_t* feather);
void maat_stat_table(struct _Maat_table_info_t* p_table,int scan_len,struct timespec* start, struct timespec* end,int thread_num);
void maat_stat_output(struct _Maat_feather_t* feather);

View File

@@ -660,23 +660,35 @@ int main(int argc,char* argv[])
feather=Maat_feather(g_iThreadNum, table_info_path, logger);
Maat_set_feather_opt(feather,MAAT_OPT_INSTANCE_NAME,"demo", strlen("demo")+1);
Maat_set_feather_opt(feather,MAAT_OPT_DECRYPT_KEY,decrypt_key, strlen(decrypt_key)+1);
if(argc>1&&0==strcmp(argv[1],"update"))
int oc=0;
while((oc=getopt(argc,argv,"ujrd"))!=-1)
{
switch(oc)
{
case 'u'://update
Maat_set_feather_opt(feather, MAAT_OPT_FULL_CFG_DIR, ful_cfg_dir, strlen(ful_cfg_dir)+1);
Maat_set_feather_opt(feather, MAAT_OPT_INC_CFG_DIR, inc_cfg_dir, strlen(inc_cfg_dir)+1);
wait_second=14;
}
else if(argc>1&&0==strcmp(argv[1],"redis"))
{
break;
case 'r'://redis
Maat_set_feather_opt(feather, MAAT_OPT_REDIS_IP, redis_ip, strlen(redis_ip)+1);
Maat_set_feather_opt(feather, MAAT_OPT_REDIS_PORT, &redis_port, sizeof(redis_port));
using_redis=1;
}
else
{
break;
case 'j'://json
Maat_set_feather_opt(feather, MAAT_OPT_JSON_FILE_PATH, json_path, strlen(json_path)+1);
break;
case 'd'://deferred
Maat_set_feather_opt(feather, MAAT_OPT_DEFERRED_INIT, NULL,0);
wait_second=14;
break;
default:
return 0;
break;
}
}
Maat_set_feather_opt(feather, MAAT_OPT_SCANDIR_INTERVAL_MS,&scan_interval_ms, sizeof(scan_interval_ms));
Maat_set_feather_opt(feather, MAAT_OPT_STAT_FILE_PATH, stat_file, strlen(stat_file)+1);
Maat_set_feather_opt(feather, MAAT_OPT_STAT_ON, NULL, 0);