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
5f358dae
Commit
5f358dae
authored
Apr 13, 2018
by
artix
Browse files
Cluster Manager: set-timeout command
parent
52f17f6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
5f358dae
...
@@ -1890,6 +1890,7 @@ static int clusterManagerCommandCheck(int argc, char **argv);
...
@@ -1890,6 +1890,7 @@ static int clusterManagerCommandCheck(int argc, char **argv);
static
int
clusterManagerCommandFix
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandFix
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandReshard
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandReshard
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandRebalance
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandRebalance
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandSetTimeout
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandImport
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandImport
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandCall
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandCall
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandHelp
(
int
argc
,
char
**
argv
);
static
int
clusterManagerCommandHelp
(
int
argc
,
char
**
argv
);
...
@@ -1905,21 +1906,23 @@ typedef struct clusterManagerCommandDef {
...
@@ -1905,21 +1906,23 @@ typedef struct clusterManagerCommandDef {
clusterManagerCommandDef
clusterManagerCommands
[]
=
{
clusterManagerCommandDef
clusterManagerCommands
[]
=
{
{
"create"
,
clusterManagerCommandCreate
,
-
2
,
"host1:port1 ... hostN:portN"
,
{
"create"
,
clusterManagerCommandCreate
,
-
2
,
"host1:port1 ... hostN:portN"
,
"replicas <arg>"
},
"replicas <arg>"
},
{
"add-node"
,
clusterManagerCommandAddNode
,
2
,
"new_host:new_port existing_host:existing_port"
,
"slave,master-id <arg>"
},
{
"del-node"
,
clusterManagerCommandDeleteNode
,
2
,
"host:port node_id"
,
NULL
},
{
"check"
,
clusterManagerCommandCheck
,
-
1
,
"host:port"
,
NULL
},
{
"check"
,
clusterManagerCommandCheck
,
-
1
,
"host:port"
,
NULL
},
{
"fix"
,
clusterManagerCommandFix
,
-
1
,
"host:port"
,
NULL
},
{
"info"
,
clusterManagerCommandInfo
,
-
1
,
"host:port"
,
NULL
},
{
"info"
,
clusterManagerCommandInfo
,
-
1
,
"host:port"
,
NULL
},
{
"fix"
,
clusterManagerCommandFix
,
-
1
,
"host:port"
,
NULL
},
{
"reshard"
,
clusterManagerCommandReshard
,
-
1
,
"host:port"
,
{
"reshard"
,
clusterManagerCommandReshard
,
-
1
,
"host:port"
,
"from <arg>,to <arg>,slots <arg>,yes,timeout <arg>,pipeline <arg>"
},
"from <arg>,to <arg>,slots <arg>,yes,timeout <arg>,pipeline <arg>"
},
{
"rebalance"
,
clusterManagerCommandRebalance
,
-
1
,
"host:port"
,
{
"rebalance"
,
clusterManagerCommandRebalance
,
-
1
,
"host:port"
,
"weight <node1=w1...nodeN=wN>,use-empty-masters,"
"weight <node1=w1...nodeN=wN>,use-empty-masters,"
"timeout <arg>,simulate,pipeline <arg>,threshold <arg>"
},
"timeout <arg>,simulate,pipeline <arg>,threshold <arg>"
},
{
"import"
,
clusterManagerCommandImport
,
1
,
"host:port"
,
{
"add-node"
,
clusterManagerCommandAddNode
,
2
,
"from <arg>,copy,replace"
},
"new_host:new_port existing_host:existing_port"
,
"slave,master-id <arg>"
},
{
"del-node"
,
clusterManagerCommandDeleteNode
,
2
,
"host:port node_id"
,
NULL
},
{
"call"
,
clusterManagerCommandCall
,
-
2
,
{
"call"
,
clusterManagerCommandCall
,
-
2
,
"host:port command arg arg .. arg"
,
NULL
},
"host:port command arg arg .. arg"
,
NULL
},
{
"set-timeout"
,
clusterManagerCommandSetTimeout
,
2
,
"host:port milliseconds"
,
NULL
},
{
"import"
,
clusterManagerCommandImport
,
1
,
"host:port"
,
"from <arg>,copy,replace"
},
{
"help"
,
clusterManagerCommandHelp
,
0
,
NULL
,
NULL
}
{
"help"
,
clusterManagerCommandHelp
,
0
,
NULL
,
NULL
}
};
};
...
@@ -4882,6 +4885,61 @@ invalid_args:
...
@@ -4882,6 +4885,61 @@ invalid_args:
return
0
;
return
0
;
}
}
static
int
clusterManagerCommandSetTimeout
(
int
argc
,
char
**
argv
)
{
UNUSED
(
argc
);
int
port
=
0
;
char
*
ip
=
NULL
;
if
(
!
getClusterHostFromCmdArgs
(
1
,
argv
,
&
ip
,
&
port
))
goto
invalid_args
;
int
timeout
=
atoi
(
argv
[
1
]);
if
(
timeout
<
100
)
{
fprintf
(
stderr
,
"Setting a node timeout of less than 100 "
"milliseconds is a bad idea.
\n
"
);
return
0
;
}
// Load cluster information
clusterManagerNode
*
node
=
clusterManagerNewNode
(
ip
,
port
);
if
(
!
clusterManagerLoadInfoFromNode
(
node
,
0
))
return
0
;
int
ok_count
=
0
,
err_count
=
0
;
clusterManagerLogInfo
(
">>> Reconfiguring node timeout in every "
"cluster node...
\n
"
);
listIter
li
;
listNode
*
ln
;
listRewind
(
cluster_manager
.
nodes
,
&
li
);
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
clusterManagerNode
*
n
=
ln
->
value
;
char
*
err
=
NULL
;
redisReply
*
reply
=
CLUSTER_MANAGER_COMMAND
(
n
,
"CONFIG %s %s %d"
,
"SET"
,
"cluster-node-timeout"
,
timeout
);
if
(
reply
==
NULL
)
goto
reply_err
;
int
ok
=
clusterManagerCheckRedisReply
(
n
,
reply
,
&
err
);
freeReplyObject
(
reply
);
if
(
!
ok
)
goto
reply_err
;
reply
=
CLUSTER_MANAGER_COMMAND
(
n
,
"CONFIG %s"
,
"REWRITE"
);
if
(
reply
==
NULL
)
goto
reply_err
;
ok
=
clusterManagerCheckRedisReply
(
n
,
reply
,
&
err
);
freeReplyObject
(
reply
);
if
(
!
ok
)
goto
reply_err
;
clusterManagerLogWarn
(
"*** New timeout set for %s:%d
\n
"
,
n
->
ip
,
n
->
port
);
ok_count
++
;
continue
;
reply_err:
if
(
err
==
NULL
)
err
=
""
;
clusterManagerLogErr
(
"ERR setting node-timeot for %s:%d: %s
\n
"
,
n
->
ip
,
n
->
port
,
err
);
err_count
++
;
}
clusterManagerLogInfo
(
">>> New node timeout set. %d OK, %d ERR.
\n
"
,
ok_count
,
err_count
);
return
1
;
invalid_args:
fprintf
(
stderr
,
CLUSTER_MANAGER_INVALID_HOST_ARG
);
return
0
;
}
static
int
clusterManagerCommandImport
(
int
argc
,
char
**
argv
)
{
static
int
clusterManagerCommandImport
(
int
argc
,
char
**
argv
)
{
int
success
=
1
;
int
success
=
1
;
int
port
=
0
,
src_port
=
0
;
int
port
=
0
,
src_port
=
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