From 88047473a5357d6a050f75593ea0a2679f73b2ad Mon Sep 17 00:00:00 2001 From: sharpeye Date: Fri, 15 Dec 2023 23:55:34 +0300 Subject: [PATCH] tweak topic_api service --- .../logbroker/topic_api_impl/topic_api.cpp | 32 ++++++++++++++++--- .../ut/CMakeLists.darwin-x86_64.txt | 8 ++--- .../ut/CMakeLists.linux-aarch64.txt | 8 ++--- .../ut/CMakeLists.linux-x86_64.txt | 8 ++--- .../ut/CMakeLists.windows-x86_64.txt | 8 ++--- .../libs/logbroker/topic_api_impl/ut/ya.make | 2 +- 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/cloud/blockstore/libs/logbroker/topic_api_impl/topic_api.cpp b/cloud/blockstore/libs/logbroker/topic_api_impl/topic_api.cpp index d3e91829e61..97763696757 100644 --- a/cloud/blockstore/libs/logbroker/topic_api_impl/topic_api.cpp +++ b/cloud/blockstore/libs/logbroker/topic_api_impl/topic_api.cpp @@ -13,6 +13,9 @@ #include #include +#include +#include + namespace NCloud::NBlockStore::NLogbroker { using namespace NThreading; @@ -119,6 +122,9 @@ class TService final const ILoggingServicePtr Logging; TLog Log; + std::optional Driver; + std::mutex DriverMutex; + public: TService( TLogbrokerConfigPtr config, @@ -129,8 +135,7 @@ class TService final TFuture Write(TVector messages, TInstant now) override { - NYdb::TDriver driver = CreateDriver(); - NYdb::NTopic::TTopicClient client {driver}; + NYdb::NTopic::TTopicClient client {GetDriver()}; auto batch = std::make_shared(); batch->Messages = std::move(messages); @@ -152,7 +157,13 @@ class TService final } void Stop() override - {} + { + std::unique_lock lock {DriverMutex}; + if (Driver) { + Driver->Stop(false); + Driver.reset(); + } + } private: void WaitEvent(std::shared_ptr batch) @@ -197,7 +208,7 @@ class TService final } } - NYdb::TDriver CreateDriver() + NYdb::TDriverConfig CreateDriverConfig() const { auto cfg = NYdb::TDriverConfig() .SetEndpoint(TStringBuilder() @@ -224,7 +235,18 @@ class TService final : TString()); } - return NYdb::TDriver {cfg}; + return cfg; + } + + NYdb::TDriver GetDriver() + { + std::unique_lock lock {DriverMutex}; + + if (!Driver) { + Driver.emplace(CreateDriverConfig()); + } + + return *Driver; } }; diff --git a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.darwin-x86_64.txt b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.darwin-x86_64.txt index 2111d9caa32..a17318a7a43 100644 --- a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.darwin-x86_64.txt +++ b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.darwin-x86_64.txt @@ -38,7 +38,7 @@ set_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY SPLIT_FACTOR - 15 + 10 ) add_yunittest( NAME @@ -57,21 +57,21 @@ set_yunittest_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY LABELS - SMALL + MEDIUM ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY PROCESSORS - 2 + 4 ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY TIMEOUT - 60 + 600 ) target_allocator(cloud-blockstore-libs-logbroker-topic_api_impl-ut system_allocator diff --git a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-aarch64.txt b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-aarch64.txt index ef05f671af5..764a195e978 100644 --- a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-aarch64.txt +++ b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-aarch64.txt @@ -41,7 +41,7 @@ set_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY SPLIT_FACTOR - 15 + 10 ) add_yunittest( NAME @@ -60,21 +60,21 @@ set_yunittest_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY LABELS - SMALL + MEDIUM ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY PROCESSORS - 2 + 4 ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY TIMEOUT - 60 + 600 ) target_allocator(cloud-blockstore-libs-logbroker-topic_api_impl-ut cpp-malloc-jemalloc diff --git a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-x86_64.txt b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-x86_64.txt index e79bbdf71de..2f14dce772e 100644 --- a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-x86_64.txt +++ b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.linux-x86_64.txt @@ -42,7 +42,7 @@ set_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY SPLIT_FACTOR - 15 + 10 ) add_yunittest( NAME @@ -61,21 +61,21 @@ set_yunittest_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY LABELS - SMALL + MEDIUM ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY PROCESSORS - 2 + 4 ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY TIMEOUT - 60 + 600 ) target_allocator(cloud-blockstore-libs-logbroker-topic_api_impl-ut cpp-malloc-tcmalloc diff --git a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.windows-x86_64.txt b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.windows-x86_64.txt index 773504cf121..47b62f14714 100644 --- a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.windows-x86_64.txt +++ b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/CMakeLists.windows-x86_64.txt @@ -31,7 +31,7 @@ set_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY SPLIT_FACTOR - 15 + 10 ) add_yunittest( NAME @@ -50,21 +50,21 @@ set_yunittest_property( cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY LABELS - SMALL + MEDIUM ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY PROCESSORS - 2 + 4 ) set_yunittest_property( TEST cloud-blockstore-libs-logbroker-topic_api_impl-ut PROPERTY TIMEOUT - 60 + 600 ) target_allocator(cloud-blockstore-libs-logbroker-topic_api_impl-ut system_allocator diff --git a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/ya.make b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/ya.make index a9126c17063..ce1a7120e51 100644 --- a/cloud/blockstore/libs/logbroker/topic_api_impl/ut/ya.make +++ b/cloud/blockstore/libs/logbroker/topic_api_impl/ut/ya.make @@ -1,6 +1,6 @@ UNITTEST_FOR(cloud/blockstore/libs/logbroker/topic_api_impl) -INCLUDE(${ARCADIA_ROOT}/cloud/storage/core/tests/recipes/small.inc) +INCLUDE(${ARCADIA_ROOT}/cloud/storage/core/tests/recipes/medium.inc) SRCS( topic_api_ut.cpp