From 12ae6fbfbd78f5afd120977d3466536d8acd80a9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 24 Apr 2024 11:25:30 +0200 Subject: [PATCH] chore: drop revision from Durable State by slice index and migration docs --- .../persistence/r2dbc/internal/h2/H2Dialect.scala | 4 ++-- ddl-scripts/create_tables_postgres.sql | 2 +- ddl-scripts/create_tables_postgres_0-1.sql | 4 ++-- ddl-scripts/create_tables_postgres_2-3.sql | 4 ++-- ddl-scripts/create_tables_postgres_jsonb.sql | 2 +- ddl-scripts/create_tables_sqlserver.sql | 2 +- ddl-scripts/create_tables_yugabyte.sql | 2 +- docs/src/main/paradox/migration-guide.md | 12 ++++++++++++ 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/src/main/scala/akka/persistence/r2dbc/internal/h2/H2Dialect.scala b/core/src/main/scala/akka/persistence/r2dbc/internal/h2/H2Dialect.scala index bb311982..a95d10ed 100644 --- a/core/src/main/scala/akka/persistence/r2dbc/internal/h2/H2Dialect.scala +++ b/core/src/main/scala/akka/persistence/r2dbc/internal/h2/H2Dialect.scala @@ -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 ++ @@ -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) ) """ } diff --git a/ddl-scripts/create_tables_postgres.sql b/ddl-scripts/create_tables_postgres.sql index 0a1c5fc9..dfff08d0 100644 --- a/ddl-scripts/create_tables_postgres.sql +++ b/ddl-scripts/create_tables_postgres.sql @@ -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); diff --git a/ddl-scripts/create_tables_postgres_0-1.sql b/ddl-scripts/create_tables_postgres_0-1.sql index fe5819b7..70ac81e2 100644 --- a/ddl-scripts/create_tables_postgres_0-1.sql +++ b/ddl-scripts/create_tables_postgres_0-1.sql @@ -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); diff --git a/ddl-scripts/create_tables_postgres_2-3.sql b/ddl-scripts/create_tables_postgres_2-3.sql index 64ba5909..079b22ba 100644 --- a/ddl-scripts/create_tables_postgres_2-3.sql +++ b/ddl-scripts/create_tables_postgres_2-3.sql @@ -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); diff --git a/ddl-scripts/create_tables_postgres_jsonb.sql b/ddl-scripts/create_tables_postgres_jsonb.sql index 117effdc..336af00a 100644 --- a/ddl-scripts/create_tables_postgres_jsonb.sql +++ b/ddl-scripts/create_tables_postgres_jsonb.sql @@ -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); diff --git a/ddl-scripts/create_tables_sqlserver.sql b/ddl-scripts/create_tables_sqlserver.sql index 89437cae..4987e9e4 100644 --- a/ddl-scripts/create_tables_sqlserver.sql +++ b/ddl-scripts/create_tables_sqlserver.sql @@ -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; diff --git a/ddl-scripts/create_tables_yugabyte.sql b/ddl-scripts/create_tables_yugabyte.sql index ceb8977b..c9f57335 100644 --- a/ddl-scripts/create_tables_yugabyte.sql +++ b/ddl-scripts/create_tables_yugabyte.sql @@ -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)); diff --git a/docs/src/main/paradox/migration-guide.md b/docs/src/main/paradox/migration-guide.md index ebc43579..7b22496b 100644 --- a/docs/src/main/paradox/migration-guide.md +++ b/docs/src/main/paradox/migration-guide.md @@ -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