Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
dc43f66e
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,发现更多精彩内容 >>
提交
dc43f66e
编写于
11月 08, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cluster: UPDATE msg data structure and sending function.
上级
6c6572be
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
3 deletion
+36
-3
src/cluster.c
src/cluster.c
+23
-2
src/cluster.h
src/cluster.h
+13
-1
未找到文件。
src/cluster.c
浏览文件 @
dc43f66e
...
...
@@ -59,6 +59,7 @@ void clusterSetMaster(clusterNode *n);
void
clusterHandleSlaveFailover
(
void
);
int
bitmapTestBit
(
unsigned
char
*
bitmap
,
int
pos
);
void
clusterDoBeforeSleep
(
int
flags
);
void
clusterSendUpdate
(
clusterLink
*
link
,
clusterNode
*
node
);
/* -----------------------------------------------------------------------------
* Initialization
...
...
@@ -1181,8 +1182,11 @@ int clusterProcessPacket(clusterLink *link) {
if
(
server
.
cluster
->
slots
[
j
]
->
configEpoch
>
senderConfigEpoch
)
{
printf
(
"MASTER or SLAVE have old config
\n
"
);
break
;
redisLog
(
REDIS_WARNING
,
"Node %.40s has old slots configuration, sending "
"an UPDATE message about %.40s
\n
"
,
sender
->
name
,
server
.
cluster
->
slots
[
j
]
->
name
);
clusterSendUpdate
(
sender
->
link
,
server
.
cluster
->
slots
[
j
]);
}
}
}
...
...
@@ -1413,6 +1417,9 @@ void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
if
(
type
==
CLUSTERMSG_TYPE_FAIL
)
{
totlen
=
sizeof
(
clusterMsg
)
-
sizeof
(
union
clusterMsgData
);
totlen
+=
sizeof
(
clusterMsgDataFail
);
}
else
if
(
type
==
CLUSTERMSG_TYPE_UPDATE
)
{
totlen
=
sizeof
(
clusterMsg
)
-
sizeof
(
union
clusterMsgData
);
totlen
+=
sizeof
(
clusterMsgDataUpdate
);
}
hdr
->
totlen
=
htonl
(
totlen
);
/* For PING, PONG, and MEET, fixing the totlen field is up to the caller. */
...
...
@@ -1562,6 +1569,20 @@ void clusterSendFail(char *nodename) {
clusterBroadcastMessage
(
buf
,
ntohl
(
hdr
->
totlen
));
}
/* Send an UPDATE message to the specified link carrying the specified 'node'
* slots configuration. The node name, slots bitmap, and configEpoch info
* are included. */
void
clusterSendUpdate
(
clusterLink
*
link
,
clusterNode
*
node
)
{
unsigned
char
buf
[
4096
];
clusterMsg
*
hdr
=
(
clusterMsg
*
)
buf
;
clusterBuildMessageHdr
(
hdr
,
CLUSTERMSG_TYPE_UPDATE
);
memcpy
(
hdr
->
data
.
update
.
nodecfg
.
nodename
,
node
->
name
,
REDIS_CLUSTER_NAMELEN
);
hdr
->
data
.
update
.
nodecfg
.
configEpoch
=
htonu64
(
node
->
configEpoch
);
memcpy
(
hdr
->
data
.
update
.
nodecfg
.
slots
,
node
->
slots
,
sizeof
(
node
->
slots
));
clusterSendMessage
(
link
,
buf
,
ntohl
(
hdr
->
totlen
));
}
/* -----------------------------------------------------------------------------
* CLUSTER Pub/Sub support
*
...
...
src/cluster.h
浏览文件 @
dc43f66e
...
...
@@ -112,7 +112,8 @@ typedef struct clusterState {
#define CLUSTERMSG_TYPE_FAIL 3
/* Mark node xxx as failing */
#define CLUSTERMSG_TYPE_PUBLISH 4
/* Pub/Sub Publish propagation */
#define CLUSTERMSG_TYPE_FAILOVER_AUTH_REQUEST 5
/* May I failover? */
#define CLUSTERMSG_TYPE_FAILOVER_AUTH_ACK 6
/* Yes, you can failover. */
#define CLUSTERMSG_TYPE_FAILOVER_AUTH_ACK 6
/* Yes, you have my vote */
#define CLUSTERMSG_TYPE_UPDATE 7
/* Another node slots configuration */
/* Initially we don't know our "name", but we'll find it once we connect
* to the first node, using the getsockname() function. Then we'll use this
...
...
@@ -137,6 +138,12 @@ typedef struct {
unsigned
char
bulk_data
[
8
];
/* defined as 8 just for alignment concerns. */
}
clusterMsgDataPublish
;
typedef
struct
{
uint64_t
configEpoch
;
/* Config epoch of the specified instance. */
char
nodename
[
REDIS_CLUSTER_NAMELEN
];
/* Name of the slots owner. */
unsigned
char
slots
[
REDIS_CLUSTER_SLOTS
/
8
];
/* Slots bitmap. */
}
clusterMsgDataUpdate
;
union
clusterMsgData
{
/* PING, MEET and PONG */
struct
{
...
...
@@ -153,6 +160,11 @@ union clusterMsgData {
struct
{
clusterMsgDataPublish
msg
;
}
publish
;
/* UPDATE */
struct
{
clusterMsgDataUpdate
nodecfg
;
}
update
;
};
typedef
struct
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录