mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
Cluster: broadcast master/slave replication offset in bus header.
This commit is contained in:
parent
8b32bd483a
commit
befcf6259e
@ -1615,34 +1615,47 @@ 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;
|
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 master, we send its slots bitmap and configEpoch.
|
||||||
* If this node is a slave we send the master's information instead (the
|
* 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
|
* node is flagged as slave so the receiver knows that it is NOT really
|
||||||
* in charge for this slots. */
|
* in charge for this slots. */
|
||||||
master = (server.cluster->myself->flags & REDIS_NODE_SLAVE &&
|
master = (myself->flags & REDIS_NODE_SLAVE && myself->slaveof) ?
|
||||||
server.cluster->myself->slaveof) ?
|
myself->slaveof : myself;
|
||||||
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,myself->name,REDIS_CLUSTER_NAMELEN);
|
||||||
|
|
||||||
memcpy(hdr->myslots,master->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 (myself->slaveof != NULL)
|
||||||
memcpy(hdr->slaveof,server.cluster->myself->slaveof->name,
|
memcpy(hdr->slaveof,myself->slaveof->name, REDIS_CLUSTER_NAMELEN);
|
||||||
REDIS_CLUSTER_NAMELEN);
|
|
||||||
}
|
|
||||||
hdr->port = htons(server.port);
|
hdr->port = htons(server.port);
|
||||||
hdr->flags = htons(server.cluster->myself->flags);
|
hdr->flags = htons(myself->flags);
|
||||||
hdr->state = server.cluster->state;
|
hdr->state = server.cluster->state;
|
||||||
|
|
||||||
/* Set the currentEpoch and configEpochs. */
|
/* Set the currentEpoch and configEpochs. */
|
||||||
hdr->currentEpoch = htonu64(server.cluster->currentEpoch);
|
hdr->currentEpoch = htonu64(server.cluster->currentEpoch);
|
||||||
hdr->configEpoch = htonu64(master->configEpoch);
|
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) {
|
if (type == CLUSTERMSG_TYPE_FAIL) {
|
||||||
totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
|
totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
|
||||||
totlen += sizeof(clusterMsgDataFail);
|
totlen += sizeof(clusterMsgDataFail);
|
||||||
|
@ -178,6 +178,8 @@ typedef struct {
|
|||||||
uint64_t configEpoch; /* The config epoch if it's a master, or the last
|
uint64_t configEpoch; /* The config epoch if it's a master, or the last
|
||||||
epoch advertised by its master if it is a
|
epoch advertised by its master if it is a
|
||||||
slave. */
|
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 */
|
char sender[REDIS_CLUSTER_NAMELEN]; /* Name of the sender node */
|
||||||
unsigned char myslots[REDIS_CLUSTER_SLOTS/8];
|
unsigned char myslots[REDIS_CLUSTER_SLOTS/8];
|
||||||
char slaveof[REDIS_CLUSTER_NAMELEN];
|
char slaveof[REDIS_CLUSTER_NAMELEN];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user