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
279b4a14
Unverified
Commit
279b4a14
authored
Jul 10, 2020
by
马永泽
Committed by
GitHub
Jul 10, 2020
Browse files
fix benchmark in cluster mode fails to authenticate (#7488)
Co-authored-by: Oran Agra <oran@redislabs.com> (styling)
parent
d5648d61
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-benchmark.c
View file @
279b4a14
/* Redis benchmark utility.
/* Redis benchmark utility.
*
* Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
* All rights reserved.
...
...
@@ -183,6 +183,8 @@ static void *execBenchmarkThread(void *ptr);
static
clusterNode
*
createClusterNode
(
char
*
ip
,
int
port
);
static
redisConfig
*
getRedisConfig
(
const
char
*
ip
,
int
port
,
const
char
*
hostsocket
);
static
redisContext
*
getRedisContext
(
const
char
*
ip
,
int
port
,
const
char
*
hostsocket
);
static
void
freeRedisConfig
(
redisConfig
*
cfg
);
static
int
fetchClusterSlotsConfiguration
(
client
c
);
static
void
updateClusterSlotsConfiguration
();
...
...
@@ -238,40 +240,64 @@ void _serverAssert(const char *estr, const char *file, int line) {
*
((
char
*
)
-
1
)
=
'x'
;
}
static
redisCon
fig
*
getRedisCon
fig
(
const
char
*
ip
,
int
port
,
const
char
*
hostsocket
)
static
redisCon
text
*
getRedisCon
text
(
const
char
*
ip
,
int
port
,
const
char
*
hostsocket
)
{
redisConfig
*
cfg
=
zcalloc
(
sizeof
(
*
cfg
));
if
(
!
cfg
)
return
NULL
;
redisContext
*
c
=
NULL
;
redisReply
*
reply
=
NULL
,
*
sub_reply
=
NULL
;
redisContext
*
ctx
=
NULL
;
redisReply
*
reply
=
NULL
;
if
(
hostsocket
==
NULL
)
c
=
redisConnect
(
ip
,
port
);
c
tx
=
redisConnect
(
ip
,
port
);
else
c
=
redisConnectUnix
(
hostsocket
);
if
(
c
==
NULL
||
c
->
err
)
{
c
tx
=
redisConnectUnix
(
hostsocket
);
if
(
c
tx
==
NULL
||
c
tx
->
err
)
{
fprintf
(
stderr
,
"Could not connect to Redis at "
);
char
*
err
=
(
c
!=
NULL
?
c
->
errstr
:
""
);
if
(
hostsocket
==
NULL
)
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
ip
,
port
,
err
);
else
fprintf
(
stderr
,
"%s: %s
\n
"
,
hostsocket
,
err
);
goto
fail
;
}
if
(
config
.
auth
)
{
void
*
authReply
=
NULL
;
if
(
config
.
user
==
NULL
)
redisAppendCommand
(
c
,
"AUTH %s"
,
config
.
auth
);
char
*
err
=
(
ctx
!=
NULL
?
ctx
->
errstr
:
""
);
if
(
hostsocket
==
NULL
)
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
ip
,
port
,
err
);
else
redisAppendCommand
(
c
,
"AUTH %s %s"
,
config
.
user
,
config
.
auth
);
if
(
REDIS_OK
!=
redisGetReply
(
c
,
&
authReply
))
goto
fail
;
if
(
reply
)
freeReplyObject
(
reply
);
reply
=
((
redisReply
*
)
authReply
);
fprintf
(
stderr
,
"%s: %s
\n
"
,
hostsocket
,
err
);
goto
cleanup
;
}
if
(
config
.
auth
==
NULL
)
return
ctx
;
if
(
config
.
user
==
NULL
)
reply
=
redisCommand
(
ctx
,
"AUTH %s"
,
config
.
auth
);
else
reply
=
redisCommand
(
ctx
,
"AUTH %s %s"
,
config
.
user
,
config
.
auth
);
if
(
reply
!=
NULL
)
{
if
(
reply
->
type
==
REDIS_REPLY_ERROR
)
{
fprintf
(
stderr
,
"ERROR: %s
\n
"
,
reply
->
str
);
goto
fail
;
if
(
hostsocket
==
NULL
)
fprintf
(
stderr
,
"Node %s:%d replied with error:
\n
%s
\n
"
,
ip
,
port
,
reply
->
str
);
else
fprintf
(
stderr
,
"Node %s replied with error:
\n
%s
\n
"
,
hostsocket
,
reply
->
str
);
goto
cleanup
;
}
freeReplyObject
(
reply
);
return
ctx
;
}
fprintf
(
stderr
,
"ERROR: failed to fetch reply from "
);
if
(
hostsocket
==
NULL
)
fprintf
(
stderr
,
"%s:%d
\n
"
,
ip
,
port
);
else
fprintf
(
stderr
,
"%s
\n
"
,
hostsocket
);
cleanup:
freeReplyObject
(
reply
);
redisFree
(
ctx
);
return
NULL
;
}
static
redisConfig
*
getRedisConfig
(
const
char
*
ip
,
int
port
,
const
char
*
hostsocket
)
{
redisConfig
*
cfg
=
zcalloc
(
sizeof
(
*
cfg
));
if
(
!
cfg
)
return
NULL
;
redisContext
*
c
=
NULL
;
redisReply
*
reply
=
NULL
,
*
sub_reply
=
NULL
;
c
=
getRedisContext
(
ip
,
port
,
hostsocket
);
if
(
c
==
NULL
)
{
freeRedisConfig
(
cfg
);
return
NULL
;
}
redisAppendCommand
(
c
,
"CONFIG GET %s"
,
"save"
);
redisAppendCommand
(
c
,
"CONFIG GET %s"
,
"appendonly"
);
int
i
=
0
;
...
...
@@ -994,16 +1020,8 @@ static int fetchClusterConfiguration() {
int
success
=
1
;
redisContext
*
ctx
=
NULL
;
redisReply
*
reply
=
NULL
;
if
(
config
.
hostsocket
==
NULL
)
ctx
=
redisConnect
(
config
.
hostip
,
config
.
hostport
);
else
ctx
=
redisConnectUnix
(
config
.
hostsocket
);
if
(
ctx
->
err
)
{
fprintf
(
stderr
,
"Could not connect to Redis at "
);
if
(
config
.
hostsocket
==
NULL
)
{
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
config
.
hostip
,
config
.
hostport
,
ctx
->
errstr
);
}
else
fprintf
(
stderr
,
"%s: %s
\n
"
,
config
.
hostsocket
,
ctx
->
errstr
);
ctx
=
getRedisContext
(
config
.
hostip
,
config
.
hostport
,
config
.
hostsocket
);
if
(
ctx
==
NULL
)
{
exit
(
1
);
}
clusterNode
*
firstNode
=
createClusterNode
((
char
*
)
config
.
hostip
,
...
...
@@ -1199,11 +1217,9 @@ static int fetchClusterSlotsConfiguration(client c) {
assert
(
node
->
port
);
/* Use first node as entry point to connect to. */
if
(
ctx
==
NULL
)
{
ctx
=
r
edisCon
nec
t
(
node
->
ip
,
node
->
port
);
if
(
!
ctx
||
ctx
->
err
)
{
ctx
=
getR
edisCon
tex
t
(
node
->
ip
,
node
->
port
,
NULL
);
if
(
!
ctx
)
{
success
=
0
;
if
(
ctx
&&
ctx
->
err
)
fprintf
(
stderr
,
"REDIS CONNECTION ERROR: %s
\n
"
,
ctx
->
errstr
);
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