Skip to content
Snippets Groups Projects
Verified Commit 087555a0 authored by Dmitry Gruzd's avatar Dmitry Gruzd 🔴 Committed by GitLab
Browse files

Merge branch 'jm-zoekt-watermark-callback' into 'master'

Add zoekt index watermark level update callback

See merge request !181056



Merged-by: default avatarDmitry Gruzd <dgruzd@gitlab.com>
Approved-by: default avatarDmitry Gruzd <dgruzd@gitlab.com>
Co-authored-by: default avatarJohn Mason <9717668-johnmason@users.noreply.gitlab.com>
Co-authored-by: default avatarJohn Mason <jmason@gitlab.com>
parents fcdad32b 99e74190
No related branches found
No related tags found
1 merge request!181056Add zoekt index watermark level update callback
Pipeline #1678318713 passed
......@@ -27,6 +27,7 @@ class Index < ApplicationRecord
validates :metadata, json_schema: { filename: 'zoekt_indices_metadata' }
before_save :set_watermark_level, if: :storage_bytes_changed?
after_commit :delete_from_index, on: :destroy
enum state: {
......@@ -133,7 +134,6 @@ def update_reserved_storage_bytes!
return if new_reserved_bytes == reserved_storage_bytes
self.reserved_storage_bytes = new_reserved_bytes
self.watermark_level = appropriate_watermark_level
save!
rescue ActiveRecord::ActiveRecordError => err
logger.error(build_structured_payload(
......@@ -176,6 +176,14 @@ def appropriate_watermark_level
end
end
def set_watermark_level
self.watermark_level = appropriate_watermark_level
end
def storage_bytes_changed?
reserved_storage_bytes_changed? || used_storage_bytes_changed?
end
def delete_from_index
::Search::Zoekt::NamespaceIndexerWorker.perform_async(namespace_id, 'delete', zoekt_node_id)
end
......
......@@ -295,13 +295,15 @@
it 'returns indices where watermark_level is mismatched (healthy)' do
# Setup a healthy record but with incorrect watermark_level
create(
idx = create(
:zoekt_index,
used_storage_bytes: 40,
reserved_storage_bytes: 100,
watermark_level: :low_watermark_exceeded # Incorrect level
reserved_storage_bytes: 100
)
# Skip active record callback: set_watermark_level
idx.update!(watermark_level: :low_watermark_exceeded) # Incorrect level
expect(mismatched_indices.count).to eq(1)
expect(mismatched_indices.first.watermark_level).to eq('low_watermark_exceeded')
end
......@@ -320,24 +322,30 @@
it 'detects overprovisioned mismatches' do
# Setup an overprovisioned record with incorrect watermark_level
create(
idx = create(
:zoekt_index,
used_storage_bytes: 10,
reserved_storage_bytes: 100,
watermark_level: :healthy # Incorrect level
reserved_storage_bytes: 100
)
# Skip active record callback: set_watermark_level
idx.update!(watermark_level: :healthy) # Incorrect level
expect(mismatched_indices.count).to eq(1)
expect(mismatched_indices.first.watermark_level).to eq('healthy')
end
it 'handles edge cases at the exact boundary' do
# Setup a record exactly at the STORAGE_LOW_WATERMARK
create(
idx = create(
:zoekt_index,
used_storage_bytes: (low_watermark * 100).to_i,
reserved_storage_bytes: 100,
watermark_level: :healthy
reserved_storage_bytes: 100
)
# Skip active record callback
idx.update!(
watermark_level: :healthy # Incorrect level
)
expect(mismatched_indices.count).to eq(1)
......@@ -358,13 +366,14 @@
it 'returns indices where watermark_level is mismatched (critical)' do
# Setup a record that should be critical but has incorrect watermark_level
create(
idx = create(
:zoekt_index,
used_storage_bytes: (critical_watermark * 100) + 1,
reserved_storage_bytes: 100,
watermark_level: :high_watermark_exceeded # Incorrect level
reserved_storage_bytes: 100
)
idx.update!(watermark_level: :high_watermark_exceeded) # Incorrect level
expect(mismatched_indices.count).to eq(1)
expect(mismatched_indices.first.watermark_level).to eq('high_watermark_exceeded')
end
......
......@@ -32,7 +32,8 @@
let_it_be_with_reload(:mismatched_index) { create(:zoekt_index, :critical_watermark_exceeded) }
before do
mismatched_index.healthy!
mismatched_index.update!(watermark_level: :healthy) # skip active record callback
negative_bytes_index.update!(watermark_level: :healthy)
end
it 'calls update_reserved_storage_bytes! on the indices' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment