Skip to content

Commit 3392e5e

Browse files
chore: drop revision from Durable State by slice index and migration docs (#561)
1 parent 408ac9a commit 3392e5e

8 files changed

+22
-10
lines changed

core/src/main/scala/akka/persistence/r2dbc/internal/h2/H2Dialect.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private[r2dbc] object H2Dialect extends Dialect {
154154
}
155155
val durableStateSliceIndexes = allDurableStateTablesWithSchema.map { table =>
156156
val sliceIndexWithSchema = table + "_slice_idx"
157-
sql"""CREATE INDEX IF NOT EXISTS $sliceIndexWithSchema ON $table(slice, entity_type, db_timestamp, revision)"""
157+
sql"""CREATE INDEX IF NOT EXISTS $sliceIndexWithSchema ON $table(slice, entity_type, db_timestamp)"""
158158
}
159159
journalSliceIndexes ++
160160
snapshotSliceIndexes ++
@@ -219,7 +219,7 @@ private[r2dbc] object H2Dialect extends Dialect {
219219
state_payload BYTEA NOT NULL,
220220
tags TEXT ARRAY,
221221

222-
PRIMARY KEY(persistence_id, revision)
222+
PRIMARY KEY(persistence_id)
223223
)
224224
"""
225225
}

ddl-scripts/create_tables_postgres.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ CREATE TABLE IF NOT EXISTS durable_state (
6161
);
6262

6363
-- `durable_state_slice_idx` is only needed if the slice based queries are used
64-
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp, revision);
64+
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);

ddl-scripts/create_tables_postgres_0-1.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,5 @@ CREATE TABLE IF NOT EXISTS durable_state_1 (
121121
);
122122

123123
-- `durable_state_slice_idx` is only needed if the slice based queries are used
124-
CREATE INDEX IF NOT EXISTS durable_state_0_slice_idx ON durable_state_0(slice, entity_type, db_timestamp, revision);
125-
CREATE INDEX IF NOT EXISTS durable_state_1_slice_idx ON durable_state_1(slice, entity_type, db_timestamp, revision);
124+
CREATE INDEX IF NOT EXISTS durable_state_0_slice_idx ON durable_state_0(slice, entity_type, db_timestamp);
125+
CREATE INDEX IF NOT EXISTS durable_state_1_slice_idx ON durable_state_1(slice, entity_type, db_timestamp);

ddl-scripts/create_tables_postgres_2-3.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,5 @@ CREATE TABLE IF NOT EXISTS durable_state_3 (
121121
);
122122

123123
-- `durable_state_slice_idx` is only needed if the slice based queries are used
124-
CREATE INDEX IF NOT EXISTS durable_state_2_slice_idx ON durable_state_2(slice, entity_type, db_timestamp, revision);
125-
CREATE INDEX IF NOT EXISTS durable_state_3_slice_idx ON durable_state_3(slice, entity_type, db_timestamp, revision);
124+
CREATE INDEX IF NOT EXISTS durable_state_2_slice_idx ON durable_state_2(slice, entity_type, db_timestamp);
125+
CREATE INDEX IF NOT EXISTS durable_state_3_slice_idx ON durable_state_3(slice, entity_type, db_timestamp);

ddl-scripts/create_tables_postgres_jsonb.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ CREATE TABLE IF NOT EXISTS durable_state (
6161
);
6262

6363
-- `durable_state_slice_idx` is only needed if the slice based queries are used
64-
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp, revision);
64+
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);

ddl-scripts/create_tables_sqlserver.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ IF object_id('durable_state') is null
6767
-- `durable_state_slice_idx` is only needed if the slice based queries are used
6868
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'durable_state_slice_idx' AND object_id = OBJECT_ID('durable_state'))
6969
BEGIN
70-
CREATE INDEX durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp, revision);
70+
CREATE INDEX durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);
7171
END;

ddl-scripts/create_tables_yugabyte.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ CREATE TABLE IF NOT EXISTS durable_state (
6363
);
6464

6565
-- `durable_state_slice_idx` is only needed if the slice based queries are used
66-
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice ASC, entity_type ASC, db_timestamp ASC, revision ASC, persistence_id)
66+
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice ASC, entity_type ASC, db_timestamp ASC, persistence_id)
6767
SPLIT AT VALUES ((127), (255), (383), (511), (639), (767), (895));

docs/src/main/paradox/migration-guide.md

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ DROP CONSTRAINT durable_state_pkey,
1414
ADD PRIMARY KEY(persistence_id);
1515
```
1616
17+
Same goes for the (optional) index `durable_state_slice_idx` used for slice base queries. To remove the column from the index, use:
18+
19+
Postgres / Yugabyte:
20+
: ```sql
21+
DROP INDEX IF EXISTS durable_state_slice_idx;
22+
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);
23+
```
24+
25+
As mentioned above, this is optional. Changes to the database schema like this one can have an impact on the availability of the database under certain conditions.
26+
27+
Make sure to test them on a copy of your database to learn more about the potential impact.
28+
1729
If you are using @ref[data partitioning](./data-partition.md), please make sure to apply the change to all tables.
1830

1931
## 1.1.x to 1.2.0

0 commit comments

Comments
 (0)