Check index existence on raw SQL creation (#5624)
* Add conditional check on index existence before we try again * Add conditional check on index existence before we try again * Changelog * remit * remit * debug statements
This commit is contained in:
parent
a2a0a8a662
commit
b982abbfbe
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 5547
|
||||
title: "The addition of the indexes `idx_sp_uri_hash_identity_pattern_ops` and `idx_sp_string_hash_nrm_pattern_ops` could occasionally timeout during migration in Postgresql on large databases, leaving the migration table in a failed state, and Smile CDR unable to boot.
|
||||
Now existence of the index is checked before attempting to add it again."
|
|
@ -184,8 +184,10 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
|
|||
QUERY_FOR_COLUMN_COLLATION_TEMPLATE,
|
||||
"HFJ_SPIDX_STRING".toLowerCase(),
|
||||
"SP_VALUE_NORMALIZED".toLowerCase()),
|
||||
"Column HFJ_SPIDX_STRING.SP_VALUE_NORMALIZED already has a collation of 'C' so doing nothing");
|
||||
|
||||
"Column HFJ_SPIDX_STRING.SP_VALUE_NORMALIZED already has a collation of 'C' so doing nothing")
|
||||
.onlyIf(
|
||||
"SELECT NOT EXISTS(select 1 from pg_indexes where indexname='idx_sp_string_hash_nrm_pattern_ops')",
|
||||
"Index idx_sp_string_hash_nrm_pattern_ops already exists");
|
||||
version.executeRawSql(
|
||||
"20231212.2",
|
||||
"CREATE UNIQUE INDEX idx_sp_uri_hash_identity_pattern_ops ON public.hfj_spidx_uri USING btree (hash_identity, sp_uri varchar_pattern_ops, res_id, partition_id)")
|
||||
|
@ -195,7 +197,10 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
|
|||
QUERY_FOR_COLUMN_COLLATION_TEMPLATE,
|
||||
"HFJ_SPIDX_URI".toLowerCase(),
|
||||
"SP_URI".toLowerCase()),
|
||||
"Column HFJ_SPIDX_STRING.SP_VALUE_NORMALIZED already has a collation of 'C' so doing nothing");
|
||||
"Column HFJ_SPIDX_STRING.SP_VALUE_NORMALIZED already has a collation of 'C' so doing nothing")
|
||||
.onlyIf(
|
||||
"SELECT NOT EXISTS(select 1 from pg_indexes where indexname='idx_sp_uri_hash_identity_pattern_ops')",
|
||||
"Index idx_sp_uri_hash_identity_pattern_ops already exists.");
|
||||
}
|
||||
|
||||
// This fix was bad for MSSQL, it has been set to do nothing.
|
||||
|
|
|
@ -597,11 +597,11 @@ public class Builder {
|
|||
"Only SELECT statements (including CTEs) are allowed here. Please check your SQL: [%s]",
|
||||
theSql));
|
||||
}
|
||||
ourLog.info("SQL to evaluate: {}", theSql);
|
||||
ourLog.debug("SQL to evaluate: {}", theSql);
|
||||
|
||||
myTask.addPrecondition(new ExecuteTaskPrecondition(
|
||||
() -> {
|
||||
ourLog.info("Checking precondition for SQL: {}", theSql);
|
||||
ourLog.debug("Checking precondition for SQL: {}", theSql);
|
||||
return MigrationJdbcUtils.queryForSingleBooleanResultMultipleThrowsException(
|
||||
theSql, myTask.newJdbcTemplate());
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue