From f4ab233199d3c73d4149389e13597af85b4a21c2 Mon Sep 17 00:00:00 2001 From: Sami Hiltunen Date: Tue, 23 Feb 2021 17:15:04 +0100 Subject: add an index for replication job source replicas 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. --- ...0210223160555_replication_queue_source_index.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 internal/praefect/datastore/migrations/20210223160555_replication_queue_source_index.go 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) +} -- cgit v1.2.3