可以select除表名和表ID。

This commit is contained in:
zhengchao
2018-12-11 19:52:40 +06:00
parent 54778d65a5
commit 12baa32183
4 changed files with 60 additions and 12 deletions

View File

@@ -161,6 +161,13 @@ int Maat_cmd_set_file(Maat_feather_t feather,const char* key, const char* value,
//Return the value of key after the increment. //Return the value of key after the increment.
//If the key does not exist, it is set to 0 before performing the operation. //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); long long Maat_cmd_incrby(Maat_feather_t feather,const char* key, int increment);
struct Maat_cmd_key
{
char* table_name;
int rule_id;
};
void Maat_cmd_key_free(struct Maat_cmd_key**keys, int number);
int Maat_cmd_key_select(Maat_feather_t feather, int label_id, struct Maat_cmd_key** keys);
int Maat_cmd_select(Maat_feather_t feather, int label_id, int * output_ids, unsigned int size); int Maat_cmd_select(Maat_feather_t feather, int label_id, int * output_ids, unsigned int size);
int Maat_cmd_flushDB(Maat_feather_t feather); int Maat_cmd_flushDB(Maat_feather_t feather);
#endif #endif

View File

@@ -1129,9 +1129,11 @@ void _exec_serial_rule(redisContext* ctx, long long version, struct serial_rule_
} }
if(s_rule[i].label_id>0) if(s_rule[i].label_id>0)
{ {
redisAppendCommand(ctx,"ZADD %s NX %d %d",rm_label_sset redisAppendCommand(ctx,"ZADD %s NX %d %s,%d",
,s_rule[i].label_id rm_label_sset,
,s_rule[i].rule_id); s_rule[i].label_id,
s_rule[i].table_name,
s_rule[i].rule_id);
expect_reply[*cnt].srule_seq=i+offset; expect_reply[*cnt].srule_seq=i+offset;
expect_reply[*cnt].reply.type=REDIS_REPLY_INTEGER; expect_reply[*cnt].reply.type=REDIS_REPLY_INTEGER;
expect_reply[*cnt].reply.integer=1; expect_reply[*cnt].reply.integer=1;
@@ -2400,26 +2402,64 @@ long long Maat_cmd_incrby(Maat_feather_t feather,const char* key, int increment)
} }
freeReplyObject(data_reply); freeReplyObject(data_reply);
return result; return result;
} }
void Maat_cmd_key_free(struct Maat_cmd_key**keys, int size)
{
int i=0;
struct Maat_cmd_key* p=*keys;
for(i=0; i<size; i++)
{
free(p->table_name);
p->table_name=NULL;
p->rule_id=0;
}
free(p);
*keys=NULL;
return;
}
int Maat_cmd_key_select(Maat_feather_t feather, int label_id, struct Maat_cmd_key** keys) int Maat_cmd_key_select(Maat_feather_t feather, int label_id, struct Maat_cmd_key** keys)
{ {
_Maat_feather_t* _feather=(_Maat_feather_t*)feather; _Maat_feather_t* _feather=(_Maat_feather_t*)feather;
redisReply* data_reply=NULL;
char* tmp=NULL; char* tmp=NULL;
unsigned int i=0;
struct Maat_cmd_key* result=NULL;
int result_cnt=0; int result_cnt=0;
redisContext* write_ctx=get_redis_ctx_for_write(_feather); redisContext* write_ctx=get_redis_ctx_for_write(_feather);
if(write_ctx==NULL) if(write_ctx==NULL)
{ {
return -1; return -1;
} }
data_reply=_wrap_redisCommand(write_ctx,"ZRANGEBYSCORE %s %d %d" data_reply=_wrap_redisCommand(write_ctx,"ZRANGEBYSCORE %s %d %d",
,rm_label_sset rm_label_sset,
,label_id label_id,
,label_id); label_id);
result_cnt=data_reply->elements;
result=ALLOC(struct Maat_cmd_key, data_reply->elements);
for(i=0;i<data_reply->elements;i++) for(i=0;i<data_reply->elements;i++)
{ {
result[i].table_name=_maat_strdup(data_reply->element[i]->str);
tmp=strchr(result[i].table_name, ',');
*tmp='\0';
tmp++;
result[i].rule_id=atoi(tmp); result[i].rule_id=atoi(tmp);
} }
freeReplyObject(data_reply);
*keys=result;
return result_cnt;
}
int Maat_cmd_select(Maat_feather_t feather, int label_id, int * output_ids, unsigned int size)
{
struct Maat_cmd_key* keys=NULL;
int result_cnt=0, i=0;
result_cnt=Maat_cmd_key_select(feather, label_id, &keys);
for(i=0; i<result_cnt && i<(int)size; i++)
{
output_ids[i]=keys[i].rule_id;
}
Maat_cmd_key_free(&keys, result_cnt); Maat_cmd_key_free(&keys, result_cnt);
return i; return i;
} }

View File

@@ -621,7 +621,7 @@ int read_plugin_table_description(const char* line, struct Maat_table_desc* p)
} }
plug_info=copy_line+offset; plug_info=copy_line+offset;
if(strlen(plug_info)<COLUMN_PLUGIN_DESCR_JSON)//For old version compatible. if(NULL==strchr(plug_info,'{'))//For old version compatible.
{ {
ret=sscanf(plug_info, "%d", &(plugin_desc->valid_flag_column)); ret=sscanf(plug_info, "%d", &(plugin_desc->valid_flag_column));
if(ret==0||ret==EOF) if(ret==0||ret==EOF)

View File

@@ -1246,6 +1246,7 @@ TEST_F(MaatCmdTest, SetLines)
return; return;
} }
/*
//Following tests must be coded/tested at last, for they stalled the maat update thread and interrupt other tests. //Following tests must be coded/tested at last, for they stalled the maat update thread and interrupt other tests.
TEST_F(MaatCmdTest, SetExprOneMillion) TEST_F(MaatCmdTest, SetExprOneMillion)
{ {
@@ -1335,7 +1336,7 @@ TEST_F(MaatCmdTest, SetLinesOneMillion)
return; return;
} }
*/
int g_test_update_paused=0; int g_test_update_paused=0;
void pause_update_test_entry_cb(int table_id,const char* table_line,void* u_para) void pause_update_test_entry_cb(int table_id,const char* table_line,void* u_para)
{ {