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
35bb0212
Unverified
Commit
35bb0212
authored
Mar 29, 2022
by
Viktor Söderqvist
Committed by
GitHub
Mar 29, 2022
Browse files
redis-cli: Do DNS lookup before sending CLUSTER MEET (#10436)
Affects `--cluster create` and `--cluster add-node`.
parent
001e1925
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
35bb0212
...
@@ -156,6 +156,9 @@
...
@@ -156,6 +156,9 @@
#define CC_FORCE (1<<0)
/* Re-connect if already connected. */
#define CC_FORCE (1<<0)
/* Re-connect if already connected. */
#define CC_QUIET (1<<1)
/* Don't log connecting errors. */
#define CC_QUIET (1<<1)
/* Don't log connecting errors. */
/* DNS lookup */
#define NET_IP_STR_LEN 46
/* INET6_ADDRSTRLEN is 46 */
/* --latency-dist palettes. */
/* --latency-dist palettes. */
int
spectrum_palette_color_size
=
19
;
int
spectrum_palette_color_size
=
19
;
int
spectrum_palette_color
[]
=
{
0
,
233
,
234
,
235
,
237
,
239
,
241
,
243
,
245
,
247
,
144
,
143
,
142
,
184
,
226
,
214
,
208
,
202
,
196
};
int
spectrum_palette_color
[]
=
{
0
,
233
,
234
,
235
,
237
,
239
,
241
,
243
,
245
,
247
,
144
,
143
,
142
,
184
,
226
,
214
,
208
,
202
,
196
};
...
@@ -6306,16 +6309,26 @@ assign_replicas:
...
@@ -6306,16 +6309,26 @@ assign_replicas:
clusterManagerLogInfo
(
">>> Sending CLUSTER MEET messages to join "
clusterManagerLogInfo
(
">>> Sending CLUSTER MEET messages to join "
"the cluster
\n
"
);
"the cluster
\n
"
);
clusterManagerNode
*
first
=
NULL
;
clusterManagerNode
*
first
=
NULL
;
char
first_ip
[
NET_IP_STR_LEN
];
/* first->ip may be a hostname */
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
;
if
(
first
==
NULL
)
{
if
(
first
==
NULL
)
{
first
=
node
;
first
=
node
;
/* Although hiredis supports connecting to a hostname, CLUSTER
* MEET requires an IP address, so we do a DNS lookup here. */
if
(
anetResolve
(
NULL
,
first
->
ip
,
first_ip
,
sizeof
(
first_ip
),
ANET_NONE
)
==
ANET_ERR
)
{
fprintf
(
stderr
,
"Invalid IP address or hostname specified: %s
\n
"
,
first
->
ip
);
success
=
0
;
goto
cleanup
;
}
continue
;
continue
;
}
}
redisReply
*
reply
=
NULL
;
redisReply
*
reply
=
NULL
;
reply
=
CLUSTER_MANAGER_COMMAND
(
node
,
"cluster meet %s %d"
,
reply
=
CLUSTER_MANAGER_COMMAND
(
node
,
"cluster meet %s %d"
,
first
->
ip
,
first
->
port
);
first
_
ip
,
first
->
port
);
int
is_err
=
0
;
int
is_err
=
0
;
if
(
reply
!=
NULL
)
{
if
(
reply
!=
NULL
)
{
if
((
is_err
=
reply
->
type
==
REDIS_REPLY_ERROR
))
if
((
is_err
=
reply
->
type
==
REDIS_REPLY_ERROR
))
...
@@ -6487,8 +6500,15 @@ static int clusterManagerCommandAddNode(int argc, char **argv) {
...
@@ -6487,8 +6500,15 @@ static int clusterManagerCommandAddNode(int argc, char **argv) {
// Send CLUSTER MEET command to the new node
// Send CLUSTER MEET command to the new node
clusterManagerLogInfo
(
">>> Send CLUSTER MEET to node %s:%d to make it "
clusterManagerLogInfo
(
">>> Send CLUSTER MEET to node %s:%d to make it "
"join the cluster.
\n
"
,
ip
,
port
);
"join the cluster.
\n
"
,
ip
,
port
);
/* CLUSTER MEET requires an IP address, so we do a DNS lookup here. */
char
first_ip
[
NET_IP_STR_LEN
];
if
(
anetResolve
(
NULL
,
first
->
ip
,
first_ip
,
sizeof
(
first_ip
),
ANET_NONE
)
==
ANET_ERR
)
{
fprintf
(
stderr
,
"Invalid IP address or hostname specified: %s
\n
"
,
first
->
ip
);
success
=
0
;
goto
cleanup
;
}
reply
=
CLUSTER_MANAGER_COMMAND
(
new_node
,
"CLUSTER MEET %s %d"
,
reply
=
CLUSTER_MANAGER_COMMAND
(
new_node
,
"CLUSTER MEET %s %d"
,
first
->
ip
,
first
->
port
);
first
_
ip
,
first
->
port
);
if
(
!
(
success
=
clusterManagerCheckRedisReply
(
new_node
,
reply
,
NULL
)))
if
(
!
(
success
=
clusterManagerCheckRedisReply
(
new_node
,
reply
,
NULL
)))
goto
cleanup
;
goto
cleanup
;
...
...
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