mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
Cluster: slave nodes advertise master slots bitmap and configEpoch.
This commit is contained in:
parent
1461422ce6
commit
72f38cd70f
@ -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) {
|
|||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user