Skip to content

Commit 15ae6cd

Browse files
author
Francesco Komauli
committed
LWLocks for dynamic shared memory, with an ad-hoc implementation for parallel foreign scans
1 parent a4f9048 commit 15ae6cd

File tree

10 files changed

+1155
-4
lines changed

10 files changed

+1155
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ exclude = [
4040
"pgrx-examples/numeric",
4141
"pgrx-examples/pgtrybuilder",
4242
"pgrx-examples/operators",
43+
"pgrx-examples/parallel_scan_lwlock",
4344
"pgrx-examples/range",
4445
"pgrx-examples/schemas",
4546
"pgrx-examples/shmem",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.idea/
3+
/target
4+
*.iml
5+
**/*.rs.bk
6+
Cargo.lock
7+
sql/shmem-1.0.sql
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "parallel_scan_lwlock"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[lib]
8+
crate-type = ["cdylib", "lib"]
9+
10+
[[bin]]
11+
name = "pgrx_embed_parallel_scan_lwlock"
12+
path = "./src/bin/pgrx_embed.rs"
13+
14+
[features]
15+
default = ["pg17"]
16+
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
17+
pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
18+
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
19+
pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
20+
pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
21+
pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
22+
pg_test = []
23+
24+
[dependencies]
25+
pgrx = { path = "../../pgrx", default-features = false }
26+
27+
[dev-dependencies]
28+
pgrx-tests = { path = "../../pgrx-tests" }
29+
30+
# uncomment these if compiling outside of 'pgrx'
31+
# [profile.dev]
32+
# panic = "unwind"
33+
34+
# [profile.release]
35+
# panic = "unwind"
36+
# opt-level = 3
37+
# lto = "fat"
38+
# codegen-units = 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Postgres Dynamic Shared Memory in Parallel Foreign Scans and LWLock Support
2+
3+
Important:
4+
> Extensions that use shared memory **must** be loaded via `postgresql.conf`'s
5+
>`shared_preload_libraries` configuration setting.
6+
7+
The example in [src/lib.rs](src/lib.rs) implements a parallel scan implementation for a "generator" foreign table type
8+
that yields numbers from an integer counter, guarded by a dynamically allocated LWLock. It is meant to illustrate how to
9+
set up a lock for foreign scans, keeping the shared memory handling as simple as possible. Check out the `shmem` example
10+
project for more insights on shared memory handling in `pgrx` extensions.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
comment = 'parallel_scan_lwlock: Created by pgrx'
2+
default_version = '@CARGO_VERSION@'
3+
module_pathname = 'parallel_scan_lwlock'
4+
relocatable = false
5+
superuser = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::pgrx::pgrx_embed!();

0 commit comments

Comments
 (0)