Skip to content

Apply SessionVars to initPool so schema dumps honor --shard#1259

Open
lizztheblizz wants to merge 1 commit into
mainfrom
apply-session-vars-init-pool
Open

Apply SessionVars to initPool so schema dumps honor --shard#1259
lizztheblizz wants to merge 1 commit into
mainfrom
apply-session-vars-init-pool

Conversation

@lizztheblizz
Copy link
Copy Markdown
Contributor

What's broken

pscale database dump --schema-only --keyspace <target> --shard <s> against a MoveTables-import target keyspace returns the source keyspace's schema, not the target's. Routing rules redirect the fully-qualified SHOW CREATE TABLE <target>.<t> to the source despite the --shard flag being set.

Why

dumper.Run creates two pools:

  • initPool (line 92): no SessionVars. Used for SHOW DATABASES, SHOW TABLES FROM, view enumeration, AND dumpTableSchema.
  • per-database pool (line 149): gets cfg.SessionVars (including the USE keyspace/shard injected by --shard). Used for data-only dumps.

dumpTableSchema lives in initPool, so the USE keyspace/shard session pin never reaches the connection that issues SHOW CREATE TABLE. With no session pin, vtgate applies routing rules to the qualified table reference.

Verified empirically: in pscale shell, USE <target-keyspace>/<shard>; SHOW CREATE TABLE <target-keyspace>.<table> returns target schema as expected; routing-rule bypass works. The bug is solely that the dumper doesn't apply the session pin to its schema-fetch path.

Fix

One line: pass d.cfg.SessionVars to NewPool for initPool too.

Test plan

  • Existing dumper unit tests pass (go test ./internal/dumper/...)
  • pscale database dump --keyspace <target> --shard <s> --schema-only against an active MoveTables-import target returns target schema instead of routing-rule-redirected source schema (verified locally with a freshly-built binary)
  • Without --shard / --replica / --rdonly, behavior is essentially unchanged (SessionVars only has set workload=olap;, which doesn't affect schema-fetch result content)

🤖 Generated with Claude Code

dumpTableSchema runs against initPool, so it needs the same session
pin (USE keyspace/shard from --shard) that the per-database data pool
already gets. Without this, schema-only dumps of a MoveTables-import
target return the source's schema because vtgate falls back to
routing-rule resolution for fully-qualified SHOW CREATE TABLE.
@lizztheblizz lizztheblizz marked this pull request as ready for review May 27, 2026 12:17
@lizztheblizz lizztheblizz requested a review from a team as a code owner May 27, 2026 12:17
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.

1 participant