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
4b8d8826
Commit
4b8d8826
authored
Jun 16, 2020
by
antirez
Browse files
Use cluster connections too, to limit maxclients.
See #7401.
parent
62fc7f4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
4b8d8826
...
...
@@ -691,6 +691,13 @@ void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
}
}
/* Return the approximated number of sockets we are using in order to
* take the cluster bus connections. */
unsigned
long
getClusterConnectionsCount
(
void
)
{
return
server
.
cluster_enabled
?
(
dictSize
(
server
.
cluster
->
nodes
)
*
2
)
:
0
;
}
/* -----------------------------------------------------------------------------
* Key space handling
* -------------------------------------------------------------------------- */
...
...
src/cluster.h
View file @
4b8d8826
...
...
@@ -283,5 +283,6 @@ typedef struct {
clusterNode
*
getNodeByQuery
(
client
*
c
,
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
hashslot
,
int
*
ask
);
int
clusterRedirectBlockedClientIfNeeded
(
client
*
c
);
void
clusterRedirectClient
(
client
*
c
,
clusterNode
*
n
,
int
hashslot
,
int
error_code
);
unsigned
long
getClusterConnectionsCount
(
void
);
#endif
/* __CLUSTER_H */
src/networking.c
View file @
4b8d8826
...
...
@@ -892,17 +892,24 @@ static void acceptCommonHandler(connection *conn, int flags, char *ip) {
client
*
c
;
UNUSED
(
ip
);
/* Admission control will happen before a client is created and connAccept()
/* Limit the number of connections we take at the same time.
*
* Admission control will happen before a client is created and connAccept()
* called, because we don't want to even start transport-level negotiation
* if rejected.
*/
if
(
listLength
(
server
.
clients
)
>=
server
.
maxclients
)
{
char
*
err
=
"-ERR max number of clients reached
\r\n
"
;
* if rejected. */
if
(
listLength
(
server
.
clients
)
+
getClusterConnectionsCount
()
>=
server
.
maxclients
)
{
char
*
err
;
if
(
server
.
cluster_enabled
)
err
=
"-ERR max number of clients reached
\r\n
"
;
else
err
=
"-ERR max number of clients + cluster "
"connections reached
\r\n
"
;
/* That's a best effort error message, don't check write errors.
* Note that for TLS connections, no handshake was done yet so nothing is written
* and the connection will just drop.
*/
* Note that for TLS connections, no handshake was done yet so nothing
* is written and the connection will just drop. */
if
(
connWrite
(
conn
,
err
,
strlen
(
err
))
==
-
1
)
{
/* Nothing to do, Just to avoid the warning... */
}
...
...
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