From 9396bb9e63dcc4548575e4ad52ba733dc58a0e8f Mon Sep 17 00:00:00 2001 From: zhengchao Date: Thu, 31 Aug 2017 18:21:56 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=8F=90=E4=BE=9BMaat=5Fcmd=5Fset=5F?= =?UTF-8?q?lines=E5=87=BD=E6=95=B0=EF=BC=8C=E6=94=AF=E6=8C=81=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=86=99=E5=85=A5line=5Frule=EF=BC=9B2=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=9F=E6=9C=89Maat=5Fcmd=5Fset=5Fline?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E7=9A=84?= =?UTF-8?q?bug=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/Maat_command.h | 2 +- src/entry/Maat_command.cpp | 81 ++++++++++++++++++++++++-------------- test/maat_test.cpp | 28 ++++++++----- test/reset_redis4maat.sh | 1 - 4 files changed, 71 insertions(+), 41 deletions(-) diff --git a/inc/Maat_command.h b/inc/Maat_command.h index 1d65383..0ff1dae 100644 --- a/inc/Maat_command.h +++ b/inc/Maat_command.h @@ -145,7 +145,7 @@ int Maat_cmd_commit(Maat_feather_t feather); int Maat_cmd_set_group(Maat_feather_t feather, int group_id, const struct Maat_region_t* region, enum MAAT_OPERATION op); int Maat_cmd_set_line(Maat_feather_t feather,const struct Maat_line_t* line_rule, enum MAAT_OPERATION op); - +int Maat_cmd_set_lines(Maat_feather_t feather,const struct Maat_line_t** line_rule, int line_num ,enum MAAT_OPERATION op); //Return the value of key after the increment. //If the key does not exist, it is set to 0 before performing the operation. long long Maat_cmd_incrby(Maat_feather_t feather,const char* key, int increment); diff --git a/src/entry/Maat_command.cpp b/src/entry/Maat_command.cpp index 9e3b606..dfe2b5f 100644 --- a/src/entry/Maat_command.cpp +++ b/src/entry/Maat_command.cpp @@ -388,6 +388,10 @@ int get_rm_key_list(unsigned int version,redisContext *c,struct serial_rule_t** } *new_version=version_in_redis; + if(version==0) + { + goto FULL_UPDATE; + } if(version_in_redismap_tablename2id, line_rule->table_name, &table_id); - if(ret<0) - { - MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_module - ,"Command set line id %d failed: unknown table %s." - , line_rule->rule_id - , line_rule->table_name); - - return -1; - } - if(TABLE_TYPE_PLUGIN!=_feather->p_table_info[table_id]->table_type) - { - MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_module - ,"Command set line id %d failed: table %s is not a plugin table." - , line_rule->rule_id - , line_rule->table_name); - return -1; - } - server_time=redis_server_time(_feather->redis_write_ctx); - if( line_rule->expire_after>0) + s_rule=(struct serial_rule_t *)calloc(sizeof(struct serial_rule_t),line_num); + for(i=0;iexpire_after; + ret=map_str2int(_feather->map_tablename2id, line_rule[i]->table_name, &table_id); + if(ret<0) + { + MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_module + ,"Command set line id %d failed: unknown table %s." + , line_rule[i]->rule_id + , line_rule[i]->table_name); + ret=-1; + goto error_out; + } + if(TABLE_TYPE_PLUGIN!=_feather->p_table_info[table_id]->table_type) + { + MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_module + ,"Command set line id %d failed: table %s is not a plugin table." + , line_rule[i]->rule_id + , line_rule[i]->table_name); + ret=-1; + goto error_out; + } + + if(line_rule[i]->expire_after>0) + { + absolute_expire_time=server_time+line_rule[i]->expire_after; + } + set_serial_rule(s_rule+i, op,line_rule[i]->rule_id,line_rule[i]->label_id,line_rule[i]->table_name,line_rule[i]->table_line, absolute_expire_time); } - set_serial_rule(&s_rule, op,line_rule->rule_id,line_rule->label_id,line_rule->table_name,line_rule->table_line, absolute_expire_time); ret=0; - while(ret==0) + while(success_cntredis_write_ctx,&s_rule, 1,server_time); + success_cnt+=exec_serial_rule(_feather->redis_write_ctx,s_rule+success_cnt, line_num-success_cnt,server_time); retry++; } if(retry>10) { MESA_handle_runtime_log(_feather->logger,RLOG_LV_INFO,maat_module ,"Command set line id %d success after retry %d times." - , line_rule->rule_id + , line_rule[0]->rule_id ); } - return 0; +error_out: + for(i=0;i