[BFTree] Add RangeIndex cluster migration#1731
Draft
tiagonapoli wants to merge 1 commit intodevfrom
Draft
Conversation
RangeIndex keys are backed by a live BfTree instance whose on-disk state
lives in a separate file (data.bftree) and whose main-store record is a
35-byte stub carrying a process-local TreeHandle. Shipping just the stub
bytes is not enough — the destination needs both the tree's on-disk
snapshot and a freshly-recovered local TreeHandle.
This change adds end-to-end migration for MIGRATE SLOTS, mirroring the
Vector Set migration pattern but transferring a GZip-compressed native
snapshot of the tree in chunks over the existing migration transport.
Wire format (piggybacks on TryWriteRecordSpan):
- New MigrationRecordSpanType.RangeIndexSnapshotChunk (4):
[int keyLen][key][int chunkIndex][int totalChunks][long uncompressedLen][int chunkLen][bytes]
- New MigrationRecordSpanType.RangeIndexStub (5) — finalizer:
[int keyLen][key][35-byte stub]
Source side:
- MigrateScanFunctions.Reader captures RangeIndex records (RecordType == 2)
onto MigrateOperation.RangeIndexes instead of the regular DiskLogRecord path.
- RangeIndexManager.SnapshotForMigration acquires the per-tree exclusive lock,
native-snapshots the tree to migrate.bftree, releases the lock, then
GZip-compresses to migrate.bftree.gz.
- MigrateSessionRangeIndex.TransmitRangeIndex streams 256 KB chunks followed
by the stub finalizer, deletes the source main-store key, and cleans up
temporary files.
- MigrateSessionSlots loops over migrateOperation.SelectMany(mo => mo.RangeIndexes)
after the Vector Set block.
Destination side:
- RangeIndexManager.HandleMigratedRangeIndexChunk appends chunks to
restore.bftree.gz (validates monotonic ordering per key).
- RangeIndexManager.HandleMigratedRangeIndexStub decompresses to data.bftree,
recovers a fresh BfTreeService via BfTreeService.RecoverFromSnapshot,
rewrites the stub's TreeHandle to the new local pointer, issues an
RICREATE RMW inline (using StorageSession.CompletePendingForSession),
and registers the tree on success.
- RespClusterMigrateCommands.NetworkClusterMigrate dispatches both new span
types; the stub branch also validates the key's hash slot is importing.
Not included in this PR (tracked separately):
- MIGRATE KEYS path — explicit per-key command requires a pre-probe to
detect RangeIndex keys before TransmitKeys. To be added once the SLOTS
path is validated end-to-end.
- AOF replication of migrated trees to destination replicas.
- Cluster migration integration tests.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RangeIndex keys are backed by a live BfTree instance whose on-disk state lives in a separate file (data.bftree) and whose main-store record is a 35-byte stub carrying a process-local TreeHandle. Shipping just the stub bytes is not enough — the destination needs both the tree's on-disk snapshot and a freshly-recovered local TreeHandle.
This change adds end-to-end migration for MIGRATE SLOTS, mirroring the Vector Set migration pattern but transferring a GZip-compressed native snapshot of the tree in chunks over the existing migration transport.
Wire format (piggybacks on TryWriteRecordSpan):
Source side:
Destination side:
Not included in this PR (tracked separately):