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
15c7f131
Unverified
Commit
15c7f131
authored
Feb 06, 2020
by
Salvatore Sanfilippo
Committed by
GitHub
Feb 06, 2020
Browse files
Merge pull request #6854 from guybe7/mem_overhead_miscalc
Fix small bugs related to replica and monitor ambiguity
parents
edfe1b2f
91c41b6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
15c7f131
...
@@ -369,9 +369,10 @@ void addReplyErrorLength(client *c, const char *s, size_t len) {
...
@@ -369,9 +369,10 @@ void addReplyErrorLength(client *c, const char *s, size_t len) {
* Where the master must propagate the first change even if the second
* Where the master must propagate the first change even if the second
* will produce an error. However it is useful to log such events since
* will produce an error. However it is useful to log such events since
* they are rare and may hint at errors in a script or a bug in Redis. */
* they are rare and may hint at errors in a script or a bug in Redis. */
if
(
c
->
flags
&
(
CLIENT_MASTER
|
CLIENT_SLAVE
)
&&
!
(
c
->
flags
&
CLIENT_MONITOR
))
{
int
ctype
=
getClientType
(
c
);
char
*
to
=
c
->
flags
&
CLIENT_MASTER
?
"master"
:
"replica"
;
if
(
ctype
==
CLIENT_TYPE_MASTER
||
ctype
==
CLIENT_TYPE_SLAVE
)
{
char
*
from
=
c
->
flags
&
CLIENT_MASTER
?
"replica"
:
"master"
;
char
*
to
=
ctype
==
CLIENT_TYPE_MASTER
?
"master"
:
"replica"
;
char
*
from
=
ctype
==
CLIENT_TYPE_MASTER
?
"replica"
:
"master"
;
char
*
cmdname
=
c
->
lastcmd
?
c
->
lastcmd
->
name
:
"<unknown>"
;
char
*
cmdname
=
c
->
lastcmd
?
c
->
lastcmd
->
name
:
"<unknown>"
;
serverLog
(
LL_WARNING
,
"== CRITICAL == This %s is sending an error "
serverLog
(
LL_WARNING
,
"== CRITICAL == This %s is sending an error "
"to its %s: '%s' after processing the command "
"to its %s: '%s' after processing the command "
...
@@ -1074,7 +1075,7 @@ void freeClient(client *c) {
...
@@ -1074,7 +1075,7 @@ void freeClient(client *c) {
}
}
/* Log link disconnection with slave */
/* Log link disconnection with slave */
if
(
(
c
->
flags
&
CLIENT_SLAVE
)
&&
!
(
c
->
flags
&
CLIENT_MONITOR
)
)
{
if
(
getClientType
(
c
)
==
CLIENT_TYPE_SLAVE
)
{
serverLog
(
LL_WARNING
,
"Connection with replica %s lost."
,
serverLog
(
LL_WARNING
,
"Connection with replica %s lost."
,
replicationGetSlaveName
(
c
));
replicationGetSlaveName
(
c
));
}
}
...
@@ -1121,7 +1122,7 @@ void freeClient(client *c) {
...
@@ -1121,7 +1122,7 @@ void freeClient(client *c) {
/* We need to remember the time when we started to have zero
/* We need to remember the time when we started to have zero
* attached slaves, as after some time we'll free the replication
* attached slaves, as after some time we'll free the replication
* backlog. */
* backlog. */
if
(
c
->
flags
&
CLIENT_SLAVE
&&
listLength
(
server
.
slaves
)
==
0
)
if
(
getClientType
(
c
)
==
CLIENT_
TYPE_
SLAVE
&&
listLength
(
server
.
slaves
)
==
0
)
server
.
repl_no_slaves_since
=
server
.
unixtime
;
server
.
repl_no_slaves_since
=
server
.
unixtime
;
refreshGoodSlavesCount
();
refreshGoodSlavesCount
();
/* Fire the replica change modules event. */
/* Fire the replica change modules event. */
...
@@ -1252,8 +1253,8 @@ int writeToClient(client *c, int handler_installed) {
...
@@ -1252,8 +1253,8 @@ int writeToClient(client *c, int handler_installed) {
* just deliver as much data as it is possible to deliver.
* just deliver as much data as it is possible to deliver.
*
*
* Moreover, we also send as much as possible if the client is
* Moreover, we also send as much as possible if the client is
* a slave (otherwise, on high-speed traffic, the
replication
* a slave
or a monitor
(otherwise, on high-speed traffic, the
* buffer will grow indefinitely) */
*
replication/output
buffer will grow indefinitely) */
if
(
totwritten
>
NET_MAX_WRITES_PER_EVENT
&&
if
(
totwritten
>
NET_MAX_WRITES_PER_EVENT
&&
(
server
.
maxmemory
==
0
||
(
server
.
maxmemory
==
0
||
zmalloc_used_memory
()
<
server
.
maxmemory
)
&&
zmalloc_used_memory
()
<
server
.
maxmemory
)
&&
...
@@ -1439,7 +1440,7 @@ int processInlineBuffer(client *c) {
...
@@ -1439,7 +1440,7 @@ int processInlineBuffer(client *c) {
/* Newline from slaves can be used to refresh the last ACK time.
/* Newline from slaves can be used to refresh the last ACK time.
* This is useful for a slave to ping back while loading a big
* This is useful for a slave to ping back while loading a big
* RDB file. */
* RDB file. */
if
(
querylen
==
0
&&
c
->
flags
&
CLIENT_SLAVE
)
if
(
querylen
==
0
&&
getClientType
(
c
)
==
CLIENT_
TYPE_
SLAVE
)
c
->
repl_ack_time
=
server
.
unixtime
;
c
->
repl_ack_time
=
server
.
unixtime
;
/* Move querybuffer position to the next query in the buffer. */
/* Move querybuffer position to the next query in the buffer. */
...
@@ -2433,12 +2434,14 @@ unsigned long getClientOutputBufferMemoryUsage(client *c) {
...
@@ -2433,12 +2434,14 @@ unsigned long getClientOutputBufferMemoryUsage(client *c) {
*
*
* The function will return one of the following:
* The function will return one of the following:
* CLIENT_TYPE_NORMAL -> Normal client
* CLIENT_TYPE_NORMAL -> Normal client
* CLIENT_TYPE_SLAVE -> Slave
or client executing MONITOR command
* CLIENT_TYPE_SLAVE -> Slave
* CLIENT_TYPE_PUBSUB -> Client subscribed to Pub/Sub channels
* CLIENT_TYPE_PUBSUB -> Client subscribed to Pub/Sub channels
* CLIENT_TYPE_MASTER -> The client representing our replication master.
* CLIENT_TYPE_MASTER -> The client representing our replication master.
*/
*/
int
getClientType
(
client
*
c
)
{
int
getClientType
(
client
*
c
)
{
if
(
c
->
flags
&
CLIENT_MASTER
)
return
CLIENT_TYPE_MASTER
;
if
(
c
->
flags
&
CLIENT_MASTER
)
return
CLIENT_TYPE_MASTER
;
/* Even though MONITOR clients are marked as replicas, we
* want the expose them as normal clients. */
if
((
c
->
flags
&
CLIENT_SLAVE
)
&&
!
(
c
->
flags
&
CLIENT_MONITOR
))
if
((
c
->
flags
&
CLIENT_SLAVE
)
&&
!
(
c
->
flags
&
CLIENT_MONITOR
))
return
CLIENT_TYPE_SLAVE
;
return
CLIENT_TYPE_SLAVE
;
if
(
c
->
flags
&
CLIENT_PUBSUB
)
return
CLIENT_TYPE_PUBSUB
;
if
(
c
->
flags
&
CLIENT_PUBSUB
)
return
CLIENT_TYPE_PUBSUB
;
...
...
src/object.c
View file @
15c7f131
...
@@ -974,38 +974,29 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
...
@@ -974,38 +974,29 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
mh
->
repl_backlog
=
mem
;
mh
->
repl_backlog
=
mem
;
mem_total
+=
mem
;
mem_total
+=
mem
;
mem
=
0
;
if
(
listLength
(
server
.
slaves
))
{
listIter
li
;
listNode
*
ln
;
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
mem
+=
getClientOutputBufferMemoryUsage
(
c
);
mem
+=
sdsAllocSize
(
c
->
querybuf
);
mem
+=
sizeof
(
client
);
}
}
mh
->
clients_slaves
=
mem
;
mem_total
+=
mem
;
mem
=
0
;
mem
=
0
;
if
(
listLength
(
server
.
clients
))
{
if
(
listLength
(
server
.
clients
))
{
listIter
li
;
listIter
li
;
listNode
*
ln
;
listNode
*
ln
;
size_t
mem_normal
=
0
,
mem_slaves
=
0
;
listRewind
(
server
.
clients
,
&
li
);
listRewind
(
server
.
clients
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
while
((
ln
=
listNext
(
&
li
)))
{
size_t
mem_curr
=
0
;
client
*
c
=
listNodeValue
(
ln
);
client
*
c
=
listNodeValue
(
ln
);
if
(
c
->
flags
&
CLIENT_SLAVE
&&
!
(
c
->
flags
&
CLIENT_MONITOR
))
int
type
=
getClientType
(
c
);
continue
;
mem_curr
+=
getClientOutputBufferMemoryUsage
(
c
);
mem
+=
getClientOutputBufferMemoryUsage
(
c
);
mem_curr
+=
sdsAllocSize
(
c
->
querybuf
);
mem
+=
sdsAllocSize
(
c
->
querybuf
);
mem_curr
+=
sizeof
(
client
);
mem
+=
sizeof
(
client
);
if
(
type
==
CLIENT_TYPE_SLAVE
)
mem_slaves
+=
mem_curr
;
else
mem_normal
+=
mem_curr
;
}
}
mh
->
clients_slaves
=
mem_slaves
;
mh
->
clients_normal
=
mem_normal
;
mem
=
mem_slaves
+
mem_normal
;
}
}
mh
->
clients_normal
=
mem
;
mem_total
+=
mem
;
mem_total
+=
mem
;
mem
=
0
;
mem
=
0
;
...
...
src/server.c
View file @
15c7f131
...
@@ -1498,7 +1498,7 @@ int clientsCronHandleTimeout(client *c, mstime_t now_ms) {
...
@@ -1498,7 +1498,7 @@ int clientsCronHandleTimeout(client *c, mstime_t now_ms) {
time_t
now
=
now_ms
/
1000
;
time_t
now
=
now_ms
/
1000
;
if
(
server
.
maxidletime
&&
if
(
server
.
maxidletime
&&
!
(
c
->
flags
&
CLIENT_SLAVE
)
&&
/* no timeout for slaves */
!
(
c
->
flags
&
CLIENT_SLAVE
)
&&
/* no timeout for slaves
and monitors
*/
!
(
c
->
flags
&
CLIENT_MASTER
)
&&
/* no timeout for masters */
!
(
c
->
flags
&
CLIENT_MASTER
)
&&
/* no timeout for masters */
!
(
c
->
flags
&
CLIENT_BLOCKED
)
&&
/* no timeout for BLPOP */
!
(
c
->
flags
&
CLIENT_BLOCKED
)
&&
/* no timeout for BLPOP */
!
(
c
->
flags
&
CLIENT_PUBSUB
)
&&
/* no timeout for Pub/Sub clients */
!
(
c
->
flags
&
CLIENT_PUBSUB
)
&&
/* no timeout for Pub/Sub clients */
...
...
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