Feature request: lock the data directory so a second PGlite in another process fails fast instead of corrupting it

オープン
#1,106 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
node.js, postgresql, typescript
領域
database

調査の方向性

new PGlite(dataDir) が使用する Node filesystem VFS パスから始め、open、close、process-exit のライフサイクルを追跡します。2 プロセスのケースを再現し、live lock がそのプロセスを識別し、stale lock が引き継がれ、data directory を破損させずに lock が解放されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

New feature requestPostgres refuses to start on a data directory another postmaster holds (postmaster.pid). PGlite on the Node filesystem VFS takes no such lock, so two processes opening the same dataDir both succeed, both write, and the directory ends up unreadable. The next open then dies with RuntimeError: Aborted() (the symptom in #884) or a checkpoint panic (#327), with nothing pointing at the cause.

The two openers in our case were ordinary: a dev server running with --hot, and a script that imported the same database module. A rm -rf of the data directory under a running server ends the same way.

Describe the solution you'd like

new PGlite(dataDir) on the Node filesystem writes a lock file in the directory holding its process id, and a second open throws when that process is alive, naming it. A stale file (process gone) is taken over. Released on close and on process exit. Same idea as postmaster.pid, scoped to what PGlite can know in one process.

Describe alternatives you've considered

  • We wrote this lock in the application (pid file beside the directory, process.kill(pid, 0) for liveness). It works, but every PGlite user with more than one process hits the same corruption and rediscovers it from Aborted().
  • A documentation note. It does not stop the second open.

Additional context

The lock request in #85 is for the IndexedDB VFS. This one is the Node filesystem VFS, where the second opener is another OS process.

主要言語
TypeScript
スター
16.3k
フォーク
474
平均マージ
23時間 53分
マージ済み PR(30日)
53

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

electric-sql/pglite のほかの issue

electric-sql/pglite の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。