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
fdb3be93
Commit
fdb3be93
authored
Sep 30, 2015
by
antirez
Browse files
Refactoring: new function to test if client has pending output.
parent
825f65d2
Changes
3
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
fdb3be93
...
@@ -163,9 +163,11 @@ int prepareClientToWrite(client *c) {
...
@@ -163,9 +163,11 @@ int prepareClientToWrite(client *c) {
if
(
c
->
fd
<=
0
)
return
C_ERR
;
/* Fake client for AOF loading. */
if
(
c
->
fd
<=
0
)
return
C_ERR
;
/* Fake client for AOF loading. */
/* Only install the handler if not already installed and, in case of
/* Schedule the client to write the output buffers to the socket only
* slaves, if the client can actually receive writes. */
* if not already done (there were no pending writes alreday and the client
if
(
c
->
bufpos
==
0
&&
listLength
(
c
->
reply
)
==
0
&&
* was yet not flagged), and, for slaves, if the slave can actually
* receive writes at this stage. */
if
(
!
clientHasPendingReplies
(
c
)
&&
!
(
c
->
flags
&
CLIENT_PENDING_WRITE
)
&&
!
(
c
->
flags
&
CLIENT_PENDING_WRITE
)
&&
(
c
->
replstate
==
REPL_STATE_NONE
||
(
c
->
replstate
==
REPL_STATE_NONE
||
(
c
->
replstate
==
SLAVE_STATE_ONLINE
&&
!
c
->
repl_put_online_on_ack
)))
(
c
->
replstate
==
SLAVE_STATE_ONLINE
&&
!
c
->
repl_put_online_on_ack
)))
...
@@ -591,6 +593,12 @@ void copyClientOutputBuffer(client *dst, client *src) {
...
@@ -591,6 +593,12 @@ void copyClientOutputBuffer(client *dst, client *src) {
dst
->
reply_bytes
=
src
->
reply_bytes
;
dst
->
reply_bytes
=
src
->
reply_bytes
;
}
}
/* Return true if the specified client has pending reply buffers to write to
* the socket. */
int
clientHasPendingReplies
(
client
*
c
)
{
return
c
->
bufpos
||
listLength
(
c
->
reply
);
}
#define MAX_ACCEPTS_PER_CALL 1000
#define MAX_ACCEPTS_PER_CALL 1000
static
void
acceptCommonHandler
(
int
fd
,
int
flags
)
{
static
void
acceptCommonHandler
(
int
fd
,
int
flags
)
{
client
*
c
;
client
*
c
;
...
@@ -824,7 +832,7 @@ int writeToClient(int fd, client *c, int handler_installed) {
...
@@ -824,7 +832,7 @@ int writeToClient(int fd, client *c, int handler_installed) {
size_t
objmem
;
size_t
objmem
;
robj
*
o
;
robj
*
o
;
while
(
c
->
bufpos
>
0
||
listLength
(
c
->
reply
))
{
while
(
c
lientHasPendingReplies
(
c
))
{
if
(
c
->
bufpos
>
0
)
{
if
(
c
->
bufpos
>
0
)
{
nwritten
=
write
(
fd
,
c
->
buf
+
c
->
sentlen
,
c
->
bufpos
-
c
->
sentlen
);
nwritten
=
write
(
fd
,
c
->
buf
+
c
->
sentlen
,
c
->
bufpos
-
c
->
sentlen
);
if
(
nwritten
<=
0
)
break
;
if
(
nwritten
<=
0
)
break
;
...
@@ -890,7 +898,7 @@ int writeToClient(int fd, client *c, int handler_installed) {
...
@@ -890,7 +898,7 @@ int writeToClient(int fd, client *c, int handler_installed) {
* We just rely on data / pings received for timeout detection. */
* We just rely on data / pings received for timeout detection. */
if
(
!
(
c
->
flags
&
CLIENT_MASTER
))
c
->
lastinteraction
=
server
.
unixtime
;
if
(
!
(
c
->
flags
&
CLIENT_MASTER
))
c
->
lastinteraction
=
server
.
unixtime
;
}
}
if
(
c
->
bufpos
==
0
&&
listLength
(
c
->
reply
)
==
0
)
{
if
(
!
clientHasPendingReplies
(
c
)
)
{
c
->
sentlen
=
0
;
c
->
sentlen
=
0
;
if
(
handler_installed
)
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
if
(
handler_installed
)
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
...
@@ -929,7 +937,7 @@ void handleClientsWithPendingWrites(void) {
...
@@ -929,7 +937,7 @@ void handleClientsWithPendingWrites(void) {
/* If there is nothing left, do nothing. Otherwise install
/* If there is nothing left, do nothing. Otherwise install
* the write handler. */
* the write handler. */
if
(
(
c
->
bufpos
||
listLength
(
c
->
reply
)
)
&&
if
(
clientHasPendingReplies
(
c
)
&&
aeCreateFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
,
aeCreateFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
,
sendReplyToClient
,
c
)
==
AE_ERR
)
sendReplyToClient
,
c
)
==
AE_ERR
)
{
{
...
...
src/replication.c
View file @
fdb3be93
...
@@ -570,7 +570,7 @@ void syncCommand(client *c) {
...
@@ -570,7 +570,7 @@ void syncCommand(client *c) {
* the client about already issued commands. We need a fresh reply
* the client about already issued commands. We need a fresh reply
* buffer registering the differences between the BGSAVE and the current
* buffer registering the differences between the BGSAVE and the current
* dataset, so that we can copy to other slaves if needed. */
* dataset, so that we can copy to other slaves if needed. */
if
(
li
stLength
(
c
->
reply
)
!=
0
||
c
->
bufpos
!=
0
)
{
if
(
c
li
entHasPendingReplies
(
c
)
)
{
addReplyError
(
c
,
"SYNC and PSYNC are invalid with pending output"
);
addReplyError
(
c
,
"SYNC and PSYNC are invalid with pending output"
);
return
;
return
;
}
}
...
@@ -1924,7 +1924,7 @@ void replicationResurrectCachedMaster(int newfd) {
...
@@ -1924,7 +1924,7 @@ void replicationResurrectCachedMaster(int newfd) {
/* We may also need to install the write handler as well if there is
/* We may also need to install the write handler as well if there is
* pending data in the write buffers. */
* pending data in the write buffers. */
if
(
server
.
master
->
bufpos
||
listLength
(
server
.
master
->
reply
))
{
if
(
clientHasPendingReplies
(
server
.
master
))
{
if
(
aeCreateFileEvent
(
server
.
el
,
newfd
,
AE_WRITABLE
,
if
(
aeCreateFileEvent
(
server
.
el
,
newfd
,
AE_WRITABLE
,
sendReplyToClient
,
server
.
master
))
{
sendReplyToClient
,
server
.
master
))
{
serverLog
(
LL_WARNING
,
"Error resurrecting the cached master, impossible to add the writable handler: %s"
,
strerror
(
errno
));
serverLog
(
LL_WARNING
,
"Error resurrecting the cached master, impossible to add the writable handler: %s"
,
strerror
(
errno
));
...
...
src/server.h
View file @
fdb3be93
...
@@ -1111,6 +1111,7 @@ void pauseClients(mstime_t duration);
...
@@ -1111,6 +1111,7 @@ void pauseClients(mstime_t duration);
int
clientsArePaused
(
void
);
int
clientsArePaused
(
void
);
int
processEventsWhileBlocked
(
void
);
int
processEventsWhileBlocked
(
void
);
void
handleClientsWithPendingWrites
(
void
);
void
handleClientsWithPendingWrites
(
void
);
int
clientHasPendingReplies
(
client
*
c
);
#ifdef __GNUC__
#ifdef __GNUC__
void
addReplyErrorFormat
(
client
*
c
,
const
char
*
fmt
,
...)
void
addReplyErrorFormat
(
client
*
c
,
const
char
*
fmt
,
...)
...
...
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