Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
adebee8a
Commit
adebee8a
authored
Mar 06, 2018
by
artix
Browse files
clusterManagerAddSlots: changed the way ADDSLOTS command is built
parent
a4a1c7bb
Changes
1
Show whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
adebee8a
...
@@ -2354,32 +2354,28 @@ static int clusterManagerAddSlots(clusterManagerNode *node, char**err)
...
@@ -2354,32 +2354,28 @@ static int clusterManagerAddSlots(clusterManagerNode *node, char**err)
redisReply
*
reply
=
NULL
;
redisReply
*
reply
=
NULL
;
void
*
_reply
=
NULL
;
void
*
_reply
=
NULL
;
int
is_err
=
0
,
success
=
1
;
int
is_err
=
0
,
success
=
1
;
int argc;
/* First two args are used for the command itself. */
sds *argv = NULL;
int
argc
=
node
->
slots_count
+
2
;
size_t *argvlen = NULL;
sds
*
argv
=
zmalloc
(
argc
*
sizeof
(
*
argv
));
size_t
*
argvlen
=
zmalloc
(
argc
*
sizeof
(
*
argvlen
));
argv
[
0
]
=
"CLUSTER"
;
argv
[
1
]
=
"ADDSLOTS"
;
argvlen
[
0
]
=
7
;
argvlen
[
1
]
=
8
;
*
err
=
NULL
;
*
err
=
NULL
;
sds cmd = sdsnew("CLUSTER ADDSLOTS ");
int
i
,
argv_idx
=
2
;
int i, added = 0;
for
(
i
=
0
;
i
<
CLUSTER_MANAGER_SLOTS
;
i
++
)
{
for
(
i
=
0
;
i
<
CLUSTER_MANAGER_SLOTS
;
i
++
)
{
i
nt last_slot = (i == (CLUSTER_MANAGER_SLOTS - 1))
;
i
f
(
argv_idx
>=
argc
)
break
;
if
(
node
->
slots
[
i
])
{
if
(
node
->
slots
[
i
])
{
char *fmt = (!last_slot ? "%u " : "%u");
argv
[
argv_idx
]
=
sdsfromlonglong
((
long
long
)
i
);
cmd = sdscatfmt(cmd, fmt, i);
argvlen
[
argv_idx
]
=
sdslen
(
argv
[
argv_idx
]);
added++;
argv_idx
++
;
}
}
}
if (!added) {
success = 0;
goto cleanup;
}
}
argv = cliSplitArgs(cmd, &argc);
if
(
!
argv_idx
)
{
if (argc == 0 || argv == NULL) {
success
=
0
;
success
=
0
;
goto
cleanup
;
goto
cleanup
;
}
}
argvlen = zmalloc(argc*sizeof(size_t));
for (i = 0; i < argc; i++)
argvlen[i] = sdslen(argv[i]);
redisAppendCommandArgv
(
node
->
context
,
argc
,(
const
char
**
)
argv
,
argvlen
);
redisAppendCommandArgv
(
node
->
context
,
argc
,(
const
char
**
)
argv
,
argvlen
);
if
(
redisGetReply
(
node
->
context
,
&
_reply
)
!=
REDIS_OK
)
{
if
(
redisGetReply
(
node
->
context
,
&
_reply
)
!=
REDIS_OK
)
{
success
=
0
;
success
=
0
;
...
@@ -2395,9 +2391,11 @@ static int clusterManagerAddSlots(clusterManagerNode *node, char**err)
...
@@ -2395,9 +2391,11 @@ static int clusterManagerAddSlots(clusterManagerNode *node, char**err)
goto
cleanup
;
goto
cleanup
;
}
}
cleanup:
cleanup:
sdsfree(cmd);
zfree
(
argvlen
);
zfree
(
argvlen
);
if (argv != NULL) sdsfreesplitres(argv,argc);
if
(
argv
!=
NULL
)
{
for
(
i
=
2
;
i
<
argc
;
i
++
)
sdsfree
(
argv
[
i
]);
zfree
(
argv
);
}
if
(
reply
!=
NULL
)
freeReplyObject
(
reply
);
if
(
reply
!=
NULL
)
freeReplyObject
(
reply
);
return
success
;
return
success
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment