From a92e7b4253c503b500bd8ac9ea74bd78fb45c7cb Mon Sep 17 00:00:00 2001 From: zhengchao Date: Thu, 6 Dec 2018 21:11:51 +0600 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=80=E6=AC=A1=E5=86=99?= =?UTF-8?q?=E5=85=A520=E4=B8=87lines=E5=92=8Crule=E7=9A=84=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/Maat_rule.h | 5 +- src/entry/Maat_api.cpp | 14 ++ src/entry/Maat_command.cpp | 18 +- src/inc_internal/Maat_rule_internal.h | 2 +- test/maat_demo.cpp | 19 +- test/test_maatframe.cpp | 265 ++++++++++++++++++-------- tools/maat_redis_tool.cpp | 6 +- 7 files changed, 224 insertions(+), 105 deletions(-) diff --git a/inc/Maat_rule.h b/inc/Maat_rule.h index d5e4621..0163650 100644 --- a/inc/Maat_rule.h +++ b/inc/Maat_rule.h @@ -165,8 +165,9 @@ enum MAAT_INIT_OPT int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const void* value,int size); enum MAAT_STATE_OPT { - MAAT_STATE_VERSION=1, //Get current maat version. VALUE is long long, SIZE=sizeof(long long). - MAAT_STATE_LAST_UPDATING_TABLE //Query at Maat_finish_callback_t to determine whether this table is the last one to update. VALUE is interger, SIZE=sizeof(int), 1:yes, 0: no + MAAT_STATE_VERSION=1, //Get current maat version, if maat is in update progress, the updating version is returned. VALUE is long long, SIZE=sizeof(long long). + MAAT_STATE_LAST_UPDATING_TABLE, //Query at Maat_finish_callback_t to determine whether this table is the last one to update. VALUE is interger, SIZE=sizeof(int), 1:yes, 0: no + MAAT_STATE_IN_UPDATING }; int Maat_read_state(Maat_feather_t feather, enum MAAT_STATE_OPT type, void* value, int size); diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp index 803ee46..a8ccf77 100644 --- a/src/entry/Maat_api.cpp +++ b/src/entry/Maat_api.cpp @@ -2260,6 +2260,20 @@ int Maat_read_state(Maat_feather_t feather,enum MAAT_STATE_OPT type, void* valu case MAAT_STATE_LAST_UPDATING_TABLE: *int_val=_feather->is_last_plugin_table_updating; break; + case MAAT_STATE_IN_UPDATING: + if(size!=sizeof(int)) + { + return -1; + } + if(0==pthread_mutex_trylock(&(_feather->backgroud_update_mutex))) + { + *int_val=0; + pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + } + else + { + *int_val=1; + } default: return -1; break; diff --git a/src/entry/Maat_command.cpp b/src/entry/Maat_command.cpp index 8b6f188..c3f156d 100644 --- a/src/entry/Maat_command.cpp +++ b/src/entry/Maat_command.cpp @@ -1213,21 +1213,21 @@ void _exec_serial_rule(redisContext* ctx, long long version, struct serial_rule_ return; } -int exec_serial_rule(redisContext* ctx,struct serial_rule_t* s_rule,int serial_rule_num, long long server_time, void* logger) +int exec_serial_rule(redisContext* ctx,struct serial_rule_t* s_rule, unsigned int serial_rule_num, long long server_time, void* logger) { - int max_redis_batch=1*1024,batch_cnt=0; - int success_cnt=0,j=0,renew_allowed=0,last_failed=-1; + unsigned int max_redis_batch=1*1024, batch_cnt=0; + int renew_allowed=0,last_failed=-1; redisReply*transaction_reply=NULL,*p=NULL; unsigned int i=0; - unsigned int multi_cmd_cnt=0; + unsigned int multi_cmd_cnt=0, success_cnt=0; const int MAX_REDIS_OP_PER_SRULE=8; unsigned int max_multi_cmd_num=MAX_REDIS_OP_PER_SRULE*serial_rule_num+2;// 2 for operation in _exec_serial_rule_end() struct expected_reply_t *expected_reply=(struct expected_reply_t*)calloc(sizeof(struct expected_reply_t), max_multi_cmd_num); long long new_version=0; int renew_num=0,ret=0; - for(i=0;i<(unsigned int)serial_rule_num;i++) + for(i=0;i