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
2f9c032a
Commit
2f9c032a
authored
May 15, 2018
by
artix
Browse files
Cluster Manager: print flags as strings.
parent
3c039996
Changes
1
Show whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
2f9c032a
...
...
@@ -1815,6 +1815,7 @@ typedef struct clusterManagerNode {
time_t ping_sent;
time_t ping_recv;
int flags;
list *flags_str; /* Flags string representations */
sds replicate; /* Master ID if node is a slave */
list replicas;
int dirty; /* Node has changes that can be flushed */
...
...
@@ -2001,6 +2002,17 @@ static int getClusterHostFromCmdArgs(int argc, char **argv,
return 1;
}
static void freeClusterManagerNodeFlags(list *flags) {
listIter li;
listNode *ln;
listRewind(flags, &li);
while ((ln = listNext(&li)) != NULL) {
sds flag = ln->value;
sdsfree(flag);
}
listRelease(flags);
}
static void freeClusterManagerNode(clusterManagerNode *node) {
if (node->context != NULL) redisFree(node->context);
if (node->friends != NULL) {
...
...
@@ -2027,6 +2039,10 @@ static void freeClusterManagerNode(clusterManagerNode *node) {
for (i = 0; i < node->importing_count; i++) sdsfree(node->importing[i]);
zfree(node->importing);
}
if (node->flags_str != NULL) {
freeClusterManagerNodeFlags(node->flags_str);
node->flags_str = NULL;
}
zfree(node);
}
...
...
@@ -2065,6 +2081,7 @@ static clusterManagerNode *clusterManagerNewNode(char *ip, int port) {
node->ping_sent = 0;
node->ping_recv = 0;
node->flags = 0;
node->flags_str = NULL;
node->replicate = NULL;
node->dirty = 0;
node->friends = NULL;
...
...
@@ -2391,6 +2408,24 @@ cleanup:
zfree(offenders);
}
/* Return a representable string of the node's flags */
static sds clusterManagerNodeFlagString(clusterManagerNode *node) {
sds flags = sdsempty();
if (!node->flags_str) return flags;
int empty = 1;
listIter li;
listNode *ln;
listRewind(node->flags_str, &li);
while ((ln = listNext(&li)) != NULL) {
sds flag = ln->value;
if (strcmp(flag, "myself") == 0) continue;
if (!empty) flags = sdscat(flags, ",");
flags = sdscatfmt(flags, "%S", flag);
empty = 0;
}
return flags;
}
/* Return a representable string of the node's slots */
static sds clusterManagerNodeSlotsString(clusterManagerNode *node) {
sds slots = sdsempty();
...
...
@@ -2466,12 +2501,14 @@ static sds clusterManagerNodeInfo(clusterManagerNode *node, int indent) {
info = sdscatfmt(info, "S: %S %s:%u", node->name, node->ip, node->port);
else {
slots = clusterManagerNodeSlotsString(node);
sds flags = clusterManagerNodeFlagString(node);
info = sdscatfmt(info, "%s: %S %s:%u\n"
"%s slots:%S (%u slots) "
"",
//TODO: flags string
"
%S
",
role, node->name, node->ip, node->port, spaces,
slots, node->slots_count);
slots, node->slots_count
, flags
);
sdsfree(slots);
sdsfree(flags);
}
if (node->replicate != NULL)
info = sdscatfmt(info, "\n%s replicates %S", spaces, node->replicate);
...
...
@@ -3008,19 +3045,36 @@ static int clusterManagerNodeLoadInfo(clusterManagerNode *node, int opts,
if (currentNode->name) sdsfree(currentNode->name);
currentNode->name = sdsnew(name);
}
if (strstr(flags, "noaddr") != NULL)
if (currentNode->flags_str != NULL)
freeClusterManagerNodeFlags(currentNode->flags_str);
currentNode->flags_str = listCreate();
int flag_len;
while ((flag_len = strlen(flags)) > 0) {
sds flag = NULL;
char *fp = strchr(flags, ',');
if (fp) {
*fp = '\0';
flag = sdsnew(flags);
flags = fp + 1;
} else {
flag = sdsnew(flags);
flags += flag_len;
}
if (strcmp(flag, "noaddr") == 0)
currentNode->flags |= CLUSTER_MANAGER_FLAG_NOADDR;
if (str
str
(flag
s
, "disconnected")
!
=
NULL
)
else
if (str
cmp
(flag, "disconnected")
=
=
0
)
currentNode->flags |= CLUSTER_MANAGER_FLAG_DISCONNECT;
if (str
str
(flag
s
, "fail")
!
=
NULL
)
else
if (str
cmp
(flag, "fail")
=
=
0
)
currentNode->flags |= CLUSTER_MANAGER_FLAG_FAIL;
if (str
str
(flag
s
, "slave")
!
=
NULL
) {
else
if (str
cmp
(flag, "slave")
=
=
0
) {
currentNode->flags |= CLUSTER_MANAGER_FLAG_SLAVE;
if (master_id
!
=
NULL
) {
if (master_id
=
=
0
) {
if (currentNode->replicate) sdsfree(currentNode->replicate);
currentNode->replicate = sdsnew(master_id);
}
}
listAddNodeTail(currentNode->flags_str, flag);
}
if (config_epoch != NULL)
currentNode->current_epoch = atoll(config_epoch);
if (ping_sent != NULL) currentNode->ping_sent = atoll(ping_sent);
...
...
@@ -4283,12 +4337,12 @@ assign_replicas:
goto cleanup;
}
}
/
/
Give one second for the join to start, in order to avoid that
//
waiting for cluster join will find all the nodes agree about
//
the config as they are still empty with unassigned slots.
/
*
Give one second for the join to start, in order to avoid that
*
waiting for cluster join will find all the nodes agree about
*
the config as they are still empty with unassigned slots.
*/
sleep(1);
clusterManagerWaitForClusterJoin();
/
/
Useful for the replicas /
/TODO: create a function for this?
/
*
Useful for the replicas
*
/
listRewind(cluster_manager.nodes, &li);
while ((ln = listNext(&li)) != NULL) {
clusterManagerNode *node = ln->value;
...
...
@@ -4315,7 +4369,7 @@ assign_replicas:
listEmpty(cluster_manager.nodes);
if (!clusterManagerLoadInfoFromNode(first_node, 0)) {
success = 0;
goto cleanup;
//TODO: msg?
goto cleanup;
}
clusterManagerCheckCluster(0);
}
...
...
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