Skip to content

[Bug] information_schema metadata lookup reuses materialized sink source before all owners release #28266

Closed

Description

@XuPeng-SH

Summary

MatrixOne fails a deterministic, single-connection schema bootstrap with:

internal error: materialized sink source reused before all owners released

The failure is returned as error number 20101 and prevents the client from
starting. The workload is sequential (one Astra schema pool with one
connection); there is no concurrent application query or cancellation.

Environment

  • MatrixOne commit: 9add8e46c19b40a1a6488ba5d2969d0b380e2083
  • standalone quickstart, one TN/CN, MySQL protocol on 127.0.0.1:6001
  • Linux amd64
  • fresh database, ASTRA_AUTO_CREATE_DATABASE=1
  • Astra schema bootstrap uses a one-connection schema pool and awaits every
    statement before issuing the next one

The same failure was observed on the earlier MatrixOne commit
49da1b40cf14c1c7b1d1056a4b611ccbb86158a4.

Reproduction

Build/start the MatrixOne quickstart and run the Astra server against a fresh
database:

ASTRA_DATABASE=astra_materialized_repro \
ASTRA_DATABASE_BOOTSTRAP_CATALOG=mysql \
ASTRA_AUTO_CREATE_DATABASE=1 \
ASTRA_API_HOST=127.0.0.1 ASTRA_API_PORT=17019 \
./target/release/astra-server

The server exits while bootstrapping the core schema. The final successful
statement is:

CREATE TABLE IF NOT EXISTS conversation_manifest_nodes (
    isolation_domain VARCHAR(128) NOT NULL,
    owner_user_id VARCHAR(128) NOT NULL,
    session_id VARCHAR(128) NOT NULL,
    branch_id VARCHAR(128) NOT NULL,
    manifest_root CHAR(64) NOT NULL,
    parent_manifest_root CHAR(64) NULL,
    completed_turn BIGINT NOT NULL,
    conversation_seq BIGINT NOT NULL,
    compaction_generation BIGINT NOT NULL DEFAULT 0,
    canonical_segment_bytes BIGINT NOT NULL,
    total_canonical_bytes BIGINT NOT NULL,
    total_message_count BIGINT NOT NULL,
    reachable TINYINT NOT NULL DEFAULT 0,
    manifest_json LONGTEXT NOT NULL,
    created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
    PRIMARY KEY (isolation_domain, owner_user_id, session_id, branch_id, manifest_root),
    INDEX idx_context_manifest_parent (isolation_domain, owner_user_id, session_id, branch_id, parent_manifest_root),
    INDEX idx_context_manifest_sequence (isolation_domain, owner_user_id, session_id, branch_id, conversation_seq),
    INDEX idx_context_manifest_reachable_sequence (isolation_domain, owner_user_id, session_id, branch_id, reachable, conversation_seq),
    INDEX idx_context_manifest_generation_sequence (isolation_domain, owner_user_id, session_id, branch_id, compaction_generation, reachable, conversation_seq)
);

The next bootstrap operation is an idempotent metadata check of the form:

SELECT 1
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?
LIMIT 1;

The client receives:

Database(MySqlDatabaseError {
  code: Some("HY000"),
  number: 20101,
  message: "internal error: materialized sink source reused before all owners released"
})

The fresh database is left with the ordinary tables created so far, but both
astra_schema_contracts and astra_schema_table_contracts remain empty, so
bootstrap never reaches its completion marker.

Evidence of the affected plan shape

On the same server/database, this query is accepted but its plan contains a
shared materialized producer:

EXPLAIN SELECT 1
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'astra_materialized_repro'
  AND TABLE_NAME = 'conversation_manifest_nodes'
  AND COLUMN_NAME = 'total_canonical_bytes'
LIMIT 1;

The output contains:

Plan 0:
  -> Table Function on mo_current_roles
Plan 1:
  ... Sink Scan (DataSource: Plan 0)
  ... Sink Scan (DataSource: Plan 0)
  ... Sink Scan (DataSource: Plan 0)

This means a harmless information_schema lookup exercises the multi-reader
materialized-CTE path. The bootstrap is otherwise serial and uses no user CTE.

Relevant implementation

pkg/sql/internal/materialized/source.go rejects Begin when the previous
generation is still active and any producer/reader owner has not released:

if s.active && !s.allReleasedLocked() {
    return moerr.NewInternalErrorNoCtx("materialized sink source reused before all owners released")
}

pkg/sql/compile/compile.go calls source.Begin before each pipeline run, and
getMaterializedSource creates one source for a materialized CTE with at least
two readers. The observed error therefore means the previous generation's
producer or one of its readers was still owned when the next statement entered
Begin.

Expected behavior

Sequential metadata queries must not fail. MatrixOne should either release all
materialized-CTE owners before the next statement starts, or avoid reusing the
source/compiled plan until the prior generation is fully quiescent. The error
should also include the source generation, reader IDs, statement/trace ID, and
whether producer or reader ownership remained, because the current message is
not sufficient to identify the leaking execution.

I have not reduced this to a single standalone SQL statement yet; the above is a
deterministic integration reproduction from a fresh database, and the
EXPLAIN output identifies the shared materialized system-view plan involved.

Activity

  1. self-assigned this
    on Sep 5, 2026
  2. added
    kind/bug
    severity/s0
    on Sep 5, 2026
  3. Ariznawlll commented on Sep 6, 2026

    @Ariznawlll
    Collaborator

    最新 main 验证结论

    • 验证版本:MatrixOne main@109bf926fdb31de31e0578ad0fb17be160d7d8d0(2026-09-06)
    • 环境:本地最新 main 新编译 standalone,1 TN / 1 CN / 1 LogService,MySQL 6001,单连接

    测试步骤

    1. 新建 issue_28266 数据库和 conversation_manifest_nodes 表,使用原问题的复合主键、多个索引及 LONGTEXT 字段形状。
    2. 在同一连接准备以下 metadata lookup:
      SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME=? AND COLUMN_NAME=? LIMIT 1
    3. 绑定 issue_28266 / conversation_manifest_nodes / total_canonical_bytes,连续执行两次。
    4. 执行 DEALLOCATE PREPARE,再查询底表确认连接仍可继续使用。
    5. 同时执行回归单测:TestPipelineAttemptAlwaysClosesMaterializedSources、TestPipelineAttemptClosesMaterializedSourcesAfterPanic,连续 3 次通过。

    测试结果

    • 两次 prepared metadata lookup 均返回 1;
    • 未出现 20101 internal error: materialized sink source reused before all owners released;
    • prepared statement 释放后连接仍可继续执行查询,底表结果保持正确;
    • 对应修复已在当前 main,未复现原问题。

    MOTR 黑盒用例已加入 motr#146,覆盖同一连接重复执行该 metadata lookup 的场景。

    结论

    在最新 main 上原问题已验证通过,达到关闭条件,关闭 issue。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions