Repository navigation
Description
Additional consolidated scope
cleanOrphanTempTables must be safe across CN-local session sets and must make progress for valid but quoted identifiers; both reports exercise the same orphan-GC routine. Related reports remain separate reproductions where they exercise distinct paths. Closing a source issue records tracking consolidation only; no fix is claimed.
Additional acceptance criteria
- A CN must never drop a live temporary table owned by a session attached to another CN; use cluster-wide liveness/ownership evidence.
- Orphan physical names containing backticks are correctly escaped (using the repository SQL-identifier helper) and reclaimed instead of warned-and-skipped.
- Cover a multi-CN live-session case and an orphan identifier-escaping case in deterministic regression tests.
Additional reports
- #30507 — original report and discussion remain on that issue.
Environment
- MatrixOne:
main@ commit b111224 (workspace build), macOS 15.7, arm64. - Deployment:
etc/launch-multi-cn(LOG + TN + two CN services), started as onemo-serviceprocess; CN1 MySQL port 16001, CN2 MySQL port 16002 (both offset by 20000 in the test config: 36001/36002). Clients: pymysql, one persistent connection per CN. - The shipped GC ticker interval is 24h (
pkg/frontend/server.go:133,mo.startTempTableGC(24 * time.Hour)). To make the tick observable within minutes I rebuiltmo-servicewith that single line changed to 30s (test-only build; the change was reverted in the source tree right aftergo build; nothing was committed). Everything else is stock.
Actual Behavior
Each CN runs its own cleanOrphanTempTables loop (log line temp table gc started appears once per CN). The loop:
- queries the SHARED catalog:
select reldatabase, relname from mo_catalog.mo_tables where relkind = 'temporary_table'— this returns the temp physicals of every session of the whole cluster, regardless of which CN the session is attached to; - builds the skip-set from
mo.rm.sessionManager.GetAllSessions(), which is a CN-LOCAL in-memory map (pkg/queryservice/session_manager.go: "SessionManager manages all sessions locally"); - executes
drop table if exists <db>.<name>for every temp physical whose session-UUID prefix is not in that local set.
Consequence: with >= 2 CNs, each CN's tick destroys the live temporary tables of all sessions attached to the OTHER CNs. Reproduced 3/3 times in a 2-CN instance, deterministic: on every run, after two 30s ticks, ALL temp physicals of two simultaneously connected, fully active sessions (one per CN) were gone from mo_catalog.mo_tables (including the hidden __mo_tmp_...___mo_index_secondary_... index physical), and both sessions got ERROR 1146: SQL parser error: table ... does not exist on their next statement, mid-connection. A permanent table created in the same database was untouched (the relkind filter works). With the shipped 24h interval the same destruction happens within 24h of the other CN's uptime, so any multi-CN deployment loses session temporary tables (and any in-flight work stored in them) once per day per CN, at unpredictable times, without any error on the dropping side (drop table if exists).
Expected Behavior
A temporary table must live exactly as long as its owning session: the GC may only clean physical tables whose owning session is gone from the WHOLE cluster, not from this CN's local session registry. An active session (connected elsewhere in the cluster) must never have its temporary tables dropped by another node: its select * from <temp alias> must keep returning its rows for the whole lifetime of the connection.
Steps to Reproduce
(With the stock build the same destruction occurs after up to 24h; the steps below use the 30s-interval test build to make it observable.)
- Copy
etc/launch-multi-cnto a private directory; on a fresh checkout apply this one-line test change and rebuild:
--- pkg/frontend/server.go
- mo.startTempTableGC(24 * time.Hour)
+ mo.startTempTableGC(30 * time.Second)export CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
go build -o .loom-test/mo-service ./cmd/mo-service
./.loom-test/mo-service -launch <your-launch-mc>/launch.toml # log+tn+cn1+cn2- Open session A on CN1 (port 36001) and session D on CN2 (port 36002), keep both connected:
-- A on CN1
CREATE DATABASE loommc; USE loommc;
CREATE TABLE perm_control(id INT PRIMARY KEY, v VARCHAR(20));
INSERT INTO perm_control VALUES (1, 'keep');
CREATE TEMPORARY TABLE a_tmp(id INT PRIMARY KEY, v VARCHAR(30));
INSERT INTO a_tmp VALUES (1, 'session-a-private-1'), (2, 'session-a-private-2');
-- D on CN2
USE loommc;
CREATE TEMPORARY TABLE d_tmp(id INT PRIMARY KEY, v VARCHAR(30));
INSERT INTO d_tmp VALUES (1, 'session-d-private-1'), (2, 'session-d-private-2');
-- A on CN1
CREATE TEMPORARY TABLE a_idx(id INT PRIMARY KEY, v INT, KEY kv(v));
INSERT INTO a_idx VALUES (1, 10), (2, 20);
SELECT * FROM a_tmp ORDER BY id; -- returns 2 rows- Wait ~75 seconds (two GC ticks), without closing either connection, then in each session:
-- A on CN1
SELECT * FROM a_tmp ORDER BY id; -- ERROR 1146: table "a_tmp" does not exist
SELECT * FROM a_idx ORDER BY id; -- ERROR 1146: table "a_idx" does not exist
SELECT * FROM perm_control; -- still OK (permanent table survives)
-- D on CN2
SELECT * FROM d_tmp ORDER BY id; -- ERROR 1146: table "d_tmp" does not exist- Optional confirmation on either CN:
SELECT relname FROM mo_catalog.mo_tables
WHERE reldatabase='loommc' AND relname LIKE '\_\_mo\_tmp\_%'; -- emptyAdditional information
- Root cause links:
pkg/frontend/server.go:133— per-CN ticker default 24h.pkg/frontend/server.go:360(queryTempTables) — enumerates the cluster-wide shared catalogmo_catalog.mo_tables(relkind='temporary_table'), so candidates include other CNs' live sessions' tables.pkg/frontend/server.go:327—activeSessions := mo.rm.sessionManager.GetAllSessions();pkg/queryservice/session_manager.go:35— the manager is documented as CN-local ("SessionManager manages all sessions locally").pkg/frontend/server.go:343— the unconditionaldrop table if existsfor every candidate whose session prefix is not in the local set.
- Single-CN instances are unaffected: the only MOServer's session manager naturally contains every temp-table owner, which is why the BVT/orphan-GC behaviour passes on standalone deployments. This was verified in the same environment: with the same 30s-interval binary in a 1-CN launch, a live session's temporary tables survived multiple ticks.
- Affected scenarios: any deployment with >= 2 CNs (the standard distributed production shape), proxy-connected pools, and proxy-driven session migration windows where the original session's physicals linger on the source CN.
- Suggested fix direction: make the skip decision cluster-wide instead of CN-local — e.g. resolve the session UUID against a cluster-visible session registry (query service/hakeeper session listing already maintains cluster session status for
show processlist-style features), or record the owning CN/lease heartbeats with the temp physical rows so the GC can distinguish "session gone cluster-wide" from "session not on this CN". Keeping the 24h interval but fixing the ownership check restores the documented behavior with no data-format change.
Full reproduction, exactly as Loom ran it
# 1) One-line test-only change to make the 24h GC tick observable (revert after build):
# pkg/frontend/server.go:133 mo.startTempTableGC(24 * time.Hour) -> (30 * time.Second)
export CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include"
go build -o .loom-test/mo-service ./cmd/mo-service
# 2) Two-CN instance from etc/launch-multi-cn (all ports offset by 20000):
./.loom-test/mo-service -launch .loom-test/launch-mc/launch.toml &
# CN1 mysql port 36001, CN2 mysql port 36002; wait until both answer.
# 3) Session A on CN1 (keep open):
# CREATE DATABASE loommc; USE loommc;
# CREATE TEMPORARY TABLE a_tmp(id INT PRIMARY KEY, v VARCHAR(30));
# INSERT INTO a_tmp VALUES (1,'session-a-private-1'), (2,'session-a-private-2');
# 4) Session D on CN2 (keep open):
# USE loommc; CREATE TEMPORARY TABLE d_tmp(id INT PRIMARY KEY, v VARCHAR(30));
# INSERT INTO d_tmp VALUES (1,'session-d-private-1'), (2,'session-d-private-2');
# 5) Wait 75 seconds, then in both still-open sessions:
sleep 75
mysql -h 127.0.0.1 -P 36001 -u dump -p111 -e 'USE loommc; SELECT * FROM a_tmp;'
# ERROR 1146 (42S02) at line 1: SQL parser error: table "a_tmp" does not exist
mysql -h 127.0.0.1 -P 36002 -u dump -p111 -e 'USE loommc; SELECT * FROM d_tmp;'
# ERROR 1146 (42S02) at line 1: SQL parser error: table "d_tmp" does not exist
mysql -h 127.0.0.1 -P 36001 -u dump -p111 -e "select relname from mo_catalog.mo_tables where reldatabase='loommc' and relname like '\_\_mo\_tmp\_%';"
# Empty set -- every temp physical (incl. hidden index tables) was dropped by the peer CN's GC.
# Control in the same run: a PERMANENT table created alongside survives; single-CN launch with the same
# 30s-interval binary leaves an active session's temp tables intact across many ticks.Found by Loom bug hunt (module: custom-5ec72c0c38; tests: unit, white-box, end-to-end)
Activity
[-][Bug]: multi-CN orphan temp-table GC drops live temporary tables of sessions attached to other CNs[/-][+][Bug]: Temporary-table orphan GC must preserve live sessions and reclaim safely quoted orphans[/+]