Skip to content

Commit 4f762a4

Browse files
committed
Lock Postgres stores on initialization
Prevent multiple nodes from opening the same PostgreSQL database table at once while allowing separate database and table pairs to coexist. Retain the session-scoped advisory lock for the store lifetime, if we lose the lock, panic to prevent mismatched states. This change was created with OpenAI Codex.
1 parent abbed3e commit 4f762a4

2 files changed

Lines changed: 192 additions & 46 deletions

File tree

src/builder.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,14 @@ impl NodeBuilder {
696696
/// The given `kv_table_name` will be used or default to
697697
/// [`DEFAULT_KV_TABLE_NAME`](io::postgres_store::DEFAULT_KV_TABLE_NAME).
698698
///
699+
/// # Warning
700+
///
701+
/// Do not point multiple [`Node`] instances at the same database and table. Concurrent access is
702+
/// unsafe and can corrupt node state. You must make sure that only one node accesses each
703+
/// database and table. The store uses a PostgreSQL advisory lock to reduce this risk. This lock
704+
/// is only a temporary safeguard and does not make concurrent access safe.
705+
/// Nodes using a different database or table on the same server may coexist.
706+
///
699707
/// If `certificate_pem` is `Some`, TLS will be used for database connections and the
700708
/// provided PEM-encoded CA certificate will be added to the system's default root
701709
/// certificates (it does not replace them). If `certificate_pem` is `None`, connections
@@ -1230,6 +1238,14 @@ impl ArcedNodeBuilder {
12301238
/// The given `kv_table_name` will be used or default to
12311239
/// [`DEFAULT_KV_TABLE_NAME`](io::postgres_store::DEFAULT_KV_TABLE_NAME).
12321240
///
1241+
/// # Warning
1242+
///
1243+
/// Do not point multiple [`Node`] instances at the same database and table. Concurrent access is
1244+
/// unsafe and can corrupt node state. You must make sure that only one node accesses each
1245+
/// database and table. The store uses a PostgreSQL advisory lock to reduce this risk. This lock
1246+
/// is only a temporary safeguard and does not make concurrent access safe.
1247+
/// Nodes using a different database or table on the same server may coexist.
1248+
///
12331249
/// If `certificate_pem` is `Some`, TLS will be used for database connections and the
12341250
/// provided PEM-encoded CA certificate will be added to the system's default root
12351251
/// certificates (it does not replace them). If `certificate_pem` is `None`, connections

0 commit comments

Comments
 (0)