diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2021-02-23 19:15:04 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2021-02-23 19:25:19 +0300 |
commit | f4ab233199d3c73d4149389e13597af85b4a21c2 (patch) | |
tree | 0a25c8bd181cf531370c9722f6b6383778befe6e | |
parent | 8c3a416f8fbd8e1187e8d7869bd77f933e91be1b (diff) |
add an index for replication job source replicassmh-replication-queue-source-index
The reconciler checks whether a replica is acting as a source of a
replication job prior to avoid breaking existing jobs when scheduling
'delete_replica' jobs. This commit adds an index for this check to ensure
it doesn't slow down linearly with then number of jobs in the replication
queue.
-rw-r--r-- | internal/praefect/datastore/migrations/20210223160555_replication_queue_source_index.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/praefect/datastore/migrations/20210223160555_replication_queue_source_index.go b/internal/praefect/datastore/migrations/20210223160555_replication_queue_source_index.go new file mode 100644 index 000000000..fbf8ce3cf --- /dev/null +++ b/internal/praefect/datastore/migrations/20210223160555_replication_queue_source_index.go @@ -0,0 +1,22 @@ +package migrations + +import migrate "github.com/rubenv/sql-migrate" + +func init() { + m := &migrate.Migration{ + Id: "20210223160555_replication_queue_source_index", + Up: []string{ + `CREATE INDEX CONCURRENTLY replication_queue_source_index +ON replication_queue ( + (job->>'virtual_storage'), + (job->>'relative_path'), + (job->>'source_node_storage') +) +WHERE state NOT IN ('completed', 'cancelled', 'dead')`, + }, + Down: []string{"DROP INDEX replication_queue_source_index"}, + DisableTransactionUp: true, + } + + allMigrations = append(allMigrations, m) +} |