Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: drop revision from Durable State by slice index and migration docs #561

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should clarify that this migration is optional. If someone is already using it I don't think it would hurt much to just continue with the existing index. Maybe same with the primary key. As mentioned below, there can be a huge performance impact on the db to recreate the index if the data volume is large.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If optional, and not even required for the migration anymore, can we just skip it from the docs? But of course, we can highlight this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, see that this section is currently under the following headline:

Durable State table schema change (optional)


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