Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
1e715383
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1e715383
编写于
9月 30, 2015
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactoring: unlinkClient() added to lower freeClient() complexity.
上级
fdb3be93
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
48 addition
and
51 deletion
+48
-51
src/networking.c
src/networking.c
+45
-29
src/replication.c
src/replication.c
+2
-22
src/server.h
src/server.h
+1
-0
未找到文件。
src/networking.c
浏览文件 @
1e715383
...
...
@@ -685,12 +685,50 @@ void disconnectSlaves(void) {
}
}
void
freeClient
(
client
*
c
)
{
/* Remove the specified client from global lists where the client could
* be referenced, not including the Pub/Sub channels.
* This is used by freeClient() and replicationCacheMaster(). */
void
unlinkClient
(
client
*
c
)
{
listNode
*
ln
;
/* If this is marked as current client unset it */
/* If this is marked as current client unset it
.
*/
if
(
server
.
current_client
==
c
)
server
.
current_client
=
NULL
;
/* Certain operations must be done only if the client has an active socket.
* If the client was already unlinked or if it's a "fake client" the
* fd is already set to -1. */
if
(
c
->
fd
!=
-
1
)
{
/* Remove from the list of active clients. */
ln
=
listSearchKey
(
server
.
clients
,
c
);
serverAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
clients
,
ln
);
/* Unregister async I/O handlers and close the socket. */
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_READABLE
);
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
close
(
c
->
fd
);
c
->
fd
=
-
1
;
}
/* Remove from the list of pending writes if needed. */
if
(
c
->
flags
&
CLIENT_PENDING_WRITE
)
{
ln
=
listSearchKey
(
server
.
clients_pending_write
,
c
);
serverAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
clients_pending_write
,
ln
);
}
/* When client was just unblocked because of a blocking operation,
* remove it from the list of unblocked clients. */
if
(
c
->
flags
&
CLIENT_UNBLOCKED
)
{
ln
=
listSearchKey
(
server
.
unblocked_clients
,
c
);
serverAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
unblocked_clients
,
ln
);
}
}
void
freeClient
(
client
*
c
)
{
listNode
*
ln
;
/* If it is our master that's beging disconnected we should make sure
* to cache the state to try a partial resynchronization later.
*
...
...
@@ -732,36 +770,14 @@ void freeClient(client *c) {
dictRelease
(
c
->
pubsub_channels
);
listRelease
(
c
->
pubsub_patterns
);
/* Close socket, unregister events, and remove list of replies and
* accumulated arguments. */
if
(
c
->
fd
!=
-
1
)
{
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_READABLE
);
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
close
(
c
->
fd
);
}
/* Free data structures. */
listRelease
(
c
->
reply
);
freeClientArgv
(
c
);
/* Remove from the list of clients */
if
(
c
->
fd
!=
-
1
)
{
ln
=
listSearchKey
(
server
.
clients
,
c
);
serverAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
clients
,
ln
);
}
/* Remove from the list of pending writes if needed. */
if
(
c
->
flags
&
CLIENT_PENDING_WRITE
)
{
ln
=
listSearchKey
(
server
.
clients_pending_write
,
c
);
listDelNode
(
server
.
clients_pending_write
,
ln
);
}
/* When client was just unblocked because of a blocking operation,
* remove it from the list of unblocked clients. */
if
(
c
->
flags
&
CLIENT_UNBLOCKED
)
{
ln
=
listSearchKey
(
server
.
unblocked_clients
,
c
);
serverAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
unblocked_clients
,
ln
);
}
/* Unlink the client: this will close the socket, remove the I/O
* handlers, and remove references of the client from different
* places where active clients may be referenced. */
unlinkClient
(
c
);
/* Master/slave cleanup Case 1:
* we lost the connection with a slave. */
...
...
src/replication.c
浏览文件 @
1e715383
...
...
@@ -1846,36 +1846,16 @@ void replicationSendAck(void) {
* handshake in order to reactivate the cached master.
*/
void
replicationCacheMaster
(
client
*
c
)
{
listNode
*
ln
;
serverAssert
(
server
.
master
!=
NULL
&&
server
.
cached_master
==
NULL
);
serverLog
(
LL_NOTICE
,
"Caching the disconnected master state."
);
/* Remove from the list of clients, we don't want this client to be
* listed by CLIENT LIST or processed in any way by batch operations. */
ln
=
listSearchKey
(
server
.
clients
,
c
);
serverAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
clients
,
ln
);
/* Remove from the list of clients with pending writes as well. */
if
(
c
->
flags
&
CLIENT_PENDING_WRITE
)
{
ln
=
listSearchKey
(
server
.
clients_pending_write
,
c
);
if
(
ln
)
listDelNode
(
server
.
clients_pending_write
,
ln
);
}
/* Unlink the client from the server structures. */
unlinkClient
(
c
);
/* Save the master. Server.master will be set to null later by
* replicationHandleMasterDisconnection(). */
server
.
cached_master
=
server
.
master
;
/* Remove the event handlers and close the socket. We'll later reuse
* the socket of the new connection with the master during PSYNC. */
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_READABLE
);
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
close
(
c
->
fd
);
/* Set fd to -1 so that we can safely call freeClient(c) later. */
c
->
fd
=
-
1
;
/* Invalidate the Peer ID cache. */
if
(
c
->
peerid
)
{
sdsfree
(
c
->
peerid
);
...
...
src/server.h
浏览文件 @
1e715383
...
...
@@ -1112,6 +1112,7 @@ int clientsArePaused(void);
int
processEventsWhileBlocked
(
void
);
void
handleClientsWithPendingWrites
(
void
);
int
clientHasPendingReplies
(
client
*
c
);
void
unlinkClient
(
client
*
c
);
#ifdef __GNUC__
void
addReplyErrorFormat
(
client
*
c
,
const
char
*
fmt
,
...)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录