Skip to content

Commit

Permalink
filtrate ':0' address in the cluster nodes command reply
Browse files Browse the repository at this point in the history
  • Loading branch information
deep011 committed Nov 20, 2015
1 parent 2cfb27f commit 44b615b
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 188 deletions.
161 changes: 91 additions & 70 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ void
redis_parse_cmd(struct cmd *r)
{
char *p, *m, *token = NULL;
char *cmd_end;
char *cmd_end;
char ch;
uint32_t rlen = 0; /* running length in parsing fsa */
uint32_t rnarg = 0; /* running # arg used by parsing fsa */
uint32_t rlen = 0; /* running length in parsing fsa */
uint32_t rnarg = 0; /* running # arg used by parsing fsa */
enum {
SW_START,
SW_NARG,
Expand Down Expand Up @@ -352,7 +352,7 @@ redis_parse_cmd(struct cmd *r)
} state;

state = SW_START;
cmd_end = r->cmd + r->clen;
cmd_end = r->cmd + r->clen;

ASSERT(state >= SW_START && state < SW_SENTINEL);
ASSERT(r->cmd != NULL && r->clen > 0);
Expand Down Expand Up @@ -445,7 +445,7 @@ redis_parse_cmd(struct cmd *r)
//m = cmd_end - 1;
//p = m;
//break;
goto error;
goto error;
}

if (*m != CR) {
Expand Down Expand Up @@ -1062,7 +1062,7 @@ redis_parse_cmd(struct cmd *r)
} else if (isdigit(ch)) {
rlen = rlen * 10 + (uint32_t)(ch - '0');
} else if (ch == CR) {
if (rnarg == 0) {
goto error;
}
Expand Down Expand Up @@ -1116,6 +1116,7 @@ redis_parse_cmd(struct cmd *r)
}
kpos->start = m;
kpos->end = p;
//kpos->v_len = 0;

state = SW_KEY_LF;
}
Expand Down Expand Up @@ -1195,6 +1196,26 @@ redis_parse_cmd(struct cmd *r)
}
rnarg--;
token = NULL;

/*
//for mset value length
if(redis_argkvx(r))
{
struct keypos *kpos;
uint32_t array_len = array_n(r->keys);
if(array_len == 0)
{
goto error;
}
kpos = array_n(r->keys, array_len-1);
if (kpos == NULL || kpos->v_len != 0) {
goto error;
}
kpos->v_len = rlen;
}
*/
state = SW_ARG1_LEN_LF;
} else {
goto error;
Expand Down Expand Up @@ -1573,95 +1594,95 @@ redis_parse_cmd(struct cmd *r)

done:

ASSERT(r->type > CMD_UNKNOWN && r->type < CMD_SENTINEL);
ASSERT(r->type > CMD_UNKNOWN && r->type < CMD_SENTINEL);
r->result = CMD_PARSE_OK;

return;

enomem:
r->result = CMD_PARSE_ERROR;

return;

error:
r->result = CMD_PARSE_ERROR;
errno = EINVAL;

}

