Potential Vulnerability in Update Sequence During Slot Migration
In the tryUpdateMigrationStatus logic, after a successful migration, the controller first updates the topology in the kvrocks cluster via SetSlot, then updates the etcd data using clusterStore.UpdateCluster. However, there appears to be a potential vulnerability here:
- If
SetSlotsucceeds but a network failure preventsUpdateClusterfrom completing (or worse, ifSetSlotpartially succeeds with some nodes updated and others failing), this could leave the kvrocks cluster version higher than the cluster version stored in etcd. - Even if another controller takes over from the failed one, it would be unable to execute new operations because subsequent "versions" issued by the controller would no longer exceed the version already in kvrocks.
To address this, I suggest reversing the order: update etcd first, then propagate the new topology to kvrocks.
As a side note, if this approach is adopted, the clusterx set slot command in kvrocks might become redundant, as we could fully update the post-migration topology using setnodes instead.
@RiversJin Thanks for your investigation, we did have this issue, and changing the order could mitigate it. Another enhancement would be allowed to update the store(ETCD) once the version in Kvrocks is higher than the controller.