diff options
author | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-02-15 13:11:12 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@yahoo-inc.com> | 2017-02-15 13:11:12 +0000 |
commit | 46f776a240dfdf12ec07bb63559099e9cfdc9f35 (patch) | |
tree | 5780ef1647869b778af00f430d30c9757f305fa1 /searchcore/src | |
parent | 4cacb06d47c48bb186738f0b4c3eddf6ecc57740 (diff) |
Add document db referent registry to proton.
Register document db referent for document db when appropriate.
Diffstat (limited to 'searchcore/src')
13 files changed, 85 insertions, 7 deletions
diff --git a/searchcore/src/tests/proton/common/dummydbowner.h b/searchcore/src/tests/proton/common/dummydbowner.h index 8e3748b5072..2ed6a6f3ad8 100644 --- a/searchcore/src/tests/proton/common/dummydbowner.h +++ b/searchcore/src/tests/proton/common/dummydbowner.h @@ -17,6 +17,9 @@ struct DummyDBOwner : IDocumentDBOwner { return searchcorespi::IIndexManagerFactory::SP(); } uint32_t getDistributionKey() const override { return -1; } + std::shared_ptr<IDocumentDBReferentRegistry> getDocumentDBReferentRegistry() const override { + return std::shared_ptr<IDocumentDBReferentRegistry>(); + } }; } // namespace proton diff --git a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp index 018849cc9ad..020f7696a7a 100644 --- a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp @@ -14,6 +14,8 @@ #include <vespa/searchcore/proton/server/memoryconfigstore.h> #include <vespa/searchcore/proton/metrics/job_tracked_flush_target.h> #include <vespa/searchcore/proton/metrics/metricswireservice.h> +#include <vespa/searchcore/proton/reference/document_db_referent_registry.h> +#include <vespa/searchcore/proton/reference/i_document_db_referent.h> #include <vespa/searchcorespi/index/indexflushtarget.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/transactionlog/translogserver.h> @@ -52,9 +54,22 @@ public: } }; +struct MyDBOwner : public DummyDBOwner +{ + std::shared_ptr<DocumentDBReferentRegistry> _registry; + MyDBOwner() + : DummyDBOwner(), + _registry(std::make_shared<DocumentDBReferentRegistry>()) + { + } + std::shared_ptr<IDocumentDBReferentRegistry> getDocumentDBReferentRegistry() const override { + return _registry; + } +}; + struct Fixture { DummyWireService _dummy; - DummyDBOwner _dummyDBOwner; + MyDBOwner _myDBOwner; vespalib::ThreadStackExecutor _summaryExecutor; HwInfo _hwInfo; DocumentDB::SP _db; @@ -68,7 +83,7 @@ struct Fixture { Fixture::Fixture() : _dummy(), - _dummyDBOwner(), + _myDBOwner(), _summaryExecutor(8, 128*1024), _hwInfo(), _db(), @@ -95,7 +110,7 @@ Fixture::Fixture() _db.reset(new DocumentDB(".", mgr.getConfig(), "tcp/localhost:9014", _queryLimiter, _clock, DocTypeName("typea"), ProtonConfig(), - _dummyDBOwner, _summaryExecutor, _summaryExecutor, NULL, _dummy, _fileHeaderContext, + _myDBOwner, _summaryExecutor, _summaryExecutor, NULL, _dummy, _fileHeaderContext, ConfigStore::UP(new MemoryConfigStore), std::make_shared<vespalib::ThreadStackExecutor> (16, 128 * 1024), @@ -219,6 +234,16 @@ TEST_F("require that session manager can be explored", Fixture) EXPECT_TRUE(DocumentDBExplorer(f._db).get_child("session").get() != nullptr); } +TEST_F("require that document db registers referent", Fixture) +{ + auto ®istry = f._myDBOwner._registry; + auto referent = registry->get("typea"); + EXPECT_TRUE(referent.get() != nullptr); + auto attr = referent->getAttribute("attr1"); + EXPECT_TRUE(attr.get() != nullptr); + EXPECT_EQUAL(search::attribute::BasicType::INT32, attr->getBasicType()); +} + } // namespace TEST_MAIN() { diff --git a/searchcore/src/vespa/searchcore/proton/reference/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/reference/CMakeLists.txt index a74a1e58221..f2528a93853 100644 --- a/searchcore/src/vespa/searchcore/proton/reference/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/reference/CMakeLists.txt @@ -6,4 +6,5 @@ vespa_add_library(searchcore_reference STATIC gid_to_lid_mapper.cpp gid_to_lid_mapper_factory.cpp DEPENDS + searchcore_documentmetastore ) diff --git a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt index afe6b392717..ee83f93043d 100644 --- a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt @@ -111,6 +111,7 @@ vespa_add_library(searchcore_server STATIC searchcore_reprocessing searchcore_summaryengine searchcore_fconfig + searchcore_reference configdefinitions stdc++fs ) diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index d6154092e72..427fd7f57fb 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -20,6 +20,7 @@ #include <vespa/searchcommon/common/schemaconfigurer.h> #include <vespa/searchlib/engine/searchreply.h> #include <vespa/searchlib/engine/docsumreply.h> +#include <vespa/searchcore/proton/reference/i_document_db_referent_registry.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/closuretask.h> @@ -203,9 +204,23 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir, } } +void DocumentDB::registerReferent() +{ + if (_state.getAllowReconfig()) { + auto registry = _owner.getDocumentDBReferentRegistry(); + if (registry) { + auto referent = _subDBs.getReadySubDB()->getDocumentDBReferent(); + if (referent) { + registry->add(_docTypeName.getName(), referent); + } + } + } +} + void DocumentDB::setActiveConfig(const DocumentDBConfig::SP &config, SerialNum serialNum) { vespalib::LockGuard guard(_configLock); + registerReferent(); _activeConfigSnapshot = config; if (_activeConfigSnapshotGeneration < config->getGeneration()) { _activeConfigSnapshotGeneration = config->getGeneration(); @@ -359,6 +374,7 @@ DocumentDB::handleRejectedConfig(DocumentDBConfig::SP &configSnapshot, _docTypeName.toString().c_str(), (cs == DDBState::ConfigState::NEED_RESTART ? "need restart" : "feed disabled")); // Use generation from rejected config (white lie ?) + registerReferent(); _activeConfigSnapshotGeneration = configSnapshot->getGeneration(); DocumentDBConfig::SP oaconfig = _activeConfigSnapshot-> getOriginalConfig(); @@ -389,6 +405,7 @@ DocumentDB::applyConfig(DocumentDBConfig::SP configSnapshot, if (_activeConfigSnapshot.get() == configSnapshot.get() || *_activeConfigSnapshot == *configSnapshot) { // generation might have changed but config is unchanged. + registerReferent(); _activeConfigSnapshot = configSnapshot; _activeConfigSnapshotGeneration = configSnapshot->getGeneration(); if (_state.getRejectedConfig()) { diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.h b/searchcore/src/vespa/searchcore/proton/server/documentdb.h index 7a6005350ca..ea42444a213 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.h @@ -150,6 +150,7 @@ private: search::CacheStats _lastDocStoreCacheStats; IBucketStateCalculator::SP _calc; + void registerReferent(); void setActiveConfig(const DocumentDBConfig::SP &config, SerialNum serialNum); DocumentDBConfig::SP getActiveConfig() const; void internalInit(); diff --git a/searchcore/src/vespa/searchcore/proton/server/idocumentdbowner.h b/searchcore/src/vespa/searchcore/proton/server/idocumentdbowner.h index b26b80b579b..00f4854e9c6 100644 --- a/searchcore/src/vespa/searchcore/proton/server/idocumentdbowner.h +++ b/searchcore/src/vespa/searchcore/proton/server/idocumentdbowner.h @@ -8,6 +8,8 @@ namespace proton { +class IDocumentDBReferentRegistry; + class IDocumentDBOwner { public: @@ -18,6 +20,7 @@ public: virtual searchcorespi::IIndexManagerFactory::SP getIndexManagerFactory(const vespalib::stringref & name) const = 0; virtual uint32_t getDistributionKey() const = 0; + virtual std::shared_ptr<IDocumentDBReferentRegistry> getDocumentDBReferentRegistry() const = 0; }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/idocumentsubdb.h b/searchcore/src/vespa/searchcore/proton/server/idocumentsubdb.h index 3a2a2e43df9..ec6bc471065 100644 --- a/searchcore/src/vespa/searchcore/proton/server/idocumentsubdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/idocumentsubdb.h @@ -40,6 +40,7 @@ class ISummaryAdapter; class IDocumentMetaStoreContext; class IDocumentRetriever; class IAttributeManager; +class IDocumentDBReferent; /** * Interface for a document sub database that handles a subset of the documents that belong to a @@ -124,6 +125,7 @@ public: virtual matching::MatchingStats getMatcherStats(const vespalib::string &rankProfile) const = 0; virtual void close() = 0; + virtual std::shared_ptr<IDocumentDBReferent> getDocumentDBReferent() = 0; }; -} // namespace proton
\ No newline at end of file +} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index 2e8005b5c23..0c3d32948ae 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -32,6 +32,8 @@ #include <vespa/vespalib/util/random.h> #include <vespa/searchcore/proton/common/hw_info.h> #include <vespa/searchcore/proton/common/hw_info_sampler.h> +#include <vespa/searchcore/proton/reference/document_db_referent_registry.h> +#include <vespa/searchcore/proton/reference/i_document_db_referent.h> #include <vespa/document/base/exceptions.h> #include <vespa/log/log.h> LOG_SETUP(".proton.server.proton"); @@ -211,8 +213,10 @@ Proton::Proton(const config::ConfigUri & configUri, _initComplete(false), _initDocumentDbsInSequence(false), _hwInfo(), - _hwInfoSampler() + _hwInfoSampler(), + _documentDBReferentRegistry() { + _documentDBReferentRegistry = std::make_shared<DocumentDBReferentRegistry>(); } BootstrapConfig::SP @@ -1130,4 +1134,11 @@ Proton::get_child(vespalib::stringref name) const return Explorer_UP(nullptr); } +std::shared_ptr<IDocumentDBReferentRegistry> +Proton::getDocumentDBReferentRegistry() const +{ + return _documentDBReferentRegistry; +} + + } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.h b/searchcore/src/vespa/searchcore/proton/server/proton.h index f92a4ce3098..09e4178fd4f 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.h +++ b/searchcore/src/vespa/searchcore/proton/server/proton.h @@ -38,6 +38,7 @@ namespace proton { class DiskMemUsageSampler; class HwInfoSampler; +class IDocumentDBReferentRegistry; class Proton : public IBootstrapOwner, public search::engine::MonitorServer, @@ -144,6 +145,7 @@ private: bool _initDocumentDbsInSequence; HwInfo _hwInfo; std::unique_ptr<HwInfoSampler> _hwInfoSampler; + std::shared_ptr<IDocumentDBReferentRegistry> _documentDBReferentRegistry; bool performDataDirectoryUpgrade(const vespalib::string &baseDir); void loadLibrary(const vespalib::string &libName); @@ -177,6 +179,8 @@ private: getIndexManagerFactory(const vespalib::stringref & name) const override; uint32_t getDistributionKey() const override { return _distributionKey; } BootstrapConfig::SP getActiveConfigSnapshot() const; + virtual std::shared_ptr<IDocumentDBReferentRegistry> getDocumentDBReferentRegistry() const override; + public: typedef std::unique_ptr<Proton> UP; diff --git a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp index e41c4ab6ed1..f6d52ca9ce7 100644 --- a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp @@ -12,6 +12,7 @@ #include <vespa/searchcore/proton/docsummary/summarymanagerinitializer.h> #include <vespa/searchcore/proton/documentmetastore/lidreusedelayer.h> #include <vespa/searchcore/proton/documentmetastore/documentmetastoreinitializer.h> +#include <vespa/searchcore/proton/reference/document_db_referent.h> #include <vespa/searchcore/proton/flushengine/threadedflushtarget.h> #include <vespa/searchcore/proton/index/index_writer.h> #include <vespa/searchcore/proton/metrics/legacy_documentdb_metrics.h> @@ -463,6 +464,12 @@ StoreOnlyDocSubDB::close() store.flush(syncToken); } +std::shared_ptr<IDocumentDBReferent> +StoreOnlyDocSubDB::getDocumentDBReferent() +{ + return std::make_shared<DocumentDBReferent>(getAttributeManager(), _dms); +} + void StoreOnlySubDBFileHeaderContext:: addTags(vespalib::GenericHeader &header, diff --git a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.h b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.h index a565da524a4..3845f255aaa 100644 --- a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.h +++ b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.h @@ -283,6 +283,7 @@ public: IDocumentRetriever::UP getDocumentRetriever() override; matching::MatchingStats getMatcherStats(const vespalib::string &rankProfile) const override; void close() override; + virtual std::shared_ptr<IDocumentDBReferent> getDocumentDBReferent() override; }; -} // namespace proton
\ No newline at end of file +} // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h b/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h index 3dad0dda937..099d65b9166 100644 --- a/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h +++ b/searchcore/src/vespa/searchcore/proton/test/dummy_document_sub_db.h @@ -95,7 +95,9 @@ struct DummyDocumentSubDb : public IDocumentSubDB matching::MatchingStats getMatcherStats(const vespalib::string &) const override { return matching::MatchingStats(); } - + virtual std::shared_ptr<IDocumentDBReferent> getDocumentDBReferent() override { + return std::shared_ptr<IDocumentDBReferent>(); + } }; } // namespace test |