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
72f38cd7
Commit
72f38cd7
authored
Oct 07, 2013
by
antirez
Browse files
Cluster: slave nodes advertise master slots bitmap and configEpoch.
parent
1461422c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
72f38cd7
...
@@ -1339,12 +1339,21 @@ void clusterBroadcastMessage(void *buf, size_t len) {
...
@@ -1339,12 +1339,21 @@ void clusterBroadcastMessage(void *buf, size_t len) {
/* Build the message header */
/* Build the message header */
void
clusterBuildMessageHdr
(
clusterMsg
*
hdr
,
int
type
)
{
void
clusterBuildMessageHdr
(
clusterMsg
*
hdr
,
int
type
)
{
int
totlen
=
0
;
int
totlen
=
0
;
clusterNode
*
master
;
/* If this node is a master, we send its slots bitmap and configEpoch.
* If this node is a slave we send the master's information instead (the
* node is flagged as slave so the receiver knows that it is NOT really
* in charge for this slots. */
master
=
(
server
.
cluster
->
myself
->
flags
&
REDIS_NODE_SLAVE
&&
server
.
cluster
->
myself
->
slaveof
)
?
server
.
cluster
->
myself
->
slaveof
:
server
.
cluster
->
myself
;
memset
(
hdr
,
0
,
sizeof
(
*
hdr
));
memset
(
hdr
,
0
,
sizeof
(
*
hdr
));
hdr
->
type
=
htons
(
type
);
hdr
->
type
=
htons
(
type
);
memcpy
(
hdr
->
sender
,
server
.
cluster
->
myself
->
name
,
REDIS_CLUSTER_NAMELEN
);
memcpy
(
hdr
->
sender
,
server
.
cluster
->
myself
->
name
,
REDIS_CLUSTER_NAMELEN
);
memcpy
(
hdr
->
myslots
,
server
.
cluster
->
myself
->
slots
,
sizeof
(
hdr
->
myslots
));
memcpy
(
hdr
->
myslots
,
master
->
slots
,
sizeof
(
hdr
->
myslots
));
memset
(
hdr
->
slaveof
,
0
,
REDIS_CLUSTER_NAMELEN
);
memset
(
hdr
->
slaveof
,
0
,
REDIS_CLUSTER_NAMELEN
);
if
(
server
.
cluster
->
myself
->
slaveof
!=
NULL
)
{
if
(
server
.
cluster
->
myself
->
slaveof
!=
NULL
)
{
memcpy
(
hdr
->
slaveof
,
server
.
cluster
->
myself
->
slaveof
->
name
,
memcpy
(
hdr
->
slaveof
,
server
.
cluster
->
myself
->
slaveof
->
name
,
...
@@ -1354,13 +1363,9 @@ void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
...
@@ -1354,13 +1363,9 @@ void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
hdr
->
flags
=
htons
(
server
.
cluster
->
myself
->
flags
);
hdr
->
flags
=
htons
(
server
.
cluster
->
myself
->
flags
);
hdr
->
state
=
server
.
cluster
->
state
;
hdr
->
state
=
server
.
cluster
->
state
;
/* Set the currentEpoch and configEpochs. Note that configEpoch is
/* Set the currentEpoch and configEpochs. */
* set to the master configEpoch if this node is a slave. */
hdr
->
currentEpoch
=
htonu64
(
server
.
cluster
->
currentEpoch
);
hdr
->
currentEpoch
=
htonu64
(
server
.
cluster
->
currentEpoch
);
if
(
server
.
cluster
->
myself
->
flags
&
REDIS_NODE_SLAVE
)
hdr
->
configEpoch
=
htonu64
(
master
->
configEpoch
);
hdr
->
configEpoch
=
htonu64
(
server
.
cluster
->
myself
->
slaveof
->
configEpoch
);
else
hdr
->
configEpoch
=
htonu64
(
server
.
cluster
->
myself
->
configEpoch
);
if
(
type
==
CLUSTERMSG_TYPE_FAIL
)
{
if
(
type
==
CLUSTERMSG_TYPE_FAIL
)
{
totlen
=
sizeof
(
clusterMsg
)
-
sizeof
(
union
clusterMsgData
);
totlen
=
sizeof
(
clusterMsg
)
-
sizeof
(
union
clusterMsgData
);
...
...
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