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
befcf625
Commit
befcf625
authored
Jan 28, 2014
by
antirez
Browse files
Cluster: broadcast master/slave replication offset in bus header.
parent
8b32bd48
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
befcf625
...
...
@@ -1615,34 +1615,47 @@ void clusterBroadcastMessage(void *buf, size_t len) {
/* Build the message header */
void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
int totlen = 0;
clusterNode
*
master
;
uint64_t offset;
clusterNode *master, *myself = server.cluster->myself;
/* 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
;
master = (myself->flags & REDIS_NODE_SLAVE && myself->slaveof) ?
myself->slaveof : myself;
memset(hdr,0,sizeof(*hdr));
hdr->type = htons(type);
memcpy
(
hdr
->
sender
,
server
.
cluster
->
myself
->
name
,
REDIS_CLUSTER_NAMELEN
);
memcpy(hdr->sender,myself->name,REDIS_CLUSTER_NAMELEN);
memcpy(hdr->myslots,master->slots,sizeof(hdr->myslots));
memset(hdr->slaveof,0,REDIS_CLUSTER_NAMELEN);
if
(
server
.
cluster
->
myself
->
slaveof
!=
NULL
)
{
memcpy
(
hdr
->
slaveof
,
server
.
cluster
->
myself
->
slaveof
->
name
,
REDIS_CLUSTER_NAMELEN
);
}
if (myself->slaveof != NULL)
memcpy(hdr->slaveof,myself->slaveof->name, REDIS_CLUSTER_NAMELEN);
hdr->port = htons(server.port);
hdr
->
flags
=
htons
(
server
.
cluster
->
myself
->
flags
);
hdr->flags = htons(myself->flags);
hdr->state = server.cluster->state;
/* Set the currentEpoch and configEpochs. */
hdr->currentEpoch = htonu64(server.cluster->currentEpoch);
hdr->configEpoch = htonu64(master->configEpoch);
/* Set the replication offset. */
if (myself->flags & REDIS_NODE_SLAVE) {
if (server.master)
offset = server.master->reploff;
else if (server.cached_master)
offset = server.cached_master->reploff;
else
offset = 0;
} else {
offset = server.master_repl_offset;
}
hdr->offset = htonu64(offset);
/* Compute the message length for certain messages. For other messages
* this is up to the caller. */
if (type == CLUSTERMSG_TYPE_FAIL) {
totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
totlen += sizeof(clusterMsgDataFail);
...
...
src/cluster.h
View file @
befcf625
...
...
@@ -178,6 +178,8 @@ typedef struct {
uint64_t
configEpoch
;
/* The config epoch if it's a master, or the last
epoch advertised by its master if it is a
slave. */
uint64_t
offset
;
/* Master replication offset if node is a master or
processed replication offset if node is a slave. */
char
sender
[
REDIS_CLUSTER_NAMELEN
];
/* Name of the sender node */
unsigned
char
myslots
[
REDIS_CLUSTER_SLOTS
/
8
];
char
slaveof
[
REDIS_CLUSTER_NAMELEN
];
...
...
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