git-hulk commented on code in PR #357:
URL: 
https://github.com/apache/kvrocks-controller/pull/357#discussion_r2396492594


##########
controller/cluster.go:
##########
@@ -338,48 +338,72 @@ func (c *ClusterChecker) tryUpdateMigrationStatus(ctx 
context.Context, clonedClu
                        ).Error("Failed to get the cluster info from the source 
node", zap.Error(err))
                        continue
                }
-               if 
!sourceNodeClusterInfo.MigratingSlot.Equal(shard.MigratingSlot.SlotRange) {
-                       log.Error("Mismatch migrating slot",
+
+               // If there is no migration information on the master node, you 
need to clear the migration information on the controller.
+               if sourceNodeClusterInfo.MigratingSlot == nil {
+                       log.Error("Mismatch migrating slot, no migrating info 
on node",
                                zap.Int("shard_index", i),
-                               zap.String("source_migrating_slot", 
sourceNodeClusterInfo.MigratingSlot.String()),
+                               zap.String("source_node", sourceNode.Addr()),
                                zap.String("migrating_slot", 
shard.MigratingSlot.String()),
                        )
+                       clonedCluster.Shards[i].ClearMigrateState()
+                       if err = c.clusterStore.UpdateCluster(ctx, c.namespace, 
clonedCluster); err != nil {
+                               log.Error("Failed to update the migrate state 
by UpdateCluster method", zap.Error(err))
+                               return
+                       }
+                       c.updateCluster(clonedCluster)
+                       continue
+               }
+               // If the migration information on the master node is 
inconsistent with the controller, you need to clear the migration information 
on the controller.
+               if sourceNodeClusterInfo.MigratingSlot != nil &&
+                       
!sourceNodeClusterInfo.MigratingSlot.Equal(shard.MigratingSlot.SlotRange) {
+                       log.Error("Mismatch migrating slot",
+                               zap.Int("shard_index", i),
+                               zap.String("source node cluster info 
migrating_slot", sourceNodeClusterInfo.MigratingSlot.String()),
+                               zap.String("controller migrating_slot", 
shard.MigratingSlot.String()),
+                       )
+                       clonedCluster.Shards[i].ClearMigrateState()
+                       if err = c.clusterStore.UpdateCluster(ctx, c.namespace, 
clonedCluster); err != nil {
+                               log.Error("Failed to update the migrate state 
by UpdateCluster method", zap.Error(err))
+                               return
+                       }
+                       c.updateCluster(clonedCluster)
                        continue
                }
+
                if shard.TargetShardIndex < 0 || shard.TargetShardIndex >= 
len(clonedCluster.Shards) {
                        log.Error("Invalid target shard index", 
zap.Int("index", shard.TargetShardIndex))
                        return
                }
 
+               migratingSlot := shard.MigratingSlot.String()
                switch sourceNodeClusterInfo.MigratingState {
                case "none", "start":
                        continue
                case "fail":
-                       migratingSlot := shard.MigratingSlot

Review Comment:
   Can we remove those following change



##########
controller/cluster.go:
##########
@@ -338,48 +338,72 @@ func (c *ClusterChecker) tryUpdateMigrationStatus(ctx 
context.Context, clonedClu
                        ).Error("Failed to get the cluster info from the source 
node", zap.Error(err))
                        continue
                }
-               if 
!sourceNodeClusterInfo.MigratingSlot.Equal(shard.MigratingSlot.SlotRange) {
-                       log.Error("Mismatch migrating slot",
+
+               // If there is no migration information on the master node, you 
need to clear the migration information on the controller.
+               if sourceNodeClusterInfo.MigratingSlot == nil {
+                       log.Error("Mismatch migrating slot, no migrating info 
on node",
                                zap.Int("shard_index", i),
-                               zap.String("source_migrating_slot", 
sourceNodeClusterInfo.MigratingSlot.String()),
+                               zap.String("source_node", sourceNode.Addr()),
                                zap.String("migrating_slot", 
shard.MigratingSlot.String()),
                        )
+                       clonedCluster.Shards[i].ClearMigrateState()
+                       if err = c.clusterStore.UpdateCluster(ctx, c.namespace, 
clonedCluster); err != nil {
+                               log.Error("Failed to update the migrate state 
by UpdateCluster method", zap.Error(err))
+                               return
+                       }
+                       c.updateCluster(clonedCluster)
+                       continue
+               }
+               // If the migration information on the master node is 
inconsistent with the controller, you need to clear the migration information 
on the controller.
+               if sourceNodeClusterInfo.MigratingSlot != nil &&
+                       
!sourceNodeClusterInfo.MigratingSlot.Equal(shard.MigratingSlot.SlotRange) {
+                       log.Error("Mismatch migrating slot",
+                               zap.Int("shard_index", i),
+                               zap.String("source node cluster info 
migrating_slot", sourceNodeClusterInfo.MigratingSlot.String()),
+                               zap.String("controller migrating_slot", 
shard.MigratingSlot.String()),
+                       )
+                       clonedCluster.Shards[i].ClearMigrateState()
+                       if err = c.clusterStore.UpdateCluster(ctx, c.namespace, 
clonedCluster); err != nil {
+                               log.Error("Failed to update the migrate state 
by UpdateCluster method", zap.Error(err))
+                               return
+                       }
+                       c.updateCluster(clonedCluster)
                        continue
                }
+
                if shard.TargetShardIndex < 0 || shard.TargetShardIndex >= 
len(clonedCluster.Shards) {
                        log.Error("Invalid target shard index", 
zap.Int("index", shard.TargetShardIndex))
                        return
                }
 
+               migratingSlot := shard.MigratingSlot.String()
                switch sourceNodeClusterInfo.MigratingState {
                case "none", "start":
                        continue
                case "fail":
-                       migratingSlot := shard.MigratingSlot

Review Comment:
   Can we remove those following change



##########
controller/cluster.go:
##########
@@ -338,48 +338,72 @@ func (c *ClusterChecker) tryUpdateMigrationStatus(ctx 
context.Context, clonedClu
                        ).Error("Failed to get the cluster info from the source 
node", zap.Error(err))
                        continue
                }
-               if 
!sourceNodeClusterInfo.MigratingSlot.Equal(shard.MigratingSlot.SlotRange) {
-                       log.Error("Mismatch migrating slot",
+
+               // If there is no migration information on the master node, you 
need to clear the migration information on the controller.
+               if sourceNodeClusterInfo.MigratingSlot == nil {

Review Comment:
   I think we can merge this block into the next `if` condition, because the 
behavior is the same.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to