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 686b338  Marshal the value into the null value if the slot is not 
migrating (#346)
686b338 is described below

commit 686b338d3ae1e26754cad80a79f1334d51089ac2
Author: Lele Huang <[email protected]>
AuthorDate: Mon Sep 29 13:44:59 2025 +0800

    Marshal the value into the null value if the slot is not migrating (#346)
    
    ---------
    
    Co-authored-by: hulk <[email protected]>
---
 store/slot.go      |  8 +-------
 store/slot_test.go | 12 +++++-------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/store/slot.go b/store/slot.go
index 394ced5..ea3ec1a 100644
--- a/store/slot.go
+++ b/store/slot.go
@@ -227,13 +227,7 @@ func (s *MigratingSlot) UnmarshalJSON(data []byte) error {
 
 func (s *MigratingSlot) MarshalJSON() ([]byte, error) {
        if !s.IsMigrating {
-               // backwards compatibility. When we read from an old cluster 
that had `-1`
-               // denoting !isMigrating. The MigratingSlot field will not be 
nil. So when
-               // this field is marshal'd back into JSON format, we can keep 
it as it was
-               // which was `-1`.
-               // The only case this turns back to null is if a migration 
happens on this
-               // shard, and the function `ClearMigrateState()` is called on 
the shard.
-               return json.Marshal(NotMigratingInt)
+               return json.Marshal(nil)
        }
        return json.Marshal(s.String())
 }
diff --git a/store/slot_test.go b/store/slot_test.go
index 6226323..0403320 100644
--- a/store/slot_test.go
+++ b/store/slot_test.go
@@ -94,17 +94,15 @@ func TestMigratingSlot_MarshalUnmarshalJSON(t *testing.T) {
        migratingSlot = MigratingSlot{SlotRange: SlotRange{Start: 0, Stop: 0}, 
IsMigrating: false}
        migratingSlotBytes, err = json.Marshal(&migratingSlot)
        require.NoError(t, err)
-       err = json.Unmarshal(migratingSlotBytes, &migratingSlot)
-       require.NoError(t, err)
-       assert.Equal(t, MigratingSlot{SlotRange{Start: 0, Stop: 0}, false}, 
migratingSlot)
+       // null []byte equal
+       assert.Equal(t, "null", string(migratingSlotBytes))
 
        // same test as earlier, but checks that it resets the start and stop
        migratingSlot = MigratingSlot{SlotRange: SlotRange{Start: 5, Stop: 5}, 
IsMigrating: false}
        migratingSlotBytes, err = json.Marshal(&migratingSlot)
        require.NoError(t, err)
-       err = json.Unmarshal(migratingSlotBytes, &migratingSlot)
-       require.NoError(t, err)
-       assert.Equal(t, MigratingSlot{SlotRange{Start: 0, Stop: 0}, false}, 
migratingSlot, "expects start and stop to reset to 0")
+       // null []byte equal
+       assert.Equal(t, "null", string(migratingSlotBytes))
 }
 
 // TestMigratingSlot_MarshalJSON will checks the resulting string
@@ -122,7 +120,7 @@ func TestMigratingSlot_MarshalJSON(t *testing.T) {
        migratingSlot = MigratingSlot{SlotRange: SlotRange{Start: 5, Stop: 10}, 
IsMigrating: false}
        migratingSlotBytes, err = json.Marshal(&migratingSlot)
        require.NoError(t, err)
-       assert.Equal(t, `-1`, string(migratingSlotBytes))
+       assert.Equal(t, `null`, string(migratingSlotBytes))
 }
 
 func TestMigrateSlotRange_MarshalAndUnmarshalJSON(t *testing.T) {

Reply via email to