MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterManagerFixSlotsCoverage

Function clusterManagerFixSlotsCoverage

src/redis-cli-cpphelper.cpp:140–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140static int clusterManagerFixSlotsCoverage(char *all_slots) {
141 dictIterator *iter = nullptr;
142 int force_fix = config.cluster_manager_command.flags &
143 CLUSTER_MANAGER_CMD_FLAG_FIX_WITH_UNREACHABLE_MASTERS;
144
145 if (cluster_manager.unreachable_masters > 0 && !force_fix) {
146 clusterManagerLogWarn("*** Fixing slots coverage with %d unreachable masters is dangerous: redis-cli will assume that slots about masters that are not reachable are not covered, and will try to reassign them to the reachable nodes. This can cause data loss and is rarely what you want to do. If you really want to proceed use the --cluster-fix-with-unreachable-masters option.\n", cluster_manager.unreachable_masters);
147 exit(1);
148 }
149
150 /* we want explicit manual confirmation from users for all the fix cases */
151 int ignore_force = 1;
152
153 int i, fixed = 0;
154 list *none = NULL, *single = NULL, *multi = NULL;
155 clusterManagerLogInfo(">>> Fixing slots coverage...\n");
156 for (i = 0; i < CLUSTER_MANAGER_SLOTS; i++) {
157 int covered = all_slots[i];
158 if (!covered) {
159 sds slot = sdsfromlonglong((long long) i);
160 list *slot_nodes = listCreate();
161 sds slot_nodes_str = sdsempty();
162 listIter li;
163 listNode *ln;
164 listRewind(cluster_manager.nodes, &li);
165 while ((ln = listNext(&li)) != NULL) {
166 clusterManagerNode *n = (clusterManagerNode*) ln->value;
167 if (n->flags & CLUSTER_MANAGER_FLAG_SLAVE || n->replicate)
168 continue;
169 redisReply *reply = (redisReply*)CLUSTER_MANAGER_COMMAND(n,
170 "CLUSTER GETKEYSINSLOT %d %d", i, 1);
171 if (!clusterManagerCheckRedisReply(n, reply, NULL)) {
172 fixed = -1;
173 if (reply) freeReplyObject(reply);
174 goto cleanup;
175 }
176 assert(reply->type == REDIS_REPLY_ARRAY);
177 if (reply->elements > 0) {
178 listAddNodeTail(slot_nodes, n);
179 if (listLength(slot_nodes) > 1)
180 slot_nodes_str = sdscat(slot_nodes_str, ", ");
181 slot_nodes_str = sdscatfmt(slot_nodes_str,
182 "%s:%u", n->ip, n->port);
183 }
184 freeReplyObject(reply);
185 }
186 sdsfree(slot_nodes_str);
187 dictAdd(clusterManagerUncoveredSlots, slot, slot_nodes);
188 }
189 }
190
191 /* For every slot, take action depending on the actual condition:
192 * 1) No node has keys for this slot.
193 * 2) A single node has keys for this slot.
194 * 3) Multiple nodes have keys for this slot. */
195 none = listCreate();
196 single = listCreate();
197 multi = listCreate();

Callers 1

Calls 15

sdsfromlonglongFunction · 0.85
listCreateFunction · 0.85
sdsemptyFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
freeReplyObjectFunction · 0.85
listAddNodeTailFunction · 0.85
sdscatFunction · 0.85
sdscatfmtFunction · 0.85
sdsfreeFunction · 0.85

Tested by

no test coverage detected