Skip to content

Commit

Permalink
Merge pull request #32580 from vespa-engine/toregge/add-and-remove-in…
Browse files Browse the repository at this point in the history
…dex-metrics-when-schema-changes

Add and remove index metrics when schema changes.
  • Loading branch information
geirst authored Oct 11, 2024
2 parents 5cdc448 + 8a0626f commit fe5045a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ DocumentSubDbInitializerResult::DocumentSubDbInitializerResult()
_summaryManager(std::make_shared<SummaryManager::SP>()),
_attributeManager(std::make_shared<AttributeManager::SP>()),
_indexManager(std::make_shared<IIndexManager::SP>()),
_flushConfig()
_flushConfig(),
_schema()
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DocumentSubDbInitializerResult
std::shared_ptr<AttributeManager::SP> _attributeManager;
std::shared_ptr<searchcorespi::IIndexManager::SP> _indexManager;
DocumentDBFlushConfig _flushConfig;
std::shared_ptr<const search::index::Schema> _schema;

public:
DocumentSubDbInitializerResult();
Expand Down Expand Up @@ -53,6 +54,8 @@ class DocumentSubDbInitializerResult

void setFlushConfig(const DocumentDBFlushConfig &flushConfig);
const DocumentDBFlushConfig &getFlushConfig() const { return _flushConfig; }
void set_schema(std::shared_ptr<const search::index::Schema> schema) { _schema = std::move(schema); }
std::shared_ptr<const search::index::Schema> get_schema() const { return _schema; }
};

} // namespace proton
Expand Down
3 changes: 3 additions & 0 deletions searchcore/src/vespa/searchcore/proton/server/documentdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vespa/searchcore/proton/flushengine/threadedflushtarget.h>
#include <vespa/searchcore/proton/index/index_manager_initializer.h>
#include <vespa/searchcore/proton/index/index_writer.h>
#include <vespa/searchcore/proton/metrics/documentdb_tagged_metrics.h>
#include <vespa/searchcore/proton/reference/document_db_reference.h>
#include <vespa/searchcore/proton/reference/gid_to_lid_change_handler.h>
#include <vespa/searchcore/proton/reference/i_document_db_reference_resolver.h>
Expand Down Expand Up @@ -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<IndexWriter>(_indexMgr);
reconfigure_index_metrics(schema);
}

DocumentSubDbInitializer::UP
Expand All @@ -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());
}
Expand Down Expand Up @@ -282,6 +284,17 @@ SearchableDocSubDB::getFlushTargetsInternal()
return ret;
}

void
SearchableDocSubDB::reconfigure_index_metrics(const Schema& schema)
{
std::vector<std::string> 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<const Schema> schema, SerialNum serialNum)
{
Expand All @@ -292,6 +305,7 @@ SearchableDocSubDB::setIndexSchema(std::shared_ptr<const Schema> schema, SerialN

_indexMgr->setSchema(*schema, serialNum);
reconfigureIndexSearchable();
reconfigure_index_metrics(*schema);
}

size_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ SearchableDocSubDB : public FastAccessDocSubDB,
const IndexConfig &indexCfg,
std::shared_ptr<searchcorespi::IIndexManager::SP> 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> configure) override;
void reconfigureIndexSearchable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit fe5045a

Please sign in to comment.