Skip to content

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

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

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

Conversation

@lizztheblizz
Copy link
Copy Markdown
Contributor

@lizztheblizz lizztheblizz commented May 27, 2026

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: USE ks/-2a; SHOW CREATE TABLE ks.table in pscale shell 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

  • pscale database dump <db> <branch> --keyspace <target> --shard <s> --schema-only returns target schema (with whatever the target actually has) instead of routing-rule-redirected source schema, against an active MoveTables-import target.
  • Without --shard / --replica / --rdonly, behavior is unchanged (SessionVars only has set workload=olap;).

🤖 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
Copy link
Copy Markdown
Contributor Author

Closing, reopening with cleaner description.

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