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
3578aabc
Commit
3578aabc
authored
Jun 06, 2018
by
artix
Browse files
Cluster Manager: improve join issue checking
parent
2f499304
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
3578aabc
...
@@ -130,6 +130,8 @@
...
@@ -130,6 +130,8 @@
#define CLUSTER_MANAGER_LOG_LVL_ERR 3
#define CLUSTER_MANAGER_LOG_LVL_ERR 3
#define CLUSTER_MANAGER_LOG_LVL_SUCCESS 4
#define CLUSTER_MANAGER_LOG_LVL_SUCCESS 4
#define CLUSTER_JOIN_CHECK_AFTER 20
#define LOG_COLOR_BOLD "29;1m"
#define LOG_COLOR_BOLD "29;1m"
#define LOG_COLOR_RED "31;1m"
#define LOG_COLOR_RED "31;1m"
#define LOG_COLOR_GREEN "32;1m"
#define LOG_COLOR_GREEN "32;1m"
...
@@ -2112,6 +2114,24 @@ static clusterManagerCommandProc *validateClusterManagerCommand(void) {
...
@@ -2112,6 +2114,24 @@ static clusterManagerCommandProc *validateClusterManagerCommand(void) {
return
proc
;
return
proc
;
}
}
static
int
parseClusterNodeAddress
(
char
*
addr
,
char
**
ip_ptr
,
int
*
port_ptr
,
int
*
bus_port_ptr
)
{
char
*
c
=
strrchr
(
addr
,
'@'
);
if
(
c
!=
NULL
)
{
*
c
=
'\0'
;
if
(
bus_port_ptr
!=
NULL
)
*
bus_port_ptr
=
atoi
(
c
+
1
);
}
c
=
strrchr
(
addr
,
':'
);
if
(
c
!=
NULL
)
{
*
c
=
'\0'
;
*
ip_ptr
=
addr
;
*
port_ptr
=
atoi
(
++
c
);
}
else
return
0
;
return
1
;
}
/* Get host ip and port from command arguments. If only one argument has
/* Get host ip and port from command arguments. If only one argument has
* been provided it must be in the form of 'ip:port', elsewhere
* been provided it must be in the form of 'ip:port', elsewhere
* the first argument must be the ip and the second one the port.
* the first argument must be the ip and the second one the port.
...
@@ -2124,14 +2144,7 @@ static int getClusterHostFromCmdArgs(int argc, char **argv,
...
@@ -2124,14 +2144,7 @@ static int getClusterHostFromCmdArgs(int argc, char **argv,
char
*
ip
=
NULL
;
char
*
ip
=
NULL
;
if
(
argc
==
1
)
{
if
(
argc
==
1
)
{
char
*
addr
=
argv
[
0
];
char
*
addr
=
argv
[
0
];
char
*
c
=
strrchr
(
addr
,
'@'
);
if
(
!
parseClusterNodeAddress
(
addr
,
&
ip
,
&
port
,
NULL
))
return
0
;
if
(
c
!=
NULL
)
*
c
=
'\0'
;
c
=
strrchr
(
addr
,
':'
);
if
(
c
!=
NULL
)
{
*
c
=
'\0'
;
ip
=
addr
;
port
=
atoi
(
++
c
);
}
else
return
0
;
}
else
{
}
else
{
ip
=
argv
[
0
];
ip
=
argv
[
0
];
port
=
atoi
(
argv
[
1
]);
port
=
atoi
(
argv
[
1
]);
...
@@ -3391,7 +3404,9 @@ cleanup:
...
@@ -3391,7 +3404,9 @@ cleanup:
/* Wait until the cluster configuration is consistent. */
/* Wait until the cluster configuration is consistent. */
static
void
clusterManagerWaitForClusterJoin
(
void
)
{
static
void
clusterManagerWaitForClusterJoin
(
void
)
{
printf
(
"Waiting for the cluster to join
\n
"
);
printf
(
"Waiting for the cluster to join
\n
"
);
int
counter
=
0
,
check_after
=
listLength
(
cluster_manager
.
nodes
)
*
2
;
int
counter
=
0
,
check_after
=
CLUSTER_JOIN_CHECK_AFTER
+
(
int
)(
listLength
(
cluster_manager
.
nodes
)
*
0
.
15
f
);
while
(
!
clusterManagerIsConfigConsistent
())
{
while
(
!
clusterManagerIsConfigConsistent
())
{
printf
(
"."
);
printf
(
"."
);
fflush
(
stdout
);
fflush
(
stdout
);
...
@@ -3400,15 +3415,24 @@ static void clusterManagerWaitForClusterJoin(void) {
...
@@ -3400,15 +3415,24 @@ static void clusterManagerWaitForClusterJoin(void) {
dict
*
status
=
clusterManagerGetLinkStatus
();
dict
*
status
=
clusterManagerGetLinkStatus
();
if
(
status
!=
NULL
&&
dictSize
(
status
)
>
0
)
{
if
(
status
!=
NULL
&&
dictSize
(
status
)
>
0
)
{
printf
(
"
\n
"
);
printf
(
"
\n
"
);
clusterManagerLogErr
(
"Warning: %d node
s
may "
clusterManagerLogErr
(
"Warning: %d node
(s)
may "
"be unreachable
\n
"
,
dictSize
(
status
));
"be unreachable
\n
"
,
dictSize
(
status
));
dictIterator
*
iter
=
dictGetIterator
(
status
);
dictIterator
*
iter
=
dictGetIterator
(
status
);
dictEntry
*
entry
;
dictEntry
*
entry
;
while
((
entry
=
dictNext
(
iter
))
!=
NULL
)
{
while
((
entry
=
dictNext
(
iter
))
!=
NULL
)
{
sds
nodename
=
(
sds
)
dictGetKey
(
entry
);
sds
nodeaddr
=
(
sds
)
dictGetKey
(
entry
);
char
*
node_ip
=
NULL
;
int
node_port
=
0
,
node_bus_port
=
0
;
list
*
from
=
(
list
*
)
dictGetVal
(
entry
);
list
*
from
=
(
list
*
)
dictGetVal
(
entry
);
clusterManagerLogErr
(
" - Node %s may be unreachable "
if
(
parseClusterNodeAddress
(
nodeaddr
,
&
node_ip
,
"from:
\n
"
,
nodename
);
&
node_port
,
&
node_bus_port
)
&&
node_bus_port
)
{
clusterManagerLogErr
(
" - The port %d of node %s may "
"be unreachable from:
\n
"
,
node_bus_port
,
node_ip
);
}
else
{
clusterManagerLogErr
(
" - Node %s may be unreachable "
"from:
\n
"
,
nodeaddr
);
}
listIter
li
;
listIter
li
;
listNode
*
ln
;
listNode
*
ln
;
listRewind
(
from
,
&
li
);
listRewind
(
from
,
&
li
);
...
@@ -3862,12 +3886,13 @@ static list *clusterManagerGetDisconnectedLinks(clusterManagerNode *node) {
...
@@ -3862,12 +3886,13 @@ static list *clusterManagerGetDisconnectedLinks(clusterManagerNode *node) {
if
(
strstr
(
flags
,
"myself"
)
!=
NULL
)
continue
;
if
(
strstr
(
flags
,
"myself"
)
!=
NULL
)
continue
;
int
disconnected
=
((
strstr
(
flags
,
"disconnected"
)
!=
NULL
)
||
int
disconnected
=
((
strstr
(
flags
,
"disconnected"
)
!=
NULL
)
||
(
strstr
(
link_status
,
"disconnected"
)));
(
strstr
(
link_status
,
"disconnected"
)));
if
(
disconnected
)
{
int
handshaking
=
(
strstr
(
flags
,
"handshake"
)
!=
NULL
);
if
(
disconnected
||
handshaking
)
{
clusterManagerLink
*
link
=
malloc
(
sizeof
(
*
link
));
clusterManagerLink
*
link
=
malloc
(
sizeof
(
*
link
));
link
->
node_name
=
sdsnew
(
nodename
);
link
->
node_name
=
sdsnew
(
nodename
);
link
->
node_addr
=
sdsnew
(
addr
);
link
->
node_addr
=
sdsnew
(
addr
);
link
->
connected
=
0
;
link
->
connected
=
0
;
link
->
handshaking
=
(
strstr
(
flags
,
"handshaking"
)
!=
NULL
)
;
link
->
handshaking
=
handshaking
;
listAddNodeTail
(
links
,
link
);
listAddNodeTail
(
links
,
link
);
}
}
}
}
...
...
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