From 306b67b34bc3cbcc90aa5935c6d422dc0297be6c Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Thu, 23 Jan 2025 17:36:30 +0100 Subject: [PATCH] Add maintenance job for clearing imported attribute search cache. --- .../searchcore/proton/server/CMakeLists.txt | 1 + ...ar_imported_attribute_search_cache_job.cpp | 38 +++++++++++++++++++ ...lear_imported_attribute_search_cache_job.h | 24 ++++++++++++ .../server/maintenance_jobs_injector.cpp | 8 ++++ 4 files changed, 71 insertions(+) create mode 100644 searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.cpp create mode 100644 searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.h diff --git a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt index e3857b2d8a99..d5e8cedf965a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt @@ -6,6 +6,7 @@ vespa_add_library(searchcore_server STATIC bootstrapconfigmanager.cpp buckethandler.cpp bucketmovejob.cpp + clear_imported_attribute_search_cache_job.cpp clusterstatehandler.cpp combiningfeedview.cpp ddbstate.cpp diff --git a/searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.cpp b/searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.cpp new file mode 100644 index 000000000000..fd2a943e8e17 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.cpp @@ -0,0 +1,38 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "clear_imported_attribute_search_cache_job.h" +#include +#include +#include + +using search::attribute::ImportedAttributeVector; + +namespace proton { + +ClearImportedAttributeSearchCacheJob::ClearImportedAttributeSearchCacheJob(std::shared_ptr mgr, + vespalib::duration visibilityDelay) + : IMaintenanceJob("clear_imported_attribute_search_cache", visibilityDelay, visibilityDelay), + _mgr(std::move(mgr)) +{ +} + +bool +ClearImportedAttributeSearchCacheJob::run() +{ + auto* imported_attributes_repo = _mgr->getImportedAttributes(); + if (imported_attributes_repo != nullptr) { + std::vector> importedAttrs; + imported_attributes_repo->getAll(importedAttrs); + for (const auto &attr : importedAttrs) { + attr->clearSearchCache(); + } + } + return true; +} + +void +ClearImportedAttributeSearchCacheJob::onStop() +{ +} + +} diff --git a/searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.h b/searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.h new file mode 100644 index 000000000000..0506b29e4a35 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/server/clear_imported_attribute_search_cache_job.h @@ -0,0 +1,24 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "i_maintenance_job.h" +#include + +namespace proton { + +struct IAttributeManager; + +/** + * Job that regularly clears the search cache for imported attributes. + */ +class ClearImportedAttributeSearchCacheJob : public IMaintenanceJob +{ + std::shared_ptr _mgr; +public: + ClearImportedAttributeSearchCacheJob(std::shared_ptr mgr, vespalib::duration visibilityDelay); + bool run() override; + void onStop() override; +}; + +} diff --git a/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp b/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp index 3ebeac3b9ce2..152bea0e257c 100644 --- a/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/maintenance_jobs_injector.cpp @@ -2,6 +2,7 @@ #include "maintenance_jobs_injector.h" #include "bucketmovejob.h" +#include "clear_imported_attribute_search_cache_job.h" #include "heart_beat_job.h" #include "job_tracked_maintenance_job.h" #include "lid_space_compaction_job.h" @@ -87,6 +88,13 @@ MaintenanceJobsInjector::injectJobs(MaintenanceController &controller, AttributeUsageFilter &attributeUsageFilter) { controller.registerJob(std::make_unique(hbHandler, config.getHeartBeatConfig())); + auto visibility_delay = config.getVisibilityDelay(); + if (visibility_delay != vespalib::duration::zero()) { + if (visibility_delay < 100ms) { + visibility_delay = 100ms; + } + controller.registerJob(std::make_unique(readyAttributeManager, config.getVisibilityDelay())); + } const auto & docTypeName = controller.getDocTypeName().getName(); const MaintenanceDocumentSubDB &mRemSubDB(controller.getRemSubDB());