Skip to content
8 changes: 1 addition & 7 deletions store/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
12 changes: 5 additions & 7 deletions store/slot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Loading