diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-04-13 07:47:33 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-04-13 07:47:33 +0000 |
commit | 045babd97ccd8ba1bf44c14d0bce326c1f1a57be (patch) | |
tree | 625e9ed63e07c80f4895bd2608821507a4b1b121 /searchcore/src | |
parent | f9cc338cc28a79045da882db7ddcc8e02cb301df (diff) |
Force having documentdb as shared_ptr.
Diffstat (limited to 'searchcore/src')
8 files changed, 119 insertions, 104 deletions
diff --git a/searchcore/src/apps/tests/persistenceconformance_test.cpp b/searchcore/src/apps/tests/persistenceconformance_test.cpp index d28e7a1f8d3..69d509c25fd 100644 --- a/searchcore/src/apps/tests/persistenceconformance_test.cpp +++ b/searchcore/src/apps/tests/persistenceconformance_test.cpp @@ -192,34 +192,18 @@ public: config::DirSpec spec(inputCfg + "/config-1"); TuneFileDocumentDB::SP tuneFileDocDB(new TuneFileDocumentDB()); DocumentDBConfigHelper mgr(spec, docType.getName()); - BootstrapConfig::SP b(new BootstrapConfig(1, - factory.getTypeCfg(), - factory.getTypeRepo(), + auto b = std::make_shared<BootstrapConfig>(1, factory.getTypeCfg(), factory.getTypeRepo(), std::make_shared<ProtonConfig>(), std::make_shared<FiledistributorrpcConfig>(), std::make_shared<BucketspacesConfig>(), - tuneFileDocDB, HwInfo())); + tuneFileDocDB, HwInfo()); mgr.forwardConfig(b); mgr.nextGeneration(0ms); - return std::make_shared<DocumentDB>(_baseDir, - mgr.getConfig(), - _tlsSpec, - _queryLimiter, - _clock, - docType, - bucketSpace, - *b->getProtonConfigSP(), - const_cast<DocumentDBFactory &>(*this), - _summaryExecutor, - _summaryExecutor, - _bucketExecutor, - _tls, - _metricsWireService, - _fileHeaderContext, - _config_stores.getConfigStore(docType.toString()), - std::make_shared<vespalib::ThreadStackExecutor> - (16, 128_Ki), - HwInfo()); + return DocumentDB::create(_baseDir, mgr.getConfig(), _tlsSpec, _queryLimiter, _clock, docType, bucketSpace, + *b->getProtonConfigSP(), const_cast<DocumentDBFactory &>(*this), + _summaryExecutor, _summaryExecutor, _bucketExecutor, _tls, _metricsWireService, + _fileHeaderContext, _config_stores.getConfigStore(docType.toString()), + std::make_shared<vespalib::ThreadStackExecutor>(16, 128_Ki), HwInfo()); } }; diff --git a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp index 846ff6ece08..4191d9bc442 100644 --- a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp +++ b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp @@ -798,24 +798,12 @@ PersistenceProviderFixture::create_document_db(const BMParams & params) tuneFileDocDB, HwInfo()); mgr.forwardConfig(bootstrap_config); mgr.nextGeneration(0ms); - _document_db = std::make_shared<DocumentDB>(_base_dir, - mgr.getConfig(), - _tls_spec, - _query_limiter, - _clock, - _doc_type_name, - _bucket_space, - *bootstrap_config->getProtonConfigSP(), - _document_db_owner, - _summary_executor, - _summary_executor, - *_persistence_engine, - _tls, - _metrics_wire_service, - _file_header_context, - _config_stores.getConfigStore(_doc_type_name.toString()), - std::make_shared<vespalib::ThreadStackExecutor>(16, 128_Ki), - HwInfo()); + _document_db = DocumentDB::create(_base_dir, mgr.getConfig(), _tls_spec, _query_limiter, _clock, _doc_type_name, + _bucket_space, *bootstrap_config->getProtonConfigSP(), _document_db_owner, + _summary_executor, _summary_executor, *_persistence_engine, _tls, + _metrics_wire_service, _file_header_context, + _config_stores.getConfigStore(_doc_type_name.toString()), + std::make_shared<vespalib::ThreadStackExecutor>(16, 128_Ki), HwInfo()); _document_db->start(); _document_db->waitForOnlineState(); } diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index 9529555a33c..8dae53abf50 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -186,7 +186,7 @@ public: const std::shared_ptr<const DocumentTypeRepo> _repo; TuneFileDocumentDB::SP _tuneFileDocumentDB; HwInfo _hwInfo; - std::unique_ptr<DocumentDB> _ddb; + std::shared_ptr<DocumentDB> _ddb; AttributeWriter::UP _aw; ISummaryAdapter::SP _sa; @@ -221,11 +221,11 @@ public: if (! FastOS_File::MakeDirectory((std::string("tmpdb/") + docTypeName).c_str())) { LOG_ABORT("should not be reached"); } - _ddb = std::make_unique<DocumentDB>("tmpdb", _configMgr.getConfig(), "tcp/localhost:9013", _queryLimiter, _clock, - DocTypeName(docTypeName), makeBucketSpace(), *b->getProtonConfigSP(), *this, - _summaryExecutor, _summaryExecutor, _bucketExecutor, _tls, _dummy, _fileHeaderContext, - std::make_unique<MemoryConfigStore>(), - std::make_shared<vespalib::ThreadStackExecutor>(16, 128_Ki), _hwInfo), + _ddb = DocumentDB::create("tmpdb", _configMgr.getConfig(), "tcp/localhost:9013", _queryLimiter, _clock, + DocTypeName(docTypeName), makeBucketSpace(), *b->getProtonConfigSP(), *this, + _summaryExecutor, _summaryExecutor, _bucketExecutor, _tls, _dummy, _fileHeaderContext, + std::make_unique<MemoryConfigStore>(), + std::make_shared<vespalib::ThreadStackExecutor>(16, 128_Ki), _hwInfo), _ddb->start(); _ddb->waitForOnlineState(); _aw = std::make_unique<AttributeWriter>(_ddb->getReadySubDB()->getAttributeManager()); diff --git a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp index 3c65326b11a..463a7b164e1 100644 --- a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp @@ -108,7 +108,7 @@ Fixture::Fixture() tuneFileDocumentDB, HwInfo()); mgr.forwardConfig(b); mgr.nextGeneration(0ms); - _db = std::make_shared<DocumentDB>(".", mgr.getConfig(), "tcp/localhost:9014", _queryLimiter, _clock, DocTypeName("typea"), + _db = DocumentDB::create(".", mgr.getConfig(), "tcp/localhost:9014", _queryLimiter, _clock, DocTypeName("typea"), makeBucketSpace(), *b->getProtonConfigSP(), _myDBOwner, _summaryExecutor, _summaryExecutor, _bucketExecutor, _tls, _dummy, _fileHeaderContext, std::make_unique<MemoryConfigStore>(), diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index d99e579b89f..1f06521f4d3 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -110,8 +110,33 @@ DocumentDB::masterExecute(FunctionType &&function) { _writeService.master().execute(makeLambdaTask(std::forward<FunctionType>(function))); } +DocumentDB::SP +DocumentDB::create(const vespalib::string &baseDir, + DocumentDBConfig::SP currentSnapshot, + const vespalib::string &tlsSpec, + matching::QueryLimiter &queryLimiter, + const vespalib::Clock &clock, + const DocTypeName &docTypeName, + document::BucketSpace bucketSpace, + const ProtonConfig &protonCfg, + IDocumentDBOwner &owner, + vespalib::SyncableThreadExecutor &warmupExecutor, + vespalib::ThreadStackExecutorBase &sharedExecutor, + storage::spi::BucketExecutor &bucketExecutor, + const search::transactionlog::WriterFactory &tlsWriterFactory, + MetricsWireService &metricsWireService, + const search::common::FileHeaderContext &fileHeaderContext, + ConfigStore::UP config_store, + InitializeThreads initializeThreads, + const HwInfo &hwInfo) +{ + return DocumentDB::SP( + new DocumentDB(baseDir, std::move(currentSnapshot), tlsSpec, queryLimiter, clock, docTypeName, bucketSpace, + protonCfg, owner, warmupExecutor, sharedExecutor, bucketExecutor, tlsWriterFactory, + metricsWireService, fileHeaderContext, std::move(config_store), initializeThreads, hwInfo)); +} DocumentDB::DocumentDB(const vespalib::string &baseDir, - const DocumentDBConfig::SP &configSnapshot, + DocumentDBConfig::SP configSnapshot, const vespalib::string &tlsSpec, matching::QueryLimiter &queryLimiter, const vespalib::Clock &clock, @@ -134,6 +159,7 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir, IDocumentSubDBOwner(), IClusterStateChangedHandler(), search::transactionlog::SyncProxy(), + std::enable_shared_from_this<DocumentDB>(), _docTypeName(docTypeName), _bucketSpace(bucketSpace), _baseDir(baseDir + "/" + _docTypeName.toString()), diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.h b/searchcore/src/vespa/searchcore/proton/server/documentdb.h index dd3d821e291..0a56ca29ea2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.h @@ -68,7 +68,8 @@ class DocumentDB : public DocumentDBConfigOwner, public IFeedHandlerOwner, public IDocumentSubDBOwner, public IClusterStateChangedHandler, - public search::transactionlog::SyncProxy + public search::transactionlog::SyncProxy, + public std::enable_shared_from_this<DocumentDB> { private: using InitializeThreads = std::shared_ptr<vespalib::SyncableThreadExecutor>; @@ -89,42 +90,42 @@ private: typedef search::index::Schema Schema; using lock_guard = std::lock_guard<std::mutex>; // variables related to reconfig - DocumentDBConfig::SP _initConfigSnapshot; - SerialNum _initConfigSerialNum; + DocumentDBConfig::SP _initConfigSnapshot; + SerialNum _initConfigSerialNum; vespalib::VarHolder<DocumentDBConfig::SP> _pendingConfigSnapshot; - mutable std::mutex _configMutex; // protects _active* below. - mutable std::condition_variable _configCV; - DocumentDBConfig::SP _activeConfigSnapshot; - int64_t _activeConfigSnapshotGeneration; - const bool _validateAndSanitizeDocStore; + mutable std::mutex _configMutex; // protects _active* below. + mutable std::condition_variable _configCV; + DocumentDBConfig::SP _activeConfigSnapshot; + int64_t _activeConfigSnapshotGeneration; + const bool _validateAndSanitizeDocStore; vespalib::Gate _initGate; typedef DocumentDBConfig::ComparisonResult ConfigComparisonResult; - ClusterStateHandler _clusterStateHandler; - BucketHandler _bucketHandler; - index::IndexConfig _indexCfg; - ConfigStore::UP _config_store; - std::shared_ptr<matching::SessionManager> _sessionManager; // TODO: This should not have to be a shared pointer. - MetricsWireService &_metricsWireService; - DocumentDBTaggedMetrics _metrics; - std::unique_ptr<metrics::UpdateHook> _metricsHook; - vespalib::VarHolder<IFeedView::SP> _feedView; - MonitoredRefCount _refCount; - bool _syncFeedViewEnabled; - IDocumentDBOwner &_owner; - storage::spi::BucketExecutor &_bucketExecutor; - DDBState _state; - DiskMemUsageForwarder _dmUsageForwarder; - AttributeUsageFilter _writeFilter; + ClusterStateHandler _clusterStateHandler; + BucketHandler _bucketHandler; + index::IndexConfig _indexCfg; + ConfigStore::UP _config_store; + std::shared_ptr<matching::SessionManager> _sessionManager; // TODO: This should not have to be a shared pointer. + MetricsWireService &_metricsWireService; + DocumentDBTaggedMetrics _metrics; + std::unique_ptr<metrics::UpdateHook> _metricsHook; + vespalib::VarHolder<IFeedView::SP> _feedView; + MonitoredRefCount _refCount; + bool _syncFeedViewEnabled; + IDocumentDBOwner &_owner; + storage::spi::BucketExecutor &_bucketExecutor; + DDBState _state; + DiskMemUsageForwarder _dmUsageForwarder; + AttributeUsageFilter _writeFilter; std::shared_ptr<TransientResourceUsageProvider> _transient_usage_provider; - std::unique_ptr<FeedHandler> _feedHandler; - DocumentSubDBCollection _subDBs; - MaintenanceController _maintenanceController; - DocumentDBJobTrackers _jobTrackers; - std::shared_ptr<IBucketStateCalculator> _calc; - DocumentDBMetricsUpdater _metricsUpdater; + std::unique_ptr<FeedHandler> _feedHandler; + DocumentSubDBCollection _subDBs; + MaintenanceController _maintenanceController; + DocumentDBJobTrackers _jobTrackers; + std::shared_ptr<IBucketStateCalculator> _calc; + DocumentDBMetricsUpdater _metricsUpdater; void registerReference(); void setActiveConfig(const DocumentDBConfig::SP &config, int64_t generation); @@ -205,26 +206,8 @@ private: // Invokes initFinish() on self friend class InitDoneTask; -public: - typedef std::unique_ptr<DocumentDB> UP; - typedef std::shared_ptr<DocumentDB> SP; - - /** - * Constructs a new document database for the given document type. - * - * @param baseDir The base directory to use for persistent data. - * @param configId The config id used to subscribe to config for this - * database. - * @param tlsSpec The frt connection spec for the TLS. - * @param docType The document type that this database will handle. - * @param docMgrCfg Current document manager config - * @param docMgrSP The document manager holding the document type. - * @param protonCfg The global proton config this database is a part of. - * @param tuneFileDocumentDB file tune config for this database. - * @param config_store Access to read and write configs. - */ DocumentDB(const vespalib::string &baseDir, - const DocumentDBConfig::SP ¤tSnapshot, + DocumentDBConfig::SP currentSnapshot, const vespalib::string &tlsSpec, matching::QueryLimiter &queryLimiter, const vespalib::Clock &clock, @@ -234,13 +217,46 @@ public: IDocumentDBOwner &owner, vespalib::SyncableThreadExecutor &warmupExecutor, vespalib::ThreadStackExecutorBase &sharedExecutor, - storage::spi::BucketExecutor & bucketExecutor, + storage::spi::BucketExecutor &bucketExecutor, const search::transactionlog::WriterFactory &tlsWriterFactory, MetricsWireService &metricsWireService, const search::common::FileHeaderContext &fileHeaderContext, ConfigStore::UP config_store, InitializeThreads initializeThreads, const HwInfo &hwInfo); +public: + using UP = std::unique_ptr<DocumentDB>; + using SP = std::shared_ptr<DocumentDB>; + + /** + * Constructs a new document database for the given document type. + * + * @param baseDir The base directory to use for persistent data. + * @param tlsSpec The frt connection spec for the TLS. + * @param docType The document type that this database will handle. + * @param docMgrSP The document manager holding the document type. + * @param protonCfg The global proton config this database is a part of. + * @param config_store Access to read and write configs. + */ + static DocumentDB::SP + create(const vespalib::string &baseDir, + DocumentDBConfig::SP currentSnapshot, + const vespalib::string &tlsSpec, + matching::QueryLimiter &queryLimiter, + const vespalib::Clock &clock, + const DocTypeName &docTypeName, + document::BucketSpace bucketSpace, + const ProtonConfig &protonCfg, + IDocumentDBOwner &owner, + vespalib::SyncableThreadExecutor &warmupExecutor, + vespalib::ThreadStackExecutorBase &sharedExecutor, + storage::spi::BucketExecutor & bucketExecutor, + const search::transactionlog::WriterFactory &tlsWriterFactory, + MetricsWireService &metricsWireService, + const search::common::FileHeaderContext &fileHeaderContext, + ConfigStore::UP config_store, + InitializeThreads initializeThreads, + const HwInfo &hwInfo); /** * Expose a cost view of the session manager. This is used by the diff --git a/searchcore/src/vespa/searchcore/proton/server/maintenancedocumentsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/maintenancedocumentsubdb.cpp index f91ed2bf608..ffbf42304d2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/maintenancedocumentsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/maintenancedocumentsubdb.cpp @@ -39,6 +39,7 @@ MaintenanceDocumentSubDB::clear() _meta_store.reset(); _retriever.reset(); _feed_view.reset(); + _pendingLidsForCommit = nullptr; } bool diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index 1beb0a04de0..afeaec5333f 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -615,11 +615,11 @@ Proton::addDocumentDB(const document::DocumentType &docType, // 1 thread per document type. initializeThreads = std::make_shared<vespalib::ThreadStackExecutor>(1, 128_Ki); } - auto ret = std::make_shared<DocumentDB>(config.basedir + "/documents", documentDBConfig, config.tlsspec, - _queryLimiter, _clock, docTypeName, bucketSpace, config, *this, - *_warmupExecutor, *_sharedExecutor, *_persistenceEngine, *_tls->getTransLogServer(), - *_metricsEngine, _fileHeaderContext, std::move(config_store), - initializeThreads, bootstrapConfig->getHwInfo()); + auto ret = DocumentDB::create(config.basedir + "/documents", documentDBConfig, config.tlsspec, + _queryLimiter, _clock, docTypeName, bucketSpace, config, *this, + *_warmupExecutor, *_sharedExecutor, *_persistenceEngine, *_tls->getTransLogServer(), + *_metricsEngine, _fileHeaderContext, std::move(config_store), + initializeThreads, bootstrapConfig->getHwInfo()); try { ret->start(); } catch (vespalib::Exception &e) { |