[Bug] Cursors / extended-protocol queries leak one DSM segment each until transaction end: "too many dynamic shared memory segments"
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c, postgresql
調査の方向性
Start by reading utils/time/sharedsnapshot.c, especially dumpSharedLocalSnapshot_forCursor() and AtEOXact_SharedSnapshot(), then trace how the 32-entry snapshot dump ring owns its DSM segments. Reproduce with the issue’s cursor script and inspect segment counts under /dev/shm. Done means repeated extended-protocol queries in one transaction no longer exhaust DSM segments while snapshots remain safe for readers.
索引モデルが issue の本文から書いたものです。
説明
Apache Cloudberry version
Version: Apache Cloudberry 2.1.0-incubating (built from the tag), Debian 13.
What happened
Every query dispatched through a portal with is_extended_query (a DECLARE CURSOR, or Bind/Execute over the extended protocol) makes the QD call verify_shared_snapshot_ready() → dumpSharedLocalSnapshot_forCursor(), which does a fresh dsm_create() (utils/time/sharedsnapshot.c:640). The segments are owned by the session-level DumpResOwner and only released in AtEOXact_SharedSnapshot(). The dump index is a 32-entry ring (SNAPSHOTDUMPARRAYSZ), but overwriting an entry does not release the old segment. So a single transaction can run at most about 64 + 9*MaxBackends such queries; the next one fails.
What you think should happen instead
No response
How to reproduce
Repro (psql only), with ~N AO tables where N > 64 + 9*MaxBackends (here 3100 tables vs a limit of 2584):
CREATE DATABASE dsmtest; -- then, one table per statement:
SELECT format('CREATE TABLE t_%s (id int) WITH (appendoptimized=true) DISTRIBUTED BY (id); INSERT INTO t_%s VALUES (1);', i, i)
FROM generate_series(1, 3100) i \gexec
psql -d dsmtest -v ON_ERROR_STOP=1 > /dev/null <<'EOF'
BEGIN;
SELECT format('DECLARE c CURSOR FOR SELECT COALESCE(sum(modcount),0) FROM gp_dist_random(%L)', segrelid::regclass),
'FETCH 1 FROM c',
'CLOSE c'
FROM pg_appendonly \gexec
COMMIT;
EOF
-- ERROR: too many dynamic shared memory segments
ls /dev/shm | grep -c '^PostgreSQL.' on the coordinator grows by one per cursor (4 → 2462) and drops back on abort. The same queries without a cursor pass, also under REPEATABLE READ and with pg_export_snapshot(). With pgbench and the same script in one transaction: -M simple passes, -M extended and -M prepared fail after ~2580 queries.
Operating System
Debian GNU/Linux 13 (trixie)
Anything else
We hit this during the gpbackup with enabled --leaf-partition-data
gpbackup --leaf-partition-data (pgx v5, extended protocol) runs one gp_dist_random modcount query per AO table in its single transaction, so a full backup of a database with more AO tables than the limit always fails (ours: 13,461 AO tables).
Also reproduced the same issue with pgbackup / psql / pgbench on lab cluster with 4 primary segments and 3100 AO tables.
Possible fixes: skip the dump when the snapshot did not change since the previous one, or release the segment of the ring entry being overwritten (whether readers can still need it is for you to judge).
Are you willing to submit PR?
- Yes, I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct.
- 主要言語
- C
- スター
- 1.5k
- フォーク
- 280
- 平均マージ
- 4日 21時間
- マージ済み PR(30日)
- 122
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/cloudberry のほかの issue
-
type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/cloudberry#2459 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
psql tab completion broken for storage servers, tags, profiles and resource groups (pre-PG15 query format)対応中かも @allenvox が 18 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/cloudberry#2316 ·
メンテナーはふだん 2 日以内に返信
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)対応中かも @talmacschen-arch が 166 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
apache/cloudberry#1825 ·
メンテナーはふだん 2 日以内に返信
-
[Bug] ORCA returns wrong system column values through a partially pruned CTE consumer対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンtype: Bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
apache/cloudberry#2458 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
[Bug] Window Sort above ROLLUP gets a larger memory quota and runs slower after "Reserve memory for one partition at a time"対応中かも @Alena0704 が 1 日前に担当しました。 オープンtype: Bug
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
apache/cloudberry#2446 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
apache/cloudberry の issue をすべて見る
似ている issue
-
HXsetdir strdup leakオープン
難易度 1/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
ly05010419/MacNativeGames#2459 ·
メンテナーはふだん 1 日以内に返信
-
2024.2 Backport Required 2025.2 Backport Required 2026.1 Backport Required 2026.2 Backport Required area/build-framework kind/enhancement priority/medium
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
yugabyte/yugabyte-db#39930 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
shinyquagsire23/OpenJKDF2#540 ·
メンテナーはふだん 12 日以内に返信
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Life-Framework/Life-Framework#5939 ·
メンテナーはふだん 1 日以内に返信