Zoekt: Add mark_ready task
What does this MR do and why?
Add a new task move_indices_to_ready
in the Search::Zoekt::SchedulingService
. This task will move all the initializing
zoekt indices to ready if there are no zoekt_repositories
in the pending
state. Also, add a logging with a payload of the total count of zoekt indices which will be moved to ready
in a single run.
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
- Open the rails console.
bin/rails c
- Create a new namespace for the testing.
- Run the following commands to create zoekt index
zoekt_node = ::Search::Zoekt::Node.find_or_create_by!(index_base_url: 'http://127.0.0.1:6080/', search_base_url: 'http://127.0.0.1:6090/', uuid: '00000000-0000-0000-0000-000000000000')
namespace = Namespace.last # Some namespace you want to enable
enabled_namespace = Search::Zoekt::EnabledNamespace.find_or_create_by(namespace: namespace)
zoekt_node.indices.create!(zoekt_enabled_namespace_id: enabled_namespace.id, namespace_id: namespace.id, state: :ready)
idx = zoekt_node.indices.last
idx.initializing!
- Create some projects under the selected
namespace
. Let's create3
projects - Create
Search::Zoekt::Repository
records
namespace.projects.each { |p| idx.zoekt_repositories.create!(zoekt_index: idx, project: p, state: :pending) }
- Run the service
Search::Zoekt::SchedulingService.new(:move_indices_to_ready).execute
- Check the state of the index. It must be
initializing
- Now move just one zoekt_repository to the
ready
state
idx.zoekt_repositories.last.ready!
- Again run the service from step 6. Check the state of the index. It must be
initializing
idx.reload.state
- Now move all the zoekt_repositories to the
ready
state
idx.zoekt_repositories.map(&:ready!)
- Again run the service from step 6. Check the state of the index. It must be
ready
idx.reload.state
Query plan
https://console.postgres.ai/shared/8b71ba27-fdd2-4201-82db-406ae75e1fc0
SELECT
"zoekt_indices".*
FROM
"zoekt_indices"
WHERE
"zoekt_indices"."state" = 1
https://console.postgres.ai/shared/6c268398-9ae7-4cea-be95-e22b567bfe5b
SELECT
"zoekt_indices".*
FROM
"zoekt_indices"
INNER JOIN "zoekt_repositories" ON "zoekt_repositories"."zoekt_index_id" = "zoekt_indices"."id"
WHERE
"zoekt_indices"."state" = 1
AND "zoekt_indices"."id" NOT IN ( SELECT DISTINCT
"zoekt_repositories"."zoekt_index_id"
FROM
"zoekt_repositories"
WHERE
"zoekt_repositories"."state" != 10)
Related to #442881 (closed)