Skip to content

Commit

Permalink
Merge pull request #32576 from vespa-engine/toregge/use-shared-pointe…
Browse files Browse the repository at this point in the history
…r-to-const-schema

Use shared_ptr to const Schema when schema is considered to be immuta…
  • Loading branch information
toregge authored Oct 11, 2024
2 parents f35fb1b + 66dcdac commit d6f625c
Show file tree
Hide file tree
Showing 33 changed files with 60 additions and 63 deletions.
8 changes: 4 additions & 4 deletions searchcore/src/tests/proton/documentdb/configurer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Fixture::initViewSet(ViewSet &views)
auto attrWriter = std::make_shared<AttributeWriter>(attrMgr);
auto summaryAdapter = std::make_shared<SummaryAdapter>(summaryMgr);
views._gidToLidChangeHandler = make_shared<MockGidToLidChangeHandler>();
Schema::SP schema(new Schema());
auto schema(std::make_shared<const Schema>());
views._summaryMgr = summaryMgr;
views._dmsc = metaStore;
IndexSearchable::SP indexSearchable;
Expand Down Expand Up @@ -318,7 +318,7 @@ MyFastAccessFeedView::~MyFastAccessFeedView() = default;
void
MyFastAccessFeedView::init() {
MySummaryAdapter::SP summaryAdapter = std::make_shared<MySummaryAdapter>();
Schema::SP schema = std::make_shared<Schema>();
auto schema = std::make_shared<const Schema>();
_dmsc = make_shared<DocumentMetaStoreContext>(std::make_shared<bucketdb::BucketDBOwner>());
std::shared_ptr<const DocumentTypeRepo> repo = createRepo();
StoreOnlyFeedView::Context storeOnlyCtx(summaryAdapter, schema, _dmsc, repo,
Expand Down Expand Up @@ -382,9 +382,9 @@ createConfig()
}

DocumentDBConfig::SP
createConfig(const Schema::SP &schema)
createConfig(std::shared_ptr<const Schema> schema)
{
return proton::test::DocumentDBConfigBuilder(0, schema, "client", DOC_TYPE).
return proton::test::DocumentDBConfigBuilder(0, std::move(schema), "client", DOC_TYPE).
repo(createRepo()).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class MyConfigBuilder {
test::DocumentDBConfigBuilder _builder;

public:
MyConfigBuilder(int64_t generation, const Schema::SP &schema, const std::shared_ptr<const DocumentTypeRepo> &repo)
: _builder(generation, schema, "client", "test")
MyConfigBuilder(int64_t generation, std::shared_ptr<const Schema> schema, const std::shared_ptr<const DocumentTypeRepo> &repo)
: _builder(generation, std::move(schema), "client", "test")
{
_builder.repo(repo);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ TEST_F("require that makeReplayConfig() drops unneeded configs", Fixture)
}

struct DelayAttributeAspectFixture {
Schema::SP schema;
std::shared_ptr<const Schema> schema;
ConfigSP attrCfg;
ConfigSP noAttrCfg;
explicit DelayAttributeAspectFixture(bool hasDocField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ std::ostream& operator<<(std::ostream& os, const AttributesConfig::Attribute::Di
namespace {

DDBCSP
getConfig(int64_t generation, const Schema::SP &schema,
getConfig(int64_t generation, std::shared_ptr<const Schema> schema,
const shared_ptr<const DocumentTypeRepo> & repo,
const AttributesConfig &attributes)
{
return test::DocumentDBConfigBuilder(generation, schema, "client", "test").
return test::DocumentDBConfigBuilder(generation, std::move(schema), "client", "test").
repo(repo).attributes(make_shared<AttributesConfig>(attributes)).build();
}

Expand Down Expand Up @@ -382,7 +382,7 @@ TEST("Test that DocumentDBConfigScout::scout looks ahead")
setupLiveAttributes(liveAttributes.attribute);

shared_ptr<const DocumentTypeRepo> repo(make_shared<DocumentTypeRepo>());
Schema::SP schema(make_shared<Schema>());
std::shared_ptr<const Schema> schema(make_shared<Schema>());
DDBCSP cfg = getConfig(4, schema, repo, attributes);
DDBCSP liveCfg = getConfig(4, schema, repo, liveAttributes);
EXPECT_FALSE(*cfg == *liveCfg);
Expand Down
2 changes: 1 addition & 1 deletion searchcore/src/tests/proton/documentdb/feedview_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ MyTransport::~MyTransport() = default;
struct SchemaContext
{
DocBuilder _builder;
Schema::SP _schema;
std::shared_ptr<const Schema> _schema;
SchemaContext();
~SchemaContext();
std::shared_ptr<const document::DocumentTypeRepo> getRepo() const { return _builder.get_repo_sp(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ saveBaseConfigSnapshot(FNET_Transport & transport, const DocumentDBConfig &snap,
DocumentDBConfig::SP
makeEmptyConfigSnapshot()
{
return test::DocumentDBConfigBuilder(0, std::make_shared<Schema>(), "client", "test").build();
return test::DocumentDBConfigBuilder(0, std::make_shared<const Schema>(), "client", "test").build();
}

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct MyMinimalFeedView : public MyMinimalFeedViewBase, public StoreOnlyFeedVie
std::atomic<int> &outstandingMoveOps_) :
MyMinimalFeedViewBase(),
StoreOnlyFeedView(StoreOnlyFeedView::Context(summaryAdapter,
search::index::Schema::SP(),
{},
std::make_shared<DocumentMetaStoreContext>(metaStore),
myGetDocumentTypeRepo(),
std::move(pendingLidsForCommit),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct DBConfigFixture {
JuniperrcConfigBuilder _juniperrcBuilder;
ImportedFieldsConfigBuilder _importedFieldsBuilder;

Schema::SP buildSchema()
std::shared_ptr<const Schema> buildSchema()
{
return DocumentDBConfig::build_schema(_attributesBuilder, _indexschemaBuilder);
}
Expand Down
6 changes: 3 additions & 3 deletions searchcore/src/tests/proton/server/memoryconfigstore_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ using namespace proton;
namespace {

DocumentDBConfig::SP
getConfig(int64_t generation, const Schema::SP &schema)
getConfig(int64_t generation, std::shared_ptr<const Schema> schema)
{
return test::DocumentDBConfigBuilder(generation, schema, "client", "test").build();
return test::DocumentDBConfigBuilder(generation, std::move(schema), "client", "test").build();
}


DocumentDBConfig::SP
getConfig(int64_t generation)
{
return getConfig(generation, Schema::SP());
return getConfig(generation, {});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MemoryIndexWrapper : public searchcorespi::index::IMemoryIndex {
bool hasReceivedDocumentInsert() const override {
return _index.getDocIdLimit() > 1u;
}
search::index::Schema::SP getPrunedSchema() const override {
std::shared_ptr<const search::index::Schema> getPrunedSchema() const override {
return _index.getPrunedSchema();
}
vespalib::MemoryUsage getMemoryUsage() const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ DocumentDB::applyConfig(DocumentDBConfig::SP configSnapshot, SerialNum serialNum

auto start_time = vespalib::steady_clock::now();
DocumentDBConfig::ComparisonResult cmpres;
Schema::SP oldSchema;
{
lock_guard guard(_configMutex);
assert(_activeConfigSnapshot.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ DocumentDBConfig::DocumentDBConfig(
const std::shared_ptr<const DocumentTypeRepo> &repo,
const ImportedFieldsConfigSP &importedFields,
const search::TuneFileDocumentDB::SP &tuneFileDocumentDB,
const Schema::SP &schema,
std::shared_ptr<const Schema> schema,
const DocumentDBMaintenanceConfig::SP &maintenance,
const search::LogDocumentStore::Config & storeConfig,
const ThreadingServiceConfig & threading_service_config,
Expand All @@ -88,7 +88,7 @@ DocumentDBConfig::DocumentDBConfig(
_repo(repo),
_importedFields(importedFields),
_tuneFileDocumentDB(tuneFileDocumentDB),
_schema(schema),
_schema(std::move(schema)),
_maintenance(maintenance),
_storeConfig(storeConfig),
_threading_service_config(threading_service_config),
Expand Down Expand Up @@ -338,7 +338,7 @@ DocumentDBConfig::getDocumentType() const
return _repo->getDocumentType(getDocTypeName());
}

std::shared_ptr<Schema>
std::shared_ptr<const Schema>
DocumentDBConfig::build_schema(const AttributesConfig& attributes_config,
const IndexschemaConfig &indexschema_config)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class DocumentDBConfig
std::shared_ptr<const document::DocumentTypeRepo> _repo;
ImportedFieldsConfigSP _importedFields;
search::TuneFileDocumentDB::SP _tuneFileDocumentDB;
search::index::Schema::SP _schema;
std::shared_ptr<const search::index::Schema> _schema;
MaintenanceConfigSP _maintenance;
search::LogDocumentStore::Config _storeConfig;
const ThreadingServiceConfig _threading_service_config;
Expand Down Expand Up @@ -165,7 +165,7 @@ class DocumentDBConfig
const std::shared_ptr<const document::DocumentTypeRepo> &repo,
const ImportedFieldsConfigSP &importedFields,
const search::TuneFileDocumentDB::SP &tuneFileDocumentDB,
const search::index::Schema::SP &schema,
std::shared_ptr<const search::index::Schema> schema,
const DocumentDBMaintenanceConfig::SP &maintenance,
const search::LogDocumentStore::Config & storeConfig,
const ThreadingServiceConfig & threading_service_config,
Expand Down Expand Up @@ -206,7 +206,7 @@ class DocumentDBConfig
const document::DocumentType *getDocumentType() const;
const ImportedFieldsConfig &getImportedFieldsConfig() const { return *_importedFields; }
const ImportedFieldsConfigSP &getImportedFieldsConfigSP() const { return _importedFields; }
const search::index::Schema::SP &getSchemaSP() const { return _schema; }
const std::shared_ptr<const search::index::Schema>& getSchemaSP() const noexcept { return _schema; }
const MaintenanceConfigSP &getMaintenanceConfigSP() const { return _maintenance; }
const search::TuneFileDocumentDB::SP &getTuneFileDocumentDBSP() const { return _tuneFileDocumentDB; }
bool getDelayedAttributeAspects() const { return _delayedAttributeAspects; }
Expand Down Expand Up @@ -253,7 +253,7 @@ class DocumentDBConfig
static SP makeDelayedAttributeAspectConfig(const SP &newCfg, const DocumentDBConfig &oldCfg);
SP make_copy() const;

static std::shared_ptr<search::index::Schema>
static std::shared_ptr<const search::index::Schema>
build_schema(const AttributesConfig& attributes_config,
const IndexschemaConfig &indexschema_config);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ DocumentDBConfigManager::createConfigKeySet() const
return set;
}

Schema::SP
std::shared_ptr<const Schema>
DocumentDBConfigManager::buildSchema(const AttributesConfig &newAttributesConfig,
const IndexschemaConfig &newIndexschemaConfig)
{
// Called with lock held
Schema::SP oldSchema;
std::shared_ptr<const Schema> oldSchema;
if (_pendingConfigSnapshot) {
oldSchema = _pendingConfigSnapshot->getSchemaSP();
}
Expand Down Expand Up @@ -335,7 +335,7 @@ DocumentDBConfigManager::update(FNET_Transport & transport, const ConfigSnapshot
JuniperrcConfigSP newJuniperrcConfig = snapshot.getConfig<JuniperrcConfig>(_configId);
ImportedFieldsConfigSP newImportedFieldsConfig = snapshot.getConfig<ImportedFieldsConfig>(_configId);

Schema::SP schema(buildSchema(*newAttributesConfig, *newIndexschemaConfig));
auto schema(buildSchema(*newAttributesConfig, *newIndexschemaConfig));
newMaintenanceConfig = buildMaintenanceConfig(_bootstrapConfig, _docTypeName);
search::LogDocumentStore::Config storeConfig = buildStoreConfig(_bootstrapConfig->getProtonConfig(),
_bootstrapConfig->getHwInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DocumentDBConfigManager
bool _ignoreForwardedConfig;
mutable std::mutex _pendingConfigMutex;

search::index::Schema::SP
std::shared_ptr<const search::index::Schema>
buildSchema(const DocumentDBConfig::AttributesConfig & newAttributesConfig,
const DocumentDBConfig::IndexschemaConfig & newIndexschemaConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using ARIConfig = AttributeReprocessingInitializer::Config;

void
FastAccessDocSubDBConfigurer::reconfigureFeedView(FastAccessFeedView & curr,
std::shared_ptr<Schema> schema,
std::shared_ptr<const Schema> schema,
std::shared_ptr<const DocumentTypeRepo> repo,
std::shared_ptr<IAttributeWriter> writer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FastAccessDocSubDBConfigurer
std::string _subDbName;

void reconfigureFeedView(FastAccessFeedView & curr,
std::shared_ptr<search::index::Schema> schema,
std::shared_ptr<const search::index::Schema> schema,
std::shared_ptr<const document::DocumentTypeRepo> repo,
std::shared_ptr<IAttributeWriter> attrWriter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class IDocumentSubDB
using UP = std::unique_ptr<IDocumentSubDB>;
using SerialNum = search::SerialNum;
using Schema = search::index::Schema;
using SchemaSP = std::shared_ptr<Schema>;
using IFlushTargetList = std::vector<std::shared_ptr<searchcorespi::IFlushTarget>>;
using IndexConfig = index::IndexConfig;
using OnDone = std::shared_ptr<vespalib::IDestructorCallback>;
Expand Down Expand Up @@ -122,7 +121,7 @@ class IDocumentSubDB
*/
virtual SerialNum getNewestFlushedSerial() = 0;
virtual void pruneRemovedFields(SerialNum serialNum) = 0;
virtual void setIndexSchema(const SchemaSP &schema, SerialNum serialNum) = 0;
virtual void setIndexSchema(std::shared_ptr<const Schema> schema, SerialNum serialNum) = 0;
virtual search::SearchableStats getSearchableStats() const = 0;
virtual std::shared_ptr<IDocumentRetriever> getDocumentRetriever() = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using ARIConfig = AttributeReprocessingInitializer::Config;

void
SearchableDocSubDBConfigurer::reconfigureFeedView(std::shared_ptr<IAttributeWriter> attrWriter,
std::shared_ptr<Schema> schema,
std::shared_ptr<const Schema> schema,
std::shared_ptr<const DocumentTypeRepo> repo)
{
auto curr = _feedView.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SearchableDocSubDBConfigurer
uint32_t _distributionKey;

void reconfigureFeedView(std::shared_ptr<IAttributeWriter> attrWriter,
std::shared_ptr<search::index::Schema> schema,
std::shared_ptr<const search::index::Schema> schema,
std::shared_ptr<const document::DocumentTypeRepo> repo);

void reconfigureMatchView(const std::shared_ptr<searchcorespi::IndexSearchable>& indexSearchable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ SearchableDocSubDB::getFlushTargetsInternal()
}

void
SearchableDocSubDB::setIndexSchema(const Schema::SP &schema, SerialNum serialNum)
SearchableDocSubDB::setIndexSchema(std::shared_ptr<const Schema> schema, SerialNum serialNum)
{
assert(_writeService.master().isCurrentThread());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ SearchableDocSubDB : public FastAccessDocSubDB,

SerialNum getOldestFlushedSerial() override;
SerialNum getNewestFlushedSerial() override;
void setIndexSchema(const Schema::SP &schema, SerialNum serialNum) override;
void setIndexSchema(std::shared_ptr<const Schema> schema, SerialNum serialNum) override;
size_t getNumActiveDocs() const override;
search::SearchableStats getSearchableStats() const override ;
std::shared_ptr<IDocumentRetriever> getDocumentRetriever() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ StoreOnlyDocSubDB::pruneRemovedFields(SerialNum)
}

void
StoreOnlyDocSubDB::setIndexSchema(const Schema::SP &, SerialNum )
StoreOnlyDocSubDB::setIndexSchema(std::shared_ptr<const Schema>, SerialNum)
{
assert(_writeService.master().isCurrentThread());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class StoreOnlyDocSubDB : public DocSubDB
SerialNum getNewestFlushedSerial() override;

void pruneRemovedFields(SerialNum serialNum) override;
void setIndexSchema(const Schema::SP &schema, SerialNum serialNum) override;
void setIndexSchema(std::shared_ptr<const Schema> schema, SerialNum serialNum) override;
search::SearchableStats getSearchableStats() const override;
std::shared_ptr<IDocumentRetriever> getDocumentRetriever() override;
matching::MatchingStats getMatcherStats(const std::string &rankProfile) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ class StoreOnlyFeedView : public IFeedView,
struct Context
{
ISummaryAdapter::SP _summaryAdapter;
search::index::Schema::SP _schema;
std::shared_ptr<const search::index::Schema> _schema;
IDocumentMetaStoreContext::SP _documentMetaStoreContext;
std::shared_ptr<const document::DocumentTypeRepo> _repo;
std::shared_ptr<PendingLidTrackerBase> _pendingLidsForCommit;
IGidToLidChangeHandler &_gidToLidChangeHandler;
searchcorespi::index::IThreadingService &_writeService;

Context(ISummaryAdapter::SP summaryAdapter,
search::index::Schema::SP schema,
std::shared_ptr<const search::index::Schema> schema,
IDocumentMetaStoreContext::SP documentMetaStoreContext,
std::shared_ptr<const document::DocumentTypeRepo> repo,
std::shared_ptr<PendingLidTrackerBase> pendingLidsForCommit,
Expand Down Expand Up @@ -126,7 +126,7 @@ class StoreOnlyFeedView : public IFeedView,
LidReuseDelayer _lidReuseDelayer;
PendingLidTracker _pendingLidsForDocStore;
std::shared_ptr<PendingLidTrackerBase> _pendingLidsForCommit;
const search::index::Schema::SP _schema;
const std::shared_ptr<const search::index::Schema> _schema;
vespalib::hash_set<int32_t> _indexedFields;
protected:
searchcorespi::index::IThreadingService &_writeService;
Expand Down Expand Up @@ -197,7 +197,7 @@ class StoreOnlyFeedView : public IFeedView,
~StoreOnlyFeedView() override;

const ISummaryAdapter::SP &getSummaryAdapter() const { return _summaryAdapter; }
const search::index::Schema::SP &getSchema() const { return _schema; }
const std::shared_ptr<const search::index::Schema> &getSchema() const noexcept { return _schema; }
const PersistentParams &getPersistentParams() const { return _params; }
const search::IDocumentStore &getDocumentStore() const { return _summaryAdapter->getDocumentStore(); }
const IDocumentMetaStoreContext::SP &getDocumentMetaStore() const { return _documentMetaStoreContext; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using proton::ThreadingServiceConfig;
namespace proton::test {

DocumentDBConfigBuilder::DocumentDBConfigBuilder(int64_t generation,
const search::index::Schema::SP &schema,
std::shared_ptr<const search::index::Schema> schema,
const std::string &configId,
const std::string &docTypeName)
: _generation(generation),
Expand All @@ -42,7 +42,7 @@ DocumentDBConfigBuilder::DocumentDBConfigBuilder(int64_t generation,
_repo(std::make_shared<document::DocumentTypeRepo>()),
_importedFields(std::make_shared<ImportedFieldsConfig>()),
_tuneFileDocumentDB(std::make_shared<TuneFileDocumentDB>()),
_schema(schema),
_schema(std::move(schema)),
_maintenance(std::make_shared<DocumentDBMaintenanceConfig>()),
_store(),
_threading_service_config(ThreadingServiceConfig::make()),
Expand Down
Loading

0 comments on commit d6f625c

Please sign in to comment.