Repository navigation
Generate correct slot information in cluster shards command on primary failure - #790
Conversation
Signed-off-by: Harkrishn Patro <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #790 +/- ##
============================================
+ Coverage 70.08% 70.42% +0.34%
============================================
Files 112 112
Lines 60587 61139 +552
============================================
+ Hits 42461 43058 +597
+ Misses 18126 18081 -45
|
enjoy-binbin
left a comment
There was a problem hiding this comment.
look like you forget to push the commit? there is only one commit that only contains the TCL code.
|
I think Hari just pushed a reproduction this pr and will update it with a fix once it's ready, |
Apologies for the confusion. Mentioned it on the issue, this is just the reproduction. Currently, the test checks if the slot array is empty for cluster shards response for a particular state and it passes (which is incorrect). Will push out the fix soon and update the test. |
|
ok, i take a quick look and i think the issue is in here: the listFirst, that is, n, is the failed primary, so when we can clusterNodeGetPrimary, it will return itself, so at last, the n is the failed primary, so in other node view, n's slot info is empty. i think we should try to look at a normal node like: /* Get the primary from the shard list. */
+clusterNode *clusterShardsGetPrimary(list *nodes) {
+ clusterNode *primary;
+ listIter li;
+ listRewind(nodes, &li);
+ for (listNode *ln = listNext(&li); ln != NULL; ln = listNext(&li)) {
+ primary = listNodeValue(ln);
+ /* Skip failed nodes because their state is stale. */
+ if (nodeFailed(primary)) continue;
+ }
+ return clusterNodeGetPrimary(primary);
+}
void addShardReplyForClusterShards(client *c, list *nodes) {
serverAssert(listLength(nodes) > 0);
- clusterNode *n = listNodeValue(listFirst(nodes));
+ clusterNode *n = clusterShardsGetPrimary(nodes);
addReplyMapLen(c, 2);
addReplyBulkCString(c, "slots");
- /* Use slot_info_pairs from the primary only */
- n = clusterNodeGetPrimary(n);
or another way is try to remove it from the shards list, but it looks like it will be troublesome. Or move the new primary node to the head +void clusterLinkNodeHeadInShard(clusterNode *node) {
+ sds s = sdsnewlen(node->shard_id, CLUSTER_NAMELEN);
+ dictEntry *de = dictFind(server.cluster->shards, s);
+ if (de != NULL) {
+ list *l = dictGetVal(de);
+ listNode *ln = listSearchKey(l, node);
+ if (ln != NULL) {
+ listUnlinkNode(l, ln);
+ listLinkNodeHead(l, ln);
+ }
+ }
+ sdsfree(s);
+}
@@ -2328,6 +2355,9 @@ void clusterSetNodeAsPrimary(clusterNode *n) {
n->flags |= CLUSTER_NODE_PRIMARY;
n->replicaof = NULL;
+ /* here, update the shard, link to head */
+ clusterLinkNodeHeadInShard(n);
+
/* Update config and state. */
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_UPDATE_STATE);
}@PingXie i think Ping can also take a look. |
|
I thought on similar line to get active primary (primary + healthy) for a given shard and use slot information of that node. However, I'm not sure if we should ever have multiple primaries in a shard. When we promote a node to primary for a shard, we should ideally mark the rest of the nodes in the shard as replica. However, we currently don't do it. What are your thoughts @madolson @enjoy-binbin @PingXie ? |
Signed-off-by: Harkrishn Patro <[email protected]>
Signed-off-by: Harkrishn Patro <[email protected]>
|
I don't think we should go look for a |
Your suggestion should work. However, the problem I've with the system in place is we aren't able to guarantee that there will be only one primary for a given shard. Maybe we can think about it separately. |
…rds output Signed-off-by: Harkrishn Patro <[email protected]>
Signed-off-by: Harkrishn Patro <[email protected]>
|
For the test failure, issue has been filled already #734. Unrelated to this PR. |
Agreed - I think #798 could lead to the "multi-primaries-in-a-shard" situation. I will work on a fix. |
|
PTAL @madolson / @enjoy-binbin / @PingXie |
Signed-off-by: Harkrishn Patro <[email protected]>
|
@PingXie PTAL |
|
Shall we merge this ? |
|
Merged. Next question - I think that we should backport it to 7.2 too. WDYT? |
Makes sense 👍 |
…y failure (valkey-io#790) Fix valkey-io#784 Prior to the change, `CLUSTER SHARDS` command processing might pick a failed primary node which won't have the slot coverage information and the slots `output` in turn would be empty. This change finds an appropriate node which has the slot coverage information served by a given shard and correctly displays it as part of `CLUSTER SHARDS` output. Before: ``` 1) 1) "slots" 2) (empty array) 3) "nodes" 4) 1) 1) "id" 2) "2936f22a490095a0a851b7956b0a88f2b67a5d44" ... 9) "role" 10) "master" ... 13) "health" 14) "fail" ``` After: ``` 1) 1) "slots" 2) 1) 0 2) 5461 3) "nodes" 4) 1) 1) "id" 2) "2936f22a490095a0a851b7956b0a88f2b67a5d44" ... 9) "role" 10) "master" ... 13) "health" 14) "fail" ``` --------- Signed-off-by: Harkrishn Patro <[email protected]>
…y failure (#790) Fix #784 Prior to the change, `CLUSTER SHARDS` command processing might pick a failed primary node which won't have the slot coverage information and the slots `output` in turn would be empty. This change finds an appropriate node which has the slot coverage information served by a given shard and correctly displays it as part of `CLUSTER SHARDS` output. Before: ``` 1) 1) "slots" 2) (empty array) 3) "nodes" 4) 1) 1) "id" 2) "2936f22a490095a0a851b7956b0a88f2b67a5d44" ... 9) "role" 10) "master" ... 13) "health" 14) "fail" ``` After: ``` 1) 1) "slots" 2) 1) 0 2) 5461 3) "nodes" 4) 1) 1) "id" 2) "2936f22a490095a0a851b7956b0a88f2b67a5d44" ... 9) "role" 10) "master" ... 13) "health" 14) "fail" ``` --------- Signed-off-by: Harkrishn Patro <[email protected]>
…y failure (valkey-io#790) Fix valkey-io#784 Prior to the change, `CLUSTER SHARDS` command processing might pick a failed primary node which won't have the slot coverage information and the slots `output` in turn would be empty. This change finds an appropriate node which has the slot coverage information served by a given shard and correctly displays it as part of `CLUSTER SHARDS` output. Before: ``` 1) 1) "slots" 2) (empty array) 3) "nodes" 4) 1) 1) "id" 2) "2936f22a490095a0a851b7956b0a88f2b67a5d44" ... 9) "role" 10) "master" ... 13) "health" 14) "fail" ``` After: ``` 1) 1) "slots" 2) 1) 0 2) 5461 3) "nodes" 4) 1) 1) "id" 2) "2936f22a490095a0a851b7956b0a88f2b67a5d44" ... 9) "role" 10) "master" ... 13) "health" 14) "fail" ``` --------- Signed-off-by: Harkrishn Patro <[email protected]>
…key-io#790) Run the existing CLUSTER SHARDS slot-information regressions in the default Tcl suite. This follow-up changes test coverage only. Server code and the existing regression expectations are unchanged. Backport-Source-PR: 790
Run the existing CLUSTER SHARDS slot-information regressions in the default Tcl suite. This follow-up changes test coverage only. Server code and the existing regression expectations are unchanged. Backport-Source-PR: 790
Fix #784
Prior to the change,
CLUSTER SHARDScommand processing might pick a failed primary node which won't have the slot coverage information and the slotsoutputin turn would be empty. This change finds an appropriate node which has the slot coverage information served by a given shard and correctly displays it as part ofCLUSTER SHARDSoutput.Before:
After: