From 8a0626fe49d918255bdfe153972e7f1faae84ffa Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Fri, 11 Oct 2024 16:00:10 +0200 Subject: [PATCH] Add and remove index metrics when schema changes. --- .../document_subdb_initializer_result.cpp | 3 ++- .../server/document_subdb_initializer_result.h | 3 +++ .../searchcore/proton/server/documentdb.cpp | 3 +++ .../proton/server/searchabledocsubdb.cpp | 18 ++++++++++++++++-- .../proton/server/searchabledocsubdb.h | 3 ++- .../proton/server/storeonlydocsubdb.cpp | 1 + 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.cpp b/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.cpp index 49aef8cb792e..32073ea17be8 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.cpp @@ -12,7 +12,8 @@ DocumentSubDbInitializerResult::DocumentSubDbInitializerResult() _summaryManager(std::make_shared()), _attributeManager(std::make_shared()), _indexManager(std::make_shared()), - _flushConfig() + _flushConfig(), + _schema() { } diff --git a/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.h b/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.h index 1bd108a588b4..53986c86d8a6 100644 --- a/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.h +++ b/searchcore/src/vespa/searchcore/proton/server/document_subdb_initializer_result.h @@ -23,6 +23,7 @@ class DocumentSubDbInitializerResult std::shared_ptr _attributeManager; std::shared_ptr _indexManager; DocumentDBFlushConfig _flushConfig; + std::shared_ptr _schema; public: DocumentSubDbInitializerResult(); @@ -53,6 +54,8 @@ class DocumentSubDbInitializerResult void setFlushConfig(const DocumentDBFlushConfig &flushConfig); const DocumentDBFlushConfig &getFlushConfig() const { return _flushConfig; } + void set_schema(std::shared_ptr schema) { _schema = std::move(schema); } + std::shared_ptr get_schema() const { return _schema; } }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index 5b9a7d495723..39c3b73e42fb 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -568,6 +568,9 @@ DocumentDB::close() _metricsWireService.set_attributes(metrics.ready.attributes, {}); _metricsWireService.set_attributes(metrics.notReady.attributes, {}); + // Tear down index metrics + _metricsWireService.set_index_fields(metrics.ready.index, {}); + masterExecute([this] () { closeSubDBs(); }); diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp index 55f5819970ed..36b76329d2ea 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -94,10 +95,11 @@ createIndexManagerInitializer(const DocumentDBConfig &configSnapshot, SerialNum } void -SearchableDocSubDB::setupIndexManager(searchcorespi::IIndexManager::SP indexManager) +SearchableDocSubDB::setupIndexManager(searchcorespi::IIndexManager::SP indexManager, const Schema& schema) { _indexMgr = std::move(indexManager); _indexWriter = std::make_shared(_indexMgr); + reconfigure_index_metrics(schema); } DocumentSubDbInitializer::UP @@ -115,7 +117,7 @@ void SearchableDocSubDB::setup(const DocumentSubDbInitializerResult &initResult) { Parent::setup(initResult); - setupIndexManager(initResult.indexManager()); + setupIndexManager(initResult.indexManager(), *initResult.get_schema()); _docIdLimit.set(_dms->getCommittedDocIdLimit()); applyFlushConfig(initResult.getFlushConfig()); } @@ -282,6 +284,17 @@ SearchableDocSubDB::getFlushTargetsInternal() return ret; } +void +SearchableDocSubDB::reconfigure_index_metrics(const Schema& schema) +{ + std::vector field_names; + field_names.reserve(schema.getNumIndexFields()); + for (auto& field : schema.getIndexFields()) { + field_names.emplace_back(field.getName()); + } + _metricsWireService.set_index_fields(_metrics.ready.index, std::move(field_names)); +} + void SearchableDocSubDB::setIndexSchema(std::shared_ptr schema, SerialNum serialNum) { @@ -292,6 +305,7 @@ SearchableDocSubDB::setIndexSchema(std::shared_ptr schema, SerialN _indexMgr->setSchema(*schema, serialNum); reconfigureIndexSearchable(); + reconfigure_index_metrics(*schema); } size_t diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h index 1836e45e86b3..92a82a042fd4 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h @@ -79,9 +79,10 @@ SearchableDocSubDB : public FastAccessDocSubDB, const IndexConfig &indexCfg, std::shared_ptr indexManager) const; - void setupIndexManager(searchcorespi::IIndexManager::SP indexManager); + void setupIndexManager(searchcorespi::IIndexManager::SP indexManager, const Schema& schema); void initFeedView(IAttributeWriter::SP attrWriter, const DocumentDBConfig &configSnapshot); void reconfigureMatchingMetrics(const vespa::config::search::RankProfilesConfig &config); + void reconfigure_index_metrics(const Schema& schema); bool reconfigure(std::unique_ptr configure) override; void reconfigureIndexSearchable(); diff --git a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp index 21ed93274c50..a94ee90877f2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp @@ -323,6 +323,7 @@ StoreOnlyDocSubDB::createInitializer(const DocumentDBConfig &configSnapshot, Ser summaryTask->addDependency(dmsInitTask); result->writableResult().setFlushConfig(configSnapshot.getMaintenanceConfigSP()->getFlushConfig()); + result->writableResult().set_schema(configSnapshot.getSchemaSP()); return result; }