bseto commented on code in PR #308:
URL: 
https://github.com/apache/kvrocks-controller/pull/308#discussion_r2083106008


##########
store/slot.go:
##########
@@ -91,15 +91,30 @@ func (slotRange *SlotRange) MarshalJSON() ([]byte, error) {
 }
 
 func (slotRange *SlotRange) UnmarshalJSON(data []byte) error {
-       var slotsString string
+       var slotsString any
        if err := json.Unmarshal(data, &slotsString); err != nil {
                return err
        }
-       slotObject, err := ParseSlotRange(slotsString)
-       if err != nil {
-               return err
+       switch t := slotsString.(type) {
+       case string:
+               slotObject, err := ParseSlotRange(t)
+               if err != nil {
+                       return err
+               }
+               *slotRange = *slotObject
+       case float64:
+               // We use integer to represent the slot because we don't 
support the slot range
+               // in the past. So we need to support the integer type for 
backward compatibility.
+               // But the number in JSON is float64, so we need to convert it 
to int here.
+               if t < MinSlotID || t > MaxSlotID {
+                       return ErrSlotOutOfRange

Review Comment:
   Tried the following:
   
   1. With old commit (before slotRange), create cluster
   2. swap to new controller and it takes in `migrating_slot: -1` 
   
   but when the `-1` enters, we get the `ErrSlotOutOfRange`
   
   It's hard to set `SlotRange` to be nil from within this function though...



-- 
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