From 44e8bee5961bbb3ddecc8118f0b30e37d9c70cf4 Mon Sep 17 00:00:00 2001 From: Ping Xie Date: Sun, 2 Jun 2024 18:22:17 -0700 Subject: [PATCH 1/9] Initial name changes Signed-off-by: Ping Xie --- src/aof.c | 17 +- src/blocked.c | 6 +- src/cluster.c | 32 +- src/cluster.h | 12 +- src/cluster_legacy.c | 1072 +++++++++++++++--------------- src/cluster_legacy.h | 64 +- src/config.c | 52 +- src/db.c | 18 +- src/debug.c | 4 +- src/evict.c | 6 +- src/expire.c | 10 +- src/logreqres.c | 4 +- src/module.c | 40 +- src/networking.c | 287 ++++---- src/object.c | 16 +- src/rdb.c | 110 ++-- src/rdb.h | 2 +- src/replication.c | 1486 +++++++++++++++++++++--------------------- src/script.c | 14 +- src/server.c | 185 +++--- src/server.h | 316 ++++----- src/timeout.c | 4 +- src/valkey-cli.c | 330 +++++----- 23 files changed, 2051 insertions(+), 2036 deletions(-) diff --git a/src/aof.c b/src/aof.c index f3538f64fa..6cabe62bcf 100644 --- a/src/aof.c +++ b/src/aof.c @@ -904,12 +904,12 @@ int aofFsyncInProgress(void) { /* Starts a background task that performs fsync() against the specified * file descriptor (the one of the AOF file) in another thread. */ void aof_background_fsync(int fd) { - bioCreateFsyncJob(fd, server.master_repl_offset, 1); + bioCreateFsyncJob(fd, server.primary_repl_offset, 1); } /* Close the fd on the basis of aof_background_fsync. */ void aof_background_fsync_and_close(int fd) { - bioCreateCloseAofJob(fd, server.master_repl_offset, 1); + bioCreateCloseAofJob(fd, server.primary_repl_offset, 1); } /* Kills an AOFRW child process if exists */ @@ -1073,7 +1073,8 @@ void flushAppendOnlyFile(int force) { * (because there's no reason, from the AOF POV, to call fsync) and then WAITAOF may wait on * the higher offset (which contains data that was only propagated to replicas, and not to AOF) */ if (!sync_in_progress && server.aof_fsync != AOF_FSYNC_NO) - atomic_store_explicit(&server.fsynced_reploff_pending, server.master_repl_offset, memory_order_relaxed); + atomic_store_explicit(&server.fsynced_reploff_pending, server.primary_repl_offset, + memory_order_relaxed); return; } } @@ -1243,7 +1244,7 @@ void flushAppendOnlyFile(int force) { latencyAddSampleIfNeeded("aof-fsync-always", latency); server.aof_last_incr_fsync_offset = server.aof_last_incr_size; server.aof_last_fsync = server.mstime; - atomic_store_explicit(&server.fsynced_reploff_pending, server.master_repl_offset, memory_order_relaxed); + atomic_store_explicit(&server.fsynced_reploff_pending, server.primary_repl_offset, memory_order_relaxed); } else if (server.aof_fsync == AOF_FSYNC_EVERYSEC && server.mstime - server.aof_last_fsync >= 1000) { if (!sync_in_progress) { aof_background_fsync(server.aof_fd); @@ -1365,9 +1366,9 @@ struct client *createAOFClient(void) { */ c->flags = CLIENT_DENY_BLOCKING; - /* We set the fake client as a slave waiting for the synchronization + /* We set the fake client as a replica waiting for the synchronization * so that the server will not try to send replies to this client. */ - c->replstate = SLAVE_STATE_WAIT_BGSAVE_START; + c->repl_state = REPLICA_STATE_WAIT_BGSAVE_START; return c; } @@ -2320,7 +2321,7 @@ int rewriteAppendOnlyFile(char *filename) { if (server.aof_use_rdb_preamble) { int error; - if (rdbSaveRio(SLAVE_REQ_NONE, &aof, &error, RDBFLAGS_AOF_PREAMBLE, NULL) == C_ERR) { + if (rdbSaveRio(REPLICA_REQ_NONE, &aof, &error, RDBFLAGS_AOF_PREAMBLE, NULL) == C_ERR) { errno = error; goto werr; } @@ -2408,7 +2409,7 @@ int rewriteAppendOnlyFileBackground(void) { /* Set the initial repl_offset, which will be applied to fsynced_reploff * when AOFRW finishes (after possibly being updated by a bio thread) */ - atomic_store_explicit(&server.fsynced_reploff_pending, server.master_repl_offset, memory_order_relaxed); + atomic_store_explicit(&server.fsynced_reploff_pending, server.primary_repl_offset, memory_order_relaxed); server.fsynced_reploff = 0; } diff --git a/src/blocked.c b/src/blocked.c index 85ef9170a0..6d8d4fbc7c 100644 --- a/src/blocked.c +++ b/src/blocked.c @@ -87,7 +87,7 @@ void initClientBlockingState(client *c) { * and will be processed when the client is unblocked. */ void blockClient(client *c, int btype) { /* Master client should never be blocked unless pause or module */ - serverAssert(!(c->flags & CLIENT_MASTER && btype != BLOCKED_MODULE && btype != BLOCKED_POSTPONE)); + serverAssert(!(c->flags & CLIENT_PRIMARY && btype != BLOCKED_MODULE && btype != BLOCKED_POSTPONE)); c->flags |= CLIENT_BLOCKED; c->bstate.btype = btype; @@ -265,8 +265,8 @@ void replyToClientsBlockedOnShutdown(void) { /* Mass-unblock clients because something changed in the instance that makes * blocking no longer safe. For example clients blocked in list operations - * in an instance which turns from master to slave is unsafe, so this function - * is called when a master turns into a slave. + * in an instance which turns from master to replica is unsafe, so this function + * is called when a master turns into a replica. * * The semantics is to send an -UNBLOCKED error to the client, disconnecting * it at the same time. */ diff --git a/src/cluster.c b/src/cluster.c index 71d1cc9124..f10ad1c735 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -911,15 +911,15 @@ void clusterCommand(client *c) { return; } - if (clusterNodeIsSlave(n)) { + if (clusterNodeIsReplica(n)) { addReplyError(c, "The specified node is not a master"); return; } /* Report TLS ports to TLS client, and report non-TLS port to non-TLS client. */ - addReplyArrayLen(c, clusterNodeNumSlaves(n)); - for (j = 0; j < clusterNodeNumSlaves(n); j++) { - sds ni = clusterGenNodeDescription(c, clusterNodeGetSlave(n, j), shouldReturnTlsInfo()); + addReplyArrayLen(c, clusterNodeNumReplicas(n)); + for (j = 0; j < clusterNodeNumReplicas(n); j++) { + sds ni = clusterGenNodeDescription(c, clusterNodeGetReplica(n, j), shouldReturnTlsInfo()); addReplyBulkCString(c, ni); sdsfree(ni); } @@ -1048,8 +1048,8 @@ getNodeByQuery(client *c, struct serverCommand *cmd, robj **argv, int argc, int * can safely serve the request, otherwise we return a TRYAGAIN * error). To do so we set the importing/migrating state and * increment a counter for every missing key. */ - if (clusterNodeIsMaster(myself) || c->flags & CLIENT_READONLY) { - if (n == clusterNodeGetMaster(myself) && getMigratingSlotDest(slot) != NULL) { + if (clusterNodeIsPrimary(myself) || c->flags & CLIENT_READONLY) { + if (n == clusterNodeGetPrimary(myself) && getMigratingSlotDest(slot) != NULL) { migrating_slot = 1; } else if (getImportingSlotSource(slot) != NULL) { importing_slot = 1; @@ -1122,7 +1122,7 @@ getNodeByQuery(client *c, struct serverCommand *cmd, robj **argv, int argc, int /* MIGRATE always works in the context of the local node if the slot * is open (migrating or importing state). We need to be able to freely * move keys among instances in this case. */ - if ((migrating_slot || importing_slot) && cmd->proc == migrateCommand && clusterNodeIsMaster(myself)) { + if ((migrating_slot || importing_slot) && cmd->proc == migrateCommand && clusterNodeIsPrimary(myself)) { return myself; } @@ -1157,8 +1157,8 @@ getNodeByQuery(client *c, struct serverCommand *cmd, robj **argv, int argc, int * is serving, we can reply without redirection. */ int is_write_command = (cmd_flags & CMD_WRITE) || (c->cmd->proc == execCommand && (c->mstate.cmd_flags & CMD_WRITE)); - if (((c->flags & CLIENT_READONLY) || pubsubshard_included) && !is_write_command && clusterNodeIsSlave(myself) && - clusterNodeGetMaster(myself) == n) { + if (((c->flags & CLIENT_READONLY) || pubsubshard_included) && !is_write_command && clusterNodeIsReplica(myself) && + clusterNodeGetPrimary(myself) == n) { return myself; } @@ -1240,8 +1240,8 @@ int clusterRedirectBlockedClientIfNeeded(client *c) { /* if the client is read-only and attempting to access key that our * replica can handle, allow it. */ - if ((c->flags & CLIENT_READONLY) && !(c->lastcmd->flags & CMD_WRITE) && clusterNodeIsSlave(myself) && - clusterNodeGetMaster(myself) == node) { + if ((c->flags & CLIENT_READONLY) && !(c->lastcmd->flags & CMD_WRITE) && clusterNodeIsReplica(myself) && + clusterNodeGetPrimary(myself) == node) { node = myself; } @@ -1332,8 +1332,8 @@ int isNodeAvailable(clusterNode *node) { void addNodeReplyForClusterSlot(client *c, clusterNode *node, int start_slot, int end_slot) { int i, nested_elements = 3; /* slots (2) + master addr (1) */ - for (i = 0; i < clusterNodeNumSlaves(node); i++) { - if (!isNodeAvailable(clusterNodeGetSlave(node, i))) continue; + for (i = 0; i < clusterNodeNumReplicas(node); i++) { + if (!isNodeAvailable(clusterNodeGetReplica(node, i))) continue; nested_elements++; } addReplyArrayLen(c, nested_elements); @@ -1342,11 +1342,11 @@ void addNodeReplyForClusterSlot(client *c, clusterNode *node, int start_slot, in addNodeToNodeReply(c, node); /* Remaining nodes in reply are replicas for slot range */ - for (i = 0; i < clusterNodeNumSlaves(node); i++) { + for (i = 0; i < clusterNodeNumReplicas(node); i++) { /* This loop is copy/pasted from clusterGenNodeDescription() * with modifications for per-slot node aggregation. */ - if (!isNodeAvailable(clusterNodeGetSlave(node, i))) continue; - addNodeToNodeReply(c, clusterNodeGetSlave(node, i)); + if (!isNodeAvailable(clusterNodeGetReplica(node, i))) continue; + addNodeToNodeReply(c, clusterNodeGetReplica(node, i)); nested_elements--; } serverAssert(nested_elements == 3); /* Original 3 elements */ diff --git a/src/cluster.h b/src/cluster.h index de58486440..a42573bb3a 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -67,7 +67,7 @@ int clusterCommandSpecial(client *c); const char **clusterCommandExtendedHelp(void); int clusterAllowFailoverCmd(client *c); -void clusterPromoteSelfToMaster(void); +void clusterPromoteSelfToPrimary(void); int clusterManualFailoverTimeLimit(void); void clusterCommandSlots(client *c); @@ -83,18 +83,18 @@ int getClusterSize(void); int getMyShardSlotCount(void); int handleDebugClusterCommand(client *c); int clusterNodePending(clusterNode *node); -int clusterNodeIsMaster(clusterNode *n); +int clusterNodeIsPrimary(clusterNode *n); char **getClusterNodesList(size_t *numnodes); char *clusterNodeIp(clusterNode *node); -int clusterNodeIsSlave(clusterNode *node); -clusterNode *clusterNodeGetMaster(clusterNode *node); +int clusterNodeIsReplica(clusterNode *node); +clusterNode *clusterNodeGetPrimary(clusterNode *node); char *clusterNodeGetName(clusterNode *node); int clusterNodeTimedOut(clusterNode *node); int clusterNodeIsFailing(clusterNode *node); int clusterNodeIsNoFailover(clusterNode *node); char *clusterNodeGetShardId(clusterNode *node); -int clusterNodeNumSlaves(clusterNode *node); -clusterNode *clusterNodeGetSlave(clusterNode *node, int slave_idx); +int clusterNodeNumReplicas(clusterNode *node); +clusterNode *clusterNodeGetReplica(clusterNode *node, int slave_idx); clusterNode *getMigratingSlotDest(int slot); clusterNode *getImportingSlotSource(int slot); clusterNode *getNodeBySlot(int slot); diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 0de6351e90..5e6983f0bb 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -63,14 +63,14 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request); void clusterUpdateState(void); int clusterNodeCoversSlot(clusterNode *n, int slot); list *clusterGetNodesInMyShard(clusterNode *node); -int clusterNodeAddSlave(clusterNode *master, clusterNode *slave); +int clusterNodeAddReplica(clusterNode *primary, clusterNode *replica); int clusterAddSlot(clusterNode *n, int slot); int clusterDelSlot(int slot); int clusterDelNodeSlots(clusterNode *node); int clusterNodeSetSlotBit(clusterNode *n, int slot); -void clusterSetMaster(clusterNode *n, int closeSlots); -void clusterHandleSlaveFailover(void); -void clusterHandleSlaveMigration(int max_slaves); +void clusterSetPrimary(clusterNode *n, int closeSlots); +void clusterHandleReplicaFailover(void); +void clusterHandleReplicaMigration(int max_replicas); int bitmapTestBit(unsigned char *bitmap, int pos); void bitmapSetBit(unsigned char *bitmap, int pos); void bitmapClearBit(unsigned char *bitmap, int pos); @@ -78,7 +78,7 @@ void clusterDoBeforeSleep(int flags); void clusterSendUpdate(clusterLink *link, clusterNode *node); void resetManualFailover(void); void clusterCloseAllSlots(void); -void clusterSetNodeAsMaster(clusterNode *n); +void clusterSetNodeAsPrimary(clusterNode *n); void clusterDelNode(clusterNode *delnode); sds representClusterNodeFlags(sds ci, uint16_t flags); sds representSlotInfo(sds ci, uint16_t *slot_info_pairs, int slot_info_pairs_count); @@ -227,8 +227,8 @@ int auxShardIdSetter(clusterNode *n, void *value, int length) { memcpy(n->shard_id, value, CLUSTER_NAMELEN); /* if n already has replicas, make sure they all agree * on the shard id */ - for (int i = 0; i < n->numslaves; i++) { - if (memcmp(n->slaves[i]->shard_id, n->shard_id, CLUSTER_NAMELEN) != 0) { + for (int i = 0; i < n->num_replicas; i++) { + if (memcmp(n->replicas[i]->shard_id, n->shard_id, CLUSTER_NAMELEN) != 0) { return C_ERR; } } @@ -361,7 +361,7 @@ int clusterLoadConfig(char *filename) { while (fgets(line, maxline, fp) != NULL) { int argc, aux_argc; sds *argv, *aux_argv; - clusterNode *n, *master; + clusterNode *n, *primary; char *p, *s; /* Skip blank lines, they can be created either by users manually @@ -529,9 +529,9 @@ int clusterLoadConfig(char *filename) { myself = server.cluster->myself = n; n->flags |= CLUSTER_NODE_MYSELF; } else if (!strcasecmp(s, "master")) { - n->flags |= CLUSTER_NODE_MASTER; + n->flags |= CLUSTER_NODE_PRIMARY; } else if (!strcasecmp(s, "slave")) { - n->flags |= CLUSTER_NODE_SLAVE; + n->flags |= CLUSTER_NODE_REPLICA; } else if (!strcasecmp(s, "fail?")) { n->flags |= CLUSTER_NODE_PFAIL; } else if (!strcasecmp(s, "fail")) { @@ -551,32 +551,32 @@ int clusterLoadConfig(char *filename) { if (p) s = p + 1; } - /* Get master if any. Set the master and populate master's - * slave list. */ + /* Get primary if any. Set the primary and populate primary's + * replica list. */ if (argv[3][0] != '-') { if (verifyClusterNodeId(argv[3], sdslen(argv[3])) == C_ERR) { sdsfreesplitres(argv, argc); goto fmterr; } - master = clusterLookupNode(argv[3], sdslen(argv[3])); - if (!master) { - master = createClusterNode(argv[3], 0); - clusterAddNode(master); + primary = clusterLookupNode(argv[3], sdslen(argv[3])); + if (!primary) { + primary = createClusterNode(argv[3], 0); + clusterAddNode(primary); } /* shard_id can be absent if we are loading a nodes.conf generated * by an older version of Redis; we should follow the primary's * shard_id in this case */ if (auxFieldHandlers[af_shard_id].isPresent(n) == 0) { - memcpy(n->shard_id, master->shard_id, CLUSTER_NAMELEN); - clusterAddNodeToShard(master->shard_id, n); - } else if (clusterGetNodesInMyShard(master) != NULL && - memcmp(master->shard_id, n->shard_id, CLUSTER_NAMELEN) != 0) { + memcpy(n->shard_id, primary->shard_id, CLUSTER_NAMELEN); + clusterAddNodeToShard(primary->shard_id, n); + } else if (clusterGetNodesInMyShard(primary) != NULL && + memcmp(primary->shard_id, n->shard_id, CLUSTER_NAMELEN) != 0) { /* If the primary has been added to a shard, make sure this * node has the same persisted shard id as the primary. */ goto fmterr; } - n->slaveof = master; - clusterNodeAddSlave(master, n); + n->replicaof = primary; + clusterNodeAddReplica(primary, n); } else if (auxFieldHandlers[af_shard_id].isPresent(n) == 0) { /* n is a primary but it does not have a persisted shard_id. * This happens if we are loading a nodes.conf generated by @@ -592,7 +592,7 @@ int clusterLoadConfig(char *filename) { /* Set configEpoch for this node. * If the node is a replica, set its config epoch to 0. * If it's a primary, load the config epoch from the configuration file. */ - n->configEpoch = (nodeIsSlave(n) && n->slaveof) ? 0 : strtoull(argv[6], NULL, 10); + n->configEpoch = (nodeIsReplica(n) && n->replicaof) ? 0 : strtoull(argv[6], NULL, 10); /* Populate hash slots served by this instance. */ for (j = 8; j < argc; j++) { @@ -831,7 +831,7 @@ void deriveAnnouncedPorts(int *announced_tcp_port, int *announced_tls_port, int void clusterUpdateMyselfFlags(void) { if (!myself) return; int oldflags = myself->flags; - int nofailover = server.cluster_slave_no_failover ? CLUSTER_NODE_NOFAILOVER : 0; + int nofailover = server.cluster_replica_no_failover ? CLUSTER_NODE_NOFAILOVER : 0; myself->flags &= ~CLUSTER_NODE_NOFAILOVER; myself->flags |= nofailover; if (myself->flags != oldflags) { @@ -919,7 +919,7 @@ static void updateShardId(clusterNode *node, const char *shard_id) { clusterAddNodeToShard(shard_id, node); clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG); } - if (shard_id && myself != node && myself->slaveof == node) { + if (shard_id && myself != node && myself->replicaof == node) { if (memcmp(myself->shard_id, shard_id, CLUSTER_NAMELEN) != 0) { /* shard-id can diverge right after a rolling upgrade * from pre-7.2 releases */ @@ -936,7 +936,7 @@ static inline int areInSameShard(clusterNode *node1, clusterNode *node2) { } static inline uint64_t nodeEpoch(clusterNode *n) { - return n->slaveof ? n->slaveof->configEpoch : n->configEpoch; + return n->replicaof ? n->replicaof->configEpoch : n->configEpoch; } /* Update my hostname based on server configuration values */ @@ -991,7 +991,7 @@ void clusterInit(void) { if (clusterLoadConfig(server.cluster_configfile) == C_ERR) { /* No configuration found. We will just use the random name provided * by the createClusterNode() function. */ - myself = server.cluster->myself = createClusterNode(NULL, CLUSTER_NODE_MYSELF | CLUSTER_NODE_MASTER); + myself = server.cluster->myself = createClusterNode(NULL, CLUSTER_NODE_MYSELF | CLUSTER_NODE_PRIMARY); serverLog(LL_NOTICE, "No cluster configuration found, I'm %.40s", myself->name); clusterAddNode(myself); clusterAddNodeToShard(myself->shard_id, myself); @@ -1022,7 +1022,7 @@ void clusterInit(void) { deriveAnnouncedPorts(&myself->tcp_port, &myself->tls_port, &myself->cport); server.cluster->mf_end = 0; - server.cluster->mf_slave = NULL; + server.cluster->mf_replica = NULL; for (connTypeForCaching conn_type = CACHE_CONN_TCP; conn_type < CACHE_CONN_TYPE_MAX; conn_type++) { server.cached_cluster_slot_info[conn_type] = NULL; } @@ -1062,20 +1062,20 @@ void clusterInitLast(void) { * * 1) All other nodes are forgotten. * 2) All the assigned / open slots are released. - * 3) If the node is a slave, it turns into a master. + * 3) If the node is a replica, it turns into a primary. * 4) Only for hard reset: a new Node ID is generated. * 5) Only for hard reset: currentEpoch and configEpoch are set to 0. * 6) The new configuration is saved and the cluster state updated. - * 7) If the node was a slave, the whole data set is flushed away. */ + * 7) If the node was a replica, the whole data set is flushed away. */ void clusterReset(int hard) { dictIterator *di; dictEntry *de; int j; - /* Turn into master. */ - if (nodeIsSlave(myself)) { - clusterSetNodeAsMaster(myself); - replicationUnsetMaster(); + /* Turn into primary. */ + if (nodeIsReplica(myself)) { + clusterSetNodeAsPrimary(myself); + replicationUnsetPrimary(); emptyData(-1, EMPTYDB_NO_FLAGS, NULL); } @@ -1250,7 +1250,7 @@ void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) { /* If the server is starting up, don't accept cluster connections: * UPDATE messages may interact with the database content. */ - if (server.masterhost == NULL && server.loading) return; + if (server.primary_host == NULL && server.loading) return; while (max--) { cfd = anetTcpAccept(server.neterr, fd, cip, sizeof(cip), &cport); @@ -1321,9 +1321,9 @@ clusterNode *createClusterNode(char *nodename, int flags) { node->slot_info_pairs = NULL; node->slot_info_pairs_count = 0; node->numslots = 0; - node->numslaves = 0; - node->slaves = NULL; - node->slaveof = NULL; + node->num_replicas = 0; + node->replicas = NULL; + node->replicaof = NULL; node->last_in_ping_gossip = 0; node->ping_sent = node->pong_received = 0; node->data_received = 0; @@ -1444,43 +1444,44 @@ static int clusterNodeNameComparator(const void *node1, const void *node2) { return strncasecmp((*(clusterNode **)node1)->name, (*(clusterNode **)node2)->name, CLUSTER_NAMELEN); } -int clusterNodeRemoveSlave(clusterNode *master, clusterNode *slave) { +int clusterNodeRemoveReplica(clusterNode *primary, clusterNode *replica) { int j; - for (j = 0; j < master->numslaves; j++) { - if (master->slaves[j] == slave) { - if ((j + 1) < master->numslaves) { - int remaining_slaves = (master->numslaves - j) - 1; - memmove(master->slaves + j, master->slaves + (j + 1), (sizeof(*master->slaves) * remaining_slaves)); + for (j = 0; j < primary->num_replicas; j++) { + if (primary->replicas[j] == replica) { + if ((j + 1) < primary->num_replicas) { + int remaining_replicas = (primary->num_replicas - j) - 1; + memmove(primary->replicas + j, primary->replicas + (j + 1), + (sizeof(*primary->replicas) * remaining_replicas)); } - master->numslaves--; - if (master->numslaves == 0) master->flags &= ~CLUSTER_NODE_MIGRATE_TO; + primary->num_replicas--; + if (primary->num_replicas == 0) primary->flags &= ~CLUSTER_NODE_MIGRATE_TO; return C_OK; } } return C_ERR; } -int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) { +int clusterNodeAddReplica(clusterNode *primary, clusterNode *replica) { int j; - /* If it's already a slave, don't add it again. */ - for (j = 0; j < master->numslaves; j++) - if (master->slaves[j] == slave) return C_ERR; - master->slaves = zrealloc(master->slaves, sizeof(clusterNode *) * (master->numslaves + 1)); - master->slaves[master->numslaves] = slave; - master->numslaves++; - qsort(master->slaves, master->numslaves, sizeof(clusterNode *), clusterNodeNameComparator); - master->flags |= CLUSTER_NODE_MIGRATE_TO; + /* If it's already a replica, don't add it again. */ + for (j = 0; j < primary->num_replicas; j++) + if (primary->replicas[j] == replica) return C_ERR; + primary->replicas = zrealloc(primary->replicas, sizeof(clusterNode *) * (primary->num_replicas + 1)); + primary->replicas[primary->num_replicas] = replica; + primary->num_replicas++; + qsort(primary->replicas, primary->num_replicas, sizeof(clusterNode *), clusterNodeNameComparator); + primary->flags |= CLUSTER_NODE_MIGRATE_TO; return C_OK; } -int clusterCountNonFailingSlaves(clusterNode *n) { - int j, okslaves = 0; +int clusterCountNonFailingReplicas(clusterNode *n) { + int j, ok_replicas = 0; - for (j = 0; j < n->numslaves; j++) - if (!nodeFailed(n->slaves[j])) okslaves++; - return okslaves; + for (j = 0; j < n->num_replicas; j++) + if (!nodeFailed(n->replicas[j])) ok_replicas++; + return ok_replicas; } /* Low level cleanup of the node structure. Only called by clusterDelNode(). */ @@ -1488,12 +1489,12 @@ void freeClusterNode(clusterNode *n) { sds nodename; int j; - /* If the node has associated slaves, we have to set - * all the slaves->slaveof fields to NULL (unknown). */ - for (j = 0; j < n->numslaves; j++) n->slaves[j]->slaveof = NULL; + /* If the node has associated replicas, we have to set + * all the replicas->replicaof fields to NULL (unknown). */ + for (j = 0; j < n->num_replicas; j++) n->replicas[j]->replicaof = NULL; - /* Remove this node from the list of slaves of its master. */ - if (nodeIsSlave(n) && n->slaveof) clusterNodeRemoveSlave(n->slaveof, n); + /* Remove this node from the list of replicas of its primary. */ + if (nodeIsReplica(n) && n->replicaof) clusterNodeRemoveReplica(n->replicaof, n); /* Unlink from the set of nodes. */ nodename = sdsnewlen(n->name, CLUSTER_NAMELEN); @@ -1506,7 +1507,7 @@ void freeClusterNode(clusterNode *n) { if (n->link) freeClusterLink(n->link); if (n->inbound_link) freeClusterLink(n->inbound_link); listRelease(n->fail_reports); - zfree(n->slaves); + zfree(n->replicas); zfree(n); } @@ -1527,8 +1528,8 @@ void clusterAddNode(clusterNode *node) { * other nodes. * 3) Remove the node from the owning shard * 4) Free the node with freeClusterNode() that will in turn remove it - * from the hash table and from the list of slaves of its master, if - * it is a slave node. + * from the hash table and from the list of replicas of its primary, if + * it is a replica node. */ void clusterDelNode(clusterNode *delnode) { int j; @@ -1571,7 +1572,7 @@ clusterNode *clusterLookupNode(const char *name, int length) { /* Get all the nodes in my shard. * Note that the list returned is not computed on the fly - * via slaveof; rather, it is maintained permanently to + * via replicaof; rather, it is maintained permanently to * track the shard membership and its life cycle is tied * to this process. Therefore, the caller must not * release the list. */ @@ -1671,8 +1672,8 @@ uint64_t clusterGetMaxEpoch(void) { * * 1) When slots are closed after importing. Otherwise resharding would be * too expensive. - * 2) When CLUSTER FAILOVER is called with options that force a slave to - * failover its master even if there is not master majority able to + * 2) When CLUSTER FAILOVER is called with options that force a replica to + * failover its primary even if there is not primary majority able to * create a new configuration epoch. * * The cluster will not explode using this function, even in the case of @@ -1695,14 +1696,14 @@ int clusterBumpConfigEpochWithoutConsensus(void) { } } -/* This function is called when this node is a master, and we receive from - * another master a configuration epoch that is equal to our configuration +/* This function is called when this node is a primary, and we receive from + * another primary a configuration epoch that is equal to our configuration * epoch. * * BACKGROUND * - * It is not possible that different slaves get the same config - * epoch during a failover election, because the slaves need to get voted + * It is not possible that different replicas get the same config + * epoch during a failover election, because the replicas need to get voted * by a majority. However when we perform a manual resharding of the cluster * the node will assign a configuration epoch to itself without to ask * for agreement. Usually resharding happens when the cluster is working well @@ -1721,13 +1722,13 @@ int clusterBumpConfigEpochWithoutConsensus(void) { * end with a different configEpoch at startup automatically. * * In all the cases, we want a mechanism that resolves this issue automatically - * as a safeguard. The same configuration epoch for masters serving different + * as a safeguard. The same configuration epoch for primaries serving different * set of slots is not harmful, but it is if the nodes end serving the same * slots for some reason (manual errors or software bugs) without a proper * failover procedure. * * In general we want a system that eventually always ends with different - * masters having different configuration epochs whatever happened, since + * primaries having different configuration epochs whatever happened, since * nothing is worse than a split-brain condition in a distributed system. * * BEHAVIOR @@ -1742,8 +1743,8 @@ int clusterBumpConfigEpochWithoutConsensus(void) { * end with a different configuration epoch. */ void clusterHandleConfigEpochCollision(clusterNode *sender) { - /* Prerequisites: nodes have the same configEpoch and are both masters. */ - if (sender->configEpoch != myself->configEpoch || !clusterNodeIsMaster(sender) || !clusterNodeIsMaster(myself)) + /* Prerequisites: nodes have the same configEpoch and are both primaries. */ + if (sender->configEpoch != myself->configEpoch || !clusterNodeIsPrimary(sender) || !clusterNodeIsPrimary(myself)) return; /* Don't act if the colliding node has a smaller Node ID. */ if (memcmp(sender->name, myself->name, CLUSTER_NAMELEN) <= 0) return; @@ -1837,8 +1838,8 @@ int clusterBlacklistExists(char *nodeid) { /* This function checks if a given node should be marked as FAIL. * It happens if the following conditions are met: * - * 1) We received enough failure reports from other master nodes via gossip. - * Enough means that the majority of the masters signaled the node is + * 1) We received enough failure reports from other primary nodes via gossip. + * Enough means that the majority of the primaries signaled the node is * down recently. * 2) We believe this node is in PFAIL state. * @@ -1846,13 +1847,13 @@ int clusterBlacklistExists(char *nodeid) { * event trying to force every other node to set the FAIL flag for the node. * * Note that the form of agreement used here is weak, as we collect the majority - * of masters state during some time, and even if we force agreement by + * of primaries state during some time, and even if we force agreement by * propagating the FAIL message, because of partitions we may not reach every * node. However: * * 1) Either we reach the majority and eventually the FAIL state will propagate * to all the cluster. - * 2) Or there is no majority so no slave promotion will be authorized and the + * 2) Or there is no majority so no replica promotion will be authorized and the * FAIL flag will be cleared after some time. */ void markNodeAsFailingIfNeeded(clusterNode *node) { @@ -1863,9 +1864,9 @@ void markNodeAsFailingIfNeeded(clusterNode *node) { if (nodeFailed(node)) return; /* Already FAILing. */ failures = clusterNodeFailureReportsCount(node); - /* Also count myself as a voter if I'm a master. */ - if (clusterNodeIsMaster(myself)) failures++; - if (failures < needed_quorum) return; /* No weak agreement from masters. */ + /* Also count myself as a voter if I'm a primary. */ + if (clusterNodeIsPrimary(myself)) failures++; + if (failures < needed_quorum) return; /* No weak agreement from primaries. */ serverLog(LL_NOTICE, "Marking node %.40s (%s) as failing (quorum reached).", node->name, node->human_nodename); @@ -1876,8 +1877,8 @@ void markNodeAsFailingIfNeeded(clusterNode *node) { /* Broadcast the failing node name to everybody, forcing all the other * reachable nodes to flag the node as FAIL. - * We do that even if this node is a replica and not a master: anyway - * the failing state is triggered collecting failure reports from masters, + * We do that even if this node is a replica and not a primary: anyway + * the failing state is triggered collecting failure reports from primaries, * so here the replica is only helping propagating this status. */ clusterSendFail(node->name); clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG); @@ -1891,20 +1892,20 @@ void clearNodeFailureIfNeeded(clusterNode *node) { serverAssert(nodeFailed(node)); - /* For slaves we always clear the FAIL flag if we can contact the + /* For replicas we always clear the FAIL flag if we can contact the * node again. */ - if (nodeIsSlave(node) || node->numslots == 0) { + if (nodeIsReplica(node) || node->numslots == 0) { serverLog(LL_NOTICE, "Clear FAIL state for node %.40s (%s):%s is reachable again.", node->name, - node->human_nodename, nodeIsSlave(node) ? "replica" : "master without slots"); + node->human_nodename, nodeIsReplica(node) ? "replica" : "master without slots"); node->flags &= ~CLUSTER_NODE_FAIL; clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG); } - /* If it is a master and... + /* If it is a primary and... * 1) The FAIL state is old enough. * 2) It is yet serving slots from our point of view (not failed over). * Apparently no one is going to fix these slots, clear the FAIL flag. */ - if (clusterNodeIsMaster(node) && node->numslots > 0 && + if (clusterNodeIsPrimary(node) && node->numslots > 0 && (now - node->fail_time) > (server.cluster_node_timeout * CLUSTER_FAIL_UNDO_TIME_MULT)) { serverLog( LL_NOTICE, @@ -2086,8 +2087,8 @@ void clusterProcessGossipSection(clusterMsg *hdr, clusterLink *link) { /* Ignore gossips about self. */ if (node && node != myself) { /* We already know this node. - Handle failure reports, only when the sender is a master. */ - if (sender && clusterNodeIsMaster(sender)) { + Handle failure reports, only when the sender is a primary. */ + if (sender && clusterNodeIsPrimary(sender)) { if (flags & (CLUSTER_NODE_FAIL | CLUSTER_NODE_PFAIL)) { if (clusterNodeAddFailureReport(node, sender)) { serverLog(LL_VERBOSE, "Node %.40s (%s) reported node %.40s (%s) as not reachable.", @@ -2227,32 +2228,32 @@ int nodeUpdateAddressIfNeeded(clusterNode *node, clusterLink *link, clusterMsg * serverLog(LL_NOTICE, "Address updated for node %.40s (%s), now %s:%d", node->name, node->human_nodename, node->ip, getNodeDefaultClientPort(node)); - /* Check if this is our master and we have to change the + /* Check if this is our primary and we have to change the * replication target as well. */ - if (nodeIsSlave(myself) && myself->slaveof == node) - replicationSetMaster(node->ip, getNodeDefaultReplicationPort(node)); + if (nodeIsReplica(myself) && myself->replicaof == node) + replicationSetPrimary(node->ip, getNodeDefaultReplicationPort(node)); return 1; } -/* Reconfigure the specified node 'n' as a master. This function is called when - * a node that we believed to be a slave is now acting as master in order to +/* Reconfigure the specified node 'n' as a primary. This function is called when + * a node that we believed to be a replica is now acting as primary in order to * update the state of the node. */ -void clusterSetNodeAsMaster(clusterNode *n) { - if (clusterNodeIsMaster(n)) return; +void clusterSetNodeAsPrimary(clusterNode *n) { + if (clusterNodeIsPrimary(n)) return; - if (n->slaveof) { - clusterNodeRemoveSlave(n->slaveof, n); + if (n->replicaof) { + clusterNodeRemoveReplica(n->replicaof, n); if (n != myself) n->flags |= CLUSTER_NODE_MIGRATE_TO; } - n->flags &= ~CLUSTER_NODE_SLAVE; - n->flags |= CLUSTER_NODE_MASTER; - n->slaveof = NULL; + n->flags &= ~CLUSTER_NODE_REPLICA; + n->flags |= CLUSTER_NODE_PRIMARY; + n->replicaof = NULL; /* Update config and state. */ clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_UPDATE_STATE); } -/* This function is called when we receive a master configuration via a +/* This function is called when we receive a primary configuration via a * PING, PONG or UPDATE packet. What we receive is a node, a configEpoch of the * node, and the set of slots claimed under this configEpoch. * @@ -2265,27 +2266,27 @@ void clusterSetNodeAsMaster(clusterNode *n) { * case we receive the info via an UPDATE packet. */ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoch, unsigned char *slots) { int j; - clusterNode *curmaster = NULL, *newmaster = NULL; + clusterNode *cur_primary = NULL, *new_primary = NULL; /* The dirty slots list is a list of slots for which we lose the ownership * while having still keys inside. This usually happens after a failover * or after a manual cluster reconfiguration operated by the admin. * - * If the update message is not able to demote a master to slave (in this - * case we'll resync with the master updating the whole key space), we + * If the update message is not able to demote a primary to replica (in this + * case we'll resync with the primary updating the whole key space), we * need to delete all the keys in the slots we lost ownership. */ uint16_t dirty_slots[CLUSTER_SLOTS]; int dirty_slots_count = 0; - /* We should detect if sender is new master of our shard. + /* We should detect if sender is new primary of our shard. * We will know it if all our slots were migrated to sender, and sender * has no slots except ours */ int sender_slots = 0; int migrated_our_slots = 0; - /* Here we set curmaster to this node or the node this node - * replicates to if it's a slave. In the for loop we are - * interested to check if slots are taken away from curmaster. */ - curmaster = clusterNodeIsMaster(myself) ? myself : myself->slaveof; + /* Here we set cur_primary to this node or the node this node + * replicates to if it's a replica. In the for loop we are + * interested to check if slots are taken away from cur_primary. */ + cur_primary = clusterNodeIsPrimary(myself) ? myself : myself->replicaof; if (sender == myself) { serverLog(LL_NOTICE, "Discarding UPDATE message about myself."); @@ -2322,8 +2323,8 @@ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoc dirty_slots_count++; } - if (server.cluster->slots[j] == curmaster) { - newmaster = sender; + if (server.cluster->slots[j] == cur_primary) { + new_primary = sender; migrated_our_slots++; } @@ -2389,7 +2390,7 @@ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoc * sender if it has just taken over the primary role. */ if (server.cluster->migrating_slots_to[j] != NULL && server.cluster->migrating_slots_to[j] != sender && (server.cluster->migrating_slots_to[j]->configEpoch < senderConfigEpoch || - nodeIsSlave(server.cluster->migrating_slots_to[j])) && + nodeIsReplica(server.cluster->migrating_slots_to[j])) && areInSameShard(server.cluster->migrating_slots_to[j], sender)) { serverLog(LL_NOTICE, "Failover occurred in migration target." @@ -2415,7 +2416,7 @@ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoc * 1. Remove the importing state for the specific slot. * 2. Finalize the slot's ownership, if I am not already the owner of * the slot. */ - if (nodeIsMaster(myself) && server.cluster->importing_slots_from[j] == sender) { + if (nodeIsPrimary(myself) && server.cluster->importing_slots_from[j] == sender) { serverLog(LL_NOTICE, "Slot %d is no longer being imported from node %.40s (%s) in shard %.40s;" " Clear my importing source for the slot.", @@ -2450,13 +2451,13 @@ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoc * keys redirections. */ if (server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_REDIRECTION) return; - /* Handle a special case where newmaster is not set but both sender + /* Handle a special case where new_primary is not set but both sender * and myself own no slots and in the same shard. Set the sender as * the new primary if my current config epoch is lower than the * sender's. */ - if (!newmaster && myself->slaveof != sender && sender_slots == 0 && myself->numslots == 0 && + if (!new_primary && myself->replicaof != sender && sender_slots == 0 && myself->numslots == 0 && nodeEpoch(myself) < senderConfigEpoch && areInSameShard(sender, myself)) { - newmaster = sender; + new_primary = sender; } /* If the shard to which this node (myself) belongs loses all of @@ -2478,7 +2479,7 @@ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoc * shard and our primary just had its last slot migrated to the * sender. In this case we don't reconfigure ourselves as a replica * of the sender. */ - if (newmaster && curmaster->numslots == 0) { + if (new_primary && cur_primary->numslots == 0) { if (server.cluster_allow_replica_migration || areInSameShard(sender, myself)) { serverLog(LL_NOTICE, "Configuration change detected. Reconfiguring myself " @@ -2486,7 +2487,7 @@ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoc sender->name, sender->human_nodename, sender->shard_id); /* Don't clear the migrating/importing states if this is a replica that * just gets promoted to the new primary in the shard. */ - clusterSetMaster(sender, !areInSameShard(sender, myself)); + clusterSetPrimary(sender, !areInSameShard(sender, myself)); clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_FSYNC_CONFIG); } else if ((sender_slots >= migrated_our_slots) && !areInSameShard(sender, myself)) { /* When all our slots are lost to the sender and the sender belongs to @@ -2494,14 +2495,14 @@ void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoc * migration. Don't reconfigure this node to migrate to the new shard * in this case. */ serverLog(LL_NOTICE, - "My last slot was migrated to node %.40s (%s) in shard %.40s. I am now an empty master.", + "My last slot was migrated to node %.40s (%s) in shard %.40s. I am now an empty primary.", sender->name, sender->human_nodename, sender->shard_id); } } else if (dirty_slots_count) { /* If we are here, we received an update message which removed * ownership for certain slots we still have keys about, but still - * we are serving some slots, so this master node was not demoted to - * a slave. + * we are serving some slots, so this primary node was not demoted to + * a replica. * * In order to maintain a consistent state between keys and slots * we need to remove all the keys from the slots we lost. */ @@ -2689,7 +2690,7 @@ void clusterProcessPingExtensions(clusterMsg *hdr, clusterLink *link) { } else if (type == CLUSTERMSG_EXT_TYPE_FORGOTTEN_NODE) { clusterMsgPingExtForgottenNode *forgotten_node_ext = &(ext->ext[0].forgotten_node); clusterNode *n = clusterLookupNode(forgotten_node_ext->name, CLUSTER_NAMELEN); - if (n && n != myself && !(nodeIsSlave(myself) && myself->slaveof == n)) { + if (n && n != myself && !(nodeIsReplica(myself) && myself->replicaof == n)) { sds id = sdsnewlen(forgotten_node_ext->name, CLUSTER_NAMELEN); dictEntry *de = dictAddOrFind(server.cluster->nodes_black_list, id); uint64_t expire = server.unixtime + ntohu64(forgotten_node_ext->ttl); @@ -2721,9 +2722,9 @@ void clusterProcessPingExtensions(clusterMsg *hdr, clusterLink *link) { * As the cluster progressively upgrades to version 7.2, we can expect the shard_ids * across all nodes to naturally converge and align. * - * If sender is a replica, set the shard_id to the shard_id of its master. + * If sender is a replica, set the shard_id to the shard_id of its primary. * Otherwise, we'll set it now. */ - if (ext_shardid == NULL) ext_shardid = clusterNodeGetMaster(sender)->shard_id; + if (ext_shardid == NULL) ext_shardid = clusterNodeGetPrimary(sender)->shard_id; updateShardId(sender, ext_shardid); } @@ -2870,7 +2871,7 @@ int clusterProcessPacket(clusterLink *link) { senderConfigEpoch = ntohu64(hdr->configEpoch); if (senderCurrentEpoch > server.cluster->currentEpoch) server.cluster->currentEpoch = senderCurrentEpoch; /* Update the sender configEpoch if it is a primary publishing a newer one. */ - if (!memcmp(hdr->slaveof, CLUSTER_NODE_NULL_NAME, sizeof(hdr->slaveof)) && + if (!memcmp(hdr->replicaof, CLUSTER_NODE_NULL_NAME, sizeof(hdr->replicaof)) && senderConfigEpoch > sender->configEpoch) { sender->configEpoch = senderConfigEpoch; clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG); @@ -2878,16 +2879,16 @@ int clusterProcessPacket(clusterLink *link) { /* Update the replication offset info for this node. */ sender->repl_offset = ntohu64(hdr->offset); sender->repl_offset_time = now; - /* If we are a slave performing a manual failover and our master + /* If we are a replica performing a manual failover and our primary * sent its offset while already paused, populate the MF state. */ - if (server.cluster->mf_end && nodeIsSlave(myself) && myself->slaveof == sender && - hdr->mflags[0] & CLUSTERMSG_FLAG0_PAUSED && server.cluster->mf_master_offset == -1) { - server.cluster->mf_master_offset = sender->repl_offset; + if (server.cluster->mf_end && nodeIsReplica(myself) && myself->replicaof == sender && + hdr->mflags[0] & CLUSTERMSG_FLAG0_PAUSED && server.cluster->mf_primary_offset == -1) { + server.cluster->mf_primary_offset = sender->repl_offset; clusterDoBeforeSleep(CLUSTER_TODO_HANDLE_MANUALFAILOVER); serverLog(LL_NOTICE, "Received replication offset for paused " - "master manual failover: %lld", - server.cluster->mf_master_offset); + "primary manual failover: %lld", + server.cluster->mf_primary_offset); } } @@ -2916,7 +2917,7 @@ int clusterProcessPacket(clusterLink *link) { /* Add this node if it is new for us and the msg type is MEET. * In this stage we don't try to add the node with the right - * flags, slaveof pointer, and so forth, as this details will be + * flags, replicaof pointer, and so forth, as this details will be * resolved when we'll receive PONGs from the node. */ if (!sender && type == CLUSTERMSG_TYPE_MEET) { clusterNode *node; @@ -2965,7 +2966,7 @@ int clusterProcessPacket(clusterLink *link) { clusterRenameNode(link->node, hdr->sender); serverLog(LL_DEBUG, "Handshake with node %.40s completed.", link->node->name); link->node->flags &= ~CLUSTER_NODE_HANDSHAKE; - link->node->flags |= flags & (CLUSTER_NODE_MASTER | CLUSTER_NODE_SLAVE); + link->node->flags |= flags & (CLUSTER_NODE_PRIMARY | CLUSTER_NODE_REPLICA); clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG); } else if (memcmp(link->node->name, hdr->sender, CLUSTER_NAMELEN) != 0) { /* If the reply has a non matching node ID we @@ -2990,8 +2991,8 @@ int clusterProcessPacket(clusterLink *link) { /* Copy the CLUSTER_NODE_NOFAILOVER flag from what the sender * announced. This is a dynamic flag that we receive from the * sender, and the latest status must be trusted. We need it to - * be propagated because the slave ranking used to understand the - * delay of each slave in the voting process, needs to know + * be propagated because the replica ranking used to understand the + * delay of each replica in the voting process, needs to know * what are the instances really competing. */ if (sender) { int nofailover = flags & CLUSTER_NODE_NOFAILOVER; @@ -3024,23 +3025,23 @@ int clusterProcessPacket(clusterLink *link) { } } - /* Check for role switch: slave -> master or master -> slave. */ + /* Check for role switch: replica -> primary or primary -> replica. */ if (sender) { serverLog(LL_DEBUG, "node %.40s (%s) announces that it is a %s in shard %.40s", sender->name, sender->human_nodename, - !memcmp(hdr->slaveof, CLUSTER_NODE_NULL_NAME, sizeof(hdr->slaveof)) ? "master" : "slave", + !memcmp(hdr->replicaof, CLUSTER_NODE_NULL_NAME, sizeof(hdr->replicaof)) ? "primary" : "replica", sender->shard_id); - if (!memcmp(hdr->slaveof, CLUSTER_NODE_NULL_NAME, sizeof(hdr->slaveof))) { - /* Node is a master. */ - clusterSetNodeAsMaster(sender); + if (!memcmp(hdr->replicaof, CLUSTER_NODE_NULL_NAME, sizeof(hdr->replicaof))) { + /* Node is a primary. */ + clusterSetNodeAsPrimary(sender); } else { - /* Node is a slave. */ - clusterNode *master = clusterLookupNode(hdr->slaveof, CLUSTER_NAMELEN); + /* Node is a replica. */ + clusterNode *primary = clusterLookupNode(hdr->replicaof, CLUSTER_NAMELEN); - if (clusterNodeIsMaster(sender)) { - /* Master turned into a slave! Reconfigure the node. */ - if (master && areInSameShard(master, sender)) { - /* `sender` was a primary and was in the same shard as `master`, its new primary */ + if (clusterNodeIsPrimary(sender)) { + /* Primary turned into a replica! Reconfigure the node. */ + if (primary && areInSameShard(primary, sender)) { + /* `sender` was a primary and was in the same shard as its new primary */ if (sender->configEpoch > senderConfigEpoch) { serverLog(LL_NOTICE, "Ignore stale message from %.40s (%s) in shard %.40s;" @@ -3048,48 +3049,48 @@ int clusterProcessPacket(clusterLink *link) { sender->name, sender->human_nodename, sender->shard_id, (unsigned long long)senderConfigEpoch, (unsigned long long)sender->configEpoch); } else { - /* `master` is still a `slave` in this observer node's view; update its role and configEpoch - */ - clusterSetNodeAsMaster(master); - master->configEpoch = senderConfigEpoch; + /* `primary` is still a `replica` in this observer node's view; + * update its role and configEpoch */ + clusterSetNodeAsPrimary(primary); + primary->configEpoch = senderConfigEpoch; serverLog(LL_NOTICE, "A failover occurred in shard %.40s; node %.40s (%s)" " failed over to node %.40s (%s) with a config epoch of %llu", - sender->shard_id, sender->name, sender->human_nodename, master->name, - master->human_nodename, (unsigned long long)master->configEpoch); + sender->shard_id, sender->name, sender->human_nodename, primary->name, + primary->human_nodename, (unsigned long long)primary->configEpoch); } } else { /* `sender` was moved to another shard and has become a replica, remove its slot assignment */ int slots = clusterDelNodeSlots(sender); serverLog(LL_NOTICE, - "Node %.40s (%s) is no longer master of shard %.40s;" + "Node %.40s (%s) is no longer primary of shard %.40s;" " removed all %d slot(s) it used to own", sender->name, sender->human_nodename, sender->shard_id, slots); - if (master != NULL) { + if (primary != NULL) { serverLog(LL_NOTICE, "Node %.40s (%s) is now part of shard %.40s", sender->name, - sender->human_nodename, master->shard_id); + sender->human_nodename, primary->shard_id); } } - sender->flags &= ~(CLUSTER_NODE_MASTER | CLUSTER_NODE_MIGRATE_TO); - sender->flags |= CLUSTER_NODE_SLAVE; + sender->flags &= ~(CLUSTER_NODE_PRIMARY | CLUSTER_NODE_MIGRATE_TO); + sender->flags |= CLUSTER_NODE_REPLICA; /* Update config and state. */ clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_UPDATE_STATE); } - /* Master node changed for this slave? */ - if (master && sender->slaveof != master) { - if (sender->slaveof) clusterNodeRemoveSlave(sender->slaveof, sender); + /* Primary node changed for this replica? */ + if (primary && sender->replicaof != primary) { + if (sender->replicaof) clusterNodeRemoveReplica(sender->replicaof, sender); serverLog(LL_NOTICE, "Node %.40s (%s) is now a replica of node %.40s (%s) in shard %.40s", - sender->name, sender->human_nodename, master->name, master->human_nodename, + sender->name, sender->human_nodename, primary->name, primary->human_nodename, sender->shard_id); - clusterNodeAddSlave(master, sender); - sender->slaveof = master; + clusterNodeAddReplica(primary, sender); + sender->replicaof = primary; /* Update the shard_id when a replica is connected to its * primary in the very first time. */ - updateShardId(sender, master->shard_id); + updateShardId(sender, primary->shard_id); /* Update config. */ clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG); @@ -3099,32 +3100,33 @@ int clusterProcessPacket(clusterLink *link) { /* Update our info about served slots. * - * Note: this MUST happen after we update the master/slave state - * so that CLUSTER_NODE_MASTER flag will be set. */ + * Note: this MUST happen after we update the primary/replica state + * so that CLUSTER_NODE_PRIMARY flag will be set. */ /* Many checks are only needed if the set of served slots this * instance claims is different compared to the set of slots we have * for it. Check this ASAP to avoid other computational expansive * checks later. */ - clusterNode *sender_master = NULL; /* Sender or its master if slave. */ - int dirty_slots = 0; /* Sender claimed slots don't match my view? */ + clusterNode *sender_primary = NULL; /* Sender or its primary if replica. */ + int dirty_slots = 0; /* Sender claimed slots don't match my view? */ if (sender) { - sender_master = clusterNodeIsMaster(sender) ? sender : sender->slaveof; - if (sender_master) { - dirty_slots = memcmp(sender_master->slots, hdr->myslots, sizeof(hdr->myslots)) != 0; + sender_primary = clusterNodeIsPrimary(sender) ? sender : sender->replicaof; + if (sender_primary) { + dirty_slots = memcmp(sender_primary->slots, hdr->myslots, sizeof(hdr->myslots)) != 0; /* Force dirty when the sending shard owns no slots so that * we have a chance to examine and repair slot migrating/importing * states that involve empty shards. */ - dirty_slots |= sender_master->numslots == 0; + dirty_slots |= sender_primary->numslots == 0; } } - /* 1) If the sender of the message is a master, and we detected that + /* 1) If the sender of the message is a primary, and we detected that * the set of slots it claims changed, scan the slots to see if we * need to update our configuration. */ - if (sender_master && dirty_slots) clusterUpdateSlotsConfigWith(sender_master, senderConfigEpoch, hdr->myslots); + if (sender_primary && dirty_slots) + clusterUpdateSlotsConfigWith(sender_primary, senderConfigEpoch, hdr->myslots); /* Explicitly check for a replication loop before attempting the replication * chain folding logic. @@ -3155,38 +3157,38 @@ int clusterProcessPacket(clusterLink *link) { * epoch than B has on slot 1. This leads to B sending an UPDATE to * A directly saying A* is the new owner of slot 1 with a higher epoch. * d. A receives the UPDATE from B and executes clusterUpdateSlotsConfigWith. - * A now realizes that it is a replica of A* hence setting myself->slaveof + * A now realizes that it is a replica of A* hence setting myself->replicaof * to A*. * e. Finally, the pre-failover PING message queued up in A*'s outgoing * buffer to A is delivered and processed, out of order though, to A. * f. This stale PING message creates the replication loop */ - if (myself->slaveof && myself->slaveof->slaveof && myself->slaveof->slaveof != myself) { - /* Safeguard against sub-replicas. A replica's master can turn itself + if (myself->replicaof && myself->replicaof->replicaof && myself->replicaof->replicaof != myself) { + /* Safeguard against sub-replicas. A replica's primary can turn itself * into a replica if its last slot is removed. If no other node takes * over the slot, there is nothing else to trigger replica migration. */ serverLog(LL_NOTICE, "I'm a sub-replica! Reconfiguring myself as a replica of %.40s from %.40s", - myself->slaveof->slaveof->name, myself->slaveof->name); - clusterSetMaster(myself->slaveof->slaveof, 1); + myself->replicaof->replicaof->name, myself->replicaof->name); + clusterSetPrimary(myself->replicaof->replicaof, 1); clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_FSYNC_CONFIG); } /* 2) We also check for the reverse condition, that is, the sender - * claims to serve slots we know are served by a master with a + * claims to serve slots we know are served by a primary with a * greater configEpoch. If this happens we inform the sender. * * This is useful because sometimes after a partition heals, a - * reappearing master may be the last one to claim a given set of + * reappearing primary may be the last one to claim a given set of * hash slots, but with a configuration that other instances know to * be deprecated. Example: * - * A and B are master and slave for slots 1,2,3. + * A and B are primary and replica for slots 1,2,3. * A is partitioned away, B gets promoted. * B is partitioned away, and A returns available. * * Usually B would PING A publishing its set of served slots and its * configEpoch, but because of the partition B can't inform A of the * new configuration, so other nodes that have an updated table must - * do it. In this way A will stop to act as a master (or can try to + * do it. In this way A will stop to act as a primary (or can try to * failover if there are the conditions to win the election). */ if (sender && dirty_slots) { int j; @@ -3212,7 +3214,7 @@ int clusterProcessPacket(clusterLink *link) { /* If our config epoch collides with the sender's try to fix * the problem. */ - if (sender && clusterNodeIsMaster(myself) && clusterNodeIsMaster(sender) && + if (sender && clusterNodeIsPrimary(myself) && clusterNodeIsPrimary(sender) && senderConfigEpoch == myself->configEpoch) { clusterHandleConfigEpochCollision(sender); } @@ -3262,10 +3264,10 @@ int clusterProcessPacket(clusterLink *link) { clusterSendFailoverAuthIfNeeded(sender, hdr); } else if (type == CLUSTERMSG_TYPE_FAILOVER_AUTH_ACK) { if (!sender) return 1; /* We don't know that node. */ - /* We consider this vote only if the sender is a master serving + /* We consider this vote only if the sender is a primary serving * a non zero number of slots, and its currentEpoch is greater or * equal to epoch where this node started the election. */ - if (clusterNodeIsMaster(sender) && sender->numslots > 0 && + if (clusterNodeIsPrimary(sender) && sender->numslots > 0 && senderCurrentEpoch >= server.cluster->failover_auth_epoch) { server.cluster->failover_auth_count++; /* Maybe we reached a quorum here, set a flag to make sure @@ -3273,20 +3275,20 @@ int clusterProcessPacket(clusterLink *link) { clusterDoBeforeSleep(CLUSTER_TODO_HANDLE_FAILOVER); } } else if (type == CLUSTERMSG_TYPE_MFSTART) { - /* This message is acceptable only if I'm a master and the sender - * is one of my slaves. */ - if (!sender || sender->slaveof != myself) return 1; - /* Manual failover requested from slaves. Initialize the state + /* This message is acceptable only if I'm a primary and the sender + * is one of my replicas. */ + if (!sender || sender->replicaof != myself) return 1; + /* Manual failover requested from replicas. Initialize the state * accordingly. */ resetManualFailover(); server.cluster->mf_end = now + CLUSTER_MF_TIMEOUT; - server.cluster->mf_slave = sender; + server.cluster->mf_replica = sender; pauseActions(PAUSE_DURING_FAILOVER, now + (CLUSTER_MF_TIMEOUT * CLUSTER_MF_PAUSE_MULT), PAUSE_ACTIONS_CLIENT_WRITE_SET); serverLog(LL_NOTICE, "Manual failover requested by replica %.40s (%s).", sender->name, sender->human_nodename); /* We need to send a ping message to the replica, as it would carry - * `server.cluster->mf_master_offset`, which means the master paused clients - * at offset `server.cluster->mf_master_offset`, so that the replica would + * `server.cluster->mf_primary_offset`, which means the primary paused clients + * at offset `server.cluster->mf_primary_offset`, so that the replica would * know that it is safe to set its `server.cluster->mf_can_start` to 1 so as * to complete failover as quickly as possible. */ clusterSendPing(link, CLUSTERMSG_TYPE_PING); @@ -3299,8 +3301,8 @@ int clusterProcessPacket(clusterLink *link) { if (!n) return 1; /* We don't know the reported node. */ if (n->configEpoch >= reportedConfigEpoch) return 1; /* Nothing new. */ - /* If in our current config the node is a slave, set it as a master. */ - if (nodeIsSlave(n)) clusterSetNodeAsMaster(n); + /* If in our current config the node is a replica, set it as a primary. */ + if (nodeIsReplica(n)) clusterSetNodeAsPrimary(n); /* Update the node's configEpoch. */ n->configEpoch = reportedConfigEpoch; @@ -3550,13 +3552,13 @@ void clusterBroadcastMessage(clusterMsgSendBlock *msgblock) { * sizeof(clusterMsg) in bytes. */ static void clusterBuildMessageHdr(clusterMsg *hdr, int type, size_t msglen) { uint64_t offset; - clusterNode *master; + clusterNode *primary; - /* 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 + /* If this node is a primary, we send its slots bitmap and configEpoch. + * If this node is a replica we send the primary's information instead (the + * node is flagged as replica so the receiver knows that it is NOT really * in charge for this slots. */ - master = (nodeIsSlave(myself) && myself->slaveof) ? myself->slaveof : myself; + primary = (nodeIsReplica(myself) && myself->replicaof) ? myself->replicaof : myself; hdr->ver = htons(CLUSTER_PROTO_VER); hdr->sig[0] = 'R'; @@ -3578,9 +3580,9 @@ static void clusterBuildMessageHdr(clusterMsg *hdr, int type, size_t msglen) { int announced_tcp_port, announced_tls_port, announced_cport; deriveAnnouncedPorts(&announced_tcp_port, &announced_tls_port, &announced_cport); - memcpy(hdr->myslots, master->slots, sizeof(hdr->myslots)); - memset(hdr->slaveof, 0, CLUSTER_NAMELEN); - if (myself->slaveof != NULL) memcpy(hdr->slaveof, myself->slaveof->name, CLUSTER_NAMELEN); + memcpy(hdr->myslots, primary->slots, sizeof(hdr->myslots)); + memset(hdr->replicaof, 0, CLUSTER_NAMELEN); + if (myself->replicaof != NULL) memcpy(hdr->replicaof, myself->replicaof->name, CLUSTER_NAMELEN); if (server.tls_cluster) { hdr->port = htons(announced_tls_port); hdr->pport = htons(announced_tcp_port); @@ -3594,17 +3596,17 @@ static void clusterBuildMessageHdr(clusterMsg *hdr, int type, size_t msglen) { /* Set the currentEpoch and configEpochs. */ hdr->currentEpoch = htonu64(server.cluster->currentEpoch); - hdr->configEpoch = htonu64(master->configEpoch); + hdr->configEpoch = htonu64(primary->configEpoch); /* Set the replication offset. */ - if (nodeIsSlave(myself)) - offset = replicationGetSlaveOffset(); + if (nodeIsReplica(myself)) + offset = replicationGetReplicaOffset(); else - offset = server.master_repl_offset; + offset = server.primary_repl_offset; hdr->offset = htonu64(offset); /* Set the message flags. */ - if (clusterNodeIsMaster(myself) && server.cluster->mf_end) hdr->mflags[0] |= CLUSTERMSG_FLAG0_PAUSED; + if (clusterNodeIsPrimary(myself) && server.cluster->mf_end) hdr->mflags[0] |= CLUSTERMSG_FLAG0_PAUSED; hdr->totlen = htonl(msglen); } @@ -3647,7 +3649,7 @@ void clusterSendPing(clusterLink *link, int type) { /* How many gossip sections we want to add? 1/10 of the number of nodes * and anyway at least 3. Why 1/10? * - * If we have N masters, with N/10 entries, and we consider that in + * If we have N primaries, with N/10 entries, and we consider that in * node_timeout we exchange with each other node at least 4 packets * (we ping in the worst case in node_timeout/2 time, and we also * receive two pings from the host), we have a total of 8 packets @@ -3660,14 +3662,14 @@ void clusterSendPing(clusterLink *link, int type) { * PROB = probability of being featured in a single gossip entry, * which is 1 / NUM_OF_NODES. * ENTRIES = 10. - * TOTAL_PACKETS = 2 * 4 * NUM_OF_MASTERS. + * TOTAL_PACKETS = 2 * 4 * NUM_OF_PRIMARIES. * - * If we assume we have just masters (so num of nodes and num of masters + * If we assume we have just primaries (so num of nodes and num of primaries * is the same), with 1/10 we always get over the majority, and specifically - * 80% of the number of nodes, to account for many masters failing at the + * 80% of the number of nodes, to account for many primaries failing at the * same time. * - * Since we have non-voting slaves that lower the probability of an entry + * Since we have non-voting replicas that lower the probability of an entry * to feature our node, we set the number of entries per packet as * 10% of the total nodes we have. */ wanted = floor(dictSize(server.cluster->nodes) / 10); @@ -3776,16 +3778,16 @@ void clusterSendPing(clusterLink *link, int type) { * In Cluster mode, pongs are not used just for failure detection, but also * to carry important configuration information. So broadcasting a pong is * useful when something changes in the configuration and we want to make - * the cluster aware ASAP (for instance after a slave promotion). + * the cluster aware ASAP (for instance after a replica promotion). * * The 'target' argument specifies the receiving instances using the * defines below: * * CLUSTER_BROADCAST_ALL -> All known instances. - * CLUSTER_BROADCAST_LOCAL_SLAVES -> All slaves in my master-slaves ring. + * CLUSTER_BROADCAST_LOCAL_REPLICAS -> All replicas in my primary-replicas ring. */ #define CLUSTER_BROADCAST_ALL 0 -#define CLUSTER_BROADCAST_LOCAL_SLAVES 1 +#define CLUSTER_BROADCAST_LOCAL_REPLICAS 1 void clusterBroadcastPong(int target) { dictIterator *di; dictEntry *de; @@ -3796,10 +3798,10 @@ void clusterBroadcastPong(int target) { if (!node->link) continue; if (node == myself || nodeInHandshake(node)) continue; - if (target == CLUSTER_BROADCAST_LOCAL_SLAVES) { - int local_slave = - nodeIsSlave(node) && node->slaveof && (node->slaveof == myself || node->slaveof == myself->slaveof); - if (!local_slave) continue; + if (target == CLUSTER_BROADCAST_LOCAL_REPLICAS) { + int local_replica = nodeIsReplica(node) && node->replicaof && + (node->replicaof == myself || node->replicaof == myself->replicaof); + if (!local_replica) continue; } clusterSendPing(node->link, CLUSTERMSG_TYPE_PONG); } @@ -3955,15 +3957,15 @@ void clusterPropagatePublish(robj *channel, robj *message, int sharded) { } /* ----------------------------------------------------------------------------- - * SLAVE node specific functions + * REPLICA node specific functions * -------------------------------------------------------------------------- */ /* This function sends a FAILOVER_AUTH_REQUEST message to every node in order to - * see if there is the quorum for this slave instance to failover its failing - * master. + * see if there is the quorum for this replica instance to failover its failing + * primary. * - * Note that we send the failover request to everybody, master and slave nodes, - * but only the masters are supposed to reply to our query. */ + * Note that we send the failover request to everybody, primary and replica nodes, + * but only the primaries are supposed to reply to our query. */ void clusterRequestFailoverAuth(void) { uint32_t msglen = sizeof(clusterMsg) - sizeof(union clusterMsgData); clusterMsgSendBlock *msgblock = createClusterMsgSendBlock(CLUSTERMSG_TYPE_FAILOVER_AUTH_REQUEST, msglen); @@ -3971,7 +3973,7 @@ void clusterRequestFailoverAuth(void) { clusterMsg *hdr = &msgblock->msg; /* If this is a manual failover, set the CLUSTERMSG_FLAG0_FORCEACK bit * in the header to communicate the nodes receiving the message that - * they should authorized the failover even if the master is working. */ + * they should authorized the failover even if the primary is working. */ if (server.cluster->mf_end) hdr->mflags[0] |= CLUSTERMSG_FLAG0_FORCEACK; clusterBroadcastMessage(msgblock); clusterMsgSendBlockDecrRefCount(msgblock); @@ -4001,18 +4003,18 @@ void clusterSendMFStart(clusterNode *node) { /* Vote for the node asking for our vote if there are the conditions. */ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { - clusterNode *master = node->slaveof; + clusterNode *primary = node->replicaof; uint64_t requestCurrentEpoch = ntohu64(request->currentEpoch); uint64_t requestConfigEpoch = ntohu64(request->configEpoch); unsigned char *claimed_slots = request->myslots; int force_ack = request->mflags[0] & CLUSTERMSG_FLAG0_FORCEACK; int j; - /* IF we are not a master serving at least 1 slot, we don't have the + /* IF we are not a primary serving at least 1 slot, we don't have the * right to vote, as the cluster size is the number - * of masters serving at least one slot, and quorum is the cluster + * of primariies serving at least one slot, and quorum is the cluster * size + 1 */ - if (nodeIsSlave(myself) || myself->numslots == 0) return; + if (nodeIsReplica(myself) || myself->numslots == 0) return; /* Request epoch must be >= our currentEpoch. * Note that it is impossible for it to actually be greater since @@ -4032,37 +4034,37 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { return; } - /* Node must be a slave and its master down. - * The master can be non failing if the request is flagged + /* Node must be a replica and its primary down. + * The primary can be non failing if the request is flagged * with CLUSTERMSG_FLAG0_FORCEACK (manual failover). */ - if (clusterNodeIsMaster(node) || master == NULL || (!nodeFailed(master) && !force_ack)) { - if (clusterNodeIsMaster(node)) { - serverLog(LL_WARNING, "Failover auth denied to %.40s (%s): it is a master node", node->name, + if (clusterNodeIsPrimary(node) || primary == NULL || (!nodeFailed(primary) && !force_ack)) { + if (clusterNodeIsPrimary(node)) { + serverLog(LL_WARNING, "Failover auth denied to %.40s (%s): it is a primary node", node->name, node->human_nodename); - } else if (master == NULL) { - serverLog(LL_WARNING, "Failover auth denied to %.40s (%s): I don't know its master", node->name, + } else if (primary == NULL) { + serverLog(LL_WARNING, "Failover auth denied to %.40s (%s): I don't know its primary", node->name, node->human_nodename); - } else if (!nodeFailed(master)) { - serverLog(LL_WARNING, "Failover auth denied to %.40s (%s): its master is up", node->name, + } else if (!nodeFailed(primary)) { + serverLog(LL_WARNING, "Failover auth denied to %.40s (%s): its primary is up", node->name, node->human_nodename); } return; } - /* We did not voted for a slave about this master for two + /* We did not voted for a replica about this primary for two * times the node timeout. This is not strictly needed for correctness * of the algorithm but makes the base case more linear. */ - if (mstime() - node->slaveof->voted_time < server.cluster_node_timeout * 2) { + if (mstime() - node->replicaof->voted_time < server.cluster_node_timeout * 2) { serverLog(LL_WARNING, "Failover auth denied to %.40s %s: " - "can't vote about this master before %lld milliseconds", + "can't vote about this primary before %lld milliseconds", node->name, node->human_nodename, - (long long)((server.cluster_node_timeout * 2) - (mstime() - node->slaveof->voted_time))); + (long long)((server.cluster_node_timeout * 2) - (mstime() - node->replicaof->voted_time))); return; } - /* The slave requesting the vote must have a configEpoch for the claimed - * slots that is >= the one of the masters currently serving the same + /* The replica requesting the vote must have a configEpoch for the claimed + * slots that is >= the one of the primaries currently serving the same * slots in the current configuration. */ for (j = 0; j < CLUSTER_SLOTS; j++) { if (bitmapTestBit(claimed_slots, j) == 0) continue; @@ -4070,8 +4072,8 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { continue; } /* If we reached this point we found a slot that in our current slots - * is served by a master with a greater configEpoch than the one claimed - * by the slave requesting our vote. Refuse to vote for this slave. */ + * is served by a primary with a greater configEpoch than the one claimed + * by the replica requesting our vote. Refuse to vote for this replica. */ serverLog(LL_WARNING, "Failover auth denied to %.40s (%s): " "slot %d epoch (%llu) > reqEpoch (%llu)", @@ -4080,46 +4082,46 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { return; } - /* We can vote for this slave. */ + /* We can vote for this replica. */ server.cluster->lastVoteEpoch = server.cluster->currentEpoch; - node->slaveof->voted_time = mstime(); + node->replicaof->voted_time = mstime(); clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG); clusterSendFailoverAuth(node); serverLog(LL_NOTICE, "Failover auth granted to %.40s (%s) for epoch %llu", node->name, node->human_nodename, (unsigned long long)server.cluster->currentEpoch); } -/* This function returns the "rank" of this instance, a slave, in the context - * of its master-slaves ring. The rank of the slave is given by the number of - * other slaves for the same master that have a better replication offset +/* This function returns the "rank" of this instance, a replica, in the context + * of its primar-replicas ring. The rank of the replica is given by the number of + * other replicas for the same primary that have a better replication offset * compared to the local one (better means, greater, so they claim more data). * - * A slave with rank 0 is the one with the greatest (most up to date) + * A replica with rank 0 is the one with the greatest (most up to date) * replication offset, and so forth. Note that because how the rank is computed - * multiple slaves may have the same rank, in case they have the same offset. + * multiple replicas may have the same rank, in case they have the same offset. * - * The slave rank is used to add a delay to start an election in order to - * get voted and replace a failing master. Slaves with better replication + * The replica rank is used to add a delay to start an election in order to + * get voted and replace a failing primary. Replicas with better replication * offsets are more likely to win. */ -int clusterGetSlaveRank(void) { +int clusterGetReplicaRank(void) { long long myoffset; int j, rank = 0; - clusterNode *master; + clusterNode *primary; - serverAssert(nodeIsSlave(myself)); - master = myself->slaveof; - if (master == NULL) return 0; /* Never called by slaves without master. */ + serverAssert(nodeIsReplica(myself)); + primary = myself->replicaof; + if (primary == NULL) return 0; /* Never called by replicas without primary. */ - myoffset = replicationGetSlaveOffset(); - for (j = 0; j < master->numslaves; j++) - if (master->slaves[j] != myself && !nodeCantFailover(master->slaves[j]) && - master->slaves[j]->repl_offset > myoffset) + myoffset = replicationGetReplicaOffset(); + for (j = 0; j < primary->num_replicas; j++) + if (primary->replicas[j] != myself && !nodeCantFailover(primary->replicas[j]) && + primary->replicas[j]->repl_offset > myoffset) rank++; return rank; } -/* This function is called by clusterHandleSlaveFailover() in order to - * let the slave log why it is not able to failover. Sometimes there are +/* This function is called by clusterHandleReplicaFailover() in order to + * let the replica log why it is not able to failover. Sometimes there are * not the conditions, but since the failover function is called again and * again, we can't log the same things continuously. * @@ -4128,18 +4130,18 @@ int clusterGetSlaveRank(void) { * * 1) The reason for which the failover can't be initiated changed. * The reasons also include a NONE reason we reset the state to - * when the slave finds that its master is fine (no FAIL flag). - * 2) Also, the log is emitted again if the master is still down and + * when the replica finds that its primary is fine (no FAIL flag). + * 2) Also, the log is emitted again if the primary is still down and * the reason for not failing over is still the same, but more than * CLUSTER_CANT_FAILOVER_RELOG_PERIOD seconds elapsed. - * 3) Finally, the function only logs if the slave is down for more than + * 3) Finally, the function only logs if the replica is down for more than * five seconds + NODE_TIMEOUT. This way nothing is logged when a * failover starts in a reasonable time. * - * The function is called with the reason why the slave can't failover + * The function is called with the reason why the replica can't failover * which is one of the integer macros CLUSTER_CANT_FAILOVER_*. * - * The function is guaranteed to be called only if 'myself' is a slave. */ + * The function is guaranteed to be called only if 'myself' is a replica. */ void clusterLogCantFailover(int reason) { char *msg; static time_t lastlog_time = 0; @@ -4152,10 +4154,11 @@ void clusterLogCantFailover(int reason) { server.cluster->cant_failover_reason = reason; - /* We also don't emit any log if the master failed no long ago, the - * goal of this function is to log slaves in a stalled condition for + /* We also don't emit any log if the primary failed no long ago, the + * goal of this function is to log replicas in a stalled condition for * a long time. */ - if (myself->slaveof && nodeFailed(myself->slaveof) && (mstime() - myself->slaveof->fail_time) < nolog_fail_time) + if (myself->replicaof && nodeFailed(myself->replicaof) && + (mstime() - myself->replicaof->fail_time) < nolog_fail_time) return; switch (reason) { @@ -4181,24 +4184,24 @@ void clusterLogCantFailover(int reason) { } /* This function implements the final part of automatic and manual failovers, - * where the slave grabs its master's hash slots, and propagates the new + * where the replica grabs its primary's hash slots, and propagates the new * configuration. * * Note that it's up to the caller to be sure that the node got a new * configuration epoch already. */ -void clusterFailoverReplaceYourMaster(void) { +void clusterFailoverReplaceYourPrimary(void) { int j; - clusterNode *oldmaster = myself->slaveof; + clusterNode *old_primary = myself->replicaof; - if (clusterNodeIsMaster(myself) || oldmaster == NULL) return; + if (clusterNodeIsPrimary(myself) || old_primary == NULL) return; - /* 1) Turn this node into a master. */ - clusterSetNodeAsMaster(myself); - replicationUnsetMaster(); + /* 1) Turn this node into a primary . */ + clusterSetNodeAsPrimary(myself); + replicationUnsetPrimary(); - /* 2) Claim all the slots assigned to our master. */ + /* 2) Claim all the slots assigned to our primary. */ for (j = 0; j < CLUSTER_SLOTS; j++) { - if (clusterNodeCoversSlot(oldmaster, j)) { + if (clusterNodeCoversSlot(old_primary, j)) { clusterDelSlot(j); clusterAddSlot(myself, j); } @@ -4209,22 +4212,22 @@ void clusterFailoverReplaceYourMaster(void) { clusterSaveConfigOrDie(1); /* 4) Pong all the other nodes so that they can update the state - * accordingly and detect that we switched to master role. */ + * accordingly and detect that we switched to primary role. */ clusterBroadcastPong(CLUSTER_BROADCAST_ALL); /* 5) If there was a manual failover in progress, clear the state. */ resetManualFailover(); } -/* This function is called if we are a slave node and our master serving +/* This function is called if we are a replica node and our primary serving * a non-zero amount of hash slots is in FAIL state. * * The goal of this function is: * 1) To check if we are able to perform a failover, is our data updated? - * 2) Try to get elected by masters. + * 2) Try to get elected by primaries. * 3) Perform the failover informing all the other nodes. */ -void clusterHandleSlaveFailover(void) { +void clusterHandleReplicaFailover(void) { mstime_t data_age; mstime_t auth_age = mstime() - server.cluster->failover_auth_time; int needed_quorum = (server.cluster->size / 2) + 1; @@ -4246,12 +4249,13 @@ void clusterHandleSlaveFailover(void) { /* Pre conditions to run the function, that must be met both in case * of an automatic or manual failover: - * 1) We are a slave. - * 2) Our master is flagged as FAIL, or this is a manual failover. + * 1) We are a replica. + * 2) Our primary is flagged as FAIL, or this is a manual failover. * 3) We don't have the no failover configuration set, and this is * not a manual failover. */ - if (clusterNodeIsMaster(myself) || myself->slaveof == NULL || (!nodeFailed(myself->slaveof) && !manual_failover) || - (server.cluster_slave_no_failover && !manual_failover)) { + if (clusterNodeIsPrimary(myself) || myself->replicaof == NULL || + (!nodeFailed(myself->replicaof) && !manual_failover) || + (server.cluster_replica_no_failover && !manual_failover)) { /* There are no reasons to failover, so we set the reason why we * are returning without failing over to NONE. */ server.cluster->cant_failover_reason = CLUSTER_CANT_FAILOVER_NONE; @@ -4259,25 +4263,25 @@ void clusterHandleSlaveFailover(void) { } /* Set data_age to the number of milliseconds we are disconnected from - * the master. */ + * the primary. */ if (server.repl_state == REPL_STATE_CONNECTED) { - data_age = (mstime_t)(server.unixtime - server.master->lastinteraction) * 1000; + data_age = (mstime_t)(server.unixtime - server.primary->last_interaction) * 1000; } else { data_age = (mstime_t)(server.unixtime - server.repl_down_since) * 1000; } /* Remove the node timeout from the data age as it is fine that we are - * disconnected from our master at least for the time it was down to be + * disconnected from our primary at least for the time it was down to be * flagged as FAIL, that's the baseline. */ if (data_age > server.cluster_node_timeout) data_age -= server.cluster_node_timeout; - /* Check if our data is recent enough according to the slave validity + /* Check if our data is recent enough according to the replica validity * factor configured by the user. * * Check bypassed for manual failovers. */ - if (server.cluster_slave_validity_factor && - data_age > (((mstime_t)server.repl_ping_slave_period * 1000) + - (server.cluster_node_timeout * server.cluster_slave_validity_factor))) { + if (server.cluster_replica_validity_factor && + data_age > (((mstime_t)server.repl_ping_replica_period * 1000) + + (server.cluster_node_timeout * server.cluster_replica_validity_factor))) { if (!manual_failover) { clusterLogCantFailover(CLUSTER_CANT_FAILOVER_DATA_AGE); return; @@ -4292,9 +4296,9 @@ void clusterHandleSlaveFailover(void) { random() % 500; /* Random delay between 0 and 500 milliseconds. */ server.cluster->failover_auth_count = 0; server.cluster->failover_auth_sent = 0; - server.cluster->failover_auth_rank = clusterGetSlaveRank(); - /* We add another delay that is proportional to the slave rank. - * Specifically 1 second * rank. This way slaves that have a probably + server.cluster->failover_auth_rank = clusterGetReplicaRank(); + /* We add another delay that is proportional to the replica rank. + * Specifically 1 second * rank. This way replicas that have a probably * less updated replication offset, are penalized. */ server.cluster->failover_auth_time += server.cluster->failover_auth_rank * 1000; /* However if this is a manual failover, no delay is needed. */ @@ -4307,21 +4311,21 @@ void clusterHandleSlaveFailover(void) { "Start of election delayed for %lld milliseconds " "(rank #%d, offset %lld).", server.cluster->failover_auth_time - mstime(), server.cluster->failover_auth_rank, - replicationGetSlaveOffset()); + replicationGetReplicaOffset()); /* Now that we have a scheduled election, broadcast our offset - * to all the other slaves so that they'll updated their offsets + * to all the other replicas so that they'll updated their offsets * if our offset is better. */ - clusterBroadcastPong(CLUSTER_BROADCAST_LOCAL_SLAVES); + clusterBroadcastPong(CLUSTER_BROADCAST_LOCAL_REPLICAS); return; } /* It is possible that we received more updated offsets from other - * slaves for the same master since we computed our election delay. + * replicas for the same primary since we computed our election delay. * Update the delay if our rank changed. * * Not performed if this is a manual failover. */ if (server.cluster->failover_auth_sent == 0 && server.cluster->mf_end == 0) { - int newrank = clusterGetSlaveRank(); + int newrank = clusterGetReplicaRank(); if (newrank > server.cluster->failover_auth_rank) { long long added_delay = (newrank - server.cluster->failover_auth_rank) * 1000; server.cluster->failover_auth_time += added_delay; @@ -4357,9 +4361,9 @@ void clusterHandleSlaveFailover(void) { /* Check if we reached the quorum. */ if (server.cluster->failover_auth_count >= needed_quorum) { - /* We have the quorum, we can finally failover the master. */ + /* We have the quorum, we can finally failover the primary. */ - serverLog(LL_NOTICE, "Failover election won: I'm the new master."); + serverLog(LL_NOTICE, "Failover election won: I'm the new primary."); /* Update my configEpoch to the epoch of the election. */ if (myself->configEpoch < server.cluster->failover_auth_epoch) { @@ -4369,99 +4373,99 @@ void clusterHandleSlaveFailover(void) { } /* Take responsibility for the cluster slots. */ - clusterFailoverReplaceYourMaster(); + clusterFailoverReplaceYourPrimary(); } else { clusterLogCantFailover(CLUSTER_CANT_FAILOVER_WAITING_VOTES); } } /* ----------------------------------------------------------------------------- - * CLUSTER slave migration + * CLUSTER replica migration * - * Slave migration is the process that allows a slave of a master that is - * already covered by at least another slave, to "migrate" to a master that - * is orphaned, that is, left with no working slaves. + * Replica migration is the process that allows a replica of a primary that is + * already covered by at least another replica, to "migrate" to a primary that + * is orphaned, that is, left with no working replicas. * ------------------------------------------------------------------------- */ /* This function is responsible to decide if this replica should be migrated - * to a different (orphaned) master. It is called by the clusterCron() function + * to a different (orphaned) primary. It is called by the clusterCron() function * only if: * - * 1) We are a slave node. - * 2) It was detected that there is at least one orphaned master in + * 1) We are a replica node. + * 2) It was detected that there is at least one orphaned primary in * the cluster. - * 3) We are a slave of one of the masters with the greatest number of - * slaves. + * 3) We are a replica of one of the primaries with the greatest number of + * replicas. * * This checks are performed by the caller since it requires to iterate - * the nodes anyway, so we spend time into clusterHandleSlaveMigration() + * the nodes anyway, so we spend time into clusterHandleReplicaMigration() * if definitely needed. * - * The function is called with a pre-computed max_slaves, that is the max - * number of working (not in FAIL state) slaves for a single master. + * The function is called with a pre-computed max_replicas, that is the max + * number of working (not in FAIL state) replicas for a single primary. * * Additional conditions for migration are examined inside the function. */ -void clusterHandleSlaveMigration(int max_slaves) { - int j, okslaves = 0; - clusterNode *mymaster = myself->slaveof, *target = NULL, *candidate = NULL; +void clusterHandleReplicaMigration(int max_replicas) { + int j, ok_replicas = 0; + clusterNode *my_primary = myself->replicaof, *target = NULL, *candidate = NULL; dictIterator *di; dictEntry *de; /* Step 1: Don't migrate if the cluster state is not ok. */ if (server.cluster->state != CLUSTER_OK) return; - /* Step 2: Don't migrate if my master will not be left with at least - * 'migration-barrier' slaves after my migration. */ - if (mymaster == NULL) return; - for (j = 0; j < mymaster->numslaves; j++) - if (!nodeFailed(mymaster->slaves[j]) && !nodeTimedOut(mymaster->slaves[j])) okslaves++; - if (okslaves <= server.cluster_migration_barrier) return; + /* Step 2: Don't migrate if my primary will not be left with at least + * 'migration-barrier' replicas after my migration. */ + if (my_primary == NULL) return; + for (j = 0; j < my_primary->num_replicas; j++) + if (!nodeFailed(my_primary->replicas[j]) && !nodeTimedOut(my_primary->replicas[j])) ok_replicas++; + if (ok_replicas <= server.cluster_migration_barrier) return; /* Step 3: Identify a candidate for migration, and check if among the - * masters with the greatest number of ok slaves, I'm the one with the - * smallest node ID (the "candidate slave"). + * primaries with the greatest number of ok replicas, I'm the one with the + * smallest node ID (the "candidate replica"). * * Note: this means that eventually a replica migration will occur - * since slaves that are reachable again always have their FAIL flag + * since replicas that are reachable again always have their FAIL flag * cleared, so eventually there must be a candidate. * There is a possible race condition causing multiple - * slaves to migrate at the same time, but this is unlikely to + * replicas to migrate at the same time, but this is unlikely to * happen and relatively harmless when it does. */ candidate = myself; di = dictGetSafeIterator(server.cluster->nodes); while ((de = dictNext(di)) != NULL) { clusterNode *node = dictGetVal(de); - int okslaves = 0, is_orphaned = 1; + int ok_replicas = 0, is_orphaned = 1; - /* We want to migrate only if this master is working, orphaned, and - * used to have slaves or if failed over a master that had slaves + /* We want to migrate only if this primary is working, orphaned, and + * used to have replicas or if failed over a primary that had replicas * (MIGRATE_TO flag). This way we only migrate to instances that were * supposed to have replicas. */ - if (nodeIsSlave(node) || nodeFailed(node)) is_orphaned = 0; + if (nodeIsReplica(node) || nodeFailed(node)) is_orphaned = 0; if (!(node->flags & CLUSTER_NODE_MIGRATE_TO)) is_orphaned = 0; - /* Check number of working slaves. */ - if (clusterNodeIsMaster(node)) okslaves = clusterCountNonFailingSlaves(node); - if (okslaves > 0) is_orphaned = 0; + /* Check number of working replicas. */ + if (clusterNodeIsPrimary(node)) ok_replicas = clusterCountNonFailingReplicas(node); + if (ok_replicas > 0) is_orphaned = 0; if (is_orphaned) { if (!target && node->numslots > 0) target = node; /* Track the starting time of the orphaned condition for this - * master. */ + * primary. */ if (!node->orphaned_time) node->orphaned_time = mstime(); } else { node->orphaned_time = 0; } - /* Check if I'm the slave candidate for the migration: attached - * to a master with the maximum number of slaves and with the smallest + /* Check if I'm the replica candidate for the migration: attached + * to a primary with the maximum number of replicas and with the smallest * node ID. */ - if (okslaves == max_slaves) { - for (j = 0; j < node->numslaves; j++) { - if (memcmp(node->slaves[j]->name, candidate->name, CLUSTER_NAMELEN) < 0) { - candidate = node->slaves[j]; + if (ok_replicas == max_replicas) { + for (j = 0; j < node->num_replicas; j++) { + if (memcmp(node->replicas[j]->name, candidate->name, CLUSTER_NAMELEN) < 0) { + candidate = node->replicas[j]; } } } @@ -4469,62 +4473,62 @@ void clusterHandleSlaveMigration(int max_slaves) { dictReleaseIterator(di); /* Step 4: perform the migration if there is a target, and if I'm the - * candidate, but only if the master is continuously orphaned for a + * candidate, but only if the primary is continuously orphaned for a * couple of seconds, so that during failovers, we give some time to - * the natural slaves of this instance to advertise their switch from - * the old master to the new one. */ - if (target && candidate == myself && (mstime() - target->orphaned_time) > CLUSTER_SLAVE_MIGRATION_DELAY && + * the natural replicas of this instance to advertise their switch from + * the old primary to the new one. */ + if (target && candidate == myself && (mstime() - target->orphaned_time) > CLUSTER_REPLICA_MIGRATION_DELAY && !(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) { - serverLog(LL_NOTICE, "Migrating to orphaned master %.40s (%s) in shard %.40s", target->name, + serverLog(LL_NOTICE, "Migrating to orphaned primary %.40s (%s) in shard %.40s", target->name, target->human_nodename, target->shard_id); - clusterSetMaster(target, 1); + clusterSetPrimary(target, 1); } } /* ----------------------------------------------------------------------------- * CLUSTER manual failover * - * This are the important steps performed by slaves during a manual failover: + * This are the important steps performed by replicas during a manual failover: * 1) User send CLUSTER FAILOVER command. The failover state is initialized * setting mf_end to the millisecond unix time at which we'll abort the * attempt. - * 2) Slave sends a MFSTART message to the master requesting to pause clients + * 2) Replica sends a MFSTART message to the primary requesting to pause clients * for two times the manual failover timeout CLUSTER_MF_TIMEOUT. - * When master is paused for manual failover, it also starts to flag + * When primary is paused for manual failover, it also starts to flag * packets with CLUSTERMSG_FLAG0_PAUSED. - * 3) Slave waits for master to send its replication offset flagged as PAUSED. - * 4) If slave received the offset from the master, and its offset matches, - * mf_can_start is set to 1, and clusterHandleSlaveFailover() will perform + * 3) Replica waits for primary to send its replication offset flagged as PAUSED. + * 4) If replica received the offset from the primary, and its offset matches, + * mf_can_start is set to 1, and clusterHandleReplicaFailover() will perform * the failover as usually, with the difference that the vote request - * will be modified to force masters to vote for a slave that has a - * working master. + * will be modified to force primaries to vote for a replica that has a + * working primary. * - * From the point of view of the master things are simpler: when a - * PAUSE_CLIENTS packet is received the master sets mf_end as well and - * the sender in mf_slave. During the time limit for the manual failover - * the master will just send PINGs more often to this slave, flagged with - * the PAUSED flag, so that the slave will set mf_master_offset when receiving - * a packet from the master with this flag set. + * From the point of view of the primary things are simpler: when a + * PAUSE_CLIENTS packet is received the primary sets mf_end as well and + * the sender in mf_replica. During the time limit for the manual failover + * the primary will just send PINGs more often to this replica, flagged with + * the PAUSED flag, so that the replica will set mf_primary_offset when receiving + * a packet from the primary with this flag set. * * The goal of the manual failover is to perform a fast failover without - * data loss due to the asynchronous master-slave replication. + * data loss due to the asynchronous primary-replica replication. * -------------------------------------------------------------------------- */ -/* Reset the manual failover state. This works for both masters and slaves +/* Reset the manual failover state. This works for both primaries and replicas * as all the state about manual failover is cleared. * * The function can be used both to initialize the manual failover state at * startup or to abort a manual failover in progress. */ void resetManualFailover(void) { - if (server.cluster->mf_slave) { - /* We were a master failing over, so we paused clients and related actions. + if (server.cluster->mf_replica) { + /* We were a primary failing over, so we paused clients and related actions. * Regardless of the outcome we unpause now to allow traffic again. */ unpauseActions(PAUSE_DURING_FAILOVER); } server.cluster->mf_end = 0; /* No manual failover in progress. */ server.cluster->mf_can_start = 0; - server.cluster->mf_slave = NULL; - server.cluster->mf_master_offset = -1; + server.cluster->mf_replica = NULL; + server.cluster->mf_primary_offset = -1; } /* If a manual failover timed out, abort it. */ @@ -4542,16 +4546,16 @@ void clusterHandleManualFailover(void) { if (server.cluster->mf_end == 0) return; /* If mf_can_start is non-zero, the failover was already triggered so the - * next steps are performed by clusterHandleSlaveFailover(). */ + * next steps are performed by clusterHandleReplicaFailover(). */ if (server.cluster->mf_can_start) return; - if (server.cluster->mf_master_offset == -1) return; /* Wait for offset... */ + if (server.cluster->mf_primary_offset == -1) return; /* Wait for offset... */ - if (server.cluster->mf_master_offset == replicationGetSlaveOffset()) { - /* Our replication offset matches the master replication offset + if (server.cluster->mf_primary_offset == replicationGetReplicaOffset()) { + /* Our replication offset matches the primary replication offset * announced after clients were paused. We can start the failover. */ server.cluster->mf_can_start = 1; - serverLog(LL_NOTICE, "All master replication stream processed, " + serverLog(LL_NOTICE, "All primary replication stream processed, " "manual failover can start."); clusterDoBeforeSleep(CLUSTER_TODO_HANDLE_FAILOVER); return; @@ -4631,9 +4635,9 @@ void clusterCron(void) { dictIterator *di; dictEntry *de; int update_state = 0; - int orphaned_masters; /* How many masters there are without ok slaves. */ - int max_slaves; /* Max number of ok slaves for a single master. */ - int this_slaves; /* Number of ok slaves for our master (if we are slave). */ + int orphaned_primaries; /* How many primaries there are without ok replicas. */ + int max_replicas; /* Max number of ok replicas for a single primary. */ + int this_replicas; /* Number of ok replicas for our primary (if we are replica). */ mstime_t min_pong = 0, now = mstime(); clusterNode *min_pong_node = NULL; static unsigned long long iteration = 0; @@ -4693,13 +4697,13 @@ void clusterCron(void) { /* Iterate nodes to check if we need to flag something as failing. * This loop is also responsible to: - * 1) Check if there are orphaned masters (masters without non failing - * slaves). - * 2) Count the max number of non failing slaves for a single master. - * 3) Count the number of slaves for our master, if we are a slave. */ - orphaned_masters = 0; - max_slaves = 0; - this_slaves = 0; + * 1) Check if there are orphaned primaries (primaries without non failing + * replicas). + * 2) Count the max number of non failing replicas for a single primary. + * 3) Count the number of replicas for our primary, if we are a replica. */ + orphaned_primaries = 0; + max_replicas = 0; + this_replicas = 0; di = dictGetSafeIterator(server.cluster->nodes); while ((de = dictNext(di)) != NULL) { clusterNode *node = dictGetVal(de); @@ -4707,19 +4711,19 @@ void clusterCron(void) { if (node->flags & (CLUSTER_NODE_MYSELF | CLUSTER_NODE_NOADDR | CLUSTER_NODE_HANDSHAKE)) continue; - /* Orphaned master check, useful only if the current instance - * is a slave that may migrate to another master. */ - if (nodeIsSlave(myself) && clusterNodeIsMaster(node) && !nodeFailed(node)) { - int okslaves = clusterCountNonFailingSlaves(node); + /* Orphaned primary check, useful only if the current instance + * is a replica that may migrate to another primary. */ + if (nodeIsReplica(myself) && clusterNodeIsPrimary(node) && !nodeFailed(node)) { + int ok_replicas = clusterCountNonFailingReplicas(node); - /* A master is orphaned if it is serving a non-zero number of - * slots, have no working slaves, but used to have at least one - * slave, or failed over a master that used to have slaves. */ - if (okslaves == 0 && node->numslots > 0 && node->flags & CLUSTER_NODE_MIGRATE_TO) { - orphaned_masters++; + /* A primary is orphaned if it is serving a non-zero number of + * slots, have no working replicas, but used to have at least one + * replica, or failed over a primary that used to have replicas. */ + if (ok_replicas == 0 && node->numslots > 0 && node->flags & CLUSTER_NODE_MIGRATE_TO) { + orphaned_primaries++; } - if (okslaves > max_slaves) max_slaves = okslaves; - if (myself->slaveof == node) this_slaves = okslaves; + if (ok_replicas > max_replicas) max_replicas = ok_replicas; + if (myself->replicaof == node) this_replicas = ok_replicas; } /* If we are not receiving any data for more than half the cluster @@ -4749,9 +4753,10 @@ void clusterCron(void) { continue; } - /* If we are a master and one of the slaves requested a manual + /* If we are a primary and one of the replicas requested a manual * failover, ping it continuously. */ - if (server.cluster->mf_end && clusterNodeIsMaster(myself) && server.cluster->mf_slave == node && node->link) { + if (server.cluster->mf_end && clusterNodeIsPrimary(myself) && server.cluster->mf_replica == node && + node->link) { clusterSendPing(node->link, CLUSTERMSG_TYPE_PING); continue; } @@ -4775,7 +4780,7 @@ void clusterCron(void) { if (!(node->flags & (CLUSTER_NODE_PFAIL | CLUSTER_NODE_FAIL))) { node->flags |= CLUSTER_NODE_PFAIL; update_state = 1; - if (clusterNodeIsMaster(myself) && server.cluster->size == 1) { + if (clusterNodeIsPrimary(myself) && server.cluster->size == 1) { markNodeAsFailingIfNeeded(node); } else { serverLog(LL_DEBUG, "*** NODE %.40s possibly failing", node->name); @@ -4785,26 +4790,27 @@ void clusterCron(void) { } dictReleaseIterator(di); - /* If we are a slave node but the replication is still turned off, - * enable it if we know the address of our master and it appears to + /* If we are a replica node but the replication is still turned off, + * enable it if we know the address of our primary and it appears to * be up. */ - if (nodeIsSlave(myself) && server.masterhost == NULL && myself->slaveof && nodeHasAddr(myself->slaveof)) { - replicationSetMaster(myself->slaveof->ip, getNodeDefaultReplicationPort(myself->slaveof)); + if (nodeIsReplica(myself) && server.primary_host == NULL && myself->replicaof && nodeHasAddr(myself->replicaof)) { + replicationSetPrimary(myself->replicaof->ip, getNodeDefaultReplicationPort(myself->replicaof)); } /* Abort a manual failover if the timeout is reached. */ manualFailoverCheckTimeout(); - if (nodeIsSlave(myself)) { + if (nodeIsReplica(myself)) { clusterHandleManualFailover(); - if (!(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) clusterHandleSlaveFailover(); - /* If there are orphaned slaves, and we are a slave among the masters - * with the max number of non-failing slaves, consider migrating to - * the orphaned masters. Note that it does not make sense to try - * a migration if there is no master with at least *two* working - * slaves. */ - if (orphaned_masters && max_slaves >= 2 && this_slaves == max_slaves && server.cluster_allow_replica_migration) - clusterHandleSlaveMigration(max_slaves); + if (!(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) clusterHandleReplicaFailover(); + /* If there are orphaned replicas, and we are a replica among the primaries + * with the max number of non-failing replicas, consider migrating to + * the orphaned primaries. Note that it does not make sense to try + * a migration if there is no primary with at least *two* working + * replicas. */ + if (orphaned_primaries && max_replicas >= 2 && this_replicas == max_replicas && + server.cluster_allow_replica_migration) + clusterHandleReplicaMigration(max_replicas); } if (update_state || server.cluster->state == CLUSTER_FAIL) clusterUpdateState(); @@ -4825,14 +4831,14 @@ void clusterBeforeSleep(void) { if (flags & CLUSTER_TODO_HANDLE_MANUALFAILOVER) { /* Handle manual failover as soon as possible so that won't have a 100ms * as it was handled only in clusterCron */ - if (nodeIsSlave(myself)) { + if (nodeIsReplica(myself)) { clusterHandleManualFailover(); - if (!(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) clusterHandleSlaveFailover(); + if (!(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) clusterHandleReplicaFailover(); } } else if (flags & CLUSTER_TODO_HANDLE_FAILOVER) { /* Handle failover, this is needed when it is likely that there is already - * the quorum from masters in order to react fast. */ - clusterHandleSlaveFailover(); + * the quorum from primaries in order to react fast. */ + clusterHandleReplicaFailover(); } /* Update the cluster state. */ @@ -4878,21 +4884,21 @@ void bitmapClearBit(unsigned char *bitmap, int pos) { bitmap[byte] &= ~(1 << bit); } -/* Return non-zero if there is at least one master with slaves in the cluster. +/* Return non-zero if there is at least one primary with replicas in the cluster. * Otherwise zero is returned. Used by clusterNodeSetSlotBit() to set the - * MIGRATE_TO flag the when a master gets the first slot. */ -int clusterMastersHaveSlaves(void) { - dictIterator *di = dictGetSafeIterator(server.cluster->nodes); + * MIGRATE_TO flag the when a primary gets the first slot. */ +int clusterPrimariesHaveReplicas(void) { + dictIterator di; + dictInitSafeIterator(&di, server.cluster->nodes); dictEntry *de; - int slaves = 0; - while ((de = dictNext(di)) != NULL) { + int replicas = 0; + while ((de = dictNext(&di)) != NULL) { clusterNode *node = dictGetVal(de); - if (nodeIsSlave(node)) continue; - slaves += node->numslaves; + if (nodeIsReplica(node)) continue; + replicas += node->num_replicas; } - dictReleaseIterator(di); - return slaves != 0; + return replicas != 0; } /* Set the slot bit and return the old value. */ @@ -4901,20 +4907,20 @@ int clusterNodeSetSlotBit(clusterNode *n, int slot) { if (!old) { bitmapSetBit(n->slots, slot); n->numslots++; - /* When a master gets its first slot, even if it has no slaves, - * it gets flagged with MIGRATE_TO, that is, the master is a valid + /* When a primary gets its first slot, even if it has no replicas, + * it gets flagged with MIGRATE_TO, that is, the primary is a valid * target for replicas migration, if and only if at least one of - * the other masters has slaves right now. + * the other primaries has replicas right now. * - * Normally masters are valid targets of replica migration if: - * 1. The used to have slaves (but no longer have). - * 2. They are slaves failing over a master that used to have slaves. + * Normally primaries are valid targets of replica migration if: + * 1. The used to have replicas (but no longer have). + * 2. They are replicas failing over a primary that used to have replicas. * - * However new masters with slots assigned are considered valid - * migration targets if the rest of the cluster is not a slave-less. + * However new primaries with slots assigned are considered valid + * migration targets if the rest of the cluster is not a replica-less. * * See https://github.com/redis/redis/issues/3043 for more info. */ - if (n->numslots == 1 && clusterMastersHaveSlaves()) n->flags |= CLUSTER_NODE_MIGRATE_TO; + if (n->numslots == 1 && clusterPrimariesHaveReplicas()) n->flags |= CLUSTER_NODE_MIGRATE_TO; } return old; } @@ -4954,7 +4960,7 @@ int clusterDelSlot(int slot) { if (!n) return C_ERR; - /* Cleanup the channels in master/replica as part of slot deletion. */ + /* Cleanup the channels in primary/replica as part of slot deletion. */ removeChannelsInSlot(slot); /* Clear the slot bit. */ serverAssert(clusterNodeClearSlotBit(n, slot) == 1); @@ -4979,7 +4985,7 @@ int clusterDelNodeSlots(clusterNode *node) { } /* Clear the migrating / importing state for all the slots. - * This is useful at initialization and when turning a master into slave. */ + * This is useful at initialization and when turning a primary into replica. */ void clusterCloseAllSlots(void) { memset(server.cluster->migrating_slots_to, 0, sizeof(server.cluster->migrating_slots_to)); memset(server.cluster->importing_slots_from, 0, sizeof(server.cluster->importing_slots_from)); @@ -4999,20 +5005,20 @@ void clusterCloseAllSlots(void) { void clusterUpdateState(void) { int j, new_state; - int reachable_masters = 0; + int reachable_primaries = 0; static mstime_t among_minority_time; static mstime_t first_call_time = 0; server.cluster->todo_before_sleep &= ~CLUSTER_TODO_UPDATE_STATE; - /* If this is a master node, wait some time before turning the state + /* If this is a primary node, wait some time before turning the state * into OK, since it is not a good idea to rejoin the cluster as a writable - * master, after a reboot, without giving the cluster a chance to + * primary, after a reboot, without giving the cluster a chance to * reconfigure this node. Note that the delay is calculated starting from * the first call to this function and not since the server start, in order * to not count the DB loading time. */ if (first_call_time == 0) first_call_time = mstime(); - if (clusterNodeIsMaster(myself) && server.cluster->state == CLUSTER_FAIL && + if (clusterNodeIsPrimary(myself) && server.cluster->state == CLUSTER_FAIL && mstime() - first_call_time < CLUSTER_WRITABLE_DELAY) return; @@ -5030,10 +5036,10 @@ void clusterUpdateState(void) { } } - /* Compute the cluster size, that is the number of master nodes + /* Compute the cluster size, that is the number of primary nodes * serving at least a single slot. * - * At the same time count the number of reachable masters having + * At the same time count the number of reachable primaries having * at least one slot. */ { dictIterator *di; @@ -5044,9 +5050,9 @@ void clusterUpdateState(void) { while ((de = dictNext(di)) != NULL) { clusterNode *node = dictGetVal(de); - if (clusterNodeIsMaster(node) && node->numslots) { + if (clusterNodeIsPrimary(node) && node->numslots) { server.cluster->size++; - if ((node->flags & (CLUSTER_NODE_FAIL | CLUSTER_NODE_PFAIL)) == 0) reachable_masters++; + if ((node->flags & (CLUSTER_NODE_FAIL | CLUSTER_NODE_PFAIL)) == 0) reachable_primaries++; } } dictReleaseIterator(di); @@ -5057,7 +5063,7 @@ void clusterUpdateState(void) { { int needed_quorum = (server.cluster->size / 2) + 1; - if (reachable_masters < needed_quorum) { + if (reachable_primaries < needed_quorum) { new_state = CLUSTER_FAIL; among_minority_time = mstime(); } @@ -5067,14 +5073,14 @@ void clusterUpdateState(void) { if (new_state != server.cluster->state) { mstime_t rejoin_delay = server.cluster_node_timeout; - /* If the instance is a master and was partitioned away with the + /* If the instance is a primary and was partitioned away with the * minority, don't let it accept queries for some time after the * partition heals, to make sure there is enough time to receive * a configuration update. */ if (rejoin_delay > CLUSTER_MAX_REJOIN_DELAY) rejoin_delay = CLUSTER_MAX_REJOIN_DELAY; if (rejoin_delay < CLUSTER_MIN_REJOIN_DELAY) rejoin_delay = CLUSTER_MIN_REJOIN_DELAY; - if (new_state == CLUSTER_OK && clusterNodeIsMaster(myself) && mstime() - among_minority_time < rejoin_delay) { + if (new_state == CLUSTER_OK && clusterNodeIsPrimary(myself) && mstime() - among_minority_time < rejoin_delay) { return; } @@ -5107,12 +5113,12 @@ int verifyClusterConfigWithData(void) { int update_config = 0; /* Return ASAP if a module disabled cluster redirections. In that case - * every master can store keys about every possible hash slot. */ + * every primary can store keys about every possible hash slot. */ if (server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_REDIRECTION) return C_OK; - /* If this node is a slave, don't perform the check at all as we + /* If this node is a replica, don't perform the check at all as we * completely depend on the replication stream. */ - if (nodeIsSlave(myself)) return C_OK; + if (nodeIsReplica(myself)) return C_OK; /* Make sure we only have keys in DB0. */ for (j = 1; j < server.dbnum; j++) { @@ -5165,35 +5171,35 @@ int verifyClusterConfigWithData(void) { /* Remove all the shard channel related information not owned by the current shard. */ static inline void removeAllNotOwnedShardChannelSubscriptions(void) { if (!kvstoreSize(server.pubsubshard_channels)) return; - clusterNode *currmaster = clusterNodeIsMaster(myself) ? myself : myself->slaveof; + clusterNode *cur_primary = clusterNodeIsPrimary(myself) ? myself : myself->replicaof; for (int j = 0; j < CLUSTER_SLOTS; j++) { - if (server.cluster->slots[j] != currmaster) { + if (server.cluster->slots[j] != cur_primary) { removeChannelsInSlot(j); } } } /* ----------------------------------------------------------------------------- - * SLAVE nodes handling + * REPLICA nodes handling * -------------------------------------------------------------------------- */ -/* Set the specified node 'n' as master for this node. - * If this node is currently a master, it is turned into a slave. */ -void clusterSetMaster(clusterNode *n, int closeSlots) { +/* Set the specified node 'n' as primary for this node. + * If this node is currently a primary, it is turned into a replica. */ +void clusterSetPrimary(clusterNode *n, int closeSlots) { serverAssert(n != myself); serverAssert(myself->numslots == 0); - if (clusterNodeIsMaster(myself)) { - myself->flags &= ~(CLUSTER_NODE_MASTER | CLUSTER_NODE_MIGRATE_TO); - myself->flags |= CLUSTER_NODE_SLAVE; + if (clusterNodeIsPrimary(myself)) { + myself->flags &= ~(CLUSTER_NODE_PRIMARY | CLUSTER_NODE_MIGRATE_TO); + myself->flags |= CLUSTER_NODE_REPLICA; } else { - if (myself->slaveof) clusterNodeRemoveSlave(myself->slaveof, myself); + if (myself->replicaof) clusterNodeRemoveReplica(myself->replicaof, myself); } if (closeSlots) clusterCloseAllSlots(); - myself->slaveof = n; + myself->replicaof = n; updateShardId(myself, n->shard_id); - clusterNodeAddSlave(n, myself); - replicationSetMaster(n->ip, getNodeDefaultReplicationPort(n)); + clusterNodeAddReplica(n, myself); + replicationSetPrimary(n->ip, getNodeDefaultReplicationPort(n)); removeAllNotOwnedShardChannelSubscriptions(); resetManualFailover(); } @@ -5208,8 +5214,8 @@ struct clusterNodeFlags { }; static struct clusterNodeFlags clusterNodeFlagsTable[] = { - {CLUSTER_NODE_MYSELF, "myself,"}, {CLUSTER_NODE_MASTER, "master,"}, - {CLUSTER_NODE_SLAVE, "slave,"}, {CLUSTER_NODE_PFAIL, "fail?,"}, + {CLUSTER_NODE_MYSELF, "myself,"}, {CLUSTER_NODE_PRIMARY, "master,"}, + {CLUSTER_NODE_REPLICA, "slave,"}, {CLUSTER_NODE_PFAIL, "fail?,"}, {CLUSTER_NODE_FAIL, "fail,"}, {CLUSTER_NODE_HANDSHAKE, "handshake,"}, {CLUSTER_NODE_NOADDR, "noaddr,"}, {CLUSTER_NODE_NOFAILOVER, "nofailover,"}}; @@ -5280,10 +5286,10 @@ sds clusterGenNodeDescription(client *c, clusterNode *node, int tls_primary) { ci = sdscatlen(ci, " ", 1); ci = representClusterNodeFlags(ci, node->flags); - /* Slave of... or just "-" */ + /* Replica of... or just "-" */ ci = sdscatlen(ci, " ", 1); - if (node->slaveof) - ci = sdscatlen(ci, node->slaveof->name, CLUSTER_NAMELEN); + if (node->replicaof) + ci = sdscatlen(ci, node->replicaof->name, CLUSTER_NAMELEN); else ci = sdscatlen(ci, "-", 1); @@ -5543,7 +5549,7 @@ void clusterUpdateSlots(client *c, unsigned char *slots, int del) { long long getNodeReplicationOffset(clusterNode *node) { if (node->flags & CLUSTER_NODE_MYSELF) { - return nodeIsSlave(node) ? replicationGetSlaveOffset() : server.master_repl_offset; + return nodeIsReplica(node) ? replicationGetReplicaOffset() : server.primary_repl_offset; } else { return node->repl_offset; } @@ -5586,7 +5592,7 @@ void addNodeDetailsToShardReply(client *c, clusterNode *node) { long long node_offset = getNodeReplicationOffset(node); addReplyBulkCString(c, "role"); - addReplyBulkCString(c, nodeIsSlave(node) ? "replica" : "master"); + addReplyBulkCString(c, nodeIsReplica(node) ? "replica" : "master"); reply_count++; addReplyBulkCString(c, "replication-offset"); @@ -5597,7 +5603,7 @@ void addNodeDetailsToShardReply(client *c, clusterNode *node) { const char *health_msg = NULL; if (nodeFailed(node)) { health_msg = "fail"; - } else if (nodeIsSlave(node) && node_offset == 0) { + } else if (nodeIsReplica(node) && node_offset == 0) { health_msg = "loading"; } else { health_msg = "online"; @@ -5616,7 +5622,7 @@ void addShardReplyForClusterShards(client *c, list *nodes) { addReplyBulkCString(c, "slots"); /* Use slot_info_pairs from the primary only */ - n = clusterNodeGetMaster(n); + n = clusterNodeGetPrimary(n); if (n->slot_info_pairs != NULL) { serverAssert((n->slot_info_pairs_count % 2) == 0); @@ -5680,7 +5686,7 @@ sds genClusterInfoString(void) { "cluster_slots_fail:%d\r\n" "cluster_known_nodes:%lu\r\n" "cluster_size:%d\r\n" - "cluster_current_epoch:%llu\r\n" + "cluster_currentEpoch:%llu\r\n" "cluster_my_epoch:%llu\r\n", statestr[server.cluster->state], slots_assigned, slots_ok, slots_pfail, slots_fail, dictSize(server.cluster->nodes), server.cluster->size, @@ -5769,10 +5775,10 @@ int getClusterSize(void) { } int getMyShardSlotCount(void) { - if (!nodeIsSlave(server.cluster->myself)) { + if (!nodeIsReplica(server.cluster->myself)) { return server.cluster->myself->numslots; - } else if (server.cluster->myself->slaveof) { - return server.cluster->myself->slaveof->numslots; + } else if (server.cluster->myself->replicaof) { + return server.cluster->myself->replicaof->numslots; } else { return 0; } @@ -5798,8 +5804,8 @@ char **getClusterNodesList(size_t *numnodes) { return ids; } -int clusterNodeIsMaster(clusterNode *n) { - return n->flags & CLUSTER_NODE_MASTER; +int clusterNodeIsPrimary(clusterNode *n) { + return n->flags & CLUSTER_NODE_PRIMARY; } int handleDebugClusterCommand(client *c) { @@ -5843,12 +5849,12 @@ char *clusterNodeIp(clusterNode *node) { return node->ip; } -int clusterNodeIsSlave(clusterNode *node) { - return node->flags & CLUSTER_NODE_SLAVE; +int clusterNodeIsReplica(clusterNode *node) { + return node->flags & CLUSTER_NODE_REPLICA; } -clusterNode *clusterNodeGetMaster(clusterNode *node) { - while (node->slaveof != NULL) node = node->slaveof; +clusterNode *clusterNodeGetPrimary(clusterNode *node) { + while (node->replicaof != NULL) node = node->replicaof; return node; } @@ -5894,7 +5900,7 @@ int clusterParseSetSlotCommand(client *c, int *slot_out, clusterNode **node_out, int optarg_pos = 0; /* Allow primaries to replicate "CLUSTER SETSLOT" */ - if (!(c->flags & CLIENT_MASTER) && nodeIsSlave(myself)) { + if (!(c->flags & CLIENT_PRIMARY) && nodeIsReplica(myself)) { addReplyError(c, "Please use SETSLOT only with masters."); return 0; } @@ -5903,7 +5909,7 @@ int clusterParseSetSlotCommand(client *c, int *slot_out, clusterNode **node_out, if (!strcasecmp(c->argv[3]->ptr, "migrating") && c->argc >= 5) { /* CLUSTER SETSLOT MIGRATING */ - if (nodeIsMaster(myself) && server.cluster->slots[slot] != myself) { + if (nodeIsPrimary(myself) && server.cluster->slots[slot] != myself) { addReplyErrorFormat(c, "I'm not the owner of hash slot %u", slot); return 0; } @@ -5912,7 +5918,7 @@ int clusterParseSetSlotCommand(client *c, int *slot_out, clusterNode **node_out, addReplyErrorFormat(c, "I don't know about node %s", (char *)c->argv[4]->ptr); return 0; } - if (nodeIsSlave(n)) { + if (nodeIsReplica(n)) { addReplyError(c, "Target node is not a master"); return 0; } @@ -5928,7 +5934,7 @@ int clusterParseSetSlotCommand(client *c, int *slot_out, clusterNode **node_out, addReplyErrorFormat(c, "I don't know about node %s", (char *)c->argv[4]->ptr); return 0; } - if (nodeIsSlave(n)) { + if (nodeIsReplica(n)) { addReplyError(c, "Target node is not a master"); return 0; } @@ -5943,7 +5949,7 @@ int clusterParseSetSlotCommand(client *c, int *slot_out, clusterNode **node_out, addReplyErrorFormat(c, "Unknown node %s", (char *)c->argv[4]->ptr); return 0; } - if (nodeIsSlave(n)) { + if (nodeIsReplica(n)) { addReplyError(c, "Target node is not a master"); return 0; } @@ -6018,20 +6024,20 @@ void clusterCommandSetSlot(client *c) { * This ensures that all replicas have the latest topology information, enabling * a reliable slot ownership transfer even if the primary node went down during * the process. */ - if (nodeIsMaster(myself) && myself->numslaves != 0 && (c->flags & CLIENT_REPLICATION_DONE) == 0) { + if (nodeIsPrimary(myself) && myself->num_replicas != 0 && (c->flags & CLIENT_REPLICATION_DONE) == 0) { forceCommandPropagation(c, PROPAGATE_REPL); /* We are a primary and this is the first time we see this `SETSLOT` * command. Force-replicate the command to all of our replicas * first and only on success will we handle the command. * Note that * 1. All replicas are expected to ack the replication within the given timeout - * 2. The repl offset target is set to the master's current repl offset + 1. + * 2. The repl offset target is set to the primary's current repl offset + 1. * There is no concern of partial replication because replicas always * ack the repl offset at the command boundary. */ - blockClientForReplicaAck(c, timeout_ms, server.master_repl_offset + 1, myself->numslaves, 0); + blockClientForReplicaAck(c, timeout_ms, server.primary_repl_offset + 1, myself->num_replicas, 0); /* Mark client as pending command for execution after replication to replicas. */ c->flags |= CLIENT_PENDING_COMMAND; - replicationRequestAckFromSlaves(); + replicationRequestAckFromReplicas(); return; } @@ -6064,20 +6070,20 @@ void clusterCommandSetSlot(client *c) { clusterDelSlot(slot); clusterAddSlot(n, slot); - /* If we are a master left without slots, we should turn into a - * replica of the new master. */ + /* If we are a primary left without slots, we should turn into a + * replica of the new primary. */ if (slot_was_mine && n != myself && myself->numslots == 0 && server.cluster_allow_replica_migration) { serverLog(LL_NOTICE, "Lost my last slot during slot migration. Reconfiguring myself " "as a replica of %.40s (%s) in shard %.40s", n->name, n->human_nodename, n->shard_id); - clusterSetMaster(n, 1); + clusterSetPrimary(n, 1); clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_FSYNC_CONFIG); } /* If this node or this node's primary was importing this slot, * assigning the slot to itself also clears the importing status. */ - if ((n == myself || n == myself->slaveof) && server.cluster->importing_slots_from[slot]) { + if ((n == myself || n == myself->replicaof) && server.cluster->importing_slots_from[slot]) { server.cluster->importing_slots_from[slot] = NULL; /* Only primary broadcasts the updates */ @@ -6238,7 +6244,7 @@ int clusterCommandSpecial(client *c) { } else if (n == myself) { addReplyError(c, "I tried hard but I can't forget myself..."); return 1; - } else if (nodeIsSlave(myself) && myself->slaveof == n) { + } else if (nodeIsReplica(myself) && myself->replicaof == n) { addReplyError(c, "Can't forget my master!"); return 1; } @@ -6261,23 +6267,23 @@ int clusterCommandSpecial(client *c) { return 1; } - /* Can't replicate a slave. */ - if (nodeIsSlave(n)) { + /* Can't replicate a replica. */ + if (nodeIsReplica(n)) { addReplyError(c, "I can only replicate a master, not a replica."); return 1; } - /* If the instance is currently a master, it should have no assigned + /* If the instance is currently a primary, it should have no assigned * slots nor keys to accept to replicate some other node. - * Slaves can switch to another master without issues. */ - if (clusterNodeIsMaster(myself) && (myself->numslots != 0 || kvstoreSize(server.db[0].keys) != 0)) { + * Replicas can switch to another primary without issues. */ + if (clusterNodeIsPrimary(myself) && (myself->numslots != 0 || kvstoreSize(server.db[0].keys) != 0)) { addReplyError(c, "To set a master the node must be empty and " "without assigned slots."); return 1; } - /* Set the master. */ - clusterSetMaster(n, 1); + /* Set the primary. */ + clusterSetPrimary(n, 1); clusterBroadcastPong(CLUSTER_BROADCAST_ALL); clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG); addReply(c, shared.ok); @@ -6308,13 +6314,13 @@ int clusterCommandSpecial(client *c) { } /* Check preconditions. */ - if (clusterNodeIsMaster(myself)) { + if (clusterNodeIsPrimary(myself)) { addReplyError(c, "You should send CLUSTER FAILOVER to a replica"); return 1; - } else if (myself->slaveof == NULL) { + } else if (myself->replicaof == NULL) { addReplyError(c, "I'm a replica but my master is unknown to me"); return 1; - } else if (!force && (nodeFailed(myself->slaveof) || myself->slaveof->link == NULL)) { + } else if (!force && (nodeFailed(myself->replicaof) || myself->replicaof->link == NULL)) { addReplyError(c, "Master is down or failed, " "please use CLUSTER FAILOVER FORCE"); return 1; @@ -6325,20 +6331,20 @@ int clusterCommandSpecial(client *c) { if (takeover) { /* A takeover does not perform any initial check. It just * generates a new configuration epoch for this node without - * consensus, claims the master's slots, and broadcast the new + * consensus, claims the primary's slots, and broadcast the new * configuration. */ - serverLog(LL_NOTICE, "Taking over the master (user request)."); + serverLog(LL_NOTICE, "Taking over the primary (user request)."); clusterBumpConfigEpochWithoutConsensus(); - clusterFailoverReplaceYourMaster(); + clusterFailoverReplaceYourPrimary(); } else if (force) { /* If this is a forced failover, we don't need to talk with our - * master to agree about the offset. We just failover taking over + * primary to agree about the offset. We just failover taking over * it without coordination. */ serverLog(LL_NOTICE, "Forced failover user request accepted."); server.cluster->mf_can_start = 1; } else { serverLog(LL_NOTICE, "Manual failover user request accepted."); - clusterSendMFStart(myself->slaveof); + clusterSendMFStart(myself->replicaof); } addReply(c, shared.ok); } else if (!strcasecmp(c->argv[1]->ptr, "set-config-epoch") && c->argc == 3) { @@ -6388,9 +6394,9 @@ int clusterCommandSpecial(client *c) { } } - /* Slaves can be reset while containing data, but not master nodes + /* Replicas can be reset while containing data, but not primary nodes * that must be empty. */ - if (clusterNodeIsMaster(myself) && kvstoreSize(c->db->keys) != 0) { + if (clusterNodeIsPrimary(myself) && kvstoreSize(c->db->keys) != 0) { addReplyError(c, "CLUSTER RESET can't be called with " "master nodes containing keys"); return 1; @@ -6447,12 +6453,12 @@ const char **clusterCommandExtendedHelp(void) { return help; } -int clusterNodeNumSlaves(clusterNode *node) { - return node->numslaves; +int clusterNodeNumReplicas(clusterNode *node) { + return node->num_replicas; } -clusterNode *clusterNodeGetSlave(clusterNode *node, int slave_idx) { - return node->slaves[slave_idx]; +clusterNode *clusterNodeGetReplica(clusterNode *node, int replica_idx) { + return node->replicas[replica_idx]; } clusterNode *getMigratingSlotDest(int slot) { @@ -6498,8 +6504,8 @@ int clusterAllowFailoverCmd(client *c) { return 0; } -void clusterPromoteSelfToMaster(void) { - replicationUnsetMaster(); +void clusterPromoteSelfToPrimary(void) { + replicationUnsetPrimary(); } int detectAndUpdateCachedNodeHealth(void) { @@ -6547,7 +6553,7 @@ void clusterReplicateOpenSlots(void) { sds name = sdsnewlen(nodes_ptr[j]->name, sizeof(nodes_ptr[j]->name)); argv[4] = createObject(OBJ_STRING, name); - replicationFeedSlaves(0, argv, argc); + replicationFeedReplicas(0, argv, argc); decrRefCount(argv[2]); decrRefCount(argv[4]); diff --git a/src/cluster_legacy.h b/src/cluster_legacy.h index cc02f30a8b..a277c758df 100644 --- a/src/cluster_legacy.h +++ b/src/cluster_legacy.h @@ -5,11 +5,11 @@ /* The following defines are amount of time, sometimes expressed as * multiplicators of the node timeout value (when ending with MULT). */ -#define CLUSTER_FAIL_REPORT_VALIDITY_MULT 2 /* Fail report validity. */ -#define CLUSTER_FAIL_UNDO_TIME_MULT 2 /* Undo fail if master is back. */ -#define CLUSTER_MF_TIMEOUT 5000 /* Milliseconds to do a manual failover. */ -#define CLUSTER_MF_PAUSE_MULT 2 /* Master pause manual failover mult. */ -#define CLUSTER_SLAVE_MIGRATION_DELAY 5000 /* Delay for slave migration. */ +#define CLUSTER_FAIL_REPORT_VALIDITY_MULT 2 /* Fail report validity. */ +#define CLUSTER_FAIL_UNDO_TIME_MULT 2 /* Undo fail if primary is back. */ +#define CLUSTER_MF_TIMEOUT 5000 /* Milliseconds to do a manual failover. */ +#define CLUSTER_MF_PAUSE_MULT 2 /* Primary pause manual failover mult. */ +#define CLUSTER_REPLICA_MIGRATION_DELAY 5000 /* Delay for slave migration. */ /* Reasons why a slave is not able to failover. */ #define CLUSTER_CANT_FAILOVER_NONE 0 @@ -41,23 +41,23 @@ typedef struct clusterLink { } clusterLink; /* Cluster node flags and macros. */ -#define CLUSTER_NODE_MASTER 1 /* The node is a master */ -#define CLUSTER_NODE_SLAVE 2 /* The node is a slave */ +#define CLUSTER_NODE_PRIMARY 1 /* The node is a primary */ +#define CLUSTER_NODE_REPLICA 2 /* The node is a slave */ #define CLUSTER_NODE_PFAIL 4 /* Failure? Need acknowledge */ #define CLUSTER_NODE_FAIL 8 /* The node is believed to be malfunctioning */ #define CLUSTER_NODE_MYSELF 16 /* This node is myself */ #define CLUSTER_NODE_HANDSHAKE 32 /* We have still to exchange the first ping */ #define CLUSTER_NODE_NOADDR 64 /* We don't know the address of this node */ #define CLUSTER_NODE_MEET 128 /* Send a MEET message to this node */ -#define CLUSTER_NODE_MIGRATE_TO 256 /* Master eligible for replica migration. */ +#define CLUSTER_NODE_MIGRATE_TO 256 /* Primary eligible for replica migration. */ #define CLUSTER_NODE_NOFAILOVER 512 /* Slave will not try to failover. */ #define CLUSTER_NODE_EXTENSIONS_SUPPORTED 1024 /* This node supports extensions. */ #define CLUSTER_NODE_NULL_NAME \ "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \ "\000\000\000\000\000\000\000\000\000\000\000\000" -#define nodeIsMaster(n) ((n)->flags & CLUSTER_NODE_MASTER) -#define nodeIsSlave(n) ((n)->flags & CLUSTER_NODE_SLAVE) +#define nodeIsPrimary(n) ((n)->flags & CLUSTER_NODE_PRIMARY) +#define nodeIsReplica(n) ((n)->flags & CLUSTER_NODE_REPLICA) #define nodeInHandshake(n) ((n)->flags & CLUSTER_NODE_HANDSHAKE) #define nodeHasAddr(n) (!((n)->flags & CLUSTER_NODE_NOADDR)) #define nodeTimedOut(n) ((n)->flags & CLUSTER_NODE_PFAIL) @@ -216,14 +216,14 @@ typedef struct { uint16_t type; /* Message type */ uint16_t count; /* Number of gossip sections. */ uint64_t currentEpoch; /* The epoch accordingly to the sending node. */ - uint64_t configEpoch; /* The config epoch if it's a master, or the last - epoch advertised by its master if it is a + uint64_t configEpoch; /* The config epoch if it's a primary, or the last + epoch advertised by its primary if it is a slave. */ - uint64_t offset; /* Master replication offset if node is a master or + uint64_t offset; /* Primary replication offset if node is a primary or processed replication offset if node is a slave. */ char sender[CLUSTER_NAMELEN]; /* Name of the sender node */ unsigned char myslots[CLUSTER_SLOTS / 8]; - char slaveof[CLUSTER_NAMELEN]; + char replicaof[CLUSTER_NAMELEN]; char myip[NET_IP_STR_LEN]; /* Sender IP, if not all zeroed. */ uint16_t extensions; /* Number of extensions sent along with this packet. */ char notused1[30]; /* 30 bytes reserved for future usage. */ @@ -256,7 +256,7 @@ static_assert(offsetof(clusterMsg, configEpoch) == 24, "unexpected field offset" static_assert(offsetof(clusterMsg, offset) == 32, "unexpected field offset"); static_assert(offsetof(clusterMsg, sender) == 40, "unexpected field offset"); static_assert(offsetof(clusterMsg, myslots) == 80, "unexpected field offset"); -static_assert(offsetof(clusterMsg, slaveof) == 2128, "unexpected field offset"); +static_assert(offsetof(clusterMsg, replicaof) == 2128, "unexpected field offset"); static_assert(offsetof(clusterMsg, myip) == 2168, "unexpected field offset"); static_assert(offsetof(clusterMsg, extensions) == 2214, "unexpected field offset"); static_assert(offsetof(clusterMsg, notused1) == 2216, "unexpected field offset"); @@ -271,10 +271,10 @@ static_assert(offsetof(clusterMsg, data) == 2256, "unexpected field offset"); /* Message flags better specify the packet content or are used to * provide some information about the node state. */ -#define CLUSTERMSG_FLAG0_PAUSED (1 << 0) /* Master paused for manual failover. */ +#define CLUSTERMSG_FLAG0_PAUSED (1 << 0) /* Primary paused for manual failover. */ #define CLUSTERMSG_FLAG0_FORCEACK \ (1 << 1) /* Give ACK to AUTH_REQUEST even if \ - master is up. */ + primary is up. */ #define CLUSTERMSG_FLAG0_EXT_DATA (1 << 2) /* Message contains extension data */ struct _clusterNode { @@ -287,20 +287,20 @@ struct _clusterNode { uint16_t *slot_info_pairs; /* Slots info represented as (start/end) pair (consecutive index). */ int slot_info_pairs_count; /* Used number of slots in slot_info_pairs */ int numslots; /* Number of slots handled by this node */ - int numslaves; /* Number of slave nodes, if this is a master */ - clusterNode **slaves; /* pointers to slave nodes */ - clusterNode *slaveof; /* pointer to the master node. Note that it - may be NULL even if the node is a slave - if we don't have the master node in our - tables. */ + int num_replicas; /* Number of slave nodes, if this is a primar */ + clusterNode **replicas; /* pointers to slave nodes */ + clusterNode *replicaof; /* pointer to the primary node. Note that it + may be NULL even if the node is a slave + if we don't have the parimary node in our + tables. */ unsigned long long last_in_ping_gossip; /* The number of the last carried in the ping gossip section */ mstime_t ping_sent; /* Unix time we sent latest ping */ mstime_t pong_received; /* Unix time we received the pong */ mstime_t data_received; /* Unix time we received any data */ mstime_t fail_time; /* Unix time when FAIL flag was set */ - mstime_t voted_time; /* Last time we voted for a slave of this master */ + mstime_t voted_time; /* Last time we voted for a slave of this parimary */ mstime_t repl_offset_time; /* Unix time we received offset for this node */ - mstime_t orphaned_time; /* Starting time of orphaned master condition */ + mstime_t orphaned_time; /* Starting time of orphaned primary condition */ long long repl_offset; /* Last known repl offset for this node. */ char ip[NET_IP_STR_LEN]; /* Latest known IP address of this node */ sds hostname; /* The known hostname for this node */ @@ -319,7 +319,7 @@ struct clusterState { clusterNode *myself; /* This node */ uint64_t currentEpoch; int state; /* CLUSTER_OK, CLUSTER_FAIL, ... */ - int size; /* Num of master nodes with at least one slot */ + int size; /* Num of primary nodes with at least one slot */ dict *nodes; /* Hash table of name -> clusterNode structures */ dict *shards; /* Hash table of shard_id -> list (of nodes) structures */ dict *nodes_black_list; /* Nodes we don't re-add for a few seconds. */ @@ -337,14 +337,14 @@ struct clusterState { /* Manual failover state in common. */ mstime_t mf_end; /* Manual failover time limit (ms unixtime). It is zero if there is no MF in progress. */ - /* Manual failover state of master. */ - clusterNode *mf_slave; /* Slave performing the manual failover. */ + /* Manual failover state of primary. */ + clusterNode *mf_replica; /* Slave performing the manual failover. */ /* Manual failover state of slave. */ - long long mf_master_offset; /* Master offset the slave needs to start MF + long long mf_primary_offset; /* Primary offset the slave needs to start MF or -1 if still not received. */ - int mf_can_start; /* If non-zero signal that the manual failover - can start requesting masters vote. */ - /* The following fields are used by masters to take state on elections. */ + int mf_can_start; /* If non-zero signal that the manual failover + can start requesting primary vote. */ + /* The following fields are used by primaries to take state on elections. */ uint64_t lastVoteEpoch; /* Epoch of the last vote granted. */ int todo_before_sleep; /* Things to do in clusterBeforeSleep(). */ /* Stats */ diff --git a/src/config.c b/src/config.c index 3cd0cc5def..1c7ff9a139 100644 --- a/src/config.c +++ b/src/config.c @@ -373,7 +373,7 @@ static int updateClientOutputBufferLimit(sds *args, int arg_len, const char **er * error in a single client class is present. */ for (j = 0; j < arg_len; j += 4) { class = getClientTypeByName(args[j]); - if (class == -1 || class == CLIENT_TYPE_MASTER) { + if (class == -1 || class == CLIENT_TYPE_PRIMARY) { if (err) *err = "Invalid client class specified in " "buffer limit configuration."; @@ -574,7 +574,7 @@ void loadServerConfigFromString(char *config) { } /* Sanity checks. */ - if (server.cluster_enabled && server.masterhost) { + if (server.cluster_enabled && server.primary_host) { err = "replicaof directive not allowed in cluster mode"; goto loaderr; } @@ -1432,11 +1432,11 @@ void rewriteConfigReplicaOfOption(standardConfig *config, const char *name, stru /* If this is a master, we want all the slaveof config options * in the file to be removed. Note that if this is a cluster instance * we don't want a slaveof directive inside valkey.conf. */ - if (server.cluster_enabled || server.masterhost == NULL) { + if (server.cluster_enabled || server.primary_host == NULL) { rewriteConfigMarkAsProcessed(state, name); return; } - line = sdscatprintf(sdsempty(), "%s %s %d", name, server.masterhost, server.masterport); + line = sdscatprintf(sdsempty(), "%s %s %d", name, server.primary_host, server.primary_port); rewriteConfigRewriteLine(state, name, line, 1); } @@ -2456,7 +2456,7 @@ static int updateMaxmemory(const char **err) { static int updateGoodSlaves(const char **err) { UNUSED(err); - refreshGoodSlavesCount(); + refreshGoodReplicasCount(); return 1; } @@ -2790,7 +2790,7 @@ static int setConfigOOMScoreAdjValuesOption(standardConfig *config, sds *argv, i * keep the configuration, which may still be valid for privileged processes. */ - if (values[CONFIG_OOM_REPLICA] < values[CONFIG_OOM_MASTER] || + if (values[CONFIG_OOM_REPLICA] < values[CONFIG_OOM_PRIMARY] || values[CONFIG_OOM_BGCHILD] < values[CONFIG_OOM_REPLICA]) { serverLog(LL_WARNING, "The oom-score-adj-values configuration may not work for non-privileged processes! " "Please consult the documentation."); @@ -2869,18 +2869,18 @@ static int setConfigReplicaOfOption(standardConfig *config, sds *argv, int argc, return 0; } - sdsfree(server.masterhost); - server.masterhost = NULL; + sdsfree(server.primary_host); + server.primary_host = NULL; if (!strcasecmp(argv[0], "no") && !strcasecmp(argv[1], "one")) { return 1; } char *ptr; - server.masterport = strtol(argv[1], &ptr, 10); - if (server.masterport < 0 || server.masterport > 65535 || *ptr != '\0') { + server.primary_port = strtol(argv[1], &ptr, 10); + if (server.primary_port < 0 || server.primary_port > 65535 || *ptr != '\0') { *err = "Invalid master port"; return 0; } - server.masterhost = sdsnew(argv[0]); + server.primary_host = sdsnew(argv[0]); server.repl_state = REPL_STATE_CONNECT; return 1; } @@ -2893,8 +2893,8 @@ static sds getConfigBindOption(standardConfig *config) { static sds getConfigReplicaOfOption(standardConfig *config) { UNUSED(config); char buf[256]; - if (server.masterhost) - snprintf(buf, sizeof(buf), "%s %d", server.masterhost, server.masterport); + if (server.primary_host) + snprintf(buf, sizeof(buf), "%s %d", server.primary_host, server.primary_port); else buf[0] = '\0'; return sdsnew(buf); @@ -3032,11 +3032,11 @@ standardConfig static_configs[] = { createBoolConfig("aof-load-truncated", NULL, MODIFIABLE_CONFIG, server.aof_load_truncated, 1, NULL, NULL), createBoolConfig("aof-use-rdb-preamble", NULL, MODIFIABLE_CONFIG, server.aof_use_rdb_preamble, 1, NULL, NULL), createBoolConfig("aof-timestamp-enabled", NULL, MODIFIABLE_CONFIG, server.aof_timestamp_enabled, 0, NULL, NULL), - createBoolConfig("cluster-replica-no-failover", "cluster-slave-no-failover", MODIFIABLE_CONFIG, server.cluster_slave_no_failover, 0, NULL, updateClusterFlags), /* Failover by default. */ - createBoolConfig("replica-lazy-flush", "slave-lazy-flush", MODIFIABLE_CONFIG, server.repl_slave_lazy_flush, 0, NULL, NULL), + createBoolConfig("cluster-replica-no-failover", "cluster-slave-no-failover", MODIFIABLE_CONFIG, server.cluster_replica_no_failover, 0, NULL, updateClusterFlags), /* Failover by default. */ + createBoolConfig("replica-lazy-flush", "slave-lazy-flush", MODIFIABLE_CONFIG, server.repl_replica_lazy_flush, 0, NULL, NULL), createBoolConfig("replica-serve-stale-data", "slave-serve-stale-data", MODIFIABLE_CONFIG, server.repl_serve_stale_data, 1, NULL, NULL), - createBoolConfig("replica-read-only", "slave-read-only", DEBUG_CONFIG | MODIFIABLE_CONFIG, server.repl_slave_ro, 1, NULL, NULL), - createBoolConfig("replica-ignore-maxmemory", "slave-ignore-maxmemory", MODIFIABLE_CONFIG, server.repl_slave_ignore_maxmemory, 1, NULL, NULL), + createBoolConfig("replica-read-only", "slave-read-only", DEBUG_CONFIG | MODIFIABLE_CONFIG, server.repl_replica_ro, 1, NULL, NULL), + createBoolConfig("replica-ignore-maxmemory", "slave-ignore-maxmemory", MODIFIABLE_CONFIG, server.repl_replica_ignore_maxmemory, 1, NULL, NULL), createBoolConfig("jemalloc-bg-thread", NULL, MODIFIABLE_CONFIG, server.jemalloc_bg_thread, 1, NULL, updateJemallocBgThread), createBoolConfig("activedefrag", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, server.active_defrag_enabled, 0, isValidActiveDefrag, NULL), createBoolConfig("syslog-enabled", NULL, IMMUTABLE_CONFIG, server.syslog_enabled, 0, NULL, NULL), @@ -3060,8 +3060,8 @@ standardConfig static_configs[] = { createStringConfig("aclfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.acl_filename, "", NULL, NULL), createStringConfig("unixsocket", NULL, IMMUTABLE_CONFIG, EMPTY_STRING_IS_NULL, server.unixsocket, NULL, NULL, NULL), createStringConfig("pidfile", NULL, IMMUTABLE_CONFIG, EMPTY_STRING_IS_NULL, server.pidfile, NULL, NULL, NULL), - createStringConfig("replica-announce-ip", "slave-announce-ip", MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.slave_announce_ip, NULL, NULL, NULL), - createStringConfig("masteruser", NULL, MODIFIABLE_CONFIG | SENSITIVE_CONFIG, EMPTY_STRING_IS_NULL, server.masteruser, NULL, NULL, NULL), + createStringConfig("replica-announce-ip", "slave-announce-ip", MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.replica_announce_ip, NULL, NULL, NULL), + createStringConfig("masteruser", NULL, MODIFIABLE_CONFIG | SENSITIVE_CONFIG, EMPTY_STRING_IS_NULL, server.primary_user, NULL, NULL, NULL), createStringConfig("cluster-announce-ip", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.cluster_announce_ip, NULL, NULL, updateClusterIp), createStringConfig("cluster-config-file", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.cluster_configfile, "nodes.conf", NULL, NULL), createStringConfig("cluster-announce-hostname", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.cluster_announce_hostname, NULL, isValidAnnouncedHostname, updateClusterHostname), @@ -3084,7 +3084,7 @@ standardConfig static_configs[] = { createStringConfig("locale-collate", NULL, MODIFIABLE_CONFIG, ALLOW_EMPTY_STRING, server.locale_collate, "", NULL, updateLocaleCollate), /* SDS Configs */ - createSDSConfig("masterauth", NULL, MODIFIABLE_CONFIG | SENSITIVE_CONFIG, EMPTY_STRING_IS_NULL, server.masterauth, NULL, NULL, NULL), + createSDSConfig("masterauth", NULL, MODIFIABLE_CONFIG | SENSITIVE_CONFIG, EMPTY_STRING_IS_NULL, server.primary_auth, NULL, NULL, NULL), createSDSConfig("requirepass", NULL, MODIFIABLE_CONFIG | SENSITIVE_CONFIG, EMPTY_STRING_IS_NULL, server.requirepass, NULL, NULL, updateRequirePass), /* Enum Configs */ @@ -3110,7 +3110,7 @@ standardConfig static_configs[] = { createIntConfig("port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.port, 6379, INTEGER_CONFIG, NULL, updatePort), /* TCP port. */ createIntConfig("io-threads", NULL, DEBUG_CONFIG | IMMUTABLE_CONFIG, 1, 128, server.io_threads_num, 1, INTEGER_CONFIG, NULL, NULL), /* Single threaded by default */ createIntConfig("auto-aof-rewrite-percentage", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.aof_rewrite_perc, 100, INTEGER_CONFIG, NULL, NULL), - createIntConfig("cluster-replica-validity-factor", "cluster-slave-validity-factor", MODIFIABLE_CONFIG, 0, INT_MAX, server.cluster_slave_validity_factor, 10, INTEGER_CONFIG, NULL, NULL), /* Slave max data age factor. */ + createIntConfig("cluster-replica-validity-factor", "cluster-slave-validity-factor", MODIFIABLE_CONFIG, 0, INT_MAX, server.cluster_replica_validity_factor, 10, INTEGER_CONFIG, NULL, NULL), /* Slave max data age factor. */ createIntConfig("list-max-listpack-size", "list-max-ziplist-size", MODIFIABLE_CONFIG, INT_MIN, INT_MAX, server.list_max_listpack_size, -2, INTEGER_CONFIG, NULL, NULL), createIntConfig("tcp-keepalive", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.tcpkeepalive, 300, INTEGER_CONFIG, NULL, NULL), createIntConfig("cluster-migration-barrier", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.cluster_migration_barrier, 1, INTEGER_CONFIG, NULL, NULL), @@ -3120,26 +3120,26 @@ standardConfig static_configs[] = { createIntConfig("active-defrag-threshold-upper", NULL, MODIFIABLE_CONFIG, 0, 1000, server.active_defrag_threshold_upper, 100, INTEGER_CONFIG, NULL, updateDefragConfiguration), /* Default: maximum defrag force at 100% fragmentation */ createIntConfig("lfu-log-factor", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.lfu_log_factor, 10, INTEGER_CONFIG, NULL, NULL), createIntConfig("lfu-decay-time", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.lfu_decay_time, 1, INTEGER_CONFIG, NULL, NULL), - createIntConfig("replica-priority", "slave-priority", MODIFIABLE_CONFIG, 0, INT_MAX, server.slave_priority, 100, INTEGER_CONFIG, NULL, NULL), + createIntConfig("replica-priority", "slave-priority", MODIFIABLE_CONFIG, 0, INT_MAX, server.replica_priority, 100, INTEGER_CONFIG, NULL, NULL), createIntConfig("repl-diskless-sync-delay", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_diskless_sync_delay, 5, INTEGER_CONFIG, NULL, NULL), createIntConfig("maxmemory-samples", NULL, MODIFIABLE_CONFIG, 1, 64, server.maxmemory_samples, 5, INTEGER_CONFIG, NULL, NULL), createIntConfig("maxmemory-eviction-tenacity", NULL, MODIFIABLE_CONFIG, 0, 100, server.maxmemory_eviction_tenacity, 10, INTEGER_CONFIG, NULL, NULL), createIntConfig("timeout", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.maxidletime, 0, INTEGER_CONFIG, NULL, NULL), /* Default client timeout: infinite */ - createIntConfig("replica-announce-port", "slave-announce-port", MODIFIABLE_CONFIG, 0, 65535, server.slave_announce_port, 0, INTEGER_CONFIG, NULL, NULL), + createIntConfig("replica-announce-port", "slave-announce-port", MODIFIABLE_CONFIG, 0, 65535, server.replica_announce_port, 0, INTEGER_CONFIG, NULL, NULL), createIntConfig("tcp-backlog", NULL, IMMUTABLE_CONFIG, 0, INT_MAX, server.tcp_backlog, 511, INTEGER_CONFIG, NULL, NULL), /* TCP listen backlog. */ createIntConfig("cluster-port", NULL, IMMUTABLE_CONFIG, 0, 65535, server.cluster_port, 0, INTEGER_CONFIG, NULL, NULL), createIntConfig("cluster-announce-bus-port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.cluster_announce_bus_port, 0, INTEGER_CONFIG, NULL, updateClusterAnnouncedPort), /* Default: Use +10000 offset. */ createIntConfig("cluster-announce-port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.cluster_announce_port, 0, INTEGER_CONFIG, NULL, updateClusterAnnouncedPort), /* Use server.port */ createIntConfig("cluster-announce-tls-port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.cluster_announce_tls_port, 0, INTEGER_CONFIG, NULL, updateClusterAnnouncedPort), /* Use server.tls_port */ createIntConfig("repl-timeout", NULL, MODIFIABLE_CONFIG, 1, INT_MAX, server.repl_timeout, 60, INTEGER_CONFIG, NULL, NULL), - createIntConfig("repl-ping-replica-period", "repl-ping-slave-period", MODIFIABLE_CONFIG, 1, INT_MAX, server.repl_ping_slave_period, 10, INTEGER_CONFIG, NULL, NULL), + createIntConfig("repl-ping-replica-period", "repl-ping-slave-period", MODIFIABLE_CONFIG, 1, INT_MAX, server.repl_ping_replica_period, 10, INTEGER_CONFIG, NULL, NULL), createIntConfig("list-compress-depth", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, 0, INT_MAX, server.list_compress_depth, 0, INTEGER_CONFIG, NULL, NULL), createIntConfig("rdb-key-save-delay", NULL, MODIFIABLE_CONFIG | HIDDEN_CONFIG, INT_MIN, INT_MAX, server.rdb_key_save_delay, 0, INTEGER_CONFIG, NULL, NULL), createIntConfig("key-load-delay", NULL, MODIFIABLE_CONFIG | HIDDEN_CONFIG, INT_MIN, INT_MAX, server.key_load_delay, 0, INTEGER_CONFIG, NULL, NULL), createIntConfig("active-expire-effort", NULL, MODIFIABLE_CONFIG, 1, 10, server.active_expire_effort, 1, INTEGER_CONFIG, NULL, NULL), /* From 1 to 10. */ createIntConfig("hz", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.config_hz, CONFIG_DEFAULT_HZ, INTEGER_CONFIG, NULL, updateHZ), - createIntConfig("min-replicas-to-write", "min-slaves-to-write", MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_min_slaves_to_write, 0, INTEGER_CONFIG, NULL, updateGoodSlaves), - createIntConfig("min-replicas-max-lag", "min-slaves-max-lag", MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_min_slaves_max_lag, 10, INTEGER_CONFIG, NULL, updateGoodSlaves), + createIntConfig("min-replicas-to-write", "min-slaves-to-write", MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_min_replicas_to_write, 0, INTEGER_CONFIG, NULL, updateGoodSlaves), + createIntConfig("min-replicas-max-lag", "min-slaves-max-lag", MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_min_replicas_max_lag, 10, INTEGER_CONFIG, NULL, updateGoodSlaves), createIntConfig("watchdog-period", NULL, MODIFIABLE_CONFIG | HIDDEN_CONFIG, 0, INT_MAX, server.watchdog_period, 0, INTEGER_CONFIG, NULL, updateWatchdogPeriod), createIntConfig("shutdown-timeout", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.shutdown_timeout, 10, INTEGER_CONFIG, NULL, NULL), createIntConfig("repl-diskless-sync-max-replicas", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_diskless_sync_max_replicas, 0, INTEGER_CONFIG, NULL, NULL), diff --git a/src/db.c b/src/db.c index 2e6d85cf4e..e79c21c12e 100644 --- a/src/db.c +++ b/src/db.c @@ -104,7 +104,7 @@ robj *lookupKey(serverDb *db, robj *key, int flags) { * It's possible that the WRITE flag is set even during a readonly * command, since the command may trigger events that cause modules to * perform additional writes. */ - int is_ro_replica = server.masterhost && server.repl_slave_ro; + int is_ro_replica = server.primary_host && server.repl_replica_ro; int expire_flags = 0; if (flags & LOOKUP_WRITE && !is_ro_replica) expire_flags |= EXPIRE_FORCE_DELETE_EXPIRED; if (flags & LOOKUP_NOEXPIRE) expire_flags |= EXPIRE_AVOID_DELETE_EXPIRED; @@ -361,7 +361,7 @@ robj *dbRandomKey(serverDb *db) { key = dictGetKey(de); keyobj = createStringObject(key, sdslen(key)); if (dbFindExpires(db, key)) { - if (allvolatile && server.masterhost && --maxtries == 0) { + if (allvolatile && server.primary_host && --maxtries == 0) { /* If the DB is composed only of keys with an expire set, * it could happen that all the keys are already logically * expired in the slave, so the function cannot stop because @@ -540,7 +540,7 @@ long long emptyData(int dbnum, int flags, void(callback)(dict *)) { /* Empty the database structure. */ removed = emptyDbStructure(server.db, dbnum, async, callback); - if (dbnum == -1) flushSlaveKeysWithExpireList(); + if (dbnum == -1) flushReplicaKeysWithExpireList(); if (with_functions) { serverAssert(dbnum == -1); @@ -673,7 +673,7 @@ void flushAllDataAndResetRDB(int flags) { if (server.saveparamslen > 0) { rdbSaveInfo rsi, *rsiptr; rsiptr = rdbPopulateSaveInfo(&rsi); - rdbSave(SLAVE_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE); + rdbSave(REPLICA_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE); } #if defined(USE_JEMALLOC) @@ -1610,7 +1610,7 @@ void swapMainDbWithTempDb(serverDb *tempDb) { } trackingInvalidateKeysOnFlush(1); - flushSlaveKeysWithExpireList(); + flushReplicaKeysWithExpireList(); } /* SWAPDB db1 db2 */ @@ -1666,8 +1666,8 @@ void setExpire(client *c, serverDb *db, robj *key, long long when) { dictSetSignedIntegerVal(de, when); } - int writable_slave = server.masterhost && server.repl_slave_ro == 0; - if (c && writable_slave && !(c->flags & CLIENT_MASTER)) rememberSlaveKeyWithExpire(db, key); + int writable_slave = server.primary_host && server.repl_replica_ro == 0; + if (c && writable_slave && !(c->flags & CLIENT_PRIMARY)) rememberReplicaKeyWithExpire(db, key); } /* Return the expire time of the specified key, or -1 if no expire @@ -1795,8 +1795,8 @@ keyStatus expireIfNeeded(serverDb *db, robj *key, int flags) { * * When replicating commands from the master, keys are never considered * expired. */ - if (server.masterhost != NULL) { - if (server.current_client && (server.current_client->flags & CLIENT_MASTER)) return KEY_VALID; + if (server.primary_host != NULL) { + if (server.current_client && (server.current_client->flags & CLIENT_PRIMARY)) return KEY_VALID; if (!(flags & EXPIRE_FORCE_DELETE_EXPIRED)) return KEY_EXPIRED; } diff --git a/src/debug.c b/src/debug.c index 51e9c6e9f6..be95ab4c5c 100644 --- a/src/debug.c +++ b/src/debug.c @@ -552,7 +552,7 @@ void debugCommand(client *c) { if (save) { rdbSaveInfo rsi, *rsiptr; rsiptr = rdbPopulateSaveInfo(&rsi); - if (rdbSave(SLAVE_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE) != C_OK) { + if (rdbSave(REPLICA_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE) != C_OK) { addReplyErrorObject(c, shared.err); return; } @@ -845,7 +845,7 @@ void debugCommand(client *c) { server.aof_flush_sleep = atoi(c->argv[2]->ptr); addReply(c, shared.ok); } else if (!strcasecmp(c->argv[1]->ptr, "replicate") && c->argc >= 3) { - replicationFeedSlaves(-1, c->argv + 2, c->argc - 2); + replicationFeedReplicas(-1, c->argv + 2, c->argc - 2); addReply(c, shared.ok); } else if (!strcasecmp(c->argv[1]->ptr, "error") && c->argc == 3) { sds errstr = sdsnewlen("-", 1); diff --git a/src/evict.c b/src/evict.c index cf209ff065..5c92956a50 100644 --- a/src/evict.c +++ b/src/evict.c @@ -478,7 +478,7 @@ static int isSafeToPerformEvictions(void) { /* By default replicas should ignore maxmemory * and just be masters exact copies. */ - if (server.masterhost && server.repl_slave_ignore_maxmemory) return 0; + if (server.primary_host && server.repl_replica_ignore_maxmemory) return 0; /* If 'evict' action is paused, for whatever reason, then return false */ if (isPausedActionsWithUpdate(PAUSE_ACTION_EVICT)) return 0; @@ -538,7 +538,7 @@ int performEvictions(void) { long long mem_freed = 0; /* Maybe become negative */ mstime_t latency, eviction_latency; long long delta; - int slaves = listLength(server.slaves); + int slaves = listLength(server.replicas); int result = EVICT_FAIL; if (getMaxmemoryState(&mem_reported, NULL, &mem_tofree, NULL) == C_OK) { @@ -697,7 +697,7 @@ int performEvictions(void) { * start spending so much time here that is impossible to * deliver data to the replicas fast enough, so we force the * transmission here inside the loop. */ - if (slaves) flushSlavesOutputBuffers(); + if (slaves) flushReplicasOutputBuffers(); /* Normally our stop condition is the ability to release * a fixed, pre-computed amount of memory. However when we diff --git a/src/expire.c b/src/expire.c index 8d81473209..3ca1743344 100644 --- a/src/expire.c +++ b/src/expire.c @@ -406,7 +406,7 @@ dict *slaveKeysWithExpire = NULL; /* Check the set of keys created by the master with an expire set in order to * check if they should be evicted. */ -void expireSlaveKeys(void) { +void expireReplicaKeys(void) { if (slaveKeysWithExpire == NULL || dictSize(slaveKeysWithExpire) == 0) return; int cycles = 0, noexpire = 0; @@ -465,7 +465,7 @@ void expireSlaveKeys(void) { /* Track keys that received an EXPIRE or similar command in the context * of a writable slave. */ -void rememberSlaveKeyWithExpire(serverDb *db, robj *key) { +void rememberReplicaKeyWithExpire(serverDb *db, robj *key) { if (slaveKeysWithExpire == NULL) { static dictType dt = { dictSdsHash, /* hash function */ @@ -496,7 +496,7 @@ void rememberSlaveKeyWithExpire(serverDb *db, robj *key) { } /* Return the number of keys we are tracking. */ -size_t getSlaveKeyWithExpireCount(void) { +size_t getReplicaKeyWithExpireCount(void) { if (slaveKeysWithExpire == NULL) return 0; return dictSize(slaveKeysWithExpire); } @@ -509,7 +509,7 @@ size_t getSlaveKeyWithExpireCount(void) { * but it is not worth it since anyway race conditions using the same set * of key names in a writable slave and in its master will lead to * inconsistencies. This is just a best-effort thing we do. */ -void flushSlaveKeysWithExpireList(void) { +void flushReplicaKeysWithExpireList(void) { if (slaveKeysWithExpire) { dictRelease(slaveKeysWithExpire); slaveKeysWithExpire = NULL; @@ -523,7 +523,7 @@ int checkAlreadyExpired(long long when) { * * Instead we add the already expired key to the database with expire time * (possibly in the past) and wait for an explicit DEL from the master. */ - return (when <= commandTimeSnapshot() && !server.loading && !server.masterhost); + return (when <= commandTimeSnapshot() && !server.loading && !server.primary_host); } #define EXPIRE_NX (1 << 0) diff --git a/src/logreqres.c b/src/logreqres.c index af4021afb1..78bcf9c7f8 100644 --- a/src/logreqres.c +++ b/src/logreqres.c @@ -78,10 +78,10 @@ static int reqresShouldLog(client *c) { if (!server.req_res_logfile) return 0; /* Ignore client with streaming non-standard response */ - if (c->flags & (CLIENT_PUBSUB | CLIENT_MONITOR | CLIENT_SLAVE)) return 0; + if (c->flags & (CLIENT_PUBSUB | CLIENT_MONITOR | CLIENT_REPLICA)) return 0; /* We only work on masters (didn't implement reqresAppendResponse to work on shared slave buffers) */ - if (getClientType(c) == CLIENT_TYPE_MASTER) return 0; + if (getClientType(c) == CLIENT_TYPE_PRIMARY) return 0; return 1; } diff --git a/src/module.c b/src/module.c index f82f30326d..751fb5b9f6 100644 --- a/src/module.c +++ b/src/module.c @@ -3664,12 +3664,12 @@ int modulePopulateReplicationInfoStructure(void *ri, int structver) { ValkeyModuleReplicationInfoV1 *ri1 = ri; memset(ri1, 0, sizeof(*ri1)); ri1->version = structver; - ri1->master = server.masterhost == NULL; - ri1->masterhost = server.masterhost ? server.masterhost : ""; - ri1->masterport = server.masterport; + ri1->master = server.primary_host == NULL; + ri1->masterhost = server.primary_host ? server.primary_host : ""; + ri1->masterport = server.primary_port; ri1->replid1 = server.replid; ri1->replid2 = server.replid2; - ri1->repl1_offset = server.master_repl_offset; + ri1->repl1_offset = server.primary_repl_offset; ri1->repl2_offset = server.second_replid_offset; return VALKEYMODULE_OK; } @@ -3855,7 +3855,7 @@ int VM_GetContextFlags(ValkeyModuleCtx *ctx) { if (ctx->client) { if (ctx->client->flags & CLIENT_DENY_BLOCKING) flags |= VALKEYMODULE_CTX_FLAGS_DENY_BLOCKING; /* Module command received from MASTER, is replicated. */ - if (ctx->client->flags & CLIENT_MASTER) flags |= VALKEYMODULE_CTX_FLAGS_REPLICATED; + if (ctx->client->flags & CLIENT_PRIMARY) flags |= VALKEYMODULE_CTX_FLAGS_REPLICATED; if (ctx->client->resp == 3) { flags |= VALKEYMODULE_CTX_FLAGS_RESP3; } @@ -3880,7 +3880,7 @@ int VM_GetContextFlags(ValkeyModuleCtx *ctx) { flags |= VALKEYMODULE_CTX_FLAGS_LOADING; /* Maxmemory and eviction policy */ - if (server.maxmemory > 0 && (!server.masterhost || !server.repl_slave_ignore_maxmemory)) { + if (server.maxmemory > 0 && (!server.primary_host || !server.repl_replica_ignore_maxmemory)) { flags |= VALKEYMODULE_CTX_FLAGS_MAXMEMORY; if (server.maxmemory_policy != MAXMEMORY_NO_EVICTION) flags |= VALKEYMODULE_CTX_FLAGS_EVICT; @@ -3891,11 +3891,11 @@ int VM_GetContextFlags(ValkeyModuleCtx *ctx) { if (server.saveparamslen > 0) flags |= VALKEYMODULE_CTX_FLAGS_RDB; /* Replication flags */ - if (server.masterhost == NULL) { + if (server.primary_host == NULL) { flags |= VALKEYMODULE_CTX_FLAGS_PRIMARY; } else { flags |= VALKEYMODULE_CTX_FLAGS_REPLICA; - if (server.repl_slave_ro) flags |= VALKEYMODULE_CTX_FLAGS_READONLY; + if (server.repl_replica_ro) flags |= VALKEYMODULE_CTX_FLAGS_READONLY; /* Replica state flags. */ if (server.repl_state == REPL_STATE_CONNECT || server.repl_state == REPL_STATE_CONNECTING) { @@ -6369,21 +6369,21 @@ ValkeyModuleCallReply *VM_Call(ValkeyModuleCtx *ctx, const char *cmdname, const goto cleanup; } - if (server.masterhost && server.repl_slave_ro && !obey_client) { + if (server.primary_host && server.repl_replica_ro && !obey_client) { errno = ESPIPE; if (error_as_call_replies) { - sds msg = sdsdup(shared.roslaveerr->ptr); + sds msg = sdsdup(shared.roreplicaerr->ptr); reply = callReplyCreateError(msg, ctx); } goto cleanup; } } - if (server.masterhost && server.repl_state != REPL_STATE_CONNECTED && server.repl_serve_stale_data == 0 && + if (server.primary_host && server.repl_state != REPL_STATE_CONNECTED && server.repl_serve_stale_data == 0 && !(cmd_flags & CMD_STALE)) { errno = ESPIPE; if (error_as_call_replies) { - sds msg = sdsdup(shared.masterdownerr->ptr); + sds msg = sdsdup(shared.primarydownerr->ptr); reply = callReplyCreateError(msg, ctx); } goto cleanup; @@ -8293,7 +8293,7 @@ void moduleHandleBlockedClients(void) { /* Update the wait offset, we don't know if this blocked client propagated anything, * currently we rather not add any API for that, so we just assume it did. */ - c->woff = server.master_repl_offset; + c->woff = server.primary_repl_offset; /* Put the client in the list of clients that need to write * if there are pending replies here. This is needed since @@ -8687,7 +8687,7 @@ int VM_AddPostNotificationJob(ValkeyModuleCtx *ctx, ValkeyModulePostNotificationJobFunc callback, void *privdata, void (*free_privdata)(void *)) { - if (server.loading || (server.masterhost && server.repl_slave_ro)) { + if (server.loading || (server.primary_host && server.repl_replica_ro)) { return VALKEYMODULE_ERR; } ValkeyModulePostExecUnitJob *job = zmalloc(sizeof(*job)); @@ -8984,8 +8984,8 @@ int VM_GetClusterNodeInfo(ValkeyModuleCtx *ctx, const char *id, char *ip, char * /* If the information is not available, the function will set the * field to zero bytes, so that when the field can't be populated the * function kinda remains predictable. */ - if (clusterNodeIsSlave(node) && clusterNodeGetMaster(node)) - memcpy(master_id, clusterNodeGetName(clusterNodeGetMaster(node)), VALKEYMODULE_NODE_ID_LEN); + if (clusterNodeIsReplica(node) && clusterNodeGetPrimary(node)) + memcpy(master_id, clusterNodeGetName(clusterNodeGetPrimary(node)), VALKEYMODULE_NODE_ID_LEN); else memset(master_id, 0, VALKEYMODULE_NODE_ID_LEN); } @@ -8996,8 +8996,8 @@ int VM_GetClusterNodeInfo(ValkeyModuleCtx *ctx, const char *id, char *ip, char * if (flags) { *flags = 0; if (clusterNodeIsMyself(node)) *flags |= VALKEYMODULE_NODE_MYSELF; - if (clusterNodeIsMaster(node)) *flags |= VALKEYMODULE_NODE_PRIMARY; - if (clusterNodeIsSlave(node)) *flags |= VALKEYMODULE_NODE_REPLICA; + if (clusterNodeIsPrimary(node)) *flags |= VALKEYMODULE_NODE_PRIMARY; + if (clusterNodeIsReplica(node)) *flags |= VALKEYMODULE_NODE_REPLICA; if (clusterNodeTimedOut(node)) *flags |= VALKEYMODULE_NODE_PFAIL; if (clusterNodeIsFailing(node)) *flags |= VALKEYMODULE_NODE_FAIL; if (clusterNodeIsNoFailover(node)) *flags |= VALKEYMODULE_NODE_NOFAILOVER; @@ -12911,13 +12911,13 @@ int VM_RdbLoad(ValkeyModuleCtx *ctx, ValkeyModuleRdbStream *stream, int flags) { } /* Not allowed on replicas. */ - if (server.masterhost != NULL) { + if (server.primary_host != NULL) { errno = ENOTSUP; return VALKEYMODULE_ERR; } /* Drop replicas if exist. */ - disconnectSlaves(); + disconnectReplicas(); freeReplicationBacklog(); if (server.aof_state != AOF_OFF) stopAppendOnly(); diff --git a/src/networking.c b/src/networking.c index 9274f21c05..35e5dc70ff 100644 --- a/src/networking.c +++ b/src/networking.c @@ -164,10 +164,10 @@ client *createClient(connection *conn) { c->sentlen = 0; c->flags = 0; c->slot = -1; - c->ctime = c->lastinteraction = server.unixtime; + c->ctime = c->last_interaction = server.unixtime; c->duration = 0; clientSetDefaultAuth(c); - c->replstate = REPL_STATE_NONE; + c->repl_state = REPL_STATE_NONE; c->repl_start_cmd_stream_on_ack = 0; c->reploff = 0; c->read_reploff = 0; @@ -176,11 +176,11 @@ client *createClient(connection *conn) { c->repl_ack_time = 0; c->repl_aof_off = 0; c->repl_last_partial_write = 0; - c->slave_listening_port = 0; - c->slave_addr = NULL; + c->replica_listening_port = 0; + c->replica_addr = NULL; c->replica_version = 0; - c->slave_capa = SLAVE_CAPA_NONE; - c->slave_req = SLAVE_REQ_NONE; + c->replica_capa = REPLICA_CAPA_NONE; + c->replica_req = REPLICA_REQ_NONE; c->reply = listCreate(); c->deferred_reply_errors = NULL; c->reply_bytes = 0; @@ -242,10 +242,11 @@ void installClientWriteHandler(client *c) { * buffers can hold, then we'll really install the handler. */ void putClientInPendingWriteQueue(client *c) { /* Schedule the client to write the output buffers to the socket only - * if not already done and, for slaves, if the slave can actually receive + * if not already done and, for replicas, if the replica can actually receive * writes at this stage. */ if (!(c->flags & CLIENT_PENDING_WRITE) && - (c->replstate == REPL_STATE_NONE || (c->replstate == SLAVE_STATE_ONLINE && !c->repl_start_cmd_stream_on_ack))) { + (c->repl_state == REPL_STATE_NONE || + (c->repl_state == REPLICA_STATE_ONLINE && !c->repl_start_cmd_stream_on_ack))) { /* Here instead of installing the write handler, we just flag the * client and put it into a list of clients that have something * to write to the socket. This way before re-entering the event @@ -265,7 +266,7 @@ void putClientInPendingWriteQueue(client *c) { * loop so that when the socket is writable new data gets written. * * If the client should not receive new data, because it is a fake client - * (used to load AOF in memory), a master or because the setup of the write + * (used to load AOF in memory), a primary or because the setup of the write * handler failed, the function returns C_ERR. * * The function may return C_OK without actually installing the write @@ -273,7 +274,7 @@ void putClientInPendingWriteQueue(client *c) { * * 1) The event handler should already be installed since the output buffer * already contains something. - * 2) The client is a slave but not yet online, so we want to just accumulate + * 2) The client is a replica but not yet online, so we want to just accumulate * writes in the buffer but not actually sending them yet. * * Typically gets called every time a reply is built, before adding more @@ -291,9 +292,9 @@ int prepareClientToWrite(client *c) { * CLIENT_PUSHING handling: disables the reply silencing flags. */ if ((c->flags & (CLIENT_REPLY_OFF | CLIENT_REPLY_SKIP)) && !(c->flags & CLIENT_PUSHING)) return C_ERR; - /* Masters don't receive replies, unless CLIENT_MASTER_FORCE_REPLY flag + /* Primaries don't receive replies, unless CLIENT_PRIMARY_FORCE_REPLY flag * is set. */ - if ((c->flags & CLIENT_MASTER) && !(c->flags & CLIENT_MASTER_FORCE_REPLY)) return C_ERR; + if ((c->flags & CLIENT_PRIMARY) && !(c->flags & CLIENT_PRIMARY_FORCE_REPLY)) return C_ERR; if (!c->conn) return C_ERR; /* Fake client for AOF loading. */ @@ -428,7 +429,7 @@ void _addReplyToBufferOrList(client *c, const char *s, size_t len) { * replication link that caused a reply to be generated we'll simply disconnect it. * Note this is the simplest way to check a command added a response. Replication links are used to write data but * not for responses, so we should normally never get here on a replica client. */ - if (getClientType(c) == CLIENT_TYPE_SLAVE) { + if (getClientType(c) == CLIENT_TYPE_REPLICA) { sds cmdname = c->lastcmd ? c->lastcmd->fullname : NULL; logInvalidUseAndFreeClientAsync(c, "Replica generated a reply to command '%s'", cmdname ? cmdname : ""); @@ -563,24 +564,24 @@ void afterErrorReply(client *c, const char *s, size_t len, int flags) { c->realcmd->failed_calls++; } - /* Sometimes it could be normal that a slave replies to a master with + /* Sometimes it could be normal that a replica replies to a primary with * an error and this function gets called. Actually the error will never - * be sent because addReply*() against master clients has no effect... + * be sent because addReply*() against primary clients has no effect... * A notable example is: * * EVAL 'redis.call("incr",KEYS[1]); redis.call("nonexisting")' 1 x * - * Where the master must propagate the first change even if the second + * Where the primary must propagate the first change even if the second * will produce an error. However it is useful to log such events since * they are rare and may hint at errors in a script or a bug in the server. */ int ctype = getClientType(c); - if (ctype == CLIENT_TYPE_MASTER || ctype == CLIENT_TYPE_SLAVE || c->id == CLIENT_ID_AOF) { + if (ctype == CLIENT_TYPE_PRIMARY || ctype == CLIENT_TYPE_REPLICA || c->id == CLIENT_ID_AOF) { char *to, *from; if (c->id == CLIENT_ID_AOF) { to = "AOF-loading-client"; from = "server"; - } else if (ctype == CLIENT_TYPE_MASTER) { + } else if (ctype == CLIENT_TYPE_PRIMARY) { to = "master"; from = "replica"; } else { @@ -595,16 +596,16 @@ void afterErrorReply(client *c, const char *s, size_t len, int flags) { "to its %s: '%.*s' after processing the command " "'%s'", from, to, (int)len, s, cmdname ? cmdname : ""); - if (ctype == CLIENT_TYPE_MASTER && server.repl_backlog && server.repl_backlog->histlen > 0) { + if (ctype == CLIENT_TYPE_PRIMARY && server.repl_backlog && server.repl_backlog->histlen > 0) { showLatestBacklog(); } server.stat_unexpected_error_replies++; /* Based off the propagation error behavior, check if we need to panic here. There * are currently two checked cases: - * * If this command was from our master and we are not a writable replica. + * * If this command was from our primary and we are not a writable replica. * * We are reading from an AOF file. */ - int panic_in_replicas = (ctype == CLIENT_TYPE_MASTER && server.repl_slave_ro) && + int panic_in_replicas = (ctype == CLIENT_TYPE_PRIMARY && server.repl_replica_ro) && (server.propagation_error_behavior == PROPAGATION_ERR_BEHAVIOR_PANIC || server.propagation_error_behavior == PROPAGATION_ERR_BEHAVIOR_PANIC_ON_REPLICAS); int panic_in_aof = @@ -766,7 +767,7 @@ void *addReplyDeferredLen(client *c) { * replication link that caused a reply to be generated we'll simply disconnect it. * Note this is the simplest way to check a command added a response. Replication links are used to write data but * not for responses, so we should normally never get here on a replica client. */ - if (getClientType(c) == CLIENT_TYPE_SLAVE) { + if (getClientType(c) == CLIENT_TYPE_REPLICA) { sds cmdname = c->lastcmd ? c->lastcmd->fullname : NULL; logInvalidUseAndFreeClientAsync(c, "Replica generated a reply to command '%s'", cmdname ? cmdname : ""); @@ -1257,7 +1258,7 @@ void copyReplicaOutputBuffer(client *dst, client *src) { /* Return true if the specified client has pending reply buffers to write to * the socket. */ int clientHasPendingReplies(client *c) { - if (getClientType(c) == CLIENT_TYPE_SLAVE) { + if (getClientType(c) == CLIENT_TYPE_REPLICA) { /* Replicas use global shared replication buffer instead of * private output buffer. */ serverAssert(c->bufpos == 0 && listLength(c->reply) == 0); @@ -1415,29 +1416,29 @@ void freeClientArgv(client *c) { c->argv = NULL; } -/* Close all the slaves connections. This is useful in chained replication - * when we resync with our own master and want to force all our slaves to +/* Close all the replicas connections. This is useful in chained replication + * when we resync with our own primary and want to force all our replicas to * resync with us as well. */ -void disconnectSlaves(void) { +void disconnectReplicas(void) { listIter li; listNode *ln; - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { freeClient((client *)ln->value); } } -/* Check if there is any other slave waiting dumping RDB finished expect me. +/* Check if there is any other replica waiting dumping RDB finished expect me. * This function is useful to judge current dumping RDB can be used for full * synchronization or not. */ -int anyOtherSlaveWaitRdb(client *except_me) { +int anyOtherReplicaWaitRdb(client *except_me) { listIter li; listNode *ln; - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = ln->value; - if (slave != except_me && slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END) { + client *replica = ln->value; + if (replica != except_me && replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_END) { return 1; } } @@ -1446,7 +1447,7 @@ int anyOtherSlaveWaitRdb(client *except_me) { /* Remove the specified client from global lists where the client could * be referenced, not including the Pub/Sub channels. - * This is used by freeClient() and replicationCacheMaster(). */ + * This is used by freeClient() and replicationCachePrimary(). */ void unlinkClient(client *c) { listNode *ln; @@ -1467,7 +1468,7 @@ void unlinkClient(client *c) { /* Check if this is a replica waiting for diskless replication (rdb pipe), * in which case it needs to be cleaned from that list */ - if (c->flags & CLIENT_SLAVE && c->replstate == SLAVE_STATE_WAIT_BGSAVE_END && server.rdb_pipe_conns) { + if (c->flags & CLIENT_REPLICA && c->repl_state == REPLICA_STATE_WAIT_BGSAVE_END && server.rdb_pipe_conns) { int i; for (i = 0; i < server.rdb_pipe_numconns; i++) { if (server.rdb_pipe_conns[i] == c->conn) { @@ -1515,7 +1516,7 @@ void unlinkClient(client *c) { void clearClientConnectionState(client *c) { listNode *ln; - /* MONITOR clients are also marked with CLIENT_SLAVE, we need to + /* MONITOR clients are also marked with CLIENT_REPLICA, we need to * distinguish between the two. */ if (c->flags & CLIENT_MONITOR) { @@ -1523,10 +1524,10 @@ void clearClientConnectionState(client *c) { serverAssert(ln != NULL); listDelNode(server.monitors, ln); - c->flags &= ~(CLIENT_MONITOR | CLIENT_SLAVE); + c->flags &= ~(CLIENT_MONITOR | CLIENT_REPLICA); } - serverAssert(!(c->flags & (CLIENT_SLAVE | CLIENT_MASTER))); + serverAssert(!(c->flags & (CLIENT_REPLICA | CLIENT_PRIMARY))); if (c->flags & CLIENT_TRACKING) disableTracking(c); selectDb(c, 0); @@ -1581,7 +1582,7 @@ void freeClient(client *c) { /* If this client was scheduled for async freeing we need to remove it * from the queue. Note that we need to do this here, because later - * we may call replicationCacheMaster() and the client should already + * we may call replicationCachePrimary() and the client should already * be removed from the list of clients to free. */ if (c->flags & CLIENT_CLOSE_ASAP) { ln = listSearchKey(server.clients_to_close, c); @@ -1589,23 +1590,23 @@ void freeClient(client *c) { listDelNode(server.clients_to_close, ln); } - /* If it is our master that's being disconnected we should make sure + /* If it is our primary that's being disconnected we should make sure * to cache the state to try a partial resynchronization later. * * Note that before doing this we make sure that the client is not in * some unexpected state, by checking its flags. */ - if (server.master && c->flags & CLIENT_MASTER) { - serverLog(LL_NOTICE, "Connection with master lost."); + if (server.primary && c->flags & CLIENT_PRIMARY) { + serverLog(LL_NOTICE, "Connection with primary lost."); if (!(c->flags & (CLIENT_PROTOCOL_ERROR | CLIENT_BLOCKED))) { c->flags &= ~(CLIENT_CLOSE_ASAP | CLIENT_CLOSE_AFTER_REPLY); - replicationCacheMaster(c); + replicationCachePrimary(c); return; } } - /* Log link disconnection with slave */ - if (getClientType(c) == CLIENT_TYPE_SLAVE) { - serverLog(LL_NOTICE, "Connection with replica %s lost.", replicationGetSlaveName(c)); + /* Log link disconnection with replica */ + if (getClientType(c) == CLIENT_TYPE_REPLICA) { + serverLog(LL_NOTICE, "Connection with replica %s lost.", replicationGetReplicaName(c)); } /* Free the query buffer */ @@ -1655,44 +1656,44 @@ void freeClient(client *c) { * places where active clients may be referenced. */ unlinkClient(c); - /* Master/slave cleanup Case 1: - * we lost the connection with a slave. */ - if (c->flags & CLIENT_SLAVE) { - /* If there is no any other slave waiting dumping RDB finished, the + /* Primary/replica cleanup Case 1: + * we lost the connection with a replica. */ + if (c->flags & CLIENT_REPLICA) { + /* If there is no any other replica waiting dumping RDB finished, the * current child process need not continue to dump RDB, then we kill it. * So child process won't use more memory, and we also can fork a new * child process asap to dump rdb for next full synchronization or bgsave. * But we also need to check if users enable 'save' RDB, if enable, we * should not remove directly since that means RDB is important for users * to keep data safe and we may delay configured 'save' for full sync. */ - if (server.saveparamslen == 0 && c->replstate == SLAVE_STATE_WAIT_BGSAVE_END && + if (server.saveparamslen == 0 && c->repl_state == REPLICA_STATE_WAIT_BGSAVE_END && server.child_type == CHILD_TYPE_RDB && server.rdb_child_type == RDB_CHILD_TYPE_DISK && - anyOtherSlaveWaitRdb(c) == 0) { + anyOtherReplicaWaitRdb(c) == 0) { killRDBChild(); } - if (c->replstate == SLAVE_STATE_SEND_BULK) { + if (c->repl_state == REPLICA_STATE_SEND_BULK) { if (c->repldbfd != -1) close(c->repldbfd); if (c->replpreamble) sdsfree(c->replpreamble); } - list *l = (c->flags & CLIENT_MONITOR) ? server.monitors : server.slaves; + list *l = (c->flags & CLIENT_MONITOR) ? server.monitors : server.replicas; ln = listSearchKey(l, c); serverAssert(ln != NULL); listDelNode(l, ln); /* We need to remember the time when we started to have zero - * attached slaves, as after some time we'll free the replication + * attached replicas, as after some time we'll free the replication * backlog. */ - if (getClientType(c) == CLIENT_TYPE_SLAVE && listLength(server.slaves) == 0) - server.repl_no_slaves_since = server.unixtime; - refreshGoodSlavesCount(); + if (getClientType(c) == CLIENT_TYPE_REPLICA && listLength(server.replicas) == 0) + server.repl_no_replicas_since = server.unixtime; + refreshGoodReplicasCount(); /* Fire the replica change modules event. */ - if (c->replstate == SLAVE_STATE_ONLINE) + if (c->repl_state == REPLICA_STATE_ONLINE) moduleFireServerEvent(VALKEYMODULE_EVENT_REPLICA_CHANGE, VALKEYMODULE_SUBEVENT_REPLICA_CHANGE_OFFLINE, NULL); } - /* Master/slave cleanup Case 2: - * we lost the connection with the master. */ - if (c->flags & CLIENT_MASTER) replicationHandleMasterDisconnection(); + /* Primary/replica cleanup Case 2: + * we lost the connection with the primary. */ + if (c->flags & CLIENT_PRIMARY) replicationHandlePrimaryDisconnection(); /* Remove client from memory usage buckets */ if (c->mem_usage_bucket) { @@ -1708,7 +1709,7 @@ void freeClient(client *c) { freeClientMultiState(c); sdsfree(c->peerid); sdsfree(c->sockname); - sdsfree(c->slave_addr); + sdsfree(c->replica_addr); zfree(c); } @@ -1889,7 +1890,7 @@ static int _writevToClient(client *c, ssize_t *nwritten) { * to client. */ int _writeToClient(client *c, ssize_t *nwritten) { *nwritten = 0; - if (getClientType(c) == CLIENT_TYPE_SLAVE) { + if (getClientType(c) == CLIENT_TYPE_REPLICA) { serverAssert(c->bufpos == 0 && listLength(c->reply) == 0); replBufBlock *o = listNodeValue(c->ref_repl_buf_node); @@ -1966,14 +1967,14 @@ int writeToClient(client *c, int handler_installed) { * just deliver as much data as it is possible to deliver. * * Moreover, we also send as much as possible if the client is - * a slave or a monitor (otherwise, on high-speed traffic, the + * a replica or a monitor (otherwise, on high-speed traffic, the * replication/output buffer will grow indefinitely) */ if (totwritten > NET_MAX_WRITES_PER_EVENT && - (server.maxmemory == 0 || zmalloc_used_memory() < server.maxmemory) && !(c->flags & CLIENT_SLAVE)) + (server.maxmemory == 0 || zmalloc_used_memory() < server.maxmemory) && !(c->flags & CLIENT_REPLICA)) break; } - if (getClientType(c) == CLIENT_TYPE_SLAVE) { + if (getClientType(c) == CLIENT_TYPE_REPLICA) { atomic_fetch_add_explicit(&server.stat_net_repl_output_bytes, totwritten, memory_order_relaxed); } else { atomic_fetch_add_explicit(&server.stat_net_output_bytes, totwritten, memory_order_relaxed); @@ -1988,11 +1989,11 @@ int writeToClient(client *c, int handler_installed) { } } if (totwritten > 0) { - /* For clients representing masters we don't count sending data + /* For clients representing primaries we don't count sending data * as an interaction, since we always send REPLCONF ACK commands * that take some time to just fill the socket output buffer. * We just rely on data / pings received for timeout detection. */ - if (!(c->flags & CLIENT_MASTER)) c->lastinteraction = server.unixtime; + if (!(c->flags & CLIENT_PRIMARY)) c->last_interaction = server.unixtime; } if (!clientHasPendingReplies(c)) { c->sentlen = 0; @@ -2211,22 +2212,22 @@ int processInlineBuffer(client *c) { return C_ERR; } - /* Newline from slaves can be used to refresh the last ACK time. - * This is useful for a slave to ping back while loading a big + /* Newline from replicas can be used to refresh the last ACK time. + * This is useful for a replica to ping back while loading a big * RDB file. */ - if (querylen == 0 && getClientType(c) == CLIENT_TYPE_SLAVE) c->repl_ack_time = server.unixtime; + if (querylen == 0 && getClientType(c) == CLIENT_TYPE_REPLICA) c->repl_ack_time = server.unixtime; - /* Masters should never send us inline protocol to run actual + /* Primaries should never send us inline protocol to run actual * commands. If this happens, it is likely due to a bug in the server where * we got some desynchronization in the protocol, for example * because of a PSYNC gone bad. * - * However there is an exception: masters may send us just a newline + * However there is an exception: primaries may send us just a newline * to keep the connection active. */ - if (querylen != 0 && c->flags & CLIENT_MASTER) { + if (querylen != 0 && c->flags & CLIENT_PRIMARY) { sdsfreesplitres(argv, argc); - serverLog(LL_WARNING, "WARNING: Receiving inline protocol from master, master stream corruption? Closing the " - "master connection and discarding the cached master."); + serverLog(LL_WARNING, "WARNING: Receiving inline protocol from primary, primary stream corruption? Closing the " + "primary connection and discarding the cached primary."); setProtocolError("Master using the inline protocol. Desync?", c); return C_ERR; } @@ -2257,7 +2258,7 @@ int processInlineBuffer(client *c) { * CLIENT_PROTOCOL_ERROR. */ #define PROTO_DUMP_LEN 128 static void setProtocolError(const char *errstr, client *c) { - if (server.verbosity <= LL_VERBOSE || c->flags & CLIENT_MASTER) { + if (server.verbosity <= LL_VERBOSE || c->flags & CLIENT_PRIMARY) { sds client = catClientInfoString(sdsempty(), c); /* Sample some protocol to given an idea about what was inside. */ @@ -2278,7 +2279,7 @@ static void setProtocolError(const char *errstr, client *c) { } /* Log all the client and protocol info. */ - int loglevel = (c->flags & CLIENT_MASTER) ? LL_WARNING : LL_VERBOSE; + int loglevel = (c->flags & CLIENT_PRIMARY) ? LL_WARNING : LL_VERBOSE; serverLog(loglevel, "Protocol error (%s) from client: %s. %s", errstr, client, buf); sdsfree(client); } @@ -2369,7 +2370,7 @@ int processMultibulkBuffer(client *c) { } ok = string2ll(c->querybuf + c->qb_pos + 1, newline - (c->querybuf + c->qb_pos + 1), &ll); - if (!ok || ll < 0 || (!(c->flags & CLIENT_MASTER) && ll > server.proto_max_bulk_len)) { + if (!ok || ll < 0 || (!(c->flags & CLIENT_PRIMARY) && ll > server.proto_max_bulk_len)) { addReplyError(c, "Protocol error: invalid bulk length"); setProtocolError("invalid bulk length", c); return C_ERR; @@ -2380,8 +2381,8 @@ int processMultibulkBuffer(client *c) { } c->qb_pos = newline - c->querybuf + 2; - if (!(c->flags & CLIENT_MASTER) && ll >= PROTO_MBULK_BIG_ARG) { - /* When the client is not a master client (because master + if (!(c->flags & CLIENT_PRIMARY) && ll >= PROTO_MBULK_BIG_ARG) { + /* When the client is not a primary client (because primary * client's querybuf can only be trimmed after data applied * and sent to replicas). * @@ -2423,10 +2424,10 @@ int processMultibulkBuffer(client *c) { c->argv = zrealloc(c->argv, sizeof(robj *) * c->argv_len); } - /* Optimization: if a non-master client's buffer contains JUST our bulk element + /* Optimization: if a non-primary client's buffer contains JUST our bulk element * instead of creating a new object by *copying* the sds we * just use the current sds string. */ - if (!(c->flags & CLIENT_MASTER) && c->qb_pos == 0 && c->bulklen >= PROTO_MBULK_BIG_ARG && + if (!(c->flags & CLIENT_PRIMARY) && c->qb_pos == 0 && c->bulklen >= PROTO_MBULK_BIG_ARG && sdslen(c->querybuf) == (size_t)(c->bulklen + 2)) { c->argv[c->argc++] = createObject(OBJ_STRING, c->querybuf); c->argv_len_sum += c->bulklen; @@ -2455,8 +2456,8 @@ int processMultibulkBuffer(client *c) { /* Perform necessary tasks after a command was executed: * * 1. The client is reset unless there are reasons to avoid doing it. - * 2. In the case of master clients, the replication offset is updated. - * 3. Propagate commands we got from our master to replicas down the line. */ + * 2. In the case of primary clients, the replication offset is updated. + * 3. Propagate commands we got from our primary to replicas down the line. */ void commandProcessed(client *c) { /* If client is blocked(including paused), just return avoid reset and replicate. * @@ -2471,21 +2472,21 @@ void commandProcessed(client *c) { resetClient(c); long long prev_offset = c->reploff; - if (c->flags & CLIENT_MASTER && !(c->flags & CLIENT_MULTI)) { - /* Update the applied replication offset of our master. */ + if (c->flags & CLIENT_PRIMARY && !(c->flags & CLIENT_MULTI)) { + /* Update the applied replication offset of our primary. */ c->reploff = c->read_reploff - sdslen(c->querybuf) + c->qb_pos; } - /* If the client is a master we need to compute the difference + /* If the client is a primary we need to compute the difference * between the applied offset before and after processing the buffer, * to understand how much of the replication stream was actually - * applied to the master state: this quantity, and its corresponding + * applied to the primary state: this quantity, and its corresponding * part of the replication stream, will be propagated to the * sub-replicas and to the replication backlog. */ - if (c->flags & CLIENT_MASTER) { + if (c->flags & CLIENT_PRIMARY) { long long applied = c->reploff - prev_offset; if (applied) { - replicationFeedStreamFromMasterStream(c->querybuf + c->repl_applied, applied); + replicationFeedStreamFromPrimaryStream(c->querybuf + c->repl_applied, applied); c->repl_applied += applied; } } @@ -2519,8 +2520,8 @@ int processCommandAndResetClient(client *c) { * is dead and will stop reading from its buffer. */ server.current_client = old_client; - /* performEvictions may flush slave output buffers. This may - * result in a slave, that may be the active client, to be + /* performEvictions may flush replica output buffers. This may + * result in a replica, that may be the active client, to be * freed. */ return deadclient ? C_ERR : C_OK; } @@ -2543,7 +2544,7 @@ int processPendingCommandAndInputBuffer(client *c) { /* Now process client if it has more data in it's buffer. * - * Note: when a master client steps into this function, + * Note: when a primary client steps into this function, * it can always satisfy this condition, because its querybuf * contains data not applied. */ if (c->querybuf && sdslen(c->querybuf) > 0) { @@ -2567,11 +2568,11 @@ int processInputBuffer(client *c) { * commands to execute in c->argv. */ if (c->flags & CLIENT_PENDING_COMMAND) break; - /* Don't process input from the master while there is a busy script - * condition on the slave. We want just to accumulate the replication + /* Don't process input from the primary while there is a busy script + * condition on the replica. We want just to accumulate the replication * stream (instead of replying -BUSY like we do with other clients) and * later resume the processing. */ - if (isInsideYieldingLongCommand() && c->flags & CLIENT_MASTER) break; + if (isInsideYieldingLongCommand() && c->flags & CLIENT_PRIMARY) break; /* CLIENT_CLOSE_AFTER_REPLY closes the connection once the reply is * written to the client. Make sure to not let the reply grow after @@ -2627,15 +2628,15 @@ int processInputBuffer(client *c) { } } - if (c->flags & CLIENT_MASTER) { - /* If the client is a master, trim the querybuf to repl_applied, - * since master client is very special, its querybuf not only + if (c->flags & CLIENT_PRIMARY) { + /* If the client is a primary, trim the querybuf to repl_applied, + * since primary client is very special, its querybuf not only * used to parse command, but also proxy to sub-replicas. * * Here are some scenarios we cannot trim to qb_pos: - * 1. we don't receive complete command from master - * 2. master client blocked cause of client pause - * 3. io threads operate read, master client flagged with CLIENT_PENDING_COMMAND + * 1. we don't receive complete command from primary + * 2. primary client blocked cause of client pause + * 3. io threads operate read, primary client flagged with CLIENT_PENDING_COMMAND * * In these scenarios, qb_pos points to the part of the current command * or the beginning of next command, and the current command is not applied yet, @@ -2686,9 +2687,9 @@ void readQueryFromClient(connection *conn) { * for example once we resume a blocked client after CLIENT PAUSE. */ if (remaining > 0) readlen = remaining; - /* Master client needs expand the readlen when meet BIG_ARG(see #9100), + /* Primary client needs expand the readlen when meet BIG_ARG(see #9100), * but doesn't need align to the next arg, we can read more data. */ - if (c->flags & CLIENT_MASTER && readlen < PROTO_IOBUF_LEN) readlen = PROTO_IOBUF_LEN; + if (c->flags & CLIENT_PRIMARY && readlen < PROTO_IOBUF_LEN) readlen = PROTO_IOBUF_LEN; } if (c->querybuf == NULL) { @@ -2697,7 +2698,7 @@ void readQueryFromClient(connection *conn) { qblen = sdslen(c->querybuf); } - if (!(c->flags & CLIENT_MASTER) && // master client's querybuf can grow greedy. + if (!(c->flags & CLIENT_PRIMARY) && // primary client's querybuf can grow greedy. (big_arg || sdsalloc(c->querybuf) < PROTO_IOBUF_LEN)) { /* When reading a BIG_ARG we won't be reading more than that one arg * into the query buffer, so we don't need to pre-allocate more than we @@ -2737,8 +2738,8 @@ void readQueryFromClient(connection *conn) { qblen = sdslen(c->querybuf); if (c->querybuf_peak < qblen) c->querybuf_peak = qblen; - c->lastinteraction = server.unixtime; - if (c->flags & CLIENT_MASTER) { + c->last_interaction = server.unixtime; + if (c->flags & CLIENT_PRIMARY) { c->read_reploff += nread; atomic_fetch_add_explicit(&server.stat_net_repl_input_bytes, nread, memory_order_relaxed); } else { @@ -2746,7 +2747,7 @@ void readQueryFromClient(connection *conn) { } c->net_input_bytes += nread; - if (!(c->flags & CLIENT_MASTER) && + if (!(c->flags & CLIENT_PRIMARY) && /* The commands cached in the MULTI/EXEC queue have not been executed yet, * so they are also considered a part of the query buffer in a broader sense. * @@ -2832,14 +2833,14 @@ sds catClientInfoString(sds s, client *client) { char flags[17], events[3], conninfo[CONN_INFO_LEN], *p; p = flags; - if (client->flags & CLIENT_SLAVE) { + if (client->flags & CLIENT_REPLICA) { if (client->flags & CLIENT_MONITOR) *p++ = 'O'; else *p++ = 'S'; } /* clang-format off */ - if (client->flags & CLIENT_MASTER) *p++ = 'M'; + if (client->flags & CLIENT_PRIMARY) *p++ = 'M'; if (client->flags & CLIENT_PUBSUB) *p++ = 'P'; if (client->flags & CLIENT_MULTI) *p++ = 'x'; if (client->flags & CLIENT_BLOCKED) *p++ = 'b'; @@ -2883,7 +2884,7 @@ sds catClientInfoString(sds s, client *client) { " %s", connGetInfo(client->conn, conninfo, sizeof(conninfo)), " name=%s", client->name ? (char*)client->name->ptr : "", " age=%I", (long long)(commandTimeSnapshot() / 1000 - client->ctime), - " idle=%I", (long long)(server.unixtime - client->lastinteraction), + " idle=%I", (long long)(server.unixtime - client->last_interaction), " flags=%s", flags, " db=%i", client->db->id, " sub=%i", (int) dictSize(client->pubsub_channels), @@ -3026,13 +3027,13 @@ void clientSetinfoCommand(client *c) { /* Reset the client state to resemble a newly connected client. */ void resetCommand(client *c) { - /* MONITOR clients are also marked with CLIENT_SLAVE, we need to + /* MONITOR clients are also marked with CLIENT_REPLICA, we need to * distinguish between the two. */ uint64_t flags = c->flags; - if (flags & CLIENT_MONITOR) flags &= ~(CLIENT_MONITOR | CLIENT_SLAVE); + if (flags & CLIENT_MONITOR) flags &= ~(CLIENT_MONITOR | CLIENT_REPLICA); - if (flags & (CLIENT_SLAVE | CLIENT_MASTER | CLIENT_MODULE)) { + if (flags & (CLIENT_REPLICA | CLIENT_PRIMARY | CLIENT_MODULE)) { addReplyError(c, "can only reset normal client connections"); return; } @@ -3678,7 +3679,7 @@ void helloCommand(client *c) { if (!server.sentinel_mode) { addReplyBulkCString(c, "role"); - addReplyBulkCString(c, server.masterhost ? "replica" : "master"); + addReplyBulkCString(c, server.primary_host ? "replica" : "master"); } addReplyBulkCString(c, "modules"); @@ -3825,7 +3826,7 @@ void rewriteClientCommandArgument(client *c, int i, robj *newval) { * the caller wishes. The main usage of this function currently is * enforcing the client output length limits. */ size_t getClientOutputBufferMemoryUsage(client *c) { - if (getClientType(c) == CLIENT_TYPE_SLAVE) { + if (getClientType(c) == CLIENT_TYPE_REPLICA) { size_t repl_buf_size = 0; size_t repl_node_num = 0; size_t repl_node_size = sizeof(listNode) + sizeof(replBufBlock); @@ -3875,15 +3876,15 @@ size_t getClientMemoryUsage(client *c, size_t *output_buffer_mem_usage) { * * The function will return one of the following: * CLIENT_TYPE_NORMAL -> Normal client, including MONITOR - * CLIENT_TYPE_SLAVE -> Slave + * CLIENT_TYPE_REPLICA -> replica * CLIENT_TYPE_PUBSUB -> Client subscribed to Pub/Sub channels - * CLIENT_TYPE_MASTER -> The client representing our replication master. + * CLIENT_TYPE_PRIMARY -> The client representing our replication primary. */ int getClientType(client *c) { - if (c->flags & CLIENT_MASTER) return CLIENT_TYPE_MASTER; + if (c->flags & CLIENT_PRIMARY) return CLIENT_TYPE_PRIMARY; /* Even though MONITOR clients are marked as replicas, we * want the expose them as normal clients. */ - if ((c->flags & CLIENT_SLAVE) && !(c->flags & CLIENT_MONITOR)) return CLIENT_TYPE_SLAVE; + if ((c->flags & CLIENT_REPLICA) && !(c->flags & CLIENT_MONITOR)) return CLIENT_TYPE_REPLICA; if (c->flags & CLIENT_PUBSUB) return CLIENT_TYPE_PUBSUB; return CLIENT_TYPE_NORMAL; } @@ -3892,13 +3893,13 @@ int getClientTypeByName(char *name) { if (!strcasecmp(name, "normal")) return CLIENT_TYPE_NORMAL; else if (!strcasecmp(name, "slave")) - return CLIENT_TYPE_SLAVE; + return CLIENT_TYPE_REPLICA; else if (!strcasecmp(name, "replica")) - return CLIENT_TYPE_SLAVE; + return CLIENT_TYPE_REPLICA; else if (!strcasecmp(name, "pubsub")) return CLIENT_TYPE_PUBSUB; else if (!strcasecmp(name, "master")) - return CLIENT_TYPE_MASTER; + return CLIENT_TYPE_PRIMARY; else return -1; } @@ -3906,9 +3907,9 @@ int getClientTypeByName(char *name) { char *getClientTypeName(int class) { switch (class) { case CLIENT_TYPE_NORMAL: return "normal"; - case CLIENT_TYPE_SLAVE: return "slave"; + case CLIENT_TYPE_REPLICA: return "slave"; case CLIENT_TYPE_PUBSUB: return "pubsub"; - case CLIENT_TYPE_MASTER: return "master"; + case CLIENT_TYPE_PRIMARY: return "master"; default: return NULL; } } @@ -3924,9 +3925,9 @@ int checkClientOutputBufferLimits(client *c) { unsigned long used_mem = getClientOutputBufferMemoryUsage(c); class = getClientType(c); - /* For the purpose of output buffer limiting, masters are handled + /* For the purpose of output buffer limiting, primaries are handled * like normal clients. */ - if (class == CLIENT_TYPE_MASTER) class = CLIENT_TYPE_NORMAL; + if (class == CLIENT_TYPE_PRIMARY) class = CLIENT_TYPE_NORMAL; /* Note that it doesn't make sense to set the replica clients output buffer * limit lower than the repl-backlog-size config (partial sync will succeed @@ -3935,7 +3936,7 @@ int checkClientOutputBufferLimits(client *c) { * This doesn't have memory consumption implications since the replica client * will share the backlog buffers memory. */ size_t hard_limit_bytes = server.client_obuf_limits[class].hard_limit_bytes; - if (class == CLIENT_TYPE_SLAVE && hard_limit_bytes && (long long)hard_limit_bytes < server.repl_backlog_size) + if (class == CLIENT_TYPE_REPLICA && hard_limit_bytes && (long long)hard_limit_bytes < server.repl_backlog_size) hard_limit_bytes = server.repl_backlog_size; if (server.client_obuf_limits[class].hard_limit_bytes && used_mem >= hard_limit_bytes) hard = 1; if (server.client_obuf_limits[class].soft_limit_bytes && @@ -3979,7 +3980,7 @@ int closeClientOnOutputBufferLimitReached(client *c, int async) { serverAssert(c->reply_bytes < SIZE_MAX - (1024 * 64)); /* Note that c->reply_bytes is irrelevant for replica clients * (they use the global repl buffers). */ - if ((c->reply_bytes == 0 && getClientType(c) != CLIENT_TYPE_SLAVE) || c->flags & CLIENT_CLOSE_ASAP) return 0; + if ((c->reply_bytes == 0 && getClientType(c) != CLIENT_TYPE_REPLICA) || c->flags & CLIENT_CLOSE_ASAP) return 0; if (checkClientOutputBufferLimits(c)) { sds client = catClientInfoString(sdsempty(), c); @@ -3998,18 +3999,18 @@ int closeClientOnOutputBufferLimitReached(client *c, int async) { return 0; } -/* Helper function used by performEvictions() in order to flush slaves +/* Helper function used by performEvictions() in order to flush replicas * output buffers without returning control to the event loop. * This is also called by SHUTDOWN for a best-effort attempt to send - * slaves the latest writes. */ -void flushSlavesOutputBuffers(void) { + * replicas the latest writes. */ +void flushReplicasOutputBuffers(void) { listIter li; listNode *ln; - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = listNodeValue(ln); - int can_receive_writes = connHasWriteHandler(slave->conn) || (slave->flags & CLIENT_PENDING_WRITE); + client *replica = listNodeValue(ln); + int can_receive_writes = connHasWriteHandler(replica->conn) || (replica->flags & CLIENT_PENDING_WRITE); /* We don't want to send the pending data to the replica in a few * cases: @@ -4023,11 +4024,11 @@ void flushSlavesOutputBuffers(void) { * to send data to the replica in this case, please grep for the * flag for this flag. * - * 3. Obviously if the slave is not ONLINE. + * 3. Obviously if the replica is not ONLINE. */ - if (slave->replstate == SLAVE_STATE_ONLINE && !(slave->flags & CLIENT_CLOSE_ASAP) && can_receive_writes && - !slave->repl_start_cmd_stream_on_ack && clientHasPendingReplies(slave)) { - writeToClient(slave, 0); + if (replica->repl_state == REPLICA_STATE_ONLINE && !(replica->flags & CLIENT_CLOSE_ASAP) && + can_receive_writes && !replica->repl_start_cmd_stream_on_ack && clientHasPendingReplies(replica)) { + writeToClient(replica, 0); } } } @@ -4139,7 +4140,7 @@ uint32_t isPausedActionsWithUpdate(uint32_t actions_bitmask) { /* This function is called by the server in order to process a few events from * time to time while blocked into some not interruptible operation. * This allows to reply to clients with the -LOADING error while loading the - * data set at startup or after a full resynchronization with the master + * data set at startup or after a full resynchronization with the primary * and so forth. * * It calls the event loop in order to process a few events. Specifically we @@ -4403,7 +4404,7 @@ int handleClientsWithPendingWritesUsingThreads(void) { * buffer, to guarantee data accessing thread safe, we must put all * replicas client into io_threads_list[0] i.e. main thread handles * sending the output buffer of all replicas. */ - if (getClientType(c) == CLIENT_TYPE_SLAVE) { + if (getClientType(c) == CLIENT_TYPE_REPLICA) { listAddNodeTail(io_threads_list[0], c); continue; } @@ -4469,7 +4470,7 @@ int handleClientsWithPendingWritesUsingThreads(void) { * pending read clients and flagged as such. */ int postponeClientRead(client *c) { if (server.io_threads_active && server.io_threads_do_reads && !ProcessingEventsWhileBlocked && - !(c->flags & (CLIENT_MASTER | CLIENT_SLAVE | CLIENT_BLOCKED)) && io_threads_op == IO_THREADS_OP_IDLE) { + !(c->flags & (CLIENT_PRIMARY | CLIENT_REPLICA | CLIENT_BLOCKED)) && io_threads_op == IO_THREADS_OP_IDLE) { listAddNodeHead(server.clients_pending_read, c); c->pending_read_list_node = listFirst(server.clients_pending_read); return 1; diff --git a/src/object.c b/src/object.c index 814b8de3a9..f00effd7d1 100644 --- a/src/object.c +++ b/src/object.c @@ -1173,11 +1173,11 @@ struct serverMemOverhead *getMemoryOverheadData(void) { * only if replication buffer memory is more than the repl backlog setting, * we consider the excess as replicas' memory. Otherwise, replication buffer * memory is the consumption of repl backlog. */ - if (listLength(server.slaves) && (long long)server.repl_buffer_mem > server.repl_backlog_size) { - mh->clients_slaves = server.repl_buffer_mem - server.repl_backlog_size; + if (listLength(server.replicas) && (long long)server.repl_buffer_mem > server.repl_backlog_size) { + mh->clients_replicas = server.repl_buffer_mem - server.repl_backlog_size; mh->repl_backlog = server.repl_backlog_size; } else { - mh->clients_slaves = 0; + mh->clients_replicas = 0; mh->repl_backlog = server.repl_buffer_mem; } if (server.repl_backlog) { @@ -1186,12 +1186,12 @@ struct serverMemOverhead *getMemoryOverheadData(void) { raxSize(server.repl_backlog->blocks_index) * sizeof(void *); } mem_total += mh->repl_backlog; - mem_total += mh->clients_slaves; + mem_total += mh->clients_replicas; /* Computing the memory used by the clients would be O(N) if done * here online. We use our values computed incrementally by * updateClientMemoryUsage(). */ - mh->clients_normal = server.stat_clients_type_memory[CLIENT_TYPE_MASTER] + + mh->clients_normal = server.stat_clients_type_memory[CLIENT_TYPE_PRIMARY] + server.stat_clients_type_memory[CLIENT_TYPE_PUBSUB] + server.stat_clients_type_memory[CLIENT_TYPE_NORMAL]; mem_total += mh->clients_normal; @@ -1312,7 +1312,7 @@ sds getMemoryDoctorReport(void) { } /* Clients using more than 200k each average? */ - long numslaves = listLength(server.slaves); + long numslaves = listLength(server.replicas); long numclients = listLength(server.clients) - numslaves; if (mh->clients_normal / numclients > (1024 * 200)) { big_client_buf = 1; @@ -1320,7 +1320,7 @@ sds getMemoryDoctorReport(void) { } /* Slaves using more than 10 MB each? */ - if (numslaves > 0 && mh->clients_slaves > (1024 * 1024 * 10)) { + if (numslaves > 0 && mh->clients_replicas > (1024 * 1024 * 10)) { big_slave_buf = 1; num_reports++; } @@ -1579,7 +1579,7 @@ NULL addReplyLongLong(c, mh->repl_backlog); addReplyBulkCString(c, "clients.slaves"); - addReplyLongLong(c, mh->clients_slaves); + addReplyLongLong(c, mh->clients_replicas); addReplyBulkCString(c, "clients.normal"); addReplyLongLong(c, mh->clients_normal); diff --git a/src/rdb.c b/src/rdb.c index fe297cb7a9..d58437bcd7 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -1183,7 +1183,7 @@ int rdbSaveInfoAuxFields(rio *rdb, int rdbflags, rdbSaveInfo *rsi) { if (rsi) { if (rdbSaveAuxFieldStrInt(rdb, "repl-stream-db", rsi->repl_stream_db) == -1) return -1; if (rdbSaveAuxFieldStrStr(rdb, "repl-id", server.replid) == -1) return -1; - if (rdbSaveAuxFieldStrInt(rdb, "repl-offset", server.master_repl_offset) == -1) return -1; + if (rdbSaveAuxFieldStrInt(rdb, "repl-offset", server.primary_repl_offset) == -1) return -1; } if (rdbSaveAuxFieldStrInt(rdb, "aof-base", aof_base) == -1) return -1; return 1; @@ -1369,19 +1369,19 @@ int rdbSaveRio(int req, rio *rdb, int *error, int rdbflags, rdbSaveInfo *rsi) { snprintf(magic, sizeof(magic), "REDIS%04d", RDB_VERSION); if (rdbWriteRaw(rdb, magic, 9) == -1) goto werr; if (rdbSaveInfoAuxFields(rdb, rdbflags, rsi) == -1) goto werr; - if (!(req & SLAVE_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, VALKEYMODULE_AUX_BEFORE_RDB) == -1) goto werr; + if (!(req & REPLICA_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, VALKEYMODULE_AUX_BEFORE_RDB) == -1) goto werr; /* save functions */ - if (!(req & SLAVE_REQ_RDB_EXCLUDE_FUNCTIONS) && rdbSaveFunctions(rdb) == -1) goto werr; + if (!(req & REPLICA_REQ_RDB_EXCLUDE_FUNCTIONS) && rdbSaveFunctions(rdb) == -1) goto werr; /* save all databases, skip this if we're in functions-only mode */ - if (!(req & SLAVE_REQ_RDB_EXCLUDE_DATA)) { + if (!(req & REPLICA_REQ_RDB_EXCLUDE_DATA)) { for (j = 0; j < server.dbnum; j++) { if (rdbSaveDb(rdb, j, rdbflags, &key_counter) == -1) goto werr; } } - if (!(req & SLAVE_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, VALKEYMODULE_AUX_AFTER_RDB) == -1) goto werr; + if (!(req & REPLICA_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, VALKEYMODULE_AUX_AFTER_RDB) == -1) goto werr; /* EOF opcode */ if (rdbSaveType(rdb, RDB_OPCODE_EOF) == -1) goto werr; @@ -1495,7 +1495,7 @@ static int rdbSaveInternal(int req, const char *filename, rdbSaveInfo *rsi, int int rdbSaveToFile(const char *filename) { startSaving(RDBFLAGS_NONE); - if (rdbSaveInternal(SLAVE_REQ_NONE, filename, NULL, RDBFLAGS_NONE) != C_OK) { + if (rdbSaveInternal(REPLICA_REQ_NONE, filename, NULL, RDBFLAGS_NONE) != C_OK) { int saved_errno = errno; stopSaving(0); errno = saved_errno; @@ -1816,8 +1816,8 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { int deep_integrity_validation = server.sanitize_dump_payload == SANITIZE_DUMP_YES; if (server.sanitize_dump_payload == SANITIZE_DUMP_CLIENTS) { /* Skip sanitization when loading (an RDB), or getting a RESTORE command - * from either the master or a client using an ACL user with the skip-sanitize-payload flag. */ - int skip = server.loading || (server.current_client && (server.current_client->flags & CLIENT_MASTER)); + * from either the primary or a client using an ACL user with the skip-sanitize-payload flag. */ + int skip = server.loading || (server.current_client && (server.current_client->flags & CLIENT_PRIMARY)); if (!skip && server.current_client && server.current_client->user) skip = !!(server.current_client->user->flags & USER_FLAG_SANITIZE_PAYLOAD_SKIP); deep_integrity_validation = !skip; @@ -2434,12 +2434,12 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { } while (listpacks--) { - /* Get the master ID, the one we'll use as key of the radix tree + /* Get the primary ID, the one we'll use as key of the radix tree * node: the entries inside the listpack itself are delta-encoded * relatively to this ID. */ sds nodekey = rdbGenericLoadStringObject(rdb, RDB_LOAD_SDS, NULL); if (nodekey == NULL) { - rdbReportReadError("Stream master ID loading failed: invalid encoding or I/O error."); + rdbReportReadError("Stream primary ID loading failed: invalid encoding or I/O error."); decrRefCount(o); return NULL; } @@ -2883,7 +2883,7 @@ void rdbLoadProgressCallback(rio *r, const void *buf, size_t len) { if (server.loading_process_events_interval_bytes && (r->processed_bytes + len) / server.loading_process_events_interval_bytes > r->processed_bytes / server.loading_process_events_interval_bytes) { - if (server.masterhost && server.repl_state == REPL_STATE_TRANSFER) replicationSendNewlineToMaster(); + if (server.primary_host && server.repl_state == REPL_STATE_TRANSFER) replicationSendNewlineToPrimary(); loadingAbsProgress(r->processed_bytes); processEventsWhileBlocked(); processModuleLoadingProgressEvent(0); @@ -3198,9 +3198,9 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin /* Check if the key already expired. This function is used when loading * an RDB file from disk, either at startup, or when an RDB was - * received from the master. In the latter case, the master is + * received from the primary. In the latter case, the primary is * responsible for key expiry. If we would expire keys here, the - * snapshot taken by the master may not be reflected on the slave. + * snapshot taken by the primary may not be reflected on the replica. * Similarly, if the base AOF is RDB format, we want to load all * the keys they are, since the log of operations in the incr AOF * is assumed to work in the exact keyspace state. */ @@ -3216,18 +3216,18 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin sdsfree(key); goto eoferr; } - } else if (iAmMaster() && !(rdbflags & RDBFLAGS_AOF_PREAMBLE) && expiretime != -1 && expiretime < now) { + } else if (iAmPrimary() && !(rdbflags & RDBFLAGS_AOF_PREAMBLE) && expiretime != -1 && expiretime < now) { if (rdbflags & RDBFLAGS_FEED_REPL) { /* Caller should have created replication backlog, * and now this path only works when rebooting, * so we don't have replicas yet. */ - serverAssert(server.repl_backlog != NULL && listLength(server.slaves) == 0); + serverAssert(server.repl_backlog != NULL && listLength(server.replicas) == 0); robj keyobj; initStaticStringObject(keyobj, key); robj *argv[2]; argv[0] = server.lazyfree_lazy_expire ? shared.unlink : shared.del; argv[1] = &keyobj; - replicationFeedSlaves(dbid, argv, 2); + replicationFeedReplicas(dbid, argv, 2); } sdsfree(key); decrRefCount(val); @@ -3379,7 +3379,7 @@ static void backgroundSaveDoneHandlerDisk(int exitcode, int bysignal, time_t sav } /* A background saving child (BGSAVE) terminated its work. Handle this. - * This function covers the case of RDB -> Slaves socket transfers for + * This function covers the case of RDB -> Replicas socket transfers for * diskless replication. */ static void backgroundSaveDoneHandlerSocket(int exitcode, int bysignal) { if (!bysignal && exitcode == 0) { @@ -3417,9 +3417,9 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) { server.rdb_child_type = RDB_CHILD_TYPE_NONE; server.rdb_save_time_last = save_end - server.rdb_save_time_start; server.rdb_save_time_start = -1; - /* Possibly there are slaves waiting for a BGSAVE in order to be served + /* Possibly there are replicas waiting for a BGSAVE in order to be served * (the first stage of SYNC is a bulk transfer of dump.rdb) */ - updateSlavesWaitingBgsave((!bysignal && exitcode == 0) ? C_OK : C_ERR, type); + updateReplicasWaitingBgsave((!bysignal && exitcode == 0) ? C_OK : C_ERR, type); } /* Kill the RDB saving child using SIGUSR1 (so that the parent will know @@ -3435,9 +3435,9 @@ void killRDBChild(void) { * - rdbRemoveTempFile */ } -/* Spawn an RDB child that writes the RDB to the sockets of the slaves - * that are currently in SLAVE_STATE_WAIT_BGSAVE_START state. */ -int rdbSaveToSlavesSockets(int req, rdbSaveInfo *rsi) { +/* Spawn an RDB child that writes the RDB to the sockets of the replicas + * that are currently in REPLICA_STATE_WAIT_BGSAVE_START state. */ +int rdbSaveToReplicasSockets(int req, rdbSaveInfo *rsi) { listNode *ln; listIter li; pid_t childpid; @@ -3469,17 +3469,17 @@ int rdbSaveToSlavesSockets(int req, rdbSaveInfo *rsi) { /* Collect the connections of the replicas we want to transfer * the RDB to, which are i WAIT_BGSAVE_START state. */ - server.rdb_pipe_conns = zmalloc(sizeof(connection *) * listLength(server.slaves)); + server.rdb_pipe_conns = zmalloc(sizeof(connection *) * listLength(server.replicas)); server.rdb_pipe_numconns = 0; server.rdb_pipe_numconns_writing = 0; - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = ln->value; - if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) { - /* Check slave has the exact requirements */ - if (slave->slave_req != req) continue; - server.rdb_pipe_conns[server.rdb_pipe_numconns++] = slave->conn; - replicationSetupSlaveForFullResync(slave, getPsyncInitialOffset()); + client *replica = ln->value; + if (replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_START) { + /* Check replica has the exact requirements */ + if (replica->replica_req != req) continue; + server.rdb_pipe_conns[server.rdb_pipe_numconns++] = replica->conn; + replicationSetupReplicaForFullResync(replica, getPsyncInitialOffset()); } } @@ -3523,13 +3523,13 @@ int rdbSaveToSlavesSockets(int req, rdbSaveInfo *rsi) { serverLog(LL_WARNING, "Can't save in background: fork: %s", strerror(errno)); /* Undo the state change. The caller will perform cleanup on - * all the slaves in BGSAVE_START state, but an early call to - * replicationSetupSlaveForFullResync() turned it into BGSAVE_END */ - listRewind(server.slaves, &li); + * all the replicas in BGSAVE_START state, but an early call to + * replicationSetupReplicaForFullResync() turned it into BGSAVE_END */ + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = ln->value; - if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END) { - slave->replstate = SLAVE_STATE_WAIT_BGSAVE_START; + client *replica = ln->value; + if (replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_END) { + replica->repl_state = REPLICA_STATE_WAIT_BGSAVE_START; } } close(rdb_pipe_write); @@ -3564,7 +3564,7 @@ void saveCommand(client *c) { rdbSaveInfo rsi, *rsiptr; rsiptr = rdbPopulateSaveInfo(&rsi); - if (rdbSave(SLAVE_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE) == C_OK) { + if (rdbSave(REPLICA_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE) == C_OK) { addReply(c, shared.ok); } else { addReplyErrorObject(c, shared.err); @@ -3600,7 +3600,7 @@ void bgsaveCommand(client *c) { "Use BGSAVE SCHEDULE in order to schedule a BGSAVE whenever " "possible."); } - } else if (rdbSaveBackground(SLAVE_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE) == C_OK) { + } else if (rdbSaveBackground(REPLICA_REQ_NONE, server.rdb_filename, rsiptr, RDBFLAGS_NONE) == C_OK) { addReplyStatus(c, "Background saving started"); } else { addReplyErrorObject(c, shared.err); @@ -3609,48 +3609,48 @@ void bgsaveCommand(client *c) { /* Populate the rdbSaveInfo structure used to persist the replication * information inside the RDB file. Currently the structure explicitly - * contains just the currently selected DB from the master stream, however + * contains just the currently selected DB from the primary stream, however * if the rdbSave*() family functions receive a NULL rsi structure also * the Replication ID/offset is not saved. The function populates 'rsi' * that is normally stack-allocated in the caller, returns the populated - * pointer if the instance has a valid master client, otherwise NULL + * pointer if the instance has a valid primary client, otherwise NULL * is returned, and the RDB saving will not persist any replication related * information. */ rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi) { rdbSaveInfo rsi_init = RDB_SAVE_INFO_INIT; *rsi = rsi_init; - /* If the instance is a master, we can populate the replication info + /* If the instance is a primary, we can populate the replication info * only when repl_backlog is not NULL. If the repl_backlog is NULL, * it means that the instance isn't in any replication chains. In this - * scenario the replication info is useless, because when a slave + * scenario the replication info is useless, because when a replica * connects to us, the NULL repl_backlog will trigger a full * synchronization, at the same time we will use a new replid and clear * replid2. */ - if (!server.masterhost && server.repl_backlog) { - /* Note that when server.slaveseldb is -1, it means that this master + if (!server.primary_host && server.repl_backlog) { + /* Note that when server.replicas_eldb is -1, it means that this primary * didn't apply any write commands after a full synchronization. - * So we can let repl_stream_db be 0, this allows a restarted slave + * So we can let repl_stream_db be 0, this allows a restarted replica * to reload replication ID/offset, it's safe because the next write * command must generate a SELECT statement. */ - rsi->repl_stream_db = server.slaveseldb == -1 ? 0 : server.slaveseldb; + rsi->repl_stream_db = server.replicas_eldb == -1 ? 0 : server.replicas_eldb; return rsi; } - /* If the instance is a slave we need a connected master + /* If the instance is a replica we need a connected primary * in order to fetch the currently selected DB. */ - if (server.master) { - rsi->repl_stream_db = server.master->db->id; + if (server.primary) { + rsi->repl_stream_db = server.primary->db->id; return rsi; } - /* If we have a cached master we can use it in order to populate the - * replication selected DB info inside the RDB file: the slave can - * increment the master_repl_offset only from data arriving from the - * master, so if we are disconnected the offset in the cached master + /* If we have a cached primary we can use it in order to populate the + * replication selected DB info inside the RDB file: the replica can + * increment the primary_repl_offset only from data arriving from the + * primary, so if we are disconnected the offset in the cached primary * is valid. */ - if (server.cached_master) { - rsi->repl_stream_db = server.cached_master->db->id; + if (server.cached_primary) { + rsi->repl_stream_db = server.cached_primary->db->id; return rsi; } return NULL; diff --git a/src/rdb.h b/src/rdb.h index 48762e10e1..393d2f658a 100644 --- a/src/rdb.h +++ b/src/rdb.h @@ -154,7 +154,7 @@ int rdbSaveObjectType(rio *rdb, robj *o); int rdbLoadObjectType(rio *rdb); int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags); int rdbSaveBackground(int req, char *filename, rdbSaveInfo *rsi, int rdbflags); -int rdbSaveToSlavesSockets(int req, rdbSaveInfo *rsi); +int rdbSaveToReplicasSockets(int req, rdbSaveInfo *rsi); void rdbRemoveTempFile(pid_t childpid, int from_signal); int rdbSaveToFile(const char *filename); int rdbSave(int req, char *filename, rdbSaveInfo *rsi, int rdbflags); diff --git a/src/replication.c b/src/replication.c index 375b637f61..d7af92b395 100644 --- a/src/replication.c +++ b/src/replication.c @@ -46,8 +46,8 @@ void replicationDiscardCachedMaster(void); void replicationResurrectCachedMaster(connection *conn); void replicationSendAck(void); -int replicaPutOnline(client *slave); -void replicaStartCommandStream(client *slave); +int replicaPutOnline(client *replica); +void replicaStartCommandStream(client *replica); int cancelReplicationHandshake(int reconnect); /* We take a global flag to remember if this instance generated an RDB @@ -64,20 +64,20 @@ static ConnectionType *connTypeOfReplication(void) { return connectionTypeTcp(); } -/* Return the pointer to a string representing the slave ip:listening_port - * pair. Mostly useful for logging, since we want to log a slave using its +/* Return the pointer to a string representing the replica ip:listening_port + * pair. Mostly useful for logging, since we want to log a replica using its * IP address and its listening port which is more clear for the user, for * example: "Closing connection with replica 10.1.2.3:6380". */ -char *replicationGetSlaveName(client *c) { +char *replicationGetReplicaName(client *c) { static char buf[NET_HOST_PORT_STR_LEN]; char ip[NET_IP_STR_LEN]; ip[0] = '\0'; buf[0] = '\0'; - if (c->slave_addr || connAddrPeerName(c->conn, ip, sizeof(ip), NULL) != -1) { - char *addr = c->slave_addr ? c->slave_addr : ip; - if (c->slave_listening_port) - formatAddr(buf, sizeof(buf), addr, c->slave_listening_port); + if (c->replica_addr || connAddrPeerName(c->conn, ip, sizeof(ip), NULL) != -1) { + char *addr = c->replica_addr ? c->replica_addr : ip; + if (c->replica_listening_port) + formatAddr(buf, sizeof(buf), addr, c->replica_listening_port); else snprintf(buf, sizeof(buf), "%s:", addr); } else { @@ -126,7 +126,7 @@ void createReplicationBacklog(void) { /* We don't have any data inside our buffer, but virtually the first * byte we have is the next byte that will be generated for the * replication stream. */ - server.repl_backlog->offset = server.master_repl_offset + 1; + server.repl_backlog->offset = server.primary_repl_offset + 1; } /* This function is called when the user modifies the replication backlog @@ -141,7 +141,7 @@ void resizeReplicationBacklog(void) { } void freeReplicationBacklog(void) { - serverAssert(listLength(server.slaves) == 0); + serverAssert(listLength(server.replicas) == 0); if (server.repl_backlog == NULL) return; /* Decrease the start buffer node reference count. */ @@ -174,7 +174,7 @@ void createReplicationBacklogIndex(listNode *ln) { } /* Rebase replication buffer blocks' offset since the initial - * setting offset starts from 0 when master restart. */ + * setting offset starts from 0 when primary restart. */ void rebaseReplicationBuffer(long long base_repl_offset) { raxFree(server.repl_backlog->blocks_index); server.repl_backlog->blocks_index = raxNew(); @@ -201,7 +201,7 @@ int canFeedReplicaReplBuffer(client *replica) { if (replica->flags & CLIENT_REPL_RDBONLY) return 0; /* Don't feed replicas that are still waiting for BGSAVE to start. */ - if (replica->replstate == SLAVE_STATE_WAIT_BGSAVE_START) return 0; + if (replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_START) return 0; return 1; } @@ -215,11 +215,11 @@ int prepareReplicasToWrite(void) { listNode *ln; int prepared = 0; - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = ln->value; - if (!canFeedReplicaReplBuffer(slave)) continue; - if (prepareClientToWrite(slave) == C_ERR) continue; + client *replica = ln->value; + if (!canFeedReplicaReplBuffer(replica)) continue; + if (prepareClientToWrite(replica) == C_ERR) continue; prepared++; } @@ -259,7 +259,7 @@ void incrementalTrimReplicationBacklog(size_t max_blocks) { /* Replicas increment the refcount of the first replication buffer block * they refer to, in that case, we don't trim the backlog even if * backlog_histlen exceeds backlog_size. This implicitly makes backlog - * bigger than our setting, but makes the master accept partial resync as + * bigger than our setting, but makes the primary accept partial resync as * much as possible. So that backlog must be the last reference of * replication buffer blocks. */ listNode *first = listFirst(server.repl_buffer_blocks); @@ -294,7 +294,7 @@ void incrementalTrimReplicationBacklog(size_t max_blocks) { } /* Set the offset of the first byte we have in the backlog. */ - server.repl_backlog->offset = server.master_repl_offset - server.repl_backlog->histlen + 1; + server.repl_backlog->offset = server.primary_repl_offset - server.repl_backlog->histlen + 1; } /* Free replication buffer blocks that are referenced by this client. */ @@ -339,7 +339,7 @@ void feedReplicationBuffer(char *s, size_t len) { tail->used += copy; s += copy; len -= copy; - server.master_repl_offset += copy; + server.primary_repl_offset += copy; server.repl_backlog->histlen += copy; } if (len) { @@ -357,7 +357,7 @@ void feedReplicationBuffer(char *s, size_t len) { size_t copy = (tail->size >= len) ? len : tail->size; tail->used = copy; tail->refcount = 0; - tail->repl_offset = server.master_repl_offset + 1; + tail->repl_offset = server.primary_repl_offset + 1; tail->id = repl_block_id++; memcpy(tail->buf, s, copy); listAddNodeTail(server.repl_buffer_blocks, tail); @@ -370,27 +370,27 @@ void feedReplicationBuffer(char *s, size_t len) { } s += copy; len -= copy; - server.master_repl_offset += copy; + server.primary_repl_offset += copy; server.repl_backlog->histlen += copy; } /* For output buffer of replicas. */ listIter li; - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = ln->value; - if (!canFeedReplicaReplBuffer(slave)) continue; + client *replica = ln->value; + if (!canFeedReplicaReplBuffer(replica)) continue; /* Update shared replication buffer start position. */ - if (slave->ref_repl_buf_node == NULL) { - slave->ref_repl_buf_node = start_node; - slave->ref_block_pos = start_pos; + if (replica->ref_repl_buf_node == NULL) { + replica->ref_repl_buf_node = start_node; + replica->ref_block_pos = start_pos; /* Only increase the start block reference count. */ ((replBufBlock *)listNodeValue(start_node))->refcount++; } /* Check output buffer limit only when add new block. */ - if (add_new_block) closeClientOnOutputBufferLimitReached(slave, 1); + if (add_new_block) closeClientOnOutputBufferLimitReached(replica, 1); } /* For replication backlog */ @@ -417,11 +417,11 @@ void feedReplicationBuffer(char *s, size_t len) { /* Propagate write commands to replication stream. * - * This function is used if the instance is a master: we use the commands + * This function is used if the instance is a primary: we use the commands * received by our clients in order to create the replication stream. * Instead if the instance is a replica and has sub-replicas attached, we use * replicationFeedStreamFromMasterStream() */ -void replicationFeedSlaves(int dictid, robj **argv, int argc) { +void replicationFeedReplicas(int dictid, robj **argv, int argc) { int j, len; char llstr[LONG_STR_SIZE]; @@ -429,32 +429,32 @@ void replicationFeedSlaves(int dictid, robj **argv, int argc) { * pass dbid=-1 that indicate there is no need to replicate `select` command. */ serverAssert(dictid == -1 || (dictid >= 0 && dictid < server.dbnum)); - /* If the instance is not a top level master, return ASAP: we'll just proxy - * the stream of data we receive from our master instead, in order to - * propagate *identical* replication stream. In this way this slave can - * advertise the same replication ID as the master (since it shares the - * master replication history and has the same backlog and offsets). */ - if (server.masterhost != NULL) return; + /* If the instance is not a top level primary, return ASAP: we'll just proxy + * the stream of data we receive from our primary instead, in order to + * propagate *identical* replication stream. In this way this replica can + * advertise the same replication ID as the primary (since it shares the + * primary replication history and has the same backlog and offsets). */ + if (server.primary_host != NULL) return; - /* If there aren't slaves, and there is no backlog buffer to populate, + /* If there aren't replicas, and there is no backlog buffer to populate, * we can return ASAP. */ - if (server.repl_backlog == NULL && listLength(server.slaves) == 0) { + if (server.repl_backlog == NULL && listLength(server.replicas) == 0) { /* We increment the repl_offset anyway, since we use that for tracking AOF fsyncs * even when there's no replication active. This code will not be reached if AOF * is also disabled. */ - server.master_repl_offset += 1; + server.primary_repl_offset += 1; return; } - /* We can't have slaves attached and no backlog. */ - serverAssert(!(listLength(server.slaves) != 0 && server.repl_backlog == NULL)); + /* We can't have replicas attached and no backlog. */ + serverAssert(!(listLength(server.replicas) != 0 && server.repl_backlog == NULL)); /* Must install write handler for all replicas first before feeding * replication stream. */ prepareReplicasToWrite(); - /* Send SELECT command to every slave if needed. */ - if (dictid != -1 && server.slaveseldb != dictid) { + /* Send SELECT command to every replica if needed. */ + if (dictid != -1 && server.replicas_eldb != dictid) { robj *selectcmd; /* For a few DBs we have pre-computed SELECT command. */ @@ -472,7 +472,7 @@ void replicationFeedSlaves(int dictid, robj **argv, int argc) { if (dictid < 0 || dictid >= PROTO_SHARED_SELECT_CMDS) decrRefCount(selectcmd); - server.slaveseldb = dictid; + server.replicas_eldb = dictid; } /* Write the command to the replication buffer if any. */ @@ -532,12 +532,12 @@ void showLatestBacklog(void) { sdsfree(dump); } -/* This function is used in order to proxy what we receive from our master - * to our sub-slaves. */ +/* This function is used in order to proxy what we receive from our primary + * to our sub-replicas. */ #include -void replicationFeedStreamFromMasterStream(char *buf, size_t buflen) { - /* Debugging: this is handy to see the stream sent from master - * to slaves. Disabled with if(0). */ +void replicationFeedStreamFromPrimaryStream(char *buf, size_t buflen) { + /* Debugging: this is handy to see the stream sent from primary + * to replicas. Disabled with if(0). */ if (0) { printf("%zu:", buflen); for (size_t j = 0; j < buflen; j++) { @@ -546,8 +546,8 @@ void replicationFeedStreamFromMasterStream(char *buf, size_t buflen) { printf("\n"); } - /* There must be replication backlog if having attached slaves. */ - if (listLength(server.slaves)) serverAssert(server.repl_backlog != NULL); + /* There must be replication backlog if having attached replicas. */ + if (listLength(server.replicas)) serverAssert(server.repl_backlog != NULL); if (server.repl_backlog) { /* Must install write handler for all replicas first before feeding * replication stream. */ @@ -596,7 +596,7 @@ void replicationFeedMonitors(client *c, list *monitors, int dictid, robj **argv, decrRefCount(cmdobj); } -/* Feed the slave 'c' with the replication backlog starting from the +/* Feed the replica 'c' with the replication backlog starting from the * specified 'offset' up to the end of the backlog. */ long long addReplyReplicationBacklog(client *c, long long offset) { long long skip; @@ -663,46 +663,46 @@ long long addReplyReplicationBacklog(client *c, long long offset) { } /* Return the offset to provide as reply to the PSYNC command received - * from the slave. The returned value is only valid immediately after + * from the replica. The returned value is only valid immediately after * the BGSAVE process started and before executing any other command * from clients. */ long long getPsyncInitialOffset(void) { - return server.master_repl_offset; + return server.primary_repl_offset; } /* Send a FULLRESYNC reply in the specific case of a full resynchronization, - * as a side effect setup the slave for a full sync in different ways: + * as a side effect setup the replica for a full sync in different ways: * - * 1) Remember, into the slave client structure, the replication offset - * we sent here, so that if new slaves will later attach to the same + * 1) Remember, into the replica client structure, the replication offset + * we sent here, so that if new replicas will later attach to the same * background RDB saving process (by duplicating this client output - * buffer), we can get the right offset from this slave. - * 2) Set the replication state of the slave to WAIT_BGSAVE_END so that + * buffer), we can get the right offset from this replica. + * 2) Set the replication state of the replica to WAIT_BGSAVE_END so that * we start accumulating differences from this point. * 3) Force the replication stream to re-emit a SELECT statement so - * the new slave incremental differences will start selecting the + * the new replica incremental differences will start selecting the * right database number. * * Normally this function should be called immediately after a successful * BGSAVE for replication was started, or when there is one already in - * progress that we attached our slave to. */ -int replicationSetupSlaveForFullResync(client *slave, long long offset) { + * progress that we attached our replica to. */ +int replicationSetupReplicaForFullResync(client *replica, long long offset) { char buf[128]; int buflen; - slave->psync_initial_offset = offset; - slave->replstate = SLAVE_STATE_WAIT_BGSAVE_END; + replica->psync_initial_offset = offset; + replica->repl_state = REPLICA_STATE_WAIT_BGSAVE_END; /* We are going to accumulate the incremental changes for this - * slave as well. Set slaveseldb to -1 in order to force to re-emit + * replica as well. Set replicas_eldb to -1 in order to force to re-emit * a SELECT statement in the replication stream. */ - server.slaveseldb = -1; + server.replicas_eldb = -1; - /* Don't send this reply to slaves that approached us with + /* Don't send this reply to replicas that approached us with * the old SYNC command. */ - if (!(slave->flags & CLIENT_PRE_PSYNC)) { + if (!(replica->flags & CLIENT_PRE_PSYNC)) { buflen = snprintf(buf, sizeof(buf), "+FULLRESYNC %s %lld\r\n", server.replid, offset); - if (connWrite(slave->conn, buf, buflen) != buflen) { - freeClientAsync(slave); + if (connWrite(replica->conn, buf, buflen) != buflen) { + freeClientAsync(replica); return C_ERR; } } @@ -710,32 +710,32 @@ int replicationSetupSlaveForFullResync(client *slave, long long offset) { } /* This function handles the PSYNC command from the point of view of a - * master receiving a request for partial resynchronization. + * primary receiving a request for partial resynchronization. * * On success return C_OK, otherwise C_ERR is returned and we proceed * with the usual full resync. */ -int masterTryPartialResynchronization(client *c, long long psync_offset) { +int primaryTryPartialResynchronization(client *c, long long psync_offset) { long long psync_len; - char *master_replid = c->argv[1]->ptr; + char *primary_replid = c->argv[1]->ptr; char buf[128]; int buflen; - /* Is the replication ID of this master the same advertised by the wannabe - * slave via PSYNC? If the replication ID changed this master has a + /* Is the replication ID of this primary the same advertised by the wannabe + * replica via PSYNC? If the replication ID changed this primary has a * different replication history, and there is no way to continue. * * Note that there are two potentially valid replication IDs: the ID1 * and the ID2. The ID2 however is only valid up to a specific offset. */ - if (strcasecmp(master_replid, server.replid) && - (strcasecmp(master_replid, server.replid2) || psync_offset > server.second_replid_offset)) { - /* Replid "?" is used by slaves that want to force a full resync. */ - if (master_replid[0] != '?') { - if (strcasecmp(master_replid, server.replid) && strcasecmp(master_replid, server.replid2)) { + if (strcasecmp(primary_replid, server.replid) && + (strcasecmp(primary_replid, server.replid2) || psync_offset > server.second_replid_offset)) { + /* Replid "?" is used by replicas that want to force a full resync. */ + if (primary_replid[0] != '?') { + if (strcasecmp(primary_replid, server.replid) && strcasecmp(primary_replid, server.replid2)) { serverLog(LL_NOTICE, "Partial resynchronization not accepted: " "Replication ID mismatch (Replica asked for '%s', my " "replication IDs are '%s' and '%s')", - master_replid, server.replid, server.replid2); + primary_replid, server.replid, server.replid2); } else { serverLog(LL_NOTICE, "Partial resynchronization not accepted: " @@ -744,39 +744,39 @@ int masterTryPartialResynchronization(client *c, long long psync_offset) { psync_offset, server.second_replid_offset); } } else { - serverLog(LL_NOTICE, "Full resync requested by replica %s", replicationGetSlaveName(c)); + serverLog(LL_NOTICE, "Full resync requested by replica %s", replicationGetReplicaName(c)); } goto need_full_resync; } - /* We still have the data our slave is asking for? */ + /* We still have the data our replica is asking for? */ if (!server.repl_backlog || psync_offset < server.repl_backlog->offset || psync_offset > (server.repl_backlog->offset + server.repl_backlog->histlen)) { serverLog(LL_NOTICE, "Unable to partial resync with replica %s for lack of backlog (Replica request was: %lld).", - replicationGetSlaveName(c), psync_offset); - if (psync_offset > server.master_repl_offset) { - serverLog( - LL_WARNING, - "Warning: replica %s tried to PSYNC with an offset that is greater than the master replication offset.", - replicationGetSlaveName(c)); + replicationGetReplicaName(c), psync_offset); + if (psync_offset > server.primary_repl_offset) { + serverLog(LL_WARNING, + "Warning: replica %s tried to PSYNC with an offset that is greater than the primary replication " + "offset.", + replicationGetReplicaName(c)); } goto need_full_resync; } /* If we reached this point, we are able to perform a partial resync: - * 1) Set client state to make it a slave. + * 1) Set client state to make it a replica. * 2) Inform the client we can continue with +CONTINUE - * 3) Send the backlog data (from the offset to the end) to the slave. */ - c->flags |= CLIENT_SLAVE; - c->replstate = SLAVE_STATE_ONLINE; + * 3) Send the backlog data (from the offset to the end) to the replica. */ + c->flags |= CLIENT_REPLICA; + c->repl_state = REPLICA_STATE_ONLINE; c->repl_ack_time = server.unixtime; c->repl_start_cmd_stream_on_ack = 0; - listAddNodeTail(server.slaves, c); + listAddNodeTail(server.replicas, c); /* We can't use the connection buffers since they are used to accumulate * new commands at this stage. But we are sure the socket send buffer is * empty so this write will never fail actually. */ - if (c->slave_capa & SLAVE_CAPA_PSYNC2) { + if (c->replica_capa & REPLICA_CAPA_PSYNC2) { buflen = snprintf(buf, sizeof(buf), "+CONTINUE %s\r\n", server.replid); } else { buflen = snprintf(buf, sizeof(buf), "+CONTINUE\r\n"); @@ -789,12 +789,12 @@ int masterTryPartialResynchronization(client *c, long long psync_offset) { serverLog( LL_NOTICE, "Partial resynchronization request from %s accepted. Sending %lld bytes of backlog starting from offset %lld.", - replicationGetSlaveName(c), psync_len, psync_offset); - /* Note that we don't need to set the selected DB at server.slaveseldb - * to -1 to force the master to emit SELECT, since the slave already - * has this state from the previous connection with the master. */ + replicationGetReplicaName(c), psync_len, psync_offset); + /* Note that we don't need to set the selected DB at server.replicas_eldb + * to -1 to force the primary to emit SELECT, since the replica already + * has this state from the previous connection with the primary. */ - refreshGoodSlavesCount(); + refreshGoodReplicasCount(); /* Fire the replica change modules event. */ moduleFireServerEvent(VALKEYMODULE_EVENT_REPLICA_CHANGE, VALKEYMODULE_SUBEVENT_REPLICA_CHANGE_ONLINE, NULL); @@ -804,7 +804,7 @@ int masterTryPartialResynchronization(client *c, long long psync_offset) { need_full_resync: /* We need a full resync for some reason... Note that we can't * reply to PSYNC right now if a full SYNC is needed. The reply - * must include the master offset at the time the RDB file we transfer + * must include the primary offset at the time the RDB file we transfer * is generated, so we need to delay the reply to that moment. */ return C_ERR; } @@ -813,15 +813,15 @@ int masterTryPartialResynchronization(client *c, long long psync_offset) { * socket target depending on the configuration, and making sure that * the script cache is flushed before to start. * - * The mincapa argument is the bitwise AND among all the slaves capabilities - * of the slaves waiting for this BGSAVE, so represents the slave capabilities - * all the slaves support. Can be tested via SLAVE_CAPA_* macros. + * The mincapa argument is the bitwise AND among all the replicas capabilities + * of the replicas waiting for this BGSAVE, so represents the replica capabilities + * all the replicas support. Can be tested via REPLICA_CAPA_* macros. * * Side effects, other than starting a BGSAVE: * - * 1) Handle the slaves in WAIT_START state, by preparing them for a full + * 1) Handle the replicas in WAIT_START state, by preparing them for a full * sync if the BGSAVE was successfully started, or sending them an error - * and dropping them from the list of slaves. + * and dropping them from the list of replicas. * * 2) Flush the Lua scripting script cache if the BGSAVE was actually * started. @@ -833,22 +833,22 @@ int startBgsaveForReplication(int mincapa, int req) { listIter li; listNode *ln; - /* We use a socket target if slave can handle the EOF marker and we're configured to do diskless syncs. + /* We use a socket target if replica can handle the EOF marker and we're configured to do diskless syncs. * Note that in case we're creating a "filtered" RDB (functions-only, for example) we also force socket replication * to avoid overwriting the snapshot RDB file with filtered data. */ - socket_target = (server.repl_diskless_sync || req & SLAVE_REQ_RDB_MASK) && (mincapa & SLAVE_CAPA_EOF); + socket_target = (server.repl_diskless_sync || req & REPLICA_REQ_RDB_MASK) && (mincapa & REPLICA_CAPA_EOF); /* `SYNC` should have failed with error if we don't support socket and require a filter, assert this here */ - serverAssert(socket_target || !(req & SLAVE_REQ_RDB_MASK)); + serverAssert(socket_target || !(req & REPLICA_REQ_RDB_MASK)); serverLog(LL_NOTICE, "Starting BGSAVE for SYNC with target: %s", socket_target ? "replicas sockets" : "disk"); rdbSaveInfo rsi, *rsiptr; rsiptr = rdbPopulateSaveInfo(&rsi); /* Only do rdbSave* when rsiptr is not NULL, - * otherwise slave will miss repl-stream-db. */ + * otherwise replica will miss repl-stream-db. */ if (rsiptr) { if (socket_target) - retval = rdbSaveToSlavesSockets(req, rsiptr); + retval = rdbSaveToReplicasSockets(req, rsiptr); else { /* Keep the page cache since it'll get used soon */ retval = rdbSaveBackground(req, server.rdb_filename, rsiptr, RDBFLAGS_REPLICATION | RDBFLAGS_KEEP_CACHE); @@ -866,37 +866,37 @@ int startBgsaveForReplication(int mincapa, int req) { * the user enables it later with CONFIG SET, we are fine. */ if (retval == C_OK && !socket_target && server.rdb_del_sync_files) RDBGeneratedByReplication = 1; - /* If we failed to BGSAVE, remove the slaves waiting for a full - * resynchronization from the list of slaves, inform them with + /* If we failed to BGSAVE, remove the replicas waiting for a full + * resynchronization from the list of replicas, inform them with * an error about what happened, close the connection ASAP. */ if (retval == C_ERR) { serverLog(LL_WARNING, "BGSAVE for replication failed"); - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = ln->value; - - if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) { - slave->replstate = REPL_STATE_NONE; - slave->flags &= ~CLIENT_SLAVE; - listDelNode(server.slaves, ln); - addReplyError(slave, "BGSAVE failed, replication can't continue"); - slave->flags |= CLIENT_CLOSE_AFTER_REPLY; + client *replica = ln->value; + + if (replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_START) { + replica->repl_state = REPL_STATE_NONE; + replica->flags &= ~CLIENT_REPLICA; + listDelNode(server.replicas, ln); + addReplyError(replica, "BGSAVE failed, replication can't continue"); + replica->flags |= CLIENT_CLOSE_AFTER_REPLY; } } return retval; } - /* If the target is socket, rdbSaveToSlavesSockets() already setup - * the slaves for a full resync. Otherwise for disk target do it now.*/ + /* If the target is socket, rdbSaveToReplicasSockets() already setup + * the replicas for a full resync. Otherwise for disk target do it now.*/ if (!socket_target) { - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - client *slave = ln->value; + client *replica = ln->value; - if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) { - /* Check slave has the exact requirements */ - if (slave->slave_req != req) continue; - replicationSetupSlaveForFullResync(slave, getPsyncInitialOffset()); + if (replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_START) { + /* Check replica has the exact requirements */ + if (replica->replica_req != req) continue; + replicationSetupReplicaForFullResync(replica, getPsyncInitialOffset()); } } } @@ -906,23 +906,23 @@ int startBgsaveForReplication(int mincapa, int req) { /* SYNC and PSYNC command implementation. */ void syncCommand(client *c) { - /* ignore SYNC if already slave or in monitor mode */ - if (c->flags & CLIENT_SLAVE) return; + /* ignore SYNC if already replica or in monitor mode */ + if (c->flags & CLIENT_REPLICA) return; /* Check if this is a failover request to a replica with the same replid and - * become a master if so. */ + * become a primary if so. */ if (c->argc > 3 && !strcasecmp(c->argv[0]->ptr, "psync") && !strcasecmp(c->argv[3]->ptr, "failover")) { serverLog(LL_NOTICE, "Failover request received for replid %s.", (unsigned char *)c->argv[1]->ptr); - if (!server.masterhost) { + if (!server.primary_host) { addReplyError(c, "PSYNC FAILOVER can't be sent to a master."); return; } if (!strcasecmp(c->argv[1]->ptr, server.replid)) { if (server.cluster_enabled) { - clusterPromoteSelfToMaster(); + clusterPromoteSelfToPrimary(); } else { - replicationUnsetMaster(); + replicationUnsetPrimary(); } sds client = catClientInfoString(sdsempty(), c); serverLog(LL_NOTICE, "MASTER MODE enabled (failover request from '%s')", client); @@ -939,9 +939,9 @@ void syncCommand(client *c) { return; } - /* Refuse SYNC requests if we are a slave but the link with our master + /* Refuse SYNC requests if we are a replica but the link with our primary * is not ok... */ - if (server.masterhost && server.repl_state != REPL_STATE_CONNECTED) { + if (server.primary_host && server.repl_state != REPL_STATE_CONNECTED) { addReplyError(c, "-NOMASTERLINK Can't SYNC while not connected with my master"); return; } @@ -949,54 +949,54 @@ void syncCommand(client *c) { /* SYNC can't be issued when the server has pending data to send to * the client about already issued commands. We need a fresh reply * buffer registering the differences between the BGSAVE and the current - * dataset, so that we can copy to other slaves if needed. */ + * dataset, so that we can copy to other replicas if needed. */ if (clientHasPendingReplies(c)) { addReplyError(c, "SYNC and PSYNC are invalid with pending output"); return; } - /* Fail sync if slave doesn't support EOF capability but wants a filtered RDB. This is because we force filtered + /* Fail sync if replica doesn't support EOF capability but wants a filtered RDB. This is because we force filtered * RDB's to be generated over a socket and not through a file to avoid conflicts with the snapshot files. Forcing * use of a socket is handled, if needed, in `startBgsaveForReplication`. */ - if (c->slave_req & SLAVE_REQ_RDB_MASK && !(c->slave_capa & SLAVE_CAPA_EOF)) { + if (c->replica_req & REPLICA_REQ_RDB_MASK && !(c->replica_capa & REPLICA_CAPA_EOF)) { addReplyError(c, "Filtered replica requires EOF capability"); return; } - serverLog(LL_NOTICE, "Replica %s asks for synchronization", replicationGetSlaveName(c)); + serverLog(LL_NOTICE, "Replica %s asks for synchronization", replicationGetReplicaName(c)); /* Try a partial resynchronization if this is a PSYNC command. * If it fails, we continue with usual full resynchronization, however - * when this happens replicationSetupSlaveForFullResync will replied + * when this happens replicationSetupReplicaForFullResync will replied * with: * * +FULLRESYNC * - * So the slave knows the new replid and offset to try a PSYNC later - * if the connection with the master is lost. */ + * So the replica knows the new replid and offset to try a PSYNC later + * if the connection with the primary is lost. */ if (!strcasecmp(c->argv[0]->ptr, "psync")) { long long psync_offset; if (getLongLongFromObjectOrReply(c, c->argv[2], &psync_offset, NULL) != C_OK) { serverLog(LL_WARNING, "Replica %s asks for synchronization but with a wrong offset", - replicationGetSlaveName(c)); + replicationGetReplicaName(c)); return; } - if (masterTryPartialResynchronization(c, psync_offset) == C_OK) { + if (primaryTryPartialResynchronization(c, psync_offset) == C_OK) { server.stat_sync_partial_ok++; return; /* No full resync needed, return. */ } else { - char *master_replid = c->argv[1]->ptr; + char *primary_replid = c->argv[1]->ptr; /* Increment stats for failed PSYNCs, but only if the - * replid is not "?", as this is used by slaves to force a full + * replid is not "?", as this is used by replicas to force a full * resync on purpose when they are not able to partially * resync. */ - if (master_replid[0] != '?') server.stat_sync_partial_err++; + if (primary_replid[0] != '?') server.stat_sync_partial_err++; } } else { - /* If a slave uses SYNC, we are dealing with an old implementation - * of the replication protocol (like valkey-cli --slave). Flag the client + /* If a replica uses SYNC, we are dealing with an old implementation + * of the replication protocol (like valkey-cli --replica). Flag the client * so that we don't expect to receive REPLCONF ACK feedbacks. */ c->flags |= CLIENT_PRE_PSYNC; } @@ -1004,16 +1004,16 @@ void syncCommand(client *c) { /* Full resynchronization. */ server.stat_sync_full++; - /* Setup the slave as one waiting for BGSAVE to start. The following code - * paths will change the state if we handle the slave differently. */ - c->replstate = SLAVE_STATE_WAIT_BGSAVE_START; + /* Setup the replica as one waiting for BGSAVE to start. The following code + * paths will change the state if we handle the replica differently. */ + c->repl_state = REPLICA_STATE_WAIT_BGSAVE_START; if (server.repl_disable_tcp_nodelay) connDisableTcpNoDelay(c->conn); /* Non critical if it fails. */ c->repldbfd = -1; - c->flags |= CLIENT_SLAVE; - listAddNodeTail(server.slaves, c); + c->flags |= CLIENT_REPLICA; + listAddNodeTail(server.replicas, c); /* Create the replication backlog if needed. */ - if (listLength(server.slaves) == 1 && server.repl_backlog == NULL) { + if (listLength(server.replicas) == 1 && server.repl_backlog == NULL) { /* When we create the backlog from scratch, we always use a new * replication ID and clear the ID2, since there is no valid * past history. */ @@ -1029,30 +1029,31 @@ void syncCommand(client *c) { /* CASE 1: BGSAVE is in progress, with disk target. */ if (server.child_type == CHILD_TYPE_RDB && server.rdb_child_type == RDB_CHILD_TYPE_DISK) { /* Ok a background save is in progress. Let's check if it is a good - * one for replication, i.e. if there is another slave that is + * one for replication, i.e. if there is another replica that is * registering differences since the server forked to save. */ - client *slave; + client *replica; listNode *ln; listIter li; - listRewind(server.slaves, &li); + listRewind(server.replicas, &li); while ((ln = listNext(&li))) { - slave = ln->value; + replica = ln->value; /* If the client needs a buffer of commands, we can't use * a replica without replication buffer. */ - if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END && - (!(slave->flags & CLIENT_REPL_RDBONLY) || (c->flags & CLIENT_REPL_RDBONLY))) + if (replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_END && + (!(replica->flags & CLIENT_REPL_RDBONLY) || (c->flags & CLIENT_REPL_RDBONLY))) break; } - /* To attach this slave, we check that it has at least all the - * capabilities of the slave that triggered the current BGSAVE + /* To attach this replica, we check that it has at least all the + * capabilities of the replica that triggered the current BGSAVE * and its exact requirements. */ - if (ln && ((c->slave_capa & slave->slave_capa) == slave->slave_capa) && c->slave_req == slave->slave_req) { + if (ln && ((c->replica_capa & replica->replica_capa) == replica->replica_capa) && + c->replica_req == replica->replica_req) { /* Perfect, the server is already registering differences for - * another slave. Set the right state, and copy the buffer. + * another replica. Set the right state, and copy the buffer. * We don't copy buffer if clients don't want. */ - if (!(c->flags & CLIENT_REPL_RDBONLY)) copyReplicaOutputBuffer(c, slave); - replicationSetupSlaveForFullResync(c, slave->psync_initial_offset); + if (!(c->flags & CLIENT_REPL_RDBONLY)) copyReplicaOutputBuffer(c, replica); + replicationSetupReplicaForFullResync(c, replica->psync_initial_offset); serverLog(LL_NOTICE, "Waiting for end of BGSAVE for SYNC"); } else { /* No way, we need to wait for the next BGSAVE in order to @@ -1069,16 +1070,16 @@ void syncCommand(client *c) { /* CASE 3: There is no BGSAVE is in progress. */ } else { - if (server.repl_diskless_sync && (c->slave_capa & SLAVE_CAPA_EOF) && server.repl_diskless_sync_delay) { + if (server.repl_diskless_sync && (c->replica_capa & REPLICA_CAPA_EOF) && server.repl_diskless_sync_delay) { /* Diskless replication RDB child is created inside * replicationCron() since we want to delay its start a - * few seconds to wait for more slaves to arrive. */ + * few seconds to wait for more replicas to arrive. */ serverLog(LL_NOTICE, "Delay next BGSAVE for diskless SYNC"); } else { /* We don't have a BGSAVE in progress, let's start one. Diskless * or disk-based mode is determined by replica's capacity. */ if (!hasActiveChildProcess()) { - startBgsaveForReplication(c->slave_capa, c->slave_req); + startBgsaveForReplication(c->replica_capa, c->replica_req); } else { serverLog(LL_NOTICE, "No BGSAVE in progress, but another BG operation is active. " "BGSAVE for replication delayed"); @@ -1091,7 +1092,7 @@ void syncCommand(client *c) { /* REPLCONF