struct cmd *command_get()
{
struct cmd *command;
command = hi_alloc(sizeof(struct cmd));
if(command == NULL)
{
return NULL;
}
command->id = ++cmd_id;
command->result = CMD_PARSE_OK;
command->type = CMD_UNKNOWN;
command->cmd = NULL;
command->clen = 0;
command->keys = NULL;
command->narg_start = NULL;
command->narg_end = NULL;
command->narg = 0;
command->quit = 0;
command->noforward = 0;
command->slot_num = -1;
command->frag_seq = NULL;
command->reply = NULL;
command->sub_commands = NULL;

command->keys = hiarray_create(1, sizeof(struct keypos));
struct cmd *command;
command = hi_alloc(sizeof(struct cmd));
if(command == NULL)
{
return NULL;
}
command->id = ++cmd_id;
command->result = CMD_PARSE_OK;
command->type = CMD_UNKNOWN;
command->cmd = NULL;
command->clen = 0;
command->keys = NULL;
command->narg_start = NULL;
command->narg_end = NULL;
command->narg = 0;
command->quit = 0;
command->noforward = 0;
command->slot_num = -1;
command->frag_seq = NULL;
command->reply = NULL;
command->sub_commands = NULL;

command->keys = hiarray_create(1, sizeof(struct keypos));
if (command->keys == NULL)
{
hi_free(command);
{
hi_free(command);
return NULL;
}

return command;
return command;
}

void command_destroy(struct cmd *command)
{
if(command == NULL)
{
return;
}

if(command->cmd != NULL)
{
free(command->cmd);
}

if(command->keys != NULL)
{
command->keys->nelem = 0;
hiarray_destroy(command->keys);
}

if(command->frag_seq != NULL)
{
hi_free(command->frag_seq);
command->frag_seq = NULL;
}

if(command->reply != NULL)
{
freeReplyObject(command->reply);
}

if(command->sub_commands != NULL)
{
listRelease(command->sub_commands);
}
hi_free(command);
if(command == NULL)
{
return;
}

if(command->cmd != NULL)
{
free(command->cmd);
}

if(command->keys != NULL)
{
command->keys->nelem = 0;
hiarray_destroy(command->keys);
}

if(command->frag_seq != NULL)
{
hi_free(command->frag_seq);
command->frag_seq = NULL;
}

if(command->reply != NULL)
{
freeReplyObject(command->reply);
}

if(command->sub_commands != NULL)
{
listRelease(command->sub_commands);
}
hi_free(command);
}


30 changes: 15 additions & 15 deletions command.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,36 +137,36 @@ typedef enum cmd_type {
struct keypos {
char *start; /* key start pos */
char *end; /* key end pos */
uint32_t remain_len; /* remain length after keypos->end for more key-value pairs in command, like mset */
uint32_t remain_len; /* remain length after keypos->end for more key-value pairs in command, like mset */
};

struct cmd {

uint64_t id; /* command id */
cmd_parse_result_t result; /* command parsing result */

cmd_type_t type; /* command type */
cmd_type_t type; /* command type */

char *cmd;
uint32_t clen; /* command length */
char *cmd;
uint32_t clen; /* command length */
struct hiarray *keys; /* array of keypos, for req */

char *narg_start; /* narg start (redis) */
char *narg_end; /* narg end (redis) */
char *narg_start; /* narg start (redis) */
char *narg_end; /* narg end (redis) */
uint32_t narg; /* # arguments (redis) */

unsigned quit:1; /* quit request? */
unsigned noforward:1; /* not need forward (example: ping) */
unsigned quit:1; /* quit request? */
unsigned noforward:1; /* not need forward (example: ping) */

int slot_num; /* this command should send to witch slot?
* -1:the keys in this command cross different slots*/
struct cmd **frag_seq; /* sequence of fragment command, map from keys to fragments*/
int slot_num; /* this command should send to witch slot?
* -1:the keys in this command cross different slots*/
struct cmd **frag_seq; /* sequence of fragment command, map from keys to fragments*/

redisReply *reply;
redisReply *reply;

list *sub_commands; /* just for pipeline and multi-key commands */
list *sub_commands; /* just for pipeline and multi-key commands */

};

Expand Down
4 changes: 2 additions & 2 deletions hiarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ hiarray_destroy(struct hiarray *a)
hi_free(a);
}

rstatus_t
int
hiarray_init(struct hiarray *a, uint32_t n, size_t size)
{
ASSERT(n != 0 && size != 0);
Expand Down Expand Up @@ -166,7 +166,7 @@ hiarray_sort(struct hiarray *a, hiarray_compare_t compare)
* Calls the func once for each element in the array as long as func returns
* success. On failure short-circuits and returns the error status.
*/
rstatus_t
int
hiarray_each(struct hiarray *a, hiarray_each_t func, void *data)
{
uint32_t i, nelem;
Expand Down
17 changes: 16 additions & 1 deletion hircluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,20 @@ cluster_update_route_with_nodes(redisClusterContext *cc,
goto error;
}

//the address string is ":0", skip this node.
if(sdslen(part[1]) == 2 && strcmp(part[1], ":0") == 0)
{
sdsfreesplitres(part, count_part);
count_part = 0;
part = NULL;

start = pos + 1;
line_start = start;
pos = start;

continue;
}

if(sdslen(part[2]) >= 7 && memcmp(part[2], "myself,", 7) == 0)
{
role_len = sdslen(part[2]) - 7;
Expand Down Expand Up @@ -1122,6 +1136,7 @@ cluster_update_route_with_nodes(redisClusterContext *cc,
if(cc->nodes != NULL)
{
dictRelease(cc->nodes);
cc->nodes = NULL;
}
cc->nodes = nodes;

Expand Down Expand Up @@ -1183,7 +1198,7 @@ cluster_update_route_with_nodes(redisClusterContext *cc,
cc->nodes = NULL;
}

dictRelease(cc->nodes);
dictRelease(nodes);
}

if(nodes_name != NULL)
Expand Down
Loading

0 comments on commit 44b615b

Please sign in to comment.