From 3d159ee87f54409f0df2e306e698bb1381ec7365 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 21 Feb 2022 17:38:47 +0000 Subject: - Use common tranport for TlsClient. - Also refactor to simplify unit tests. --- .../vespa-transactionlog-inspect.cpp | 2 +- .../documentdb/configurer/configurer_test.cpp | 30 ++++++++--------- .../document_subdbs/document_subdbs_test.cpp | 24 ++++++-------- .../executor_threading_service/CMakeLists.txt | 1 + .../executor_threading_service_test.cpp | 8 +++-- .../documentdb/feedhandler/feedhandler_test.cpp | 19 ++++------- .../proton/documentdb/feedview/feedview_test.cpp | 12 +++---- .../fileconfigmanager/fileconfigmanager_test.cpp | 8 ++--- .../maintenancecontroller_test.cpp | 2 +- .../documentdb/storeonlyfeedview/CMakeLists.txt | 1 + .../storeonlyfeedview/storeonlyfeedview_test.cpp | 15 ++++----- .../lidreusedelayer/lidreusedelayer_test.cpp | 15 ++++----- searchcore/src/tests/proton/index/CMakeLists.txt | 2 ++ .../src/tests/proton/index/fusionrunner_test.cpp | 34 +++++++++---------- .../src/tests/proton/index/indexmanager_test.cpp | 18 ++++------ .../proton_config_fetcher_test.cpp | 4 +-- .../proton_disk_layout/proton_disk_layout_test.cpp | 10 +++--- .../disk_mem_usage_sampler_test.cpp | 2 +- .../shared_threading_service_test.cpp | 2 +- .../vespa/searchcore/proton/server/documentdb.cpp | 3 +- .../proton/server/executorthreadingservice.cpp | 12 ++++--- .../proton/server/executorthreadingservice.h | 5 ++- .../vespa/searchcore/proton/server/feedhandler.cpp | 2 +- .../src/vespa/searchcore/proton/server/proton.cpp | 2 +- .../proton/server/proton_config_fetcher.cpp | 1 - .../proton/server/proton_disk_layout.cpp | 7 ++-- .../searchcore/proton/server/proton_disk_layout.h | 9 +++-- .../proton/server/transactionlogmanager.cpp | 4 +-- .../proton/server/transactionlogmanager.h | 2 +- .../proton/server/transactionlogmanagerbase.cpp | 7 ++-- .../proton/server/transactionlogmanagerbase.h | 5 ++- .../vespa/searchcore/proton/test/CMakeLists.txt | 1 + .../searchcore/proton/test/dummy_document_sub_db.h | 25 +++++++------- .../proton/test/mock_shared_threading_service.cpp | 2 +- .../proton/test/mock_shared_threading_service.h | 4 +-- .../proton/test/threading_service_observer.h | 1 + .../searchcore/proton/test/transport_helper.cpp | 38 ++++++++++++++++++++-- .../searchcore/proton/test/transport_helper.h | 35 ++++++++++++++++---- 38 files changed, 214 insertions(+), 160 deletions(-) (limited to 'searchcore') diff --git a/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp b/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp index 40431b90e27..88f9938cc0a 100644 --- a/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp +++ b/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp @@ -385,7 +385,7 @@ public: _threadPool(64_Ki), _transport(), _server(_transport, _bopts.tlsName, _bopts.listenPort, _bopts.tlsDir, _fileHeader), - _client(vespalib::make_string("tcp/localhost:%d", _bopts.listenPort)) + _client(_transport, vespalib::make_string("tcp/localhost:%d", _bopts.listenPort)) { _transport.Start(&_threadPool); } diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp index b597bc18cc5..0e9eb926514 100644 --- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp @@ -2,7 +2,6 @@ #include -#include #include #include #include @@ -12,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -23,11 +21,13 @@ #include #include #include +#include #include #include #include #include #include +#include using namespace config; using namespace document; @@ -85,9 +85,8 @@ ViewPtrs::~ViewPtrs() = default; struct ViewSet { IndexManagerDummyReconfigurer _reconfigurer; - DummyFileHeaderContext _fileHeaderContext; - vespalib::ThreadStackExecutor _sharedExecutor; - ExecutorThreadingService _writeService; + DummyFileHeaderContext _fileHeaderContext; + TransportAndExecutorService _service; SearchableFeedView::SerialNum serialNum; std::shared_ptr repo; DocTypeName _docTypeName; @@ -114,8 +113,7 @@ struct ViewSet ViewSet::ViewSet() : _reconfigurer(), _fileHeaderContext(), - _sharedExecutor(1, 0x10000), - _writeService(_sharedExecutor), + _service(1), serialNum(1), repo(createRepo()), _docTypeName(DOC_TYPE), @@ -188,10 +186,10 @@ Fixture::initViewSet(ViewSet &views) using IndexConfig = proton::index::IndexConfig; auto matchers = std::make_shared(_clock, _queryLimiter, _constantValueRepo); auto indexMgr = make_shared(BASE_DIR, IndexConfig(searchcorespi::index::WarmupConfig(), 2, 0), Schema(), 1, - views._reconfigurer, views._writeService, _summaryExecutor, + views._reconfigurer, views._service.write(), _summaryExecutor, TuneFileIndexManager(), TuneFileAttributes(), views._fileHeaderContext); auto attrMgr = make_shared(BASE_DIR, "test.subdb", TuneFileAttributes(), views._fileHeaderContext, - views._writeService.attributeFieldWriter(), views._writeService.shared(), views._hwInfo); + views._service.write().attributeFieldWriter(), views._service.write().shared(), views._hwInfo); auto summaryMgr = make_shared (_summaryExecutor, search::LogDocumentStore::Config(), search::GrowStrategy(), BASE_DIR, views._docTypeName, TuneFileSummary(), views._fileHeaderContext,views._noTlSyncer, search::IBucketizer::SP()); @@ -217,7 +215,7 @@ Fixture::initViewSet(ViewSet &views) views.repo, _pendingLidsForCommit, *views._gidToLidChangeHandler, - views._writeService), + views._service.write()), SearchableFeedView::PersistentParams(views.serialNum, views.serialNum, views._docTypeName, 0u, SubDbType::READY), FastAccessFeedView::Context(attrWriter, views._docIdLimit), @@ -274,21 +272,19 @@ MyFastAccessFeedView::~MyFastAccessFeedView() = default; struct FastAccessFixture { - vespalib::ThreadStackExecutor _sharedExecutor; - ExecutorThreadingService _writeService; - MyFastAccessFeedView _view; + TransportAndExecutorService _service; + MyFastAccessFeedView _view; FastAccessDocSubDBConfigurer _configurer; FastAccessFixture() - : _sharedExecutor(1, 0x10000), - _writeService(_sharedExecutor), - _view(_writeService), + : _service(1), + _view(_service.write()), _configurer(_view._feedView, std::make_unique(), "test") { vespalib::rmdir(BASE_DIR, true); vespalib::mkdir(BASE_DIR); } ~FastAccessFixture() { - _writeService.shutdown(); + _service.shutdown(); } }; diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index 6e20d30fb36..27636324835 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -288,9 +287,8 @@ struct MyConfigSnapshot template struct FixtureBase { - TransportMgr _transport; - ThreadStackExecutor _summaryExecutor; - ExecutorThreadingService _writeService; + TransportAndExecutorService _service; + typename Traits::Config _cfg; std::shared_ptr _bucketDB; BucketDBHandler _bucketDBHandler; @@ -301,15 +299,13 @@ struct FixtureBase typename Traits::SubDB _subDb; IFeedView::SP _tmpFeedView; FixtureBase() - : _transport(), - _summaryExecutor(1, 64_Ki), - _writeService(_summaryExecutor), + : _service(1), _cfg(), _bucketDB(std::make_shared()), _bucketDBHandler(*_bucketDB), - _ctx(_writeService, _bucketDB, _bucketDBHandler), + _ctx(_service.write(), _bucketDB, _bucketDBHandler), _baseSchema(), - _snapshot(std::make_unique(_transport.transport(), _baseSchema, Traits::ConfigDir::dir())), + _snapshot(std::make_unique(_service.transport(), _baseSchema, Traits::ConfigDir::dir())), _baseDir(BASE_DIR + "/" + SUB_NAME, BASE_DIR), _subDb(_cfg._cfg, _ctx._ctx), _tmpFeedView() @@ -317,8 +313,8 @@ struct FixtureBase init(); } ~FixtureBase() { - _writeService.master().execute(makeLambdaTask([this]() { _subDb.close(); })); - _writeService.shutdown(); + _service.write().master().execute(makeLambdaTask([this]() { _subDb.close(); })); + _service.shutdown(); } void setBucketStateCalculator(const std::shared_ptr & calc) { vespalib::Gate gate; @@ -327,11 +323,11 @@ struct FixtureBase } template void runInMasterAndSync(FunctionType func) { - proton::test::runInMasterAndSync(_writeService, func); + proton::test::runInMasterAndSync(_service.write(), func); } template void runInMaster(FunctionType func) { - proton::test::runInMaster(_writeService, func); + proton::test::runInMaster(_service.write(), func); } void init() { DocumentSubDbInitializer::SP task = @@ -349,7 +345,7 @@ struct FixtureBase runInMasterAndSync([&]() { performReconfig(serialNum, reconfigSchema, reconfigConfigDir); }); } void performReconfig(SerialNum serialNum, const Schema &reconfigSchema, const vespalib::string &reconfigConfigDir) { - auto newCfg = std::make_unique(_transport.transport(), reconfigSchema, reconfigConfigDir); + auto newCfg = std::make_unique(_service.transport(), reconfigSchema, reconfigConfigDir); DocumentDBConfig::ComparisonResult cmpResult; cmpResult.attributesChanged = true; cmpResult.documenttypesChanged = true; diff --git a/searchcore/src/tests/proton/documentdb/executor_threading_service/CMakeLists.txt b/searchcore/src/tests/proton/documentdb/executor_threading_service/CMakeLists.txt index 721f2207213..ba7db5dd377 100644 --- a/searchcore/src/tests/proton/documentdb/executor_threading_service/CMakeLists.txt +++ b/searchcore/src/tests/proton/documentdb/executor_threading_service/CMakeLists.txt @@ -3,6 +3,7 @@ vespa_add_executable(searchcore_executor_threading_service_test_app TEST SOURCES executor_threading_service_test.cpp DEPENDS + searchcore_test searchcore_server GTest::GTest ) diff --git a/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp b/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp index 8d7e842bc89..934dcdb36e3 100644 --- a/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp +++ b/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -20,17 +21,18 @@ to_concrete_type(ISequencedTaskExecutor& exec) class ExecutorThreadingServiceTest : public ::testing::Test { public: - vespalib::ThreadStackExecutor shared_executor; + TransportAndExecutor _transport; std::unique_ptr field_writer_executor; std::unique_ptr service; ExecutorThreadingServiceTest() - : shared_executor(1, 1000), + : _transport(1), field_writer_executor(SequencedTaskExecutor::create(my_field_writer_executor, 3, 200)), service() { } void setup(uint32_t indexing_threads, SharedFieldWriterExecutor shared_field_writer) { - service = std::make_unique(shared_executor, + service = std::make_unique(_transport.shared(), + _transport.transport(), field_writer_executor.get(), nullptr, ThreadingServiceConfig::make(indexing_threads, shared_field_writer)); diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp index 9a8d8bad60e..0f1b4412c4f 100644 --- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -409,11 +408,9 @@ struct MyTlsWriter : TlsWriter { struct FeedHandlerFixture { DummyFileHeaderContext _fileHeaderContext; - TransportMgr _transport; + TransportAndExecutorService _service; TransLogServer tls; vespalib::string tlsSpec; - vespalib::ThreadStackExecutor sharedExecutor; - ExecutorThreadingService writeService; SchemaContext schema; MyOwner owner; MyResourceWriteFilter writeFilter; @@ -426,11 +423,9 @@ struct FeedHandlerFixture FeedHandler handler; FeedHandlerFixture() : _fileHeaderContext(), - _transport(), - tls(_transport.transport(), "mytls", 9016, "mytlsdir", _fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)), + _service(1), + tls(_service.transport(), "mytls", 9016, "mytlsdir", _fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)), tlsSpec("tcp/localhost:9016"), - sharedExecutor(1, 0x10000), - writeService(sharedExecutor), schema(), owner(), _state(), @@ -438,7 +433,7 @@ struct FeedHandlerFixture feedView(schema.getRepo(), schema.getDocType()), _bucketDB(), _bucketDBHandler(_bucketDB), - handler(writeService, tlsSpec, schema.getDocType(), owner, + handler(_service.write(), tlsSpec, schema.getDocType(), owner, writeFilter, replayConfig, tls, &tls_writer) { _state.enterLoadState(); @@ -449,15 +444,15 @@ struct FeedHandlerFixture } ~FeedHandlerFixture() { - writeService.shutdown(); + _service.shutdown(); } template inline void runAsMaster(FunctionType &&function) { - writeService.master().execute(makeLambdaTask(std::move(function))); + _service.write().master().execute(makeLambdaTask(std::move(function))); syncMaster(); } void syncMaster() { - writeService.master().sync(); + _service.write().master().sync(); } }; diff --git a/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp b/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp index 824a9273404..ba68d47ec22 100644 --- a/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -20,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -497,8 +497,7 @@ struct FixtureBase DocumentMetaStoreContext::SP _dmscReal; test::DocumentMetaStoreContextObserver::SP _dmsc; ParamsContext pc; - vespalib::ThreadStackExecutor _sharedExecutor; - ExecutorThreadingService _writeServiceReal; + TransportAndExecutorService _service; test::ThreadingServiceObserver _writeService; SerialNum serial; std::shared_ptr _gidToLidChangeHandler; @@ -690,9 +689,8 @@ FixtureBase::FixtureBase() _dmscReal(std::make_shared(std::make_shared())), _dmsc(std::make_shared(*_dmscReal)), pc(sc._builder->getDocumentType().getName(), "fileconfig_test"), - _sharedExecutor(1, 0x10000), - _writeServiceReal(_sharedExecutor), - _writeService(_writeServiceReal), + _service(1), + _writeService(_service.write()), serial(0), _gidToLidChangeHandler(std::make_shared()) { @@ -700,7 +698,7 @@ FixtureBase::FixtureBase() } FixtureBase::~FixtureBase() { - _writeServiceReal.shutdown(); + _service.shutdown(); } void diff --git a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp index d51ea25f2f5..2de24ee7803 100644 --- a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp +++ b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp @@ -127,7 +127,7 @@ addConfigsThatAreNotSavedToDisk(const DocumentDBConfig &cfg) return builder.build(); } -TEST_FF("requireThatConfigCanBeSavedAndLoaded", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) +TEST_FF("requireThatConfigCanBeSavedAndLoaded", Transport(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { DocumentDBConfig::SP fullCfg = addConfigsThatAreNotSavedToDisk(*f2); @@ -140,7 +140,7 @@ TEST_FF("requireThatConfigCanBeSavedAndLoaded", TransportMgr(), DocumentDBConfig assertEqualSnapshot(*f2, *esnap); } -TEST_FF("requireThatConfigCanBeSerializedAndDeserialized", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) +TEST_FF("requireThatConfigCanBeSerializedAndDeserialized", Transport(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { saveBaseConfigSnapshot(f1.transport(), *f2, 30); nbostream stream; @@ -161,7 +161,7 @@ TEST_FF("requireThatConfigCanBeSerializedAndDeserialized", TransportMgr(), Docum EXPECT_EQUAL("dummy", fsnap->getDocTypeName()); } -TEST_FF("requireThatConfigCanBeLoadedWithoutExtraConfigsDataFile", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) +TEST_FF("requireThatConfigCanBeLoadedWithoutExtraConfigsDataFile", Transport(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { saveBaseConfigSnapshot(f1.transport(), *f2, 70); EXPECT_FALSE(vespalib::unlink("out/config-70/extraconfigs.dat")); @@ -173,7 +173,7 @@ TEST_FF("requireThatConfigCanBeLoadedWithoutExtraConfigsDataFile", TransportMgr( } -TEST_FF("requireThatVisibilityDelayIsPropagated", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) +TEST_FF("requireThatVisibilityDelayIsPropagated", Transport(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { saveBaseConfigSnapshot(f1.transport(), *f2, 80); DocumentDBConfig::SP esnap(makeEmptyConfigSnapshot()); diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp index 39a5c69376c..0144e260ffa 100644 --- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp +++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp @@ -349,7 +349,7 @@ public: test::DiskMemUsageNotifier _diskMemUsageNotifier; BucketCreateNotifier _bucketCreateNotifier; MonitoredRefCount _refCount; - TransportMgr _transport; + Transport _transport; MaintenanceController _mc; MaintenanceControllerFixture(); diff --git a/searchcore/src/tests/proton/documentdb/storeonlyfeedview/CMakeLists.txt b/searchcore/src/tests/proton/documentdb/storeonlyfeedview/CMakeLists.txt index 3cdad86e9d7..6d94c066d20 100644 --- a/searchcore/src/tests/proton/documentdb/storeonlyfeedview/CMakeLists.txt +++ b/searchcore/src/tests/proton/documentdb/storeonlyfeedview/CMakeLists.txt @@ -3,6 +3,7 @@ vespa_add_executable(searchcore_storeonlyfeedview_test_app TEST SOURCES storeonlyfeedview_test.cpp DEPENDS + searchcore_test searchcore_server searchcore_feedoperation searchcore_documentmetastore diff --git a/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp b/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp index b1d7ee1d0a8..acd33ab749d 100644 --- a/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp +++ b/searchcore/src/tests/proton/documentdb/storeonlyfeedview/storeonlyfeedview_test.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -12,9 +11,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -211,8 +212,7 @@ struct FixtureBase { std::atomic heartbeatCount; std::atomic outstandingMoveOps; DocumentMetaStore::SP metaStore; - vespalib::ThreadStackExecutor sharedExecutor; - ExecutorThreadingService writeService; + TransportAndExecutorService _service; std::shared_ptr pendingLidsForCommit; typename FeedViewType::UP feedview; SerialNum serial_num; @@ -226,8 +226,7 @@ struct FixtureBase { DocumentMetaStore::getFixedName(), search::GrowStrategy(), subDbType)), - sharedExecutor(1, 0x10000), - writeService(sharedExecutor), + _service(1), pendingLidsForCommit(std::make_shared()), feedview(), serial_num(2u) @@ -235,7 +234,7 @@ struct FixtureBase { StoreOnlyFeedView::PersistentParams params(0, 0, DocTypeName("foo"), subdb_id, subDbType); metaStore->constructFreeList(); ISummaryAdapter::SP adapter = std::make_shared(removeCount, putCount, heartbeatCount); - feedview = std::make_unique(adapter, metaStore, writeService, + feedview = std::make_unique(adapter, metaStore, _service.write(), params, pendingLidsForCommit, outstandingMoveOps); } @@ -263,11 +262,11 @@ struct FixtureBase { template void runInMasterAndSync(FunctionType func) { - test::runInMasterAndSync(writeService, func); + test::runInMasterAndSync(_service.write(), func); } template void runInMaster(FunctionType func) { - test::runInMaster(writeService, func); + test::runInMaster(_service.write(), func); } void force_commit() { diff --git a/searchcore/src/tests/proton/documentmetastore/lidreusedelayer/lidreusedelayer_test.cpp b/searchcore/src/tests/proton/documentmetastore/lidreusedelayer/lidreusedelayer_test.cpp index 8a2e2084978..a30408a9301 100644 --- a/searchcore/src/tests/proton/documentmetastore/lidreusedelayer/lidreusedelayer_test.cpp +++ b/searchcore/src/tests/proton/documentmetastore/lidreusedelayer/lidreusedelayer_test.cpp @@ -3,11 +3,13 @@ #include #include #include -#include #include #include +#include #include #include +#include +#include #include LOG_SETUP("lidreusedelayer_test"); @@ -117,20 +119,17 @@ class Fixture { public: using LidReuseDelayer = documentmetastore::LidReuseDelayer; - vespalib::ThreadStackExecutor _sharedExecutor; - ExecutorThreadingService _writeServiceReal; + TransportAndExecutorService _service; test::ThreadingServiceObserver _writeService; MyMetaStore _store; std::unique_ptr _lidReuseDelayer; Fixture() - : _sharedExecutor(1, 0x10000), - _writeServiceReal(_sharedExecutor), - _writeService(_writeServiceReal), + : _service(1), + _writeService(_service.write()), _store(), _lidReuseDelayer(std::make_unique(_writeService, _store)) - { - } + { } ~Fixture() { commit(); diff --git a/searchcore/src/tests/proton/index/CMakeLists.txt b/searchcore/src/tests/proton/index/CMakeLists.txt index 62a631dc26e..313dd5e0457 100644 --- a/searchcore/src/tests/proton/index/CMakeLists.txt +++ b/searchcore/src/tests/proton/index/CMakeLists.txt @@ -3,6 +3,7 @@ vespa_add_executable(searchcore_indexmanager_test_app TEST SOURCES indexmanager_test.cpp DEPENDS + searchcore_test searchcore_server searchcore_index searchcore_flushengine @@ -17,6 +18,7 @@ vespa_add_executable(searchcore_fusionrunner_test_app TEST SOURCES fusionrunner_test.cpp DEPENDS + searchcore_test searchcore_server searchcore_index searchcore_pcommon diff --git a/searchcore/src/tests/proton/index/fusionrunner_test.cpp b/searchcore/src/tests/proton/index/fusionrunner_test.cpp index ae85211fe24..38314abd7e5 100644 --- a/searchcore/src/tests/proton/index/fusionrunner_test.cpp +++ b/searchcore/src/tests/proton/index/fusionrunner_test.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -17,6 +17,7 @@ #include #include #include +#include #include using document::Document; @@ -66,8 +67,7 @@ class Test : public vespalib::TestApp { FixedSourceSelector::UP _selector; FusionSpec _fusion_spec; DummyFileHeaderContext _fileHeaderContext; - vespalib::ThreadStackExecutor _sharedExecutor; - ExecutorThreadingService _threadingService; + TransportAndExecutorService _service; IndexManager::MaintainerOperations _ops; void setUp(); @@ -85,21 +85,21 @@ class Test : public vespalib::TestApp { void requireThatFusionCanBeStopped(); public: - Test() - : _fusion_runner(), - _selector(), - _fusion_spec(), - _fileHeaderContext(), - _sharedExecutor(1, 0x10000), - _threadingService(_sharedExecutor), - _ops(_fileHeaderContext, - TuneFileIndexManager(), 0, - _threadingService) - {} - ~Test() {} + Test(); + ~Test(); int Main() override; }; +Test::Test() + : _fusion_runner(), + _selector(), + _fusion_spec(), + _fileHeaderContext(), + _service(1), + _ops(_fileHeaderContext,TuneFileIndexManager(), 0, _service.write()) +{ } +Test::~Test() = default; + int Test::Main() { @@ -180,8 +180,8 @@ void Test::createIndex(const string &dir, uint32_t id, bool fusion) { Schema schema = getSchema(); DocBuilder doc_builder(schema); MemoryIndex memory_index(schema, MockFieldLengthInspector(), - _threadingService.indexFieldInverter(), - _threadingService.indexFieldWriter()); + _service.write().indexFieldInverter(), + _service.write().indexFieldWriter()); addDocument(doc_builder, memory_index, *_selector, id, id + 0, term); addDocument(doc_builder, memory_index, *_selector, id, id + 1, "bar"); addDocument(doc_builder, memory_index, *_selector, id, id + 2, "baz"); diff --git a/searchcore/src/tests/proton/index/indexmanager_test.cpp b/searchcore/src/tests/proton/index/indexmanager_test.cpp index 1e33482b055..6cca28f5b43 100644 --- a/searchcore/src/tests/proton/index/indexmanager_test.cpp +++ b/searchcore/src/tests/proton/index/indexmanager_test.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -53,7 +52,6 @@ using search::memoryindex::FieldIndexCollection; using search::queryeval::Source; using std::set; using std::string; -using vespalib::ThreadStackExecutor; using vespalib::makeLambdaTask; using std::chrono::duration_cast; @@ -108,8 +106,7 @@ struct IndexManagerTest : public ::testing::Test { SerialNum _serial_num; IndexManagerDummyReconfigurer _reconfigurer; DummyFileHeaderContext _fileHeaderContext; - vespalib::ThreadStackExecutor _sharedExecutor; - ExecutorThreadingService _writeService; + TransportAndExecutorService _service; std::unique_ptr _index_manager; Schema _schema; DocBuilder _builder; @@ -118,8 +115,7 @@ struct IndexManagerTest : public ::testing::Test { : _serial_num(0), _reconfigurer(), _fileHeaderContext(), - _sharedExecutor(1, 0x10000), - _writeService(_sharedExecutor), + _service(1), _index_manager(), _schema(getSchema()), _builder(_schema) @@ -130,13 +126,13 @@ struct IndexManagerTest : public ::testing::Test { } ~IndexManagerTest() { - _writeService.shutdown(); + _service.shutdown(); } template inline void runAsMaster(FunctionType &&function) { vespalib::Gate gate; - _writeService.master().execute(makeLambdaTask([&gate,function = std::move(function)]() { + _service.write().master().execute(makeLambdaTask([&gate,function = std::move(function)]() { function(); gate.countDown(); })); @@ -145,7 +141,7 @@ struct IndexManagerTest : public ::testing::Test { template inline void runAsIndex(FunctionType &&function) { vespalib::Gate gate; - _writeService.index().execute(makeLambdaTask([&gate,function = std::move(function)]() { + _service.write().index().execute(makeLambdaTask([&gate,function = std::move(function)]() { function(); gate.countDown(); })); @@ -210,7 +206,7 @@ IndexManagerTest::resetIndexManager() { _index_manager.reset(); _index_manager = std::make_unique(index_dir, IndexConfig(), getSchema(), 1, - _reconfigurer, _writeService, _sharedExecutor, + _reconfigurer, _service.write(), _service.shared(), TuneFileIndexManager(), TuneFileAttributes(), _fileHeaderContext); } diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index b4193b0e0b2..34bc9ea13ed 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -64,8 +64,8 @@ struct DoctypeFixture { }; struct ConfigTestFixture { - const std::string configId; - TransportMgr transport; + const std::string configId; + Transport transport; ProtonConfigBuilder protonBuilder; DocumenttypesConfigBuilder documenttypesBuilder; FiledistributorrpcConfigBuilder filedistBuilder; diff --git a/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp b/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp index 08b9a55746b..05d993a33e0 100644 --- a/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp +++ b/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp @@ -16,7 +16,7 @@ using search::transactionlog::client::TransLogClient; using search::transactionlog::TransLogServer; using proton::DocTypeName; using proton::ProtonDiskLayout; -using proton::TransportMgr; +using proton::Transport; static constexpr unsigned int tlsPort = 9018; @@ -31,7 +31,7 @@ struct FixtureBase struct DiskLayoutFixture { DummyFileHeaderContext _fileHeaderContext; - TransportMgr _transport; + Transport _transport; TransLogServer _tls; vespalib::string _tlsSpec; ProtonDiskLayout _diskLayout; @@ -45,7 +45,7 @@ struct DiskLayoutFixture { } } void createDomains(const std::set &domains) { - TransLogClient tlc(_tlsSpec); + TransLogClient tlc(_transport.transport(), _tlsSpec); for (const auto &domain : domains) { ASSERT_TRUE(tlc.create(domain)); } @@ -53,7 +53,7 @@ struct DiskLayoutFixture { std::set listDomains() { std::vector domainVector; - TransLogClient tlc(_tlsSpec); + TransLogClient tlc(_transport.transport(), _tlsSpec); ASSERT_TRUE(tlc.listDomains(domainVector)); std::set domains; for (const auto &domain : domainVector) { @@ -97,7 +97,7 @@ DiskLayoutFixture::DiskLayoutFixture() _transport(), _tls(_transport.transport(), "tls", tlsPort, baseDir, _fileHeaderContext), _tlsSpec(vespalib::make_string("tcp/localhost:%u", tlsPort)), - _diskLayout(baseDir, _tlsSpec) + _diskLayout(_transport.transport(), baseDir, _tlsSpec) { } diff --git a/searchcore/src/tests/proton/server/disk_mem_usage_sampler/disk_mem_usage_sampler_test.cpp b/searchcore/src/tests/proton/server/disk_mem_usage_sampler/disk_mem_usage_sampler_test.cpp index 9469c8b055f..0c06d27c916 100644 --- a/searchcore/src/tests/proton/server/disk_mem_usage_sampler/disk_mem_usage_sampler_test.cpp +++ b/searchcore/src/tests/proton/server/disk_mem_usage_sampler/disk_mem_usage_sampler_test.cpp @@ -38,7 +38,7 @@ public: }; struct DiskMemUsageSamplerTest : public ::testing::Test { - TransportMgr transport; + Transport transport; std::unique_ptr sampler; DiskMemUsageSamplerTest() : transport(), diff --git a/searchcore/src/tests/proton/server/shared_threading_service/shared_threading_service_test.cpp b/searchcore/src/tests/proton/server/shared_threading_service/shared_threading_service_test.cpp index 1b8c8d8491b..8f8200486d7 100644 --- a/searchcore/src/tests/proton/server/shared_threading_service/shared_threading_service_test.cpp +++ b/searchcore/src/tests/proton/server/shared_threading_service/shared_threading_service_test.cpp @@ -48,7 +48,7 @@ TEST(SharedThreadingServiceConfigTest, shared_threads_are_derived_from_cpu_cores class SharedThreadingServiceTest : public ::testing::Test { public: - TransportMgr transport; + Transport transport; std::unique_ptr service; SharedThreadingServiceTest() : transport(), diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index 078e5a69fb3..cf6193555e5 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -188,7 +188,8 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir, _baseDir(baseDir + "/" + _docTypeName.toString()), // Only one thread per executor, or performDropFeedView() will fail. _writeServiceConfig(configSnapshot->get_threading_service_config()), - _writeService(shared_service.shared(), shared_service.field_writer(), &shared_service.invokeService(), _writeServiceConfig, indexing_thread_stack_size), + _writeService(shared_service.shared(), shared_service.transport(), shared_service.field_writer(), + &shared_service.invokeService(), _writeServiceConfig, indexing_thread_stack_size), _initializeThreads(std::move(initializeThreads)), _initConfigSnapshot(), _initConfigSerialNum(0u), diff --git a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp index ca6b3d9ba0f..a268a6eac87 100644 --- a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.cpp @@ -40,17 +40,19 @@ VESPA_THREAD_STACK_TAG(field_writer_executor) } -ExecutorThreadingService::ExecutorThreadingService(vespalib::Executor &sharedExecutor, uint32_t num_treads) - : ExecutorThreadingService(sharedExecutor, nullptr, nullptr, ThreadingServiceConfig::make(num_treads)) +ExecutorThreadingService::ExecutorThreadingService(vespalib::Executor &sharedExecutor, FNET_Transport & transport, uint32_t num_treads) + : ExecutorThreadingService(sharedExecutor, transport, nullptr, nullptr, ThreadingServiceConfig::make(num_treads)) {} -ExecutorThreadingService::ExecutorThreadingService(vespalib::Executor& sharedExecutor, - vespalib::ISequencedTaskExecutor* field_writer, +ExecutorThreadingService::ExecutorThreadingService(vespalib::Executor & sharedExecutor, + FNET_Transport & transport, + vespalib::ISequencedTaskExecutor * field_writer, vespalib::InvokeService * invokerService, - const ThreadingServiceConfig& cfg, + const ThreadingServiceConfig & cfg, uint32_t stackSize) : _sharedExecutor(sharedExecutor), + _transport(transport), _masterExecutor(1, stackSize, CpuUsage::wrap(master_executor, CpuUsage::Category::WRITE)), _shared_field_writer(cfg.shared_field_writer()), _master_task_limit(cfg.master_task_limit()), diff --git a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h index 43d546927c2..77bb9042198 100644 --- a/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h +++ b/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h @@ -21,6 +21,7 @@ class ExecutorThreadingService : public searchcorespi::index::IThreadingService private: using Registration = std::unique_ptr; vespalib::Executor & _sharedExecutor; + FNET_Transport & _transport; vespalib::ThreadStackExecutor _masterExecutor; ThreadingServiceConfig::SharedFieldWriterExecutor _shared_field_writer; std::atomic _master_task_limit; @@ -42,9 +43,10 @@ public: /** * Convenience constructor used in unit tests. */ - ExecutorThreadingService(vespalib::Executor& sharedExecutor, uint32_t num_treads = 1); + ExecutorThreadingService(vespalib::Executor& sharedExecutor, FNET_Transport & transport, uint32_t num_treads = 1); ExecutorThreadingService(vespalib::Executor& sharedExecutor, + FNET_Transport & transport, vespalib::ISequencedTaskExecutor* field_writer, vespalib::InvokeService * invokeService, const ThreadingServiceConfig& cfg, @@ -79,6 +81,7 @@ public: vespalib::ISequencedTaskExecutor &indexFieldInverter() override; vespalib::ISequencedTaskExecutor &indexFieldWriter() override; vespalib::ISequencedTaskExecutor &attributeFieldWriter() override; + FNET_Transport &transport() override { return _transport; } ExecutorThreadingServiceStats getStats(); }; diff --git a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp index 16bd2537813..914753d567d 100644 --- a/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/feedhandler.cpp @@ -408,7 +408,7 @@ FeedHandler::FeedHandler(IThreadingService &writeService, _owner(owner), _writeFilter(writeFilter), _replayConfig(replayConfig), - _tlsMgr(tlsSpec, docTypeName.getName()), + _tlsMgr(writeService.transport(), tlsSpec, docTypeName.getName()), _tlsWriterfactory(tlsWriterFactory), _tlsMgrWriter(), _tlsWriter(tlsWriter), diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index 3aaf00a6541..0f20b0a7b47 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -314,7 +314,7 @@ Proton::init(const BootstrapConfig::SP & configSnapshot) strategy = std::make_shared(); break; } - _protonDiskLayout = std::make_unique(protonConfig.basedir, protonConfig.tlsspec); + _protonDiskLayout = std::make_unique(*_transport, protonConfig.basedir, protonConfig.tlsspec); vespalib::chdir(protonConfig.basedir); vespalib::alloc::MmapFileAllocatorFactory::instance().setup(protonConfig.basedir + "/swapdirs"); _tls->start(*_transport, hwInfo.cpu().cores()); diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp index f956a370ffa..464898c45a9 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp @@ -6,7 +6,6 @@ #include "i_proton_configurer.h" #include #include -#include #include #include diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp b/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp index 1c155abfd6b..0e6318158a2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp @@ -65,8 +65,9 @@ void scanDir(const vespalib::string documentsDir, DocumentDBDirScan &dirs) } -ProtonDiskLayout::ProtonDiskLayout(const vespalib::string &baseDir, const vespalib::string &tlsSpec) - : _baseDir(baseDir), +ProtonDiskLayout::ProtonDiskLayout(FNET_Transport & transport, const vespalib::string &baseDir, const vespalib::string &tlsSpec) + : _transport(transport), + _baseDir(baseDir), _tlsSpec(tlsSpec) { vespalib::mkdir(getDocumentsDir(_baseDir), true); @@ -83,7 +84,7 @@ ProtonDiskLayout::remove(const DocTypeName &docTypeName) vespalib::string removedDir(documentsDir + "/" + getRemovedName(name)); vespalib::rename(normalDir, removedDir, false, false); vespalib::File::sync(documentsDir); - TransLogClient tlc(_tlsSpec); + TransLogClient tlc(_transport, _tlsSpec); if (!tlc.remove(name)) { LOG(fatal, "Failed to remove tls domain %s", name.c_str()); LOG_ABORT("Failed to remove tls domain"); diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.h b/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.h index befce5396a1..e779b388d7c 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.h +++ b/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.h @@ -5,6 +5,8 @@ #include "i_proton_disk_layout.h" #include +class FNET_Transport; + namespace proton { /** @@ -14,11 +16,12 @@ namespace proton { class ProtonDiskLayout : public IProtonDiskLayout { private: - const vespalib::string _baseDir; - const vespalib::string _tlsSpec; + FNET_Transport & _transport; + const vespalib::string _baseDir; + const vespalib::string _tlsSpec; public: - ProtonDiskLayout(const vespalib::string &baseDir, const vespalib::string &tlsSpec); + ProtonDiskLayout(FNET_Transport & transport, const vespalib::string &baseDir, const vespalib::string &tlsSpec); ~ProtonDiskLayout() override; void remove(const DocTypeName &docTypeName) override; void initAndPruneUnused(const std::set &docTypeNames) override; diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp index 9b81904c695..58c8c5f92c2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp @@ -25,8 +25,8 @@ TransactionLogManager::doLogReplayComplete(const vespalib::string &domainName, } -TransactionLogManager::TransactionLogManager(const vespalib::string &tlsSpec, const vespalib::string &domainName) - : TransactionLogManagerBase(tlsSpec, domainName), +TransactionLogManager::TransactionLogManager(FNET_Transport & transport, const vespalib::string &tlsSpec, const vespalib::string &domainName) + : TransactionLogManagerBase(transport, tlsSpec, domainName), _visitor() { } diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h index 7634fbb2e8c..40e2b9faeb2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h @@ -24,7 +24,7 @@ public: * @param tlsSpec the spec of the transaction log server. * @param domainName the name of the domain this manager should handle. **/ - TransactionLogManager(const vespalib::string &tlsSpec, const vespalib::string &domainName); + TransactionLogManager(FNET_Transport & transport, const vespalib::string &tlsSpec, const vespalib::string &domainName); ~TransactionLogManager() override; /** diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp index 5fe54219868..55e82051de6 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp @@ -12,9 +12,10 @@ using search::transactionlog::client::Visitor; namespace proton { -TransactionLogManagerBase::TransactionLogManagerBase( - const vespalib::string &tlsSpec, const vespalib::string &domainName) : - _tlc(std::make_unique(tlsSpec)), +TransactionLogManagerBase::TransactionLogManagerBase(FNET_Transport & transport, + const vespalib::string &tlsSpec, + const vespalib::string &domainName) : + _tlc(std::make_unique(transport, tlsSpec)), _tlcSession(), _domainName(domainName), _replayLock(), diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h index 5c795ecf5ec..16d0dec1409 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h @@ -7,6 +7,8 @@ #include #include +class FNET_Transport; + namespace search::transactionlog::client { class TransLogClient; class Session; @@ -58,7 +60,8 @@ public: * @param tlsSpec the spec of the transaction log server. * @param domainName the name of the domain this manager should handle. **/ - TransactionLogManagerBase(const vespalib::string &tlsSpec, + TransactionLogManagerBase(FNET_Transport & transport, + const vespalib::string &tlsSpec, const vespalib::string &domainName); virtual ~TransactionLogManagerBase(); diff --git a/searchcore/src/vespa/searchcore/proton/test/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/test/CMakeLists.txt index e6eda87f66e..28f705716bc 100644 --- a/searchcore/src/vespa/searchcore/proton/test/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/test/CMakeLists.txt @@ -12,5 +12,6 @@ vespa_add_library(searchcore_test STATIC threading_service_observer.cpp transport_helper.cpp DEPENDS + searchcore_server searchcore_fconfig ) 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 03ddcf3605b..6632fbc856a 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 @@ -1,8 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include "transport_helper.h" #include -#include #include #include #include @@ -21,15 +21,14 @@ namespace proton::test { struct DummyDocumentSubDb : public IDocumentSubDB { using IIndexManager = searchcorespi::IIndexManager; - uint32_t _subDbId; - DocumentMetaStoreContext _metaStoreCtx; - ISummaryManager::SP _summaryManager; - IIndexManager::SP _indexManager; - ISummaryAdapter::SP _summaryAdapter; - IIndexWriter::SP _indexWriter; - vespalib::ThreadStackExecutor _sharedExecutor; - std::unique_ptr _writeService; - PendingLidTracker _pendingLidTracker; + uint32_t _subDbId; + DocumentMetaStoreContext _metaStoreCtx; + ISummaryManager::SP _summaryManager; + IIndexManager::SP _indexManager; + ISummaryAdapter::SP _summaryAdapter; + IIndexWriter::SP _indexWriter; + mutable TransportAndExecutorService _service; + PendingLidTracker _pendingLidTracker; DummyDocumentSubDb(std::shared_ptr bucketDB, uint32_t subDbId) : _subDbId(subDbId), @@ -38,8 +37,8 @@ struct DummyDocumentSubDb : public IDocumentSubDB _indexManager(), _summaryAdapter(), _indexWriter(), - _sharedExecutor(1, 0x10000), - _writeService(std::make_unique(_sharedExecutor, 1)) + _service(1), + _pendingLidTracker() { } ~DummyDocumentSubDb() override { } @@ -49,7 +48,7 @@ struct DummyDocumentSubDb : public IDocumentSubDB DocumentSubDbInitializer::UP createInitializer(const DocumentDBConfig &, SerialNum,const index::IndexConfig &) const override { return std::make_unique - (const_cast(*this), _writeService->master()); + (const_cast(*this), _service.write().master()); } void setup(const DocumentSubDbInitializerResult &) override {} void initViews(const DocumentDBConfig &, const proton::matching::SessionManager::SP &) override {} diff --git a/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.cpp b/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.cpp index e976bf1d726..d695f4d8dc7 100644 --- a/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.cpp +++ b/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.cpp @@ -8,7 +8,7 @@ MockSharedThreadingService::MockSharedThreadingService(ThreadExecutor& warmup_in : _warmup(warmup_in), _shared(shared_in), _invokeService(10ms), - _transportMgr() + _transport() { } diff --git a/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.h b/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.h index d33afcbec3d..7db208fa3ef 100644 --- a/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.h +++ b/searchcore/src/vespa/searchcore/proton/test/mock_shared_threading_service.h @@ -13,7 +13,7 @@ private: ThreadExecutor & _warmup; ThreadExecutor & _shared; vespalib::InvokeServiceImpl _invokeService; - TransportMgr _transportMgr; + Transport _transport; public: MockSharedThreadingService(ThreadExecutor& warmup_in, @@ -23,7 +23,7 @@ public: ThreadExecutor& shared() override { return _shared; } vespalib::ISequencedTaskExecutor* field_writer() override { return nullptr; } vespalib::InvokeService & invokeService() override { return _invokeService; } - FNET_Transport & transport() override { return _transportMgr.transport(); } + FNET_Transport & transport() override { return _transport.transport(); } }; } diff --git a/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h b/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h index 78a740ec2c3..f728ab5f025 100644 --- a/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h +++ b/searchcore/src/vespa/searchcore/proton/test/threading_service_observer.h @@ -49,6 +49,7 @@ public: vespalib::Executor &shared() override { return _shared; } + FNET_Transport & transport() override { return _service.transport(); } vespalib::ISequencedTaskExecutor &indexFieldInverter() override { return _indexFieldInverter; } diff --git a/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp b/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp index 10623fb0726..43e267805da 100644 --- a/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp +++ b/searchcore/src/vespa/searchcore/proton/test/transport_helper.cpp @@ -4,18 +4,52 @@ #include #include #include +#include +#include namespace proton { -TransportMgr::TransportMgr() +Transport::Transport() : _threadPool(std::make_unique(64_Ki)), _transport(std::make_unique()) { _transport->Start(_threadPool.get()); } -TransportMgr::~TransportMgr() { +Transport::~Transport() { + shutdown(); +} + +void +Transport::shutdown() { _transport->ShutDown(true); } +TransportAndExecutor::TransportAndExecutor(size_t num_threads) + : Transport(), + _sharedExecutor(std::make_unique(num_threads, 64_Ki)) +{} + +TransportAndExecutor::~TransportAndExecutor() = default; + +void +TransportAndExecutor::shutdown() { + Transport::shutdown(); +} + +TransportAndExecutorService::TransportAndExecutorService(size_t num_threads) + : TransportAndExecutor(num_threads), + _writeService(std::make_unique(shared(), transport())) +{} +TransportAndExecutorService::~TransportAndExecutorService() = default; + +searchcorespi::index::IThreadingService & +TransportAndExecutorService::write() { + return *_writeService; +} + +void TransportAndExecutorService::shutdown() { + _writeService->shutdown(); + TransportAndExecutor::shutdown(); +} } diff --git a/searchcore/src/vespa/searchcore/proton/test/transport_helper.h b/searchcore/src/vespa/searchcore/proton/test/transport_helper.h index 09cca2dd007..81610193743 100644 --- a/searchcore/src/vespa/searchcore/proton/test/transport_helper.h +++ b/searchcore/src/vespa/searchcore/proton/test/transport_helper.h @@ -1,26 +1,47 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include +#include class FastOS_ThreadPool; -class FNET_Transport; namespace proton { +class ExecutorThreadingService; + /** * Helper class contain a FNET_Transport object for use in tests. **/ -class TransportMgr { +class Transport { +public: + Transport(); + virtual ~Transport(); + FNET_Transport & transport() { return *_transport; } + FastOS_ThreadPool & threadPool() { return *_threadPool; } + virtual void shutdown(); private: std::unique_ptr _threadPool; std::unique_ptr _transport; +}; +class TransportAndExecutor : public Transport { public: - TransportMgr(); - ~TransportMgr(); - FNET_Transport & transport() { return *_transport; } - FastOS_ThreadPool & threadPool() { return *_threadPool; } + TransportAndExecutor(size_t num_threads); + ~TransportAndExecutor() override; + vespalib::Executor & shared() { return *_sharedExecutor; } + void shutdown() override; +private: + std::unique_ptr _sharedExecutor; +}; + +class TransportAndExecutorService : public TransportAndExecutor { +public: + TransportAndExecutorService(size_t num_threads); + ~TransportAndExecutorService() override; + searchcorespi::index::IThreadingService & write(); + void shutdown() override; +private: + std::unique_ptr _writeService; }; } -- cgit v1.2.3