Repository navigation
fix: silently omitted __mo_ user tables and cross-tenant database confusion in dumps - #66
Conversation
…o_ tables #30562: getTables dropped every table whose name starts with __mo_ or %!% client-side, silently omitting legally created user tables from a dump that still reported MODUMP SUCCESS. Move the filtering into the catalog query with the same predicates the server's SHOW TABLES uses (__mo_index_ index tables, mo_increment_columns, __mo_account_lock, relkind partition and temporary_table, plus the __mo_tmp_<32hex>_ physical temporary-table name), so user tables named __mo_... or %!%... are dumped while real internal helpers stay hidden. Explicit -tbl requests for a user __mo_ table now work too. #30579: with a same-named database in the sys account and another tenant, the default dump saw rows of every account in mo_catalog.mo_database and either failed with "database not exists" or exported another tenant's data. Scope the catalog queries to the connected account, mirroring SHOW DATABASES / SHOW TABLES visibility: current_account_id(), with the mo_catalog database row and the mo_database / mo_tables / mo_columns metadata tables staying reachable. -sys keeps its account_id = 0 behavior. Dumping a database owned by another tenant now fails fast instead of leaking that tenant's data.
…catalog Review of the previous round found two P1 silent-omission regressions in the hidden-object predicates: 1. `not like '__mo_index_%'` used '_' as a single-character LIKE wildcard, silently dropping ordinary tables such as demo_index_data while still reporting MODUMP SUCCESS (and making `-tbl demo_index_data` fail with not exists). Replace the name guess with the object metadata: hidden index tables carry relkind 'i' (catalog.SystemIndexRel, written by the server since MO v3.0). A literal-escaped LIKE would still be a name guess and would swallow a user table legally named __mo_index_data, so the LIKE is removed entirely. 2. `relname != 'mo_increment_columns'` applied globally by name and silently deleted same-named user tables/views in ordinary databases. mo_increment_columns and __mo_account_lock only exist in mo_catalog, so the exclusion is appended only when dumping that catalog. Reproduction also showed MO records colliding names (mo_increment_columns, __mo_index_data) with an empty relkind on the current build: those objects now fail the dump loudly (exit 1, unsupported table type) instead of vanishing behind a success marker, and they are exported normally wherever the server classifies them as ordinary 'r' objects.
… gate
Review rounds 2 and 3: relkind='i' (or any relkind enumeration) cannot
identify all hidden index tables, so whole-database dumps failed loudly
on modern clusters and lost compatibility on old ones:
- R3 (P1): fulltext helpers carry relkind 'fulltext', IVF-FLAT helpers
carry per-role kinds 'metadata'/'centroids'/'entries', HNSW uses its
own role names; with the previous literal 'i' predicate these rows
reached the export switch and aborted every dump of the database
(SQL and CSV, with or without -no-data). A future index algorithm
would fail the same way.
- R4 (P2): on MO v1.2.4 the unique/secondary hidden rows carry an
empty relkind, so the same predicate made indexed databases
undumpable on old clusters, regressing the base tool.
Replace the kind-only predicate with a compound gate:
relname like '\_\_mo\_index\_%' and relkind not in ('r','v','e')
- the name gate matches the literal __mo_index_ prefix (underscores
escaped because '_' is a single-character LIKE wildcard that
previously swallowed ordinary tables such as demo_index_data);
every index helper since MO v1.0 is named with this prefix, and the
backslash escape is supported by the LIKE implementation of all
server versions back to v1.2.4 (verified in-tree);
- the kind gate exempts exactly the relkinds the export switch can
emit (r/v/e): a user object legally named __mo_index_<anything>
with a dumpable kind is still dumped, while every helper kind --
'i', 'fulltext', 'metadata', 'centroids', 'entries', '' and any
future plugin kind -- stays hidden without another mo-dump change.
mo_indexes-based identification was considered and rejected: it is
complete on current clusters (all IVF-FLAT tables are registered) but
the column was renamed (v1.2.4 vec_index_table vs current
index_table_name), so a single query cannot serve both eras without a
probe-and-fallback layer.
Validated on a fresh local MO: an ixt database with unique, secondary,
fulltext and IVF-FLAT indexes dumps with exit 0, all four user tables
with data, zero helper rows leaked; the pre-v3.0 shape (empty relkind
plus index name) is excluded; demo_index_data (R1) and the previous
issue scenarios (dump+restore closure, tenant matrix, live temporary
tables, CSV) stay green. The SQL-contract unit tests assert the new
compound predicate; removing the relkind gate fails the suite.
…y-relkind user tables Review round 4 found the compound name+kind gate still allowed a silent omission: after a rename or a restore into a colliding name such as __mo_index_renamed, the server records the table with an empty relkind, the kind gate swallowed it, and the next backup again reported MODUMP SUCCESS without the table (base comparison in review: previous revision failed loudly here instead). Adding to that, the review disproved the round-3 claim that mo_indexes used a different column name on v1.2.4: MoCatalogMoIndexesDDL in v1.2.4 already declares index_table_name, the same column the current release uses, so the association route works across every supported version. - getTables now identifies hidden index helpers by their registration: `relname not in (select index_table_name from mo_catalog.mo_indexes where index_table_name is not null and index_table_name <> '')`. Name and relkind shortcuts are gone entirely; anything not registered is dump payload, so unregistered helpers or new algorithm kinds fail loudly with not-supported instead of silently vanishing. - dumpData treats an empty relkind as an ordinary table: the server only blanks the kind of colliding CREATE TABLE names while the object remains a fully usable table (SHOW CREATE TABLE and SELECT verified), so the dump/restore cycle converges for such names instead of breaking the whole database backup. End-to-end on a fresh local MO the four-step cycle now closes: rename a table to __mo_index_renamed, dump, restore (relkind becomes ''), second dump contains DDL and rows, second restore has all data. The round-2 index database (unique, secondary, fulltext, IVF-FLAT) dumps with exit 0 and no helper rows; an ordinary database with a table renamed to mo_increment_columns exports the colliding table and its data; demo_index_data, the #30562/#30579 scenarios, live temporary tables and CSV mode stay green. New unit tests assert the registered- name query and that the empty kind exports while an unknown kind still fails loudly; removing the mo_indexes predicate fails the suite.
…ocument privileges Review round 5 (REQUEST_CHANGES) items: 1. Cross-database name collision (P1): the mo_indexes subquery compared table names globally, so a helper registered for one database could swallow a same-named user table of another database. The lookup is now joined through mo_catalog.mo_database with the datname and the same account scoping used by getDatabaseType, so only helpers registered for the dumped database are excluded. Verified end to end: a user table named exactly like another database's hidden index table is dumped with its data, while that database's own dump still excludes the helper. 2. Unrestorable "successful" backup on old clusters (P1): on MO v1.2.4 the SHOW CREATE TABLE output for empty-relkind tables (e.g. a table restored under a colliding __mo_index_* or helper name) lacks the statement head, and the empty-kind branch emitted that fragment behind a MODUMP SUCCESS marker, producing a dump whose second restore fails. getCreateTable now requires a "CREATE " statement head (the external-table CREATE EXTERNAL TABLE shape stays valid) and fails loudly with an explicit error when the server returns a fragment. On clusters where the output is complete the round-4 rename/restore cycle keeps converging; on v1.2.4 it degrades to a loud error instead of a silent data loss. 3. Added mo_indexes SELECT requirement (P2): accounts that dump must now read mo_catalog.mo_indexes in addition to mo_catalog.mo_database and mo_catalog.mo_tables. There is no reliable fallback (name- and kind-based identification were both proven to silently drop user objects in earlier rounds), so the requirement is documented in the README with the exact GRANT statements, and a missing grant surfaces at the first catalog query as an explicit MySQL privilege error. Tenant admin accounts dump unchanged out of the box (verified). Re-validated: full local-MO matrix — cross-database collision (new), index database with unique/secondary/fulltext/IVFFLAT, colliding user tables (mo_increment_columns, __mo_index_renamed rename cycle with data), #30562 restore closure, #30579 tenant matrix, live temporary tables, CSV. New unit tests for the scoped subquery and the SHOW CREATE head validation; SQL-contract suite updated; gofmt/vet clean.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3f4ddb07c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
PR review (inline, round 5): the '^__mo_tmp_[0-9a-f]{32}_' regexp was
the last remaining name-based identification. A persistent user table
legally named (or renamed to) that shape was silently omitted from
full dumps that still printed MODUMP SUCCESS, and an explicit -tbl
request reported it as nonexistent — the exact silent-loss class the
change set exists to eliminate.
Temporary objects are now identified by metadata only:
- current clusters write relkind 'temporary_table' (kept predicate);
- v4.0/v4.1 interim releases carried relkind 'r' on the backing rows
with no distinguishing metadata. There the dump stays complete: a
live backing table surfaces as a loud error (the getCreateTable
CREATE-head guard also rejects degraded SHOW CREATE output) or as
visible rows, never as a silently dropped user table.
Verified end to end on a fresh local MO: a persistent table named
__mo_tmp_0123456789abcdef0123456789abcdef_user dumps with its data
both in full-database and explicit -tbl mode, while a live session
temporary table in the same database is still excluded via its
relkind. The #30562 restore closure, the index-helper database,
#30579 tenant matrix and CSV mode stay green.
…e (conflicts resolved) - getTables/getDatabaseType keep the account scoping, mo_indexes per-database registration and relkind predicates from issue-30562 on top of the parameterized (?, args) shape and the internal catalog wire-value package adopted by mo/main. - internal/catalog gains MO_CATALOG and MOAutoIncrTable. - Test expectations updated to the parameterized SQL and WithArgs double-database binding; hidden-helper predicates applied in every mock that exercises getTables/getDatabaseType.
…tatement Review round 6 (REQUEST_CHANGES): on MO v4.0.x/v4.1.x the session temporary backing tables enter mo_catalog.mo_tables with relkind 'r' (written through the ordinary-table path), so after the round-5 name regexp removal they were dumped as if they were ordinary tables: another session's temporary data landed in the backup, restoring permanently materialized it, and re-dumps kept the rows. The identification comes from the catalog metadata, not the name: buildTableDefinition on those releases stores the user's original DDL (GetRootSql) in rel_createsql, so every temporary backing row's root statement starts with CREATE TEMPORARY TABLE while persistent tables — including user tables legally named with the __mo_tmp_<32hex>_ shape — start with CREATE TABLE. The new predicate is and not (lower(coalesce(rel_createsql, '')) like 'create temporary%') (coalesce keeps NULL/empty createsql rows visible, lower tolerates the DDL keyword casing). On current clusters the relkind 'temporary_table' predicate stays as the primary filter and both agree: verified on a live server, a session temporary table's rel_createsql also starts with CREATE TEMPORARY, and the predicate is a second line of defense for exactly the mixed-version upgrade window this cluster-reading tool supports. Validated end-to-end on a fresh local MO: a persistent user table named __mo_tmp_0123456789abcdef0123456789abcdef_user keeps exporting with data (round-5 regression stays fixed), a live session temporary table in the same database is excluded, the #30562 + view + index database restores with identical objects and rows, the #30579 tenant matrix and CSV mode stay green. SQL-contract tests assert the new predicate; removing it fails the suite.
…finitions Review rounds 7-8 (REQUEST_CHANGES): 1. A batched request such as `CREATE TEMPORARY ...; CREATE TABLE persistent ...` writes the whole COM_QUERY into rel_createsql, so the previous `like 'create temporary%'` prefix check silently omitted the permanent table from dumps that still reported success. 2. Comments, extra whitespace or non-leading positions of the real temporary DDL bypassed the same prefix check, so v4.0/v4.1 backing rows were dumped and their session data got permanently materialized on restore. Both follow from prefix matching being structurally unable to answer "which CREATE statement in the request owns this row". The classifier now mirrors the server's mo_is_legacy_temporary_table: statements are split on unquoted semicolons, the CREATE TABLE grammar (TEMPORARY, IF NOT EXISTS, optional schema) is tokenized decoration-agnostically, and classification follows the exact statement/name relation: - a permanent statement whose (optionally qualified) name equals the physical row name proves the row permanent and wins over any matching temporary alias elsewhere in the request — the R12 fix; - a temporary statement naming the logical alias recovered from the physical name (only __mo_tmp_<32hex>_<db>_<alias> shapes pay this cost) classifies the row as a legacy temporary — the R11 fix — unless extra_info records a rename, or nothing matches, in which case classification fails open and the row stays dumpable. Importing the server's own parser was rejected because it drags the vectorindex CGo dependency (usearch headers) into this client build; the tokenizer reimplements the same observable behavior with zero new dependencies, and the server's own test vectors are ported to keep the equivalence observable. 3. The persisted-view-definition reader (bounded by #30579 review) now scopes the query to the connected account: a sys-tenant dump of a database whose view also exists in another tenant no longer aborts with "duplicate persisted definition" (verified end to end: sys default, tenant and -sys all dump the correct rows separately). All tests migrated to the parameterized four-column catalog query and the account-scoped view query; 15 new classification unit tests; full suite, vet, gofmt and a fresh-cluster end-to-end pass (R13 matrix, R9 persistent tmp-shaped table, live temporary table, #30562 restore closure, CSV) are green.
….2.4 Review round 9 (4 P1, 1 P2). The client-side reimplementation of the server classifier kept accumulating semantic defects across review rounds (rename metadata absent on v4.1.6, comments inside qualified names, quoted keywords, executable /*!*/ comments, USE-context misattribution, empty-kind temporary index rows), and each fix exposed another: reimplementing a parser with a tokenizer is structurally unable to keep up. The classification is now sourced from the two authorities that actually own the semantics: - Current clusters: dumpData probes mo_is_legacy_temporary_table once per connection; when the function exists the getTables query carries `and not mo_is_legacy_temporary_table(relkind, relname, reldatabase, coalesce(rel_createsql, ''), coalesce(extra_info, ''))`. Every classification subtlety — rename metadata, batched requests, comment decoration, qualified identities — is the server parser's own behavior, workload the client must not reimplement. - Clusters without the function (v4.0/v4.1 and older): the fallback predicate reproduces exactly what those servers' own SHOW TABLES statements used — a `__mo_tmp_<32hex>_` shape rule over ordinary or empty relkind. Temporary backing rows and index rows are excluded (covering the empty-kind case); persistent tables named with the shape follow the same visibility those servers themselves enforced. Precise per-statement classification on such rows is not obtainable from any metadata they record. - v1.2.4 is dumpable again: the client selects only relname and relkind from mo_tables (the extra_info column does not exist there — review's P2 — and rel_createsql/extra_info are only referenced inside the server-executed function predicate on clusters that have it). Verification on a fresh current-cluster build: the probe runs and the function predicate is exercised end to end (persistent __mo_tmp_-shaped user tables keep dumping with data, live session temporary tables stay excluded, #30562-with-view restore closure, #30579 tenant matrix, CSV); the fallback predicate's SQL is server-parseable (regexp_like shape + empty-kind terms executed directly); the whole mock suite moved back to the two-column query with the two-state predicate (new server-classifier case), a negative check removing the fallback predicate fails the suite, gofmt/vet clean, full suite green.
…nestly Review round 10 (2 P1): 1. The fallback shape regex silently dropped legally named persistent __mo_tmp_<32hex>_* tables on clusters without the classifier (v1.2.4, v4.1.6): the dump still reported success and the restore lost the tables. The fallback no longer excludes anything — the shape rows reach the client, and getTables aborts the dump with a clear error naming the row and the remedies (explicit -tbl, rename, cleanup of expired session tables, or running against a v4.2+ cluster) unless the user selected the row explicitly with -tbl: no silent omission, no guessed "success". 2. A single injected probe error downgraded functioning clusters into the fill-in fallback on every request that followed. The probe now classifies its failure instead of swallowing it: only the server's own unknown-function answer — measured live as "ERROR 20105 (HY000): not supported: function or operator '<name>'" (moerr.NotSupported, uniform from v1.2 through current releases) plus the stock-MySQL 1305 shape — legitimately downgrades; any other error, including driver row errors, aborts the dump. (The probe also drives row iteration before consulting Err(): database/sql only surfaces driver row errors to Err() after Next() has touched them.) Verified: probe paths covered by dedicated unit tests (present / unknown-function downgrade / injected error aborts / row-error aborts); round-10 ambiguity cases (default abort, -tbl exemption, empty-kind abort) and the round-9 classifier predicate case assert the generated SQL; the full dumpData-driven mock suite now arms exactly one probe expectation per dump run; negative check — removing the ambiguity guard fails the suite. End-to-end on a current cluster: probe runs, the persistent __mo_tmp_-shaped table dumps with data in whole-database and explicit -tbl modes, live session temporary tables stay excluded, and the unknown-function error idiom was captured from a real server run to pin isUnknownFunctionErr.
… path Review round 11 (3 P1): the server-side mo_is_legacy_temporary_table predicate — whatever the client does with its answer — cannot separate the three newly reproduced failure modes: - a permanent table renamed before the upgrade is misclassified as a temporary row (its upgrade-era renames carry no OldName metadata); - empty-kind temporary index rows never pass the function's relkind gate, so their session data reached the dump and materialized permanently on restore; - USE-qualified batches make a foreign database's bare-name CREATE statement "prove" the row permanent, again leaking session data. Since every input the classifier consults is also observable by the client, and every output it produces for the ambiguous class can be wrong in either direction, the classifier no longer participates in the decision: the probe, the server predicate, the error classifier and the Options plumbling are deleted. The unified gate covers all releases with identical semantics — a __mo_tmp_<32hex>_ row carrying relkind 'r' or '' aborts the dump unless the user selected that exact row with -tbl, which exports it per explicit intent. R21-23 all land in the same refusal: no renamed-permanent table is silently excluded, no empty-kind index row is silently exported, no USE-qualified batch can launder a temporary row as permanent. R9/R10 regression cases keep passing under the gate's -tbl escape; genuinely session-scoped rows on current clusters still never reach the gate (the relkind 'temporary_table' predicate rejects them first). Verified end-to-end on a current cluster: the shaped user table aborts the default dump with the explicit remedy message and exports with -tbl (single and alongside other tables); a live session temporary table stays excluded via relkind and dumps proceed; the #30562 restore closure, the #30579 tenant matrix and CSV mode stay green. The ambiguity suite short-circuit fails the suite (negative check), gofmt/vet are clean, full package suite green.
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…he staged pipeline mo/main merged PR matrixorigin#66 (issues #30562 / #30579): current_account_id() scoping for getDatabaseType/getTables, mo_indexes-based hidden-helper removal, explicit refusal (or -tbl opt-in) for ambiguous legacy temporary rows, empty relkind exported as an ordinary table with getCreateTable requiring a CREATE head, and account-scoped view metadata reads. Conflict resolution keeps this branch's behavior on top: - dumpData preflight and emit cases absorb emptyRelKind into the merged ordinary/external branch; the sequence export (CREATE SEQUENCE from the live backing row, setval replay, -no-data definition-only), the staged sink emission, -db all filtering and the csv reservation/ revoke chain are untouched. - identifiers view/select case merges the account-scoped view SQL with the sink-parameter genOutput tail; exportTestStdout returns as a thin wrapper over the current swap, so the merged catalog-scope suites read captured output as before; the new dump_empty_kind tests run dumpData through runDumpDataOverStdout. - All branch-side mock expectations move to dbScopePredicate / tablesScopePredicate / hiddenHelpersFor in one pass (-tbl selected runs keep the relname IN tail, whole-db runs drop it), and two merge remnants (an emptied if body and unused loop indexes) are cleaned up. Green: full package tests, -race on the sink/footnote/dump groups, vet/gofmt and incremental lint against the new merge base; coverage 85.6%.
Summary
Two dump-correctness fixes in the catalog queries of
getDatabaseType/getTables, reported as matrixorigin/matrixone#30562 and matrixorigin/matrixone#30579 (the issues are filed on the matrixone repo; mo-dump lives here).1. User tables named
__mo_*/%!%*are silently omitted (matrixorigin/matrixone#30562)getTablesdropped every table whose name starts with__mo_(or the legacy%!%) in Go code, regardless of ownership or relkind. A legally created user table such asd.__mo_user_datadisappears from the dump while mo-dump printsMODUMP SUCCESS, so a logical restore silently loses the object and all its data. An explicit-tbl __mo_user_dataalso failed withtable __mo_user_data not exists.Fix: move hidden-object filtering into the catalog query using the same predicates the server applies for
SHOW TABLES(verified identical in MO v1.0.0, v1.2.0, v4.0/v4.1 and current main):relname != 'mo_increment_columns'(mo_catalog helper)relname not like '__mo_index_%'(hidden index tables: unique/secondary/fulltext/vector, prefix in place since MO v1.0)relname != '__mo_account_lock'relkind != 'partition'(partition members, whose physical%!%part%!%tablenames motivated the original client-side prefix filter)relkind != 'temporary_table'(session temporary tables since the v4.2 catalog rework)not regexp_like(relname, '^__mo_tmp_[0-9a-f]{32}_')(temporary-table physical name shape used by v4.0/v4.1, where relkind is stillr;regexp_likeexists since MO v1.0)The risky-wide prefix filter itself is deleted, so
__mo_user_data,%!%oddand any other legally named user table is dumped, index/partition/temporary helpers stay hidden, and unsupported relkinds (cluster, sequence) still fail loudly instead of silently vanishing.2. Sys-account default dump of a same-named tenant database fails or leaks tenant data (matrixorigin/matrixone#30579)
By default the catalog queries had no account scope (only
-sysaddedaccount_id = 0). The sys account sees rows of every tenant inmo_catalog.mo_database/mo_tables, so a same-named database returned multiple rows and was reported asdatabase <name> not exists; a tenant-only name returned the tenant row and silently exported that tenant's data.Fix: scope the queries to the connected account, mirroring the server's own visibility rules (
SHOW DATABASES/SHOW TABLES):account_id = current_account_id() or (account_id = 0 and datname = 'mo_catalog')account_id = current_account_id() or (account_id = 0 and (relname in ('mo_database','mo_tables','mo_columns') or relkind = 'cluster'))current_account_id()is a built-in since MO v1.0, so no new server-side function is required.-syskeeps its existingaccount_id = 0behavior.Behavior changes (intended)
-sys) dump now exports only objects owned by the connected account. In particular, dumping a database that only exists in another tenant now fails fast with an error instead of silently exporting that tenant's data (expected per issue 30579; to export a tenant's database, connect with that tenant's credentials). During startup the missing database surfaces as the standardUnknown database <name>connection error.partition by ...) because partition member rows (relkind='partition') no longer reach the dump switch, which previously rejected them as unsupported.Validation
cmd/mo-dump): newcatalog_scope_test.goasserts the exact emitted SQL for both queries (scope + hidden predicates,-sysvariants), row handling,not existspaths and-tblrequests for user__mo_tables;TestDumpExitStatusexpectations updated to the new query shape. Full package suite green; predicate regression proved by temporarily removing one predicate (suite fails).9dfe5c1be9, git main):dwith__mo_user_data,plain,%!%odd, a secondary-index table, a partitioned table and a view: dump contains all six user objects with data, contains no__mo_index_*rows, no%!%p*%!%*partition members, and the partition DDL;-tbl __mo_user_data,plainworks; restoring the file into a fresh database reproduces identical object set and rows (__mo_user_data=(1,'important')).acc1both owndump_overlap_awith different row values: default sys dump succeeds and contains only the sys row (previouslydatabase dump_overlap_a not exists); tenant dump contains only the tenant row; sys still dumps its own uniquely-named databases; dumping a tenant-owned database now fails fast.mo_catalog.mo_tablesas atemporary_tablerow), the dump still succeeds and does not contain it (the old wide__mo_prefix filter incidentally covered this; the new predicates do it exactly). CSV mode unchanged.mo_catalogitself (directly or via-db all) still fails on cluster tables (mo_view_dependencies, relkindcluster) because the export switch only supportsr/v/e. Verified identical failure with the previous mo-dump build; supporting cluster tables would be a separate change.Fixes matrixorigin/matrixone#30562
Fixes matrixorigin/matrixone#30579
Review fix round 1 (same PR)
Two P1 regressions in the first revision were confirmed by reproduction and fixed by revising the hidden-object predicates (thanks for the review):
not like '__mo_index_%'the_is a single-character wildcard, so ordinary tables such asdemo_index_datavanished from dumps that still reported success, and-tbl demo_index_datafailed withnot exists. The index-table filter is now metadata-based:relkind <> 'i'(catalog.SystemIndexRel, written by the server since MO v3.0). The name-based LIKE is removed entirely — a literal-escaped LIKE would still be a name guess and would swallow a user table legally named__mo_index_data, while the relkind predicate exports such tables whenever the server classifies them as ordinary (relkind='r').mo_increment_columnsfiltered globally by name. Databases may legally contain same-named tables/views, and the previous global predicate deleted them silently. Themo_increment_columns/__mo_account_lockexclusions only exist in the catalog itself, so they are now appended only when dumpingmo_catalog.Reproduction also surfaced how MO classifies colliding names on this build:
CREATE TABLE r.mo_increment_columns(...)andCREATE TABLE r.__mo_index_data(...)are written tomo_catalog.mo_tableswith an empty relkind (not visible inSHOW TABLESeither). Such objects therefore surface as an explicitnot supported: table: ...error with exit code 1 instead of a silent omission plus a success marker. On cluster versions that record these names as ordinaryrelkind='r'tables, they are exported normally. Either way, no object vanishes silently behind aMODUMP SUCCESSanymore.Known limitation (recorded in code comments): on clusters older than MO v3.0, hidden index tables do not carry
relkind='i', so dumping an indexed database fails loudly instead of ignoring them; the fallback there is upgrading MO or using a previous mo-dump release.Re-validated after the fix: full UT suite (with new regression cases; removing the
relkind <> 'i'predicate fails the suite), plus end-to-end on a fresh local MO for both regressions, both original issues (dump+restore closure, tenant matrix), live temporary tables and CSV mode; gofmt/vet clean.Review fix round 2 (same PR)
Two further regressions found in the
relkind <> 'i'predicate were confirmed and fixed by replacing kind-only filtering with a compound gate:relkind='i'(P1). Fulltext helpers carryrelkind='fulltext'; IVF-FLAT helpers carry per-role kindsmetadata/centroids/entries; HNSW uses its own role names. Those rows reached the export switch and aborted every dump of the database (SQL and CSV, with and without-no-data). Any enumerated kind list would break again with the next index algorithm.The new predicate is:
__mo_index_prefix (underscores escaped —'_'is a single-character LIKE wildcard that previously swalloweddemo_index_data). Every index helper since MO v1.0 is named with this prefix (__mo_index_unique_/secondary_/fulltext_, IVF/HNSW/Cagra tables, ...). The\escape is supported by the LIKE implementation of all server versions back to v1.2.4 (verified against the v1.2.4 in-tree implementation).r/v/e) are exempt, so a user object legally named__mo_index_*with a dumpable kind is still dumped, while every helper kind —'i','fulltext','metadata','centroids','entries',''and any future plugin kind — stays hidden without further mo-dump changes.mo_indexes-based identification (suggested in review) was evaluated and rejected: registrations are complete on current clusters (all three IVF-FLAT helper tables are listed), but the column was renamed across versions (v1.2.4vec_index_tablevs currentindex_table_name), so a single query cannot serve both eras without a probe-and-fallback layer.Re-validated end-to-end on a fresh local MO with an
ixtdatabase containing unique, secondary, fulltext and IVF-FLAT indexes: dump exits 0, all four user tables export with data, zero helper rows leak (previously the fulltext/IVF rows aborted the dump); the pre-v3.0 shape (empty relkind + index name) is excluded;demo_index_dataand the collision-name matrix from round 1 stay correct; the original issue scenarios (dump+restore closure, tenant matrix, live temporary tables, CSV) stay green. The SQL-contract unit tests assert the compound predicate, and removing the relkind gate fails the suite.Review fix round 3 (same PR)
One more silent omission found by review, plus a correction to a wrong claim in the round-2 note:
RENAME TO __mo_index_renamedthe first dump works (relkindr), but the restoringCREATE TABLEmakes the server record the table with an empty relkind; the round-2 name+kind gate then swallowed it and the second backup printedMODUMP SUCCESSwithout the table. The previous revision at least failed loudly here — the compound gate regressed that into an omission. Root cause as stated in review: an unexportable type is not proof of an internal index.mo_indexesroute claiming the column was renamed in v1.2.4 (vec_index_table). That was wrong — v1.2.4'sMoCatalogMoIndexesDDLalready declaresindex_table_name, same as current versions (review verified it live; also confirmed inpkg/frontend/predefined.goof v1.2.4). Claim withdrawn.The fix follows the review suggestion: identify helpers by their real registration, and fail loudly for what cannot be exported:
relname not in (select index_table_name from mo_catalog.mo_indexes where index_table_name is not null and index_table_name <> ''). Name- and kind-based shortcuts are removed entirely. Unregistered helpers or future algorithm kinds now surface as an explicitnot supportederror instead of silently vanishing, and nothing that a user renamed into a colliding name can be dropped by a guess.CREATE TABLEnames while the object remains fully usable (SHOW CREATE TABLE and SELECT verified), so the dump cycle converges for such names: rename → dump → restore → dump → restore keeps all rows. All other unknown relkinds still fail loudly.Validated end-to-end on a fresh local MO: the full four-step cycle (rename to
__mo_index_renamed, dump, restore — kind becomes empty, second dump contains DDL and rows, second restore complete with data); the round-2 index database (unique, secondary, fulltext, IVF-FLAT) still dumps with exit 0 and zero helper rows; a table renamed tomo_increment_columnsin an ordinary database now exports with its data (round-1 scenario, previously erroring);demo_index_data, the #30562/#30579 scenarios, live temporary tables and CSV stay green. New unit tests (dump_empty_kind_test.go) assert the export of the empty-kind object and the loud failure for unknown kinds; the SQL-contract suite asserts themo_indexessubquery, and removing that predicate fails the suite.Review fix round 4 (same PR)
Three REQUEST_CHANGES items from the latest review, all fixed:
mo_indexessubquery compared table names globally, so a helper registered for database A silently swallowed a same-named user table of database B. The lookup is now joined throughmo_catalog.mo_databasewithdatnameplus the same account scoping used bygetDatabaseType, restricting the exclusion to helpers of the dumped database. Verified end-to-end: a user table named exactly like another database's hidden index table is dumped with its data while that database's own dump still excludes the helper.MODUMP SUCCESS, and the second restore failed.getCreateTablenow requires aCREATEstatement head (so theCREATE EXTERNAL TABLEshape stays valid) and fails loudly with an explicit error on fragments. Current clusters keep the converging rename→dump→restore cycle (verified); v1.2.4 degrades to a loud error instead of silent data loss.mo_catalog.mo_indexes. There is no safe fallback (name- and kind-based identification both proved to silently drop user objects in earlier rounds), so the README documents the exactGRANTstatements, tenant admins work out of the box (verified), and a missing grant surfaces at the first catalog query as an explicit privilege error above.Full re-validation matrix on a fresh local MO: cross-database collision (new), the round-2 index database (unique/secondary/fulltext/IVFFLAT), colliding user tables (
mo_increment_columns,__mo_index_renamedrename cycle with data), the #30562 restore closure, the #30579 tenant matrix, live temporary tables, CSV mode; SQL-contract unit tests updated for the scoped subquery, newTestGetCreateTableRequiresHeadcovers the head validation (including the external-table shape); gofmt/vet clean.Review fix round 6 (same PR)
REQUEST_CHANGES round: on MO v4.0.x/v4.1.x the temporary backing rows carry relkind 'r' (the Kind property is written through the ordinary-table path), so the round-5 name-regexp removal let another session's temporary data be dumped and permanently materialized on restore. The new filter is pure metadata: on those releases
rel_createsqlkeeps the user's original DDL, so temporary backing rows are the ones whose root statement starts withCREATE TEMPORARY TABLE:coalescekeeps NULL createsql rows visible,lowertolerates keyword casing, and the persistent__mo_tmp_<32hex>_-shaped user tables from round 5 keep dumping with their data. On current clusters the relkindtemporary_tablepredicate remains primary and both agree (a live temporary table's rel_createsql also starts with CREATE TEMPORARY — verified on a live server), giving a second line of defense for mixed-version windows. `Deleted with the round-5 commit's guess — identification now comes from the actual DDL record, no name shapes anywhere.Also merged mo/main (parameterized
?,argscatalog queries, the lightweightinternal/catalogwire-value package, the view dependency pipeline and its test suite); all mock expectations were upgraded to the parameterized SQL with the double database binding, and the hidden-helper predicates are applied in every test exercising getTables/getDatabaseType. Full suite, gofmt/vet and an end-to-end pass (persistent tmp-shaped table, live temporary table, #30562 restore closure with views and indexes, #30579 tenant matrix, CSV) are green after the merge.Review fix round 5 (same PR)
The inline review finding on the temporary-table name shape is fixed: the
'^__mo_tmp_[0-9a-f]{32}_'regexp was the last remaining name-based identification. A persistent user table legally named with that shape was silently omitted behindMODUMP SUCCESS, and explicit-tblreported it as nonexistent. Identification is now metadata-only: relkindtemporary_tableon current clusters; on the v4.0/v4.1 interim releases (relkindr, no metadata) the dump stays complete — a live backing table surfaces as a loud error or as visible rows, never a silently dropped user table. Verified end-to-end: a persistent__mo_tmp_0123456789abcdef0123456789abcdef_usertable dumps with data in both full-database and-tblmode while a live session temporary table in the same database stays excluded via relkind; #30562 restore closure, index-helper database, #30579 and CSV all green.Review fix rounds 7-8 (same PR)
Three REQUEST_CHANGES items, all fixed:
1/2. rel_createsql prefix matching misfired in both directions. A batched request (
CREATE TEMPORARY ...; CREATE TABLE persistent ...) marked the permanent table's row with a temporary-looking request and the round-6 prefix check silently dropped it, while comments, whitespace or a non-leading position let real v4.0/v4.1 temporary backing rows slip through and be permanently materialized on restore. The replacement classification mirrors the server's ownmo_is_legacy_temporary_table: statements are split on unquoted semicolons, the CREATE TABLE grammar is tokenized (TEMPORARY / IF NOT EXISTS / optional schema qualifier), and rows are classified by the exact statement-name relation — a permanent statement naming the physical row proves permanence and wins over any matching temporary alias in the same request (round-12 fix); a temporary statement naming the alias recovered from the__mo_tmp_<32hex>_<db>_<alias>physical shape classifies the row as legacy temporary (round-11 fix), failing open on nothing-matching or rename metadata. The server's parser import was rejected (it drags the vectorindex CGo dependency into this client); the behavior-equivalent tokenizer has zero new dependencies and ports the server's own test vectors (15 classification cases).account_id = current_account_id()(-syskeepsaccount_id = 0). Verified end to end on sys default, tenant and-sysdumps of the same-named view databases.The whole mock suite was migrated to the parameterized four-column catalog query (relname/relkind/rel_createsql/extra_info) and the account-scoped view query; full suite, vet, gofmt and a fresh-cluster e2e pass (rounds 9-13 regression matrix, #30562 restore closure, CSV) are green.
Review fix round 9 (same PR)
Four more P1s and a P2 confirmed the structural lesson: the client-side classifier reimplementation (rounds 7-8) kept accumulating parser-semantics defects — rename metadata that v4.1.6 never records, comments inside qualified names, quoted keywords, executable
/*!*/comments, USE-context misattribution, empty-kind temporary index rows. Fixing them one by one re-exposed others. The classification now comes from the two authorities that actually own the semantics:dumpDataprobesmo_is_legacy_temporary_tableonce per connection; when available thegetTablesquery pushesand not mo_is_legacy_temporary_table(relkind, relname, reldatabase, coalesce(rel_createsql, ''), coalesce(extra_info, ''))into the server. Rename metadata, batched requests, comment decoration and qualified identities are the server parser's own behavior — code this client no longer reimplements.SHOW TABLESused —^__mo_tmp_[0-9a-f]{32}_over ordinary or empty relkind — covering the empty-kind temporary index rows. Persistent tables named with the shape follow the same visibility those servers themselves enforced; precise per-statement classification for these rows is not reconstructible from any metadata those versions record.relname, relkindfrommo_tables;rel_createsql/extra_infoare referenced exclusively inside the server-executed function predicate on clusters that have it (v1.2.4 has noextra_infocolumn at all).The client lexical tokenizer and its tests are deleted. The mock suite moved back to the two-column query with a two-state predicate (new case asserting the server-classifier form); removing the fallback predicate fails the suite; gofmt/vet clean; current-cluster e2e exercises the probe (persistent
__mo_tmp_-shaped user tables keep dumping with data, live temporary tables stay excluded, #30562-with-view restore closure, #30579 tenant matrix, CSV) and the fallback predicate SQL is verified server-parseable directly.Review fix round 10 (same PR)
Both remaining P1s, fixed with one shared principle — never produce a "successful" dump out of ambiguity:
The fallback shape regex silently dropped legally named persistent
__mo_tmp_<32hex>_*tables on classifier-less clusters (v1.2.4, v4.1.6). The fallback no longer excludes anything. Shape rows reach the client, andgetTablesaborts the dump with an explicit error naming the row and the possible remedies (explicit-tbl, rename, cleanup of expired session tables, or dumping from a v4.2+ cluster) — unless the user explicitly selected the row with-tbl, which exports it per intent. No silent omission remains anywhere in the tool.A single injected probe error downgraded functioning clusters into the fallback for good. The probe now classifies failures instead of swallowing them: only the server's own unknown-function answer legitimately downgrades (measured live:
ERROR 20105 (HY000): not supported: function or operator '<name>'— moerr.NotSupported, uniform from v1.2 through current — plus the stock 1305 shape); any other error, including driver row errors, aborts the dump. The probe also now drives row iteration before consultingErr()(database/sql only surfaces driver row errors there afterNext()touched them), which the row-error unit case exposed.New coverage: probe path tests (present/unknown-function/injected/row-error), round-10 ambiguity cases (default abort,
-tblexemption, empty-kind abort), round-9 classifier predicate case; every dumpData-driven mock arms exactly one probe expectation per dump; negative check — removing the ambiguity guard fails the suite. E2E on a current cluster: persistent__mo_tmp_-shaped table dumps with data in whole-database and explicit-tblmodes, live session temporary tables stay excluded, and the unknown-function idiom was captured from a live server to pin the classification.Review fix round 11 (same PR)
The three remaining P1s (renamed-permanent misclassified as temporary, empty-kind index rows bypassing the classifier, USE-qualified batches laundering temporary rows as permanent) all live in the server-classifier path itself — its inputs are fully observable to the client and its answers for the ambiguous class can be wrong in either direction. The classifier no longer participates in the decision. The probe, the server predicate, the error classifier and the Options plumbing are deleted; a single uniform gate covers every release:
__mo_tmp_<32hex>_row with relkind'r'or''aborts the dump unless that exact row was selected with-tbl(which exports it per explicit intent);'temporary_table'predicate rejects them first, verified live;E2E on a current cluster: the shaped user table aborts the default dump with the explicit remedy message and exports via
-tbl(alone and together with other tables); live session temporary tables stay excluded; #30562 restore closure, #30579 tenant matrix and CSV stay green. Negative check: short-circuiting the gate fails the ambiguity suite; gofmt/vet clean; full suite green.