This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks-controller.git


The following commit(s) were added to refs/heads/unstable by this push:
     new a47f5a0  Fix unable to promote the new master while sequence=0 during 
cluster shard failover (#377)
a47f5a0 is described below

commit a47f5a054b6d1c8e08e5c5b595b4747f8eda6f4c
Author: Kaustubh1204 <[email protected]>
AuthorDate: Tue Feb 10 07:46:30 2026 +0530

    Fix unable to promote the new master while sequence=0 during cluster shard 
failover (#377)
---
 store/cluster_shard.go | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/store/cluster_shard.go b/store/cluster_shard.go
index 8ae7a18..1181283 100644
--- a/store/cluster_shard.go
+++ b/store/cluster_shard.go
@@ -151,6 +151,18 @@ func (shard *Shard) removeNode(nodeID string) error {
 func (shard *Shard) getNewMasterNodeIndex(ctx context.Context, masterNodeIndex 
int, preferredNodeID string) int {
        newMasterNodeIndex := -1
        var newestOffset uint64
+
+       // Get master sequence to handle empty shard case (issue #366)
+       var masterSequence uint64
+       if masterNodeIndex >= 0 && masterNodeIndex < len(shard.Nodes) {
+               masterNode := shard.Nodes[masterNodeIndex]
+               if _, err := masterNode.GetClusterInfo(ctx); err == nil {
+                       if masterInfo, err := 
masterNode.GetClusterNodeInfo(ctx); err == nil {
+                               masterSequence = masterInfo.Sequence
+                       }
+               }
+       }
+
        for i, node := range shard.Nodes {
                // don't promote the current master node
                if i == masterNodeIndex {
@@ -176,12 +188,14 @@ func (shard *Shard) getNewMasterNodeIndex(ctx 
context.Context, masterNodeIndex i
                        ).Warn("Skip the node due to failed to get info of 
node")
                        continue
                }
-               if clusterNodeInfo.Role != RoleSlave || 
clusterNodeInfo.Sequence == 0 {
+               // Fix #366: allow sequence == 0 only when master sequence is 
also 0 (empty shard)
+               if clusterNodeInfo.Role != RoleSlave || 
(clusterNodeInfo.Sequence == 0 && masterSequence != 0) {
                        logger.Get().With(
                                zap.String("id", node.ID()),
                                zap.String("addr", node.Addr()),
                                zap.String("role", clusterNodeInfo.Role),
                                zap.Uint64("sequence", 
clusterNodeInfo.Sequence),
+                               zap.Uint64("master_sequence", masterSequence),
                        ).Warn("Skip the node due to role or sequence invalid")
                        continue
                }

Reply via email to