Skip to content

Commit

Permalink
chore: drop revision from Durable State by slice index and migration …
Browse files Browse the repository at this point in the history
…docs
  • Loading branch information
sebastian-alfers committed Apr 24, 2024
1 parent d579807 commit 12ae6fb
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private[r2dbc] object H2Dialect extends Dialect {
}
val durableStateSliceIndexes = allDurableStateTablesWithSchema.map { table =>
val sliceIndexWithSchema = table + "_slice_idx"
sql"""CREATE INDEX IF NOT EXISTS $sliceIndexWithSchema ON $table(slice, entity_type, db_timestamp, revision)"""
sql"""CREATE INDEX IF NOT EXISTS $sliceIndexWithSchema ON $table(slice, entity_type, db_timestamp)"""
}
journalSliceIndexes ++
snapshotSliceIndexes ++
Expand Down Expand Up @@ -219,7 +219,7 @@ private[r2dbc] object H2Dialect extends Dialect {
state_payload BYTEA NOT NULL,
tags TEXT ARRAY,

PRIMARY KEY(persistence_id, revision)
PRIMARY KEY(persistence_id)
)
"""
}
Expand Down
2 changes: 1 addition & 1 deletion ddl-scripts/create_tables_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ CREATE TABLE IF NOT EXISTS durable_state (
);

-- `durable_state_slice_idx` is only needed if the slice based queries are used
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp, revision);
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);
4 changes: 2 additions & 2 deletions ddl-scripts/create_tables_postgres_0-1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ CREATE TABLE IF NOT EXISTS durable_state_1 (
);

-- `durable_state_slice_idx` is only needed if the slice based queries are used
CREATE INDEX IF NOT EXISTS durable_state_0_slice_idx ON durable_state_0(slice, entity_type, db_timestamp, revision);
CREATE INDEX IF NOT EXISTS durable_state_1_slice_idx ON durable_state_1(slice, entity_type, db_timestamp, revision);
CREATE INDEX IF NOT EXISTS durable_state_0_slice_idx ON durable_state_0(slice, entity_type, db_timestamp);
CREATE INDEX IF NOT EXISTS durable_state_1_slice_idx ON durable_state_1(slice, entity_type, db_timestamp);
4 changes: 2 additions & 2 deletions ddl-scripts/create_tables_postgres_2-3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ CREATE TABLE IF NOT EXISTS durable_state_3 (
);

-- `durable_state_slice_idx` is only needed if the slice based queries are used
CREATE INDEX IF NOT EXISTS durable_state_2_slice_idx ON durable_state_2(slice, entity_type, db_timestamp, revision);
CREATE INDEX IF NOT EXISTS durable_state_3_slice_idx ON durable_state_3(slice, entity_type, db_timestamp, revision);
CREATE INDEX IF NOT EXISTS durable_state_2_slice_idx ON durable_state_2(slice, entity_type, db_timestamp);
CREATE INDEX IF NOT EXISTS durable_state_3_slice_idx ON durable_state_3(slice, entity_type, db_timestamp);
2 changes: 1 addition & 1 deletion ddl-scripts/create_tables_postgres_jsonb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ CREATE TABLE IF NOT EXISTS durable_state (
);

-- `durable_state_slice_idx` is only needed if the slice based queries are used
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp, revision);
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);
2 changes: 1 addition & 1 deletion ddl-scripts/create_tables_sqlserver.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ IF object_id('durable_state') is null
-- `durable_state_slice_idx` is only needed if the slice based queries are used
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'durable_state_slice_idx' AND object_id = OBJECT_ID('durable_state'))
BEGIN
CREATE INDEX durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp, revision);
CREATE INDEX durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);
END;
2 changes: 1 addition & 1 deletion ddl-scripts/create_tables_yugabyte.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ CREATE TABLE IF NOT EXISTS durable_state (
);

-- `durable_state_slice_idx` is only needed if the slice based queries are used
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice ASC, entity_type ASC, db_timestamp ASC, revision ASC, persistence_id)
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice ASC, entity_type ASC, db_timestamp ASC, persistence_id)
SPLIT AT VALUES ((127), (255), (383), (511), (639), (767), (895));
12 changes: 12 additions & 0 deletions docs/src/main/paradox/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ DROP CONSTRAINT durable_state_pkey,
ADD PRIMARY KEY(persistence_id);
```
Same goes for the (optional) index `` used for slice base queries. To remove the column from the index, use:
Postgres / Yugabyte:
: ```sql
DROP INDEX IF EXISTS durable_state_slice_idx;
CREATE INDEX IF NOT EXISTS durable_state_slice_idx ON durable_state(slice, entity_type, db_timestamp);
```

Changes to the database schema like mentioned above can have an impact on the availability of the database under certain conditions.

Make sure to test them on a copy of your database to learn more about the potential impact.

If you are using @ref[data partitioning](./data-partition.md), please make sure to apply the change to all tables.

## 1.1.x to 1.2.0
Expand Down

0 comments on commit 12ae6fb

Please sign in to comment.