apache / apache/kvrocks

migrate-type redis-command: complex-key sub-field migration produces MOVED <wrong-slot>

Open
#3,498 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
4.4k
Forks
658
Avg merge
1d 20h
Merged PRs (30d)
10

Description

## Summary

With `migrate-type redis-command`, migrating a slot that contains a hash
key whose name has a `{tag}` aborts mid-stream:

```
[I][slot_migrate.cc:373] The key ij/staging/{N//} successfully migrated
[E][slot_migrate.cc:203] Failed to send snapshot of slot(s) .
Error: failed to migrate a key ij/staging/{N//}:101:
failed to migrate complex key: failed to send commands to restore a key:
wrong response from the destination node:
got invalid response of length 61: -MOVED :
```

The slot number returned in the `MOVED` reply is **different** from
`CLUSTER KEYSLOT ` for the same key (we saw parent=5466 and the
reported MOVED=5465). The destination is computing the slot from an
encoded sub-key buffer that does not preserve the `{tag}` hashtag, so
the destination's command dispatcher believes that sub-key belongs to a
different slot it does not own → MOVED, abort.

## Workaround

`migrate-type raw-key-value` transfers each key as a RocksDB blob and
does not decompose complex keys, so the sub-key hashing path is never
exercised. The same migration that fails with `redis-command` completes
in seconds with `raw-key-value`.

We recommend documenting `raw-key-value` as the preferred type for
production slot migration until the `redis-command` path is fixed.

## Repro (vanilla setup)

1. Two-shard cluster, `migrate-type redis-command` (current default).
2. Insert a hash with a tag: `HSET ij/staging/{T1}:101 f1 v1 f2 v2`.
3. Trigger slot migration that includes the slot of `{T1}`.
4. Migration aborts with the MOVED error above.

## Versions

- Apache Kvrocks 2.15.0

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the redis-command migration path and the slot_migrate.cc locations shown in the error, then reproduce the two-shard case with a hash key containing a {T1} tag. Trace how complex-key sub-keys are encoded and how the destination computes their slot. Done means the redis-command migration completes without MOVED for tagged hash keys; compare with raw-key-value as the workaround baseline.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, redis
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.