MCPcopy Create free account
hub / github.com/F-Stack/f-stack / verifyClusterConfigWithData

Function verifyClusterConfigWithData

app/redis-6.2.6/src/cluster.c:4058–4105  ·  view source on GitHub ↗

This function is called after the node startup in order to verify that data * loaded from disk is in agreement with the cluster configuration: * * 1) If we find keys about hash slots we have no responsibility for, the * following happens: * A) If no other node is in charge according to the current cluster * configuration, we add these slots to our node. * B) If according to o

Source from the content-addressed store, hash-verified

4056 * about desynchronizations between the data we have in memory and the
4057 * cluster configuration. */
4058int verifyClusterConfigWithData(void) {
4059 int j;
4060 int update_config = 0;
4061
4062 /* Return ASAP if a module disabled cluster redirections. In that case
4063 * every master can store keys about every possible hash slot. */
4064 if (server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_REDIRECTION)
4065 return C_OK;
4066
4067 /* If this node is a slave, don't perform the check at all as we
4068 * completely depend on the replication stream. */
4069 if (nodeIsSlave(myself)) return C_OK;
4070
4071 /* Make sure we only have keys in DB0. */
4072 for (j = 1; j < server.dbnum; j++) {
4073 if (dictSize(server.db[j].dict)) return C_ERR;
4074 }
4075
4076 /* Check that all the slots we see populated memory have a corresponding
4077 * entry in the cluster table. Otherwise fix the table. */
4078 for (j = 0; j < CLUSTER_SLOTS; j++) {
4079 if (!countKeysInSlot(j)) continue; /* No keys in this slot. */
4080 /* Check if we are assigned to this slot or if we are importing it.
4081 * In both cases check the next slot as the configuration makes
4082 * sense. */
4083 if (server.cluster->slots[j] == myself ||
4084 server.cluster->importing_slots_from[j] != NULL) continue;
4085
4086 /* If we are here data and cluster config don't agree, and we have
4087 * slot 'j' populated even if we are not importing it, nor we are
4088 * assigned to this slot. Fix this condition. */
4089
4090 update_config++;
4091 /* Case A: slot is unassigned. Take responsibility for it. */
4092 if (server.cluster->slots[j] == NULL) {
4093 serverLog(LL_WARNING, "I have keys for unassigned slot %d. "
4094 "Taking responsibility for it.",j);
4095 clusterAddSlot(myself,j);
4096 } else {
4097 serverLog(LL_WARNING, "I have keys for slot %d, but the slot is "
4098 "assigned to another node. "
4099 "Setting it to importing state.",j);
4100 server.cluster->importing_slots_from[j] = server.cluster->slots[j];
4101 }
4102 }
4103 if (update_config) clusterSaveConfigOrDie(1);
4104 return C_OK;
4105}
4106
4107/* -----------------------------------------------------------------------------
4108 * SLAVE nodes handling

Callers 1

mainFunction · 0.85

Calls 3

countKeysInSlotFunction · 0.85
clusterAddSlotFunction · 0.85
clusterSaveConfigOrDieFunction · 0.85

Tested by

no test coverage detected