Skip to content

Zoekt: Add reallocation scheduling task

Dmitry Gruzd requested to merge 454289-zoekt-add-reallocation-task into master

What does this MR do and why?

This MR takes the script from the recent incident and turns it into a scheduling task

Database plans

Search::Zoekt::EnabledNamespace.where(id: node.indices.where(namespace_id: namespace_ids).select(:zoekt_enabled_namespace_id)).update_all(search: false, updated_at: Time.zone.now)
UPDATE "zoekt_enabled_namespaces" SET "search" = FALSE, "updated_at" = '2024-04-03 15:23:22.695030' WHERE "zoekt_enabled_namespaces"."id" IN (SELECT "zoekt_indices"."zoekt_enabled_namespace_id" FROM "zoekt_indices" WHERE "zoekt_indices"."zoekt_node_id" = 10 AND "zoekt_indices"."namespace_id" IN (72020569, 81929366, 7811657, 67858724, 14160629, 71707741, 62051980, 72193585, 9526127, 57349364, 71607218, 70922445, 81433216, 11626435, 15880505, 12443608, 61051508, 6730621, 68890757, 53786701, 71137932, 81412065, 9630740, 8474779, 73919614, 14147582, 81340449, 75649675, 9619442, 65699212, 65641627, 78989449, 71684218, 55310482, 70922438, 1298254, 12962032, 70106642, 70682852, 79389339, 69991962, 80029847, 61737019, 4642167, 65818294, 6686912, 918966, 59466828, 69476815, 81794881, 11370458, 10316576, 72278023, 80428365, 7240525, 7850346, 13164390, 64635561, 8533346, 12208853, 6545253, 356589, 70204826, 81804984, 80473287, 81815306, 79739972, 4339527, 13482440, 4975871, 8659214, 52528073, 77292406, 70633179, 70460392, 5394771, 1633852, 5851859, 79600636, 53288043, 11375272, 13563809, 77382551, 6098577, 65476155, 68047298, 54502395, 65866462, 7509264, 62099140, 2299361, 67126387, 70682062, 59137690, 15081863, 73887932, 68582018, 64580754, 16012241, 78649991))

https://postgres.ai/console/gitlab/gitlab-production-main/sessions/27355/commands/85132

node.indices.where(namespace_id: namespace_ids).destroy_all

This query performs individual destroy calls for the batch of up to 100 indices

SELECT "zoekt_indices".* FROM "zoekt_indices" WHERE "zoekt_indices"."zoekt_node_id" = 10 AND "zoekt_indices"."namespace_id" IN (72020569, 81929366, 7811657, 67858724, 14160629, 71707741, 62051980, 72193585, 9526127, 57349364, 71607218, 70922445, 81433216, 11626435, 15880505, 12443608, 61051508, 6730621, 68890757, 53786701, 71137932, 81412065, 9630740, 8474779, 73919614, 14147582, 81340449, 75649675, 9619442, 65699212, 65641627, 78989449, 71684218, 55310482, 70922438, 1298254, 12962032, 70106642, 70682852, 79389339, 69991962, 80029847, 61737019, 4642167, 65818294, 6686912, 918966, 59466828, 69476815, 81794881, 11370458, 10316576, 72278023, 80428365, 7240525, 7850346, 13164390, 64635561, 8533346, 12208853, 6545253, 356589, 70204826, 81804984, 80473287, 81815306, 79739972, 4339527, 13482440, 4975871, 8659214, 52528073, 77292406, 70633179, 70460392, 5394771, 1633852, 5851859, 79600636, 53288043, 11375272, 13563809, 77382551, 6098577, 65476155, 68047298, 54502395, 65866462, 7509264, 62099140, 2299361, 67126387, 70682062, 59137690, 15081863, 73887932, 68582018, 64580754, 16012241, 78649991)

https://postgres.ai/console/gitlab/gitlab-production-main/sessions/27355/commands/85133

Batching over indices

SELECT "zoekt_indices"."namespace_id" FROM "zoekt_indices" WHERE "zoekt_indices"."zoekt_node_id" = 10 AND "zoekt_indices"."id" >= 13633 AND "zoekt_indices"."id" < 17485

Before adding a composite index: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/27383/commands/85249

After adding a composite index: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/27383/commands/85252

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

#454289 (closed)

Edited by Dmitry Gruzd

Merge request reports