Skip to content

Commit

Permalink
Merge pull request #33167 from vespa-engine/toregge/add-maintenance-j…
Browse files Browse the repository at this point in the history
…ob-for-clearing-imported-attribute-search-cache

Add maintenance job for clearing imported attribute search cache.
  • Loading branch information
vekterli authored Jan 24, 2025
2 parents f402ed5 + 306b67b commit e76c2cc
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <vespa/searchcore/proton/attribute/i_attribute_manager.h>
#include <vespa/searchcore/proton/attribute/imported_attributes_repo.h>
#include <vespa/searchlib/attribute/imported_attribute_vector.h>

using search::attribute::ImportedAttributeVector;

namespace proton {

ClearImportedAttributeSearchCacheJob::ClearImportedAttributeSearchCacheJob(std::shared_ptr<IAttributeManager> 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<std::shared_ptr<ImportedAttributeVector>> importedAttrs;
imported_attributes_repo->getAll(importedAttrs);
for (const auto &attr : importedAttrs) {
attr->clearSearchCache();
}
}
return true;
}

void
ClearImportedAttributeSearchCacheJob::onStop()
{
}

}
Original file line number Diff line number Diff line change
@@ -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 <vespa/vespalib/util/time.h>

namespace proton {

struct IAttributeManager;

/**
* Job that regularly clears the search cache for imported attributes.
*/
class ClearImportedAttributeSearchCacheJob : public IMaintenanceJob
{
std::shared_ptr<IAttributeManager> _mgr;
public:
ClearImportedAttributeSearchCacheJob(std::shared_ptr<IAttributeManager> mgr, vespalib::duration visibilityDelay);
bool run() override;
void onStop() override;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -87,6 +88,13 @@ MaintenanceJobsInjector::injectJobs(MaintenanceController &controller,
AttributeUsageFilter &attributeUsageFilter)
{
controller.registerJob(std::make_unique<HeartBeatJob>(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<ClearImportedAttributeSearchCacheJob>(readyAttributeManager, config.getVisibilityDelay()));
}

const auto & docTypeName = controller.getDocTypeName().getName();
const MaintenanceDocumentSubDB &mRemSubDB(controller.getRemSubDB());
Expand Down

0 comments on commit e76c2cc

Please sign in to comment.