bseto commented on code in PR #308:
URL:
https://github.com/apache/kvrocks-controller/pull/308#discussion_r2083107747
##########
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:
maybe we add a new state (with a function) to SlotRange where start = -1 &&
stop = -1 means it's not migrating.
So we'd do something like
```go
if shard.MigratingSlot != nil && !shard.MigratingSlot.IsMigrating() {
migratingStatus = fmt.Sprintf("%s --> %d", shard.MigratingSlot,
shard.TargetShardIndex)
}
...
```
https://github.com/apache/kvrocks-controller/blob/unstable/cmd/client/command/helper.go#L54
We'd have to do this anywhere we're currently checking `if
shard.MigratingSlot != nil`
And here in this unmarshal, if we find it's `-1`, we set `start` and `stop`
to `-1`
--
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]