Skip to content

Commit 2d256a1

Browse files
committed
fix(udb): fix postgres driver impl
1 parent e410867 commit 2d256a1

File tree

17 files changed

+916
-1488
lines changed

17 files changed

+916
-1488
lines changed

docker/dev/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ services:
147147
dockerfile: docker/universal/Dockerfile
148148
target: engine-full
149149
args:
150-
BUILD_FRONTEND: 'true'
150+
BUILD_FRONTEND: 'false'
151151
platform: linux/amd64
152152
restart: unless-stopped
153153
environment:
154+
# - RUST_LOG=debug
155+
- RUST_BACKTRACE=1
154156
- RUST_LOG_ANSI_COLOR=1
155157
- RIVET_OTEL_ENABLED=1
156158
- RIVET_OTEL_SAMPLER_RATIO=1

docker/dev/rivet-engine/config.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"postgres": {
2525
"url": "postgresql://postgres:postgres@postgres:5432/rivet_engine"
2626
},
27+
"memory": {
28+
"channel": "default"
29+
},
2730
"cache": {
2831
"driver": "in_memory"
2932
},

packages/common/cache/build/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub enum Error {
99
#[error("pools: {0}")]
1010
Pools(#[from] rivet_pools::Error),
1111

12-
#[error("getter: {0}")]
12+
#[error("cache getter: {0}")]
1313
Getter(anyhow::Error),
1414

1515
#[error("serde decode: {0}")]

packages/common/universaldb/src/driver/postgres/database.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ impl PostgresDatabaseDriver {
5252
.await
5353
.context("failed to create btree_gist extension")?;
5454

55+
conn.execute(
56+
"CREATE SEQUENCE global_version_seq START WITH 1 INCREMENT BY 1 MINVALUE 1",
57+
&[],
58+
)
59+
.await
60+
.context("failed to create global version sequence")?;
61+
5562
// Create the KV table if it doesn't exist
5663
conn.execute(
5764
"CREATE TABLE IF NOT EXISTS kv (
@@ -96,14 +103,19 @@ impl PostgresDatabaseDriver {
96103
"CREATE UNLOGGED TABLE IF NOT EXISTS conflict_ranges (
97104
range_data BYTEARANGE NOT NULL,
98105
conflict_type range_type NOT NULL,
99-
txn_id BIGINT NOT NULL DEFAULT txid_current(),
100-
101-
-- This constraint prevents read-write conflicts ONLY between different transactions
102-
-- Same transaction can have any combination of read/write overlaps
106+
start_version BIGINT NOT NULL,
107+
commit_version BIGINT NOT NULL,
108+
ts timestamp NOT NULL DEFAULT now(),
109+
103110
EXCLUDE USING gist (
104-
range_data WITH &&,
111+
-- Conflict if byte range overlaps...
112+
range_data WITH &&,
113+
-- And f conflict types are different...
105114
conflict_type WITH <>,
106-
txn_id WITH <>
115+
-- And f the txn versions overlap...
116+
int8range(start_version, commit_version, '[]') WITH &&,
117+
-- But not if the start_version is the same (from the same txn)
118+
start_version WITH <>
107119
)
108120
)",
109121
&[],

0 commit comments

Comments
 (0)