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