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
d144dc92
Unverified
Commit
d144dc92
authored
Sep 15, 2022
by
Adi Pinsky
Committed by
GitHub
Sep 14, 2022
Browse files
Adds listnode to client struct for clients_pending_write list (#11220)
parent
42e4241e
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/adlist.c
View file @
d144dc92
...
@@ -93,6 +93,14 @@ list *listAddNodeHead(list *list, void *value)
...
@@ -93,6 +93,14 @@ list *listAddNodeHead(list *list, void *value)
if
((
node
=
zmalloc
(
sizeof
(
*
node
)))
==
NULL
)
if
((
node
=
zmalloc
(
sizeof
(
*
node
)))
==
NULL
)
return
NULL
;
return
NULL
;
node
->
value
=
value
;
node
->
value
=
value
;
listLinkNodeHead
(
list
,
node
);
return
list
;
}
/*
* Add a node that has already been allocated to the head of list
*/
void
listLinkNodeHead
(
list
*
list
,
listNode
*
node
)
{
if
(
list
->
len
==
0
)
{
if
(
list
->
len
==
0
)
{
list
->
head
=
list
->
tail
=
node
;
list
->
head
=
list
->
tail
=
node
;
node
->
prev
=
node
->
next
=
NULL
;
node
->
prev
=
node
->
next
=
NULL
;
...
@@ -103,7 +111,6 @@ list *listAddNodeHead(list *list, void *value)
...
@@ -103,7 +111,6 @@ list *listAddNodeHead(list *list, void *value)
list
->
head
=
node
;
list
->
head
=
node
;
}
}
list
->
len
++
;
list
->
len
++
;
return
list
;
}
}
/* Add a new node to the list, to tail, containing the specified 'value'
/* Add a new node to the list, to tail, containing the specified 'value'
...
@@ -162,11 +169,20 @@ list *listInsertNode(list *list, listNode *old_node, void *value, int after) {
...
@@ -162,11 +169,20 @@ list *listInsertNode(list *list, listNode *old_node, void *value, int after) {
}
}
/* Remove the specified node from the specified list.
/* Remove the specified node from the specified list.
*
It's up to the caller to free the private value of the node
.
*
The node is freed. If free callback is provided the value is freed as well
.
*
*
* This function can't fail. */
* This function can't fail. */
void
listDelNode
(
list
*
list
,
listNode
*
node
)
void
listDelNode
(
list
*
list
,
listNode
*
node
)
{
{
listUnlinkNode
(
list
,
node
);
if
(
list
->
free
)
list
->
free
(
node
->
value
);
zfree
(
node
);
}
/*
* Remove the specified node from the list without freeing it.
*/
void
listUnlinkNode
(
list
*
list
,
listNode
*
node
)
{
if
(
node
->
prev
)
if
(
node
->
prev
)
node
->
prev
->
next
=
node
->
next
;
node
->
prev
->
next
=
node
->
next
;
else
else
...
@@ -175,8 +191,10 @@ void listDelNode(list *list, listNode *node)
...
@@ -175,8 +191,10 @@ void listDelNode(list *list, listNode *node)
node
->
next
->
prev
=
node
->
prev
;
node
->
next
->
prev
=
node
->
prev
;
else
else
list
->
tail
=
node
->
prev
;
list
->
tail
=
node
->
prev
;
if
(
list
->
free
)
list
->
free
(
node
->
value
);
zfree
(
node
);
node
->
next
=
NULL
;
node
->
prev
=
NULL
;
list
->
len
--
;
list
->
len
--
;
}
}
...
@@ -381,3 +399,12 @@ void listJoin(list *l, list *o) {
...
@@ -381,3 +399,12 @@ void listJoin(list *l, list *o) {
o
->
head
=
o
->
tail
=
NULL
;
o
->
head
=
o
->
tail
=
NULL
;
o
->
len
=
0
;
o
->
len
=
0
;
}
}
/* Initializes the node's value and sets its pointers
* so that it is initially not a member of any list.
*/
void
listInitNode
(
listNode
*
node
,
void
*
value
)
{
node
->
prev
=
NULL
;
node
->
next
=
NULL
;
node
->
value
=
value
;
}
src/adlist.h
View file @
d144dc92
...
@@ -88,6 +88,9 @@ void listRewindTail(list *list, listIter *li);
...
@@ -88,6 +88,9 @@ void listRewindTail(list *list, listIter *li);
void
listRotateTailToHead
(
list
*
list
);
void
listRotateTailToHead
(
list
*
list
);
void
listRotateHeadToTail
(
list
*
list
);
void
listRotateHeadToTail
(
list
*
list
);
void
listJoin
(
list
*
l
,
list
*
o
);
void
listJoin
(
list
*
l
,
list
*
o
);
void
listInitNode
(
listNode
*
node
,
void
*
value
);
void
listLinkNodeHead
(
list
*
list
,
listNode
*
node
);
void
listUnlinkNode
(
list
*
list
,
listNode
*
node
);
/* Directions for iterators */
/* Directions for iterators */
#define AL_START_HEAD 0
#define AL_START_HEAD 0
...
...
src/module.c
View file @
d144dc92
...
@@ -7542,7 +7542,7 @@ void moduleHandleBlockedClients(void) {
...
@@ -7542,7 +7542,7 @@ void moduleHandleBlockedClients(void) {
!(c->flags & CLIENT_PENDING_WRITE))
!(c->flags & CLIENT_PENDING_WRITE))
{
{
c->flags |= CLIENT_PENDING_WRITE;
c->flags |= CLIENT_PENDING_WRITE;
list
Add
NodeHead(server.clients_pending_write,
c
);
list
Link
NodeHead(server.clients_pending_write,
&c->clients_pending_write_node
);
}
}
}
}
...
...
src/networking.c
View file @
d144dc92
...
@@ -207,6 +207,7 @@ client *createClient(connection *conn) {
...
@@ -207,6 +207,7 @@ client *createClient(connection *conn) {
c
->
auth_callback
=
NULL
;
c
->
auth_callback
=
NULL
;
c
->
auth_callback_privdata
=
NULL
;
c
->
auth_callback_privdata
=
NULL
;
c
->
auth_module
=
NULL
;
c
->
auth_module
=
NULL
;
listInitNode
(
&
c
->
clients_pending_write_node
,
c
);
listSetFreeMethod
(
c
->
pubsub_patterns
,
decrRefCountVoid
);
listSetFreeMethod
(
c
->
pubsub_patterns
,
decrRefCountVoid
);
listSetMatchMethod
(
c
->
pubsub_patterns
,
listMatchObjects
);
listSetMatchMethod
(
c
->
pubsub_patterns
,
listMatchObjects
);
c
->
mem_usage_bucket
=
NULL
;
c
->
mem_usage_bucket
=
NULL
;
...
@@ -255,7 +256,7 @@ void putClientInPendingWriteQueue(client *c) {
...
@@ -255,7 +256,7 @@ void putClientInPendingWriteQueue(client *c) {
* a system call. We'll only really install the write handler if
* a system call. We'll only really install the write handler if
* we'll not be able to write the whole reply at once. */
* we'll not be able to write the whole reply at once. */
c
->
flags
|=
CLIENT_PENDING_WRITE
;
c
->
flags
|=
CLIENT_PENDING_WRITE
;
list
Add
NodeHead
(
server
.
clients_pending_write
,
c
);
list
Link
NodeHead
(
server
.
clients_pending_write
,
&
c
->
clients_pending_write_node
);
}
}
}
}
...
@@ -1439,9 +1440,9 @@ void unlinkClient(client *c) {
...
@@ -1439,9 +1440,9 @@ void unlinkClient(client *c) {
/* Remove from the list of pending writes if needed. */
/* Remove from the list of pending writes if needed. */
if
(
c
->
flags
&
CLIENT_PENDING_WRITE
)
{
if
(
c
->
flags
&
CLIENT_PENDING_WRITE
)
{
ln
=
listSearchKey
(
server
.
clients_pending_write
,
c
);
serverAssert
(
&
c
->
clients_pending_write_node
.
next
!=
NULL
||
serverAssert
(
ln
!=
NULL
);
&
c
->
clients_pending_write_node
.
prev
!=
NULL
);
list
Del
Node
(
server
.
clients_pending_write
,
ln
);
list
Unlink
Node
(
server
.
clients_pending_write
,
&
c
->
clients_pending_write_node
);
c
->
flags
&=
~
CLIENT_PENDING_WRITE
;
c
->
flags
&=
~
CLIENT_PENDING_WRITE
;
}
}
...
@@ -1975,7 +1976,7 @@ int handleClientsWithPendingWrites(void) {
...
@@ -1975,7 +1976,7 @@ int handleClientsWithPendingWrites(void) {
while
((
ln
=
listNext
(
&
li
)))
{
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
client
*
c
=
listNodeValue
(
ln
);
c
->
flags
&=
~
CLIENT_PENDING_WRITE
;
c
->
flags
&=
~
CLIENT_PENDING_WRITE
;
list
Del
Node
(
server
.
clients_pending_write
,
ln
);
list
Unlink
Node
(
server
.
clients_pending_write
,
ln
);
/* If a client is protected, don't do anything,
/* If a client is protected, don't do anything,
* that may trigger write error or recreate handler. */
* that may trigger write error or recreate handler. */
...
@@ -4156,7 +4157,7 @@ int handleClientsWithPendingWritesUsingThreads(void) {
...
@@ -4156,7 +4157,7 @@ int handleClientsWithPendingWritesUsingThreads(void) {
/* Remove clients from the list of pending writes since
/* Remove clients from the list of pending writes since
* they are going to be closed ASAP. */
* they are going to be closed ASAP. */
if
(
c
->
flags
&
CLIENT_CLOSE_ASAP
)
{
if
(
c
->
flags
&
CLIENT_CLOSE_ASAP
)
{
list
Del
Node
(
server
.
clients_pending_write
,
ln
);
list
Unlink
Node
(
server
.
clients_pending_write
,
ln
);
continue
;
continue
;
}
}
...
@@ -4215,7 +4216,9 @@ int handleClientsWithPendingWritesUsingThreads(void) {
...
@@ -4215,7 +4216,9 @@ int handleClientsWithPendingWritesUsingThreads(void) {
installClientWriteHandler
(
c
);
installClientWriteHandler
(
c
);
}
}
}
}
listEmpty
(
server
.
clients_pending_write
);
while
(
listLength
(
server
.
clients_pending_write
)
>
0
)
{
listUnlinkNode
(
server
.
clients_pending_write
,
server
.
clients_pending_write
->
head
);
}
/* Update processed count on server */
/* Update processed count on server */
server
.
stat_io_writes_processed
+=
processed
;
server
.
stat_io_writes_processed
+=
processed
;
...
...
src/server.h
View file @
d144dc92
...
@@ -1176,6 +1176,8 @@ typedef struct client {
...
@@ -1176,6 +1176,8 @@ typedef struct client {
size_t
ref_block_pos
;
/* Access position of referenced buffer block,
size_t
ref_block_pos
;
/* Access position of referenced buffer block,
* i.e. the next offset to send. */
* i.e. the next offset to send. */
/* list node in clients_pending_write list */
listNode
clients_pending_write_node
;
/* Response buffer */
/* Response buffer */
size_t
buf_peak
;
/* Peak used size of buffer in last 5 sec interval. */
size_t
buf_peak
;
/* Peak used size of buffer in last 5 sec interval. */
mstime_t
buf_peak_last_reset_time
;
/* keeps the last time the buffer peak value was reset */
mstime_t
buf_peak_last_reset_time
;
/* keeps the last time the buffer peak value was reset */
...
...
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