Skip to content

restore: support keyspace rename via --keyspace-mapping flag - #4811

Open
tarzanek with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-keyspace-rename-restore
Open

restore: support keyspace rename via --keyspace-mapping flag#4811
tarzanek with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-keyspace-rename-restore

Conversation

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Adds support for restoring backup data into a differently-named keyspace in the target cluster — a common use case for audits, diffs, and side-by-side comparisons.

Changes

Model / core logic

  • Target.KeyspaceMappings map[string]string (json:"keyspace_mapping,omitempty") — source→target keyspace pairs; absent from JSON when nil, preserving full backward compatibility
  • Target.TargetKeyspace(sourceKs string) string — returns mapped name or identity (nil-safe map lookup)
  • initUnits: stores Unit.Keyspace as the target keyspace so the entire downstream pipeline (tombstone GC, compaction, load-and-stream, repair, progress tracking) stays consistent without any special-casing
  • createRemoteDirWorkloads: applies TargetKeyspace when filtering units and constructing TableName for batches, so batch.Keyspace carries the target name into all restore operations
  • validateKeyspaceMappings (called from initTarget only when mappings are present): ensures every target keyspace exists in the cluster and that no two sources map to the same target

Behavior when flag is omitted
TargetKeyspace is an identity function when no mapping is set — all code paths are functionally identical to the pre-feature implementation. TestValidateProperties explicitly covers nil, empty, and absent mapping cases.

CLI
New --keyspace-mapping flag on sctool restore, same "src=dst,..." syntax as --dc-mapping. Immutable after task creation (consistent with other core flags). The --keyspace filter continues to reference source keyspace names.

Example

sctool restore \
  --cluster prod \
  --location s3:my-bucket \
  --snapshot-tag sm_20250101000000UTC \
  --restore-tables \
  --keyspace "ks_prod.*" \
  --keyspace-mapping "ks_prod=ks_audit"

Restores all tables from ks_prod in the backup into ks_audit in the target cluster. The target keyspace must already exist before the restore starts.


Please make sure that:

  • Code is split to commits that address a single change
  • Commit messages are informative
  • Commit titles have module prefix
  • Commit titles have issue nr. suffix

@tarzanek

tarzanek commented Apr 7, 2026

Copy link
Copy Markdown

@Michal-Leszczynski can you have a look? ev. we can continue my agent session to add any changes needed from review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants