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