Skip to content

Commit

Permalink
tweak topic_api service
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpeye committed Dec 15, 2023
1 parent 14db386 commit 8804747
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
32 changes: 27 additions & 5 deletions cloud/blockstore/libs/logbroker/topic_api_impl/topic_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <util/generic/overloaded.h>
#include <util/stream/file.h>

#include <mutex>
#include <optional>

namespace NCloud::NBlockStore::NLogbroker {

using namespace NThreading;
Expand Down Expand Up @@ -119,6 +122,9 @@ class TService final
const ILoggingServicePtr Logging;
TLog Log;

std::optional<NYdb::TDriver> Driver;
std::mutex DriverMutex;

public:
TService(
TLogbrokerConfigPtr config,
Expand All @@ -129,8 +135,7 @@ class TService final

TFuture<NProto::TError> Write(TVector<TMessage> messages, TInstant now) override
{
NYdb::TDriver driver = CreateDriver();
NYdb::NTopic::TTopicClient client {driver};
NYdb::NTopic::TTopicClient client {GetDriver()};

auto batch = std::make_shared<TBatch>();
batch->Messages = std::move(messages);
Expand All @@ -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<TBatch> batch)
Expand Down Expand Up @@ -197,7 +208,7 @@ class TService final
}
}

NYdb::TDriver CreateDriver()
NYdb::TDriverConfig CreateDriverConfig() const
{
auto cfg = NYdb::TDriverConfig()
.SetEndpoint(TStringBuilder()
Expand All @@ -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;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ set_property(
cloud-blockstore-libs-logbroker-topic_api_impl-ut
PROPERTY
SPLIT_FACTOR
15
10
)
add_yunittest(
NAME
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ set_property(
cloud-blockstore-libs-logbroker-topic_api_impl-ut
PROPERTY
SPLIT_FACTOR
15
10
)
add_yunittest(
NAME
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set_property(
cloud-blockstore-libs-logbroker-topic_api_impl-ut
PROPERTY
SPLIT_FACTOR
15
10
)
add_yunittest(
NAME
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set_property(
cloud-blockstore-libs-logbroker-topic_api_impl-ut
PROPERTY
SPLIT_FACTOR
15
10
)
add_yunittest(
NAME
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cloud/blockstore/libs/logbroker/topic_api_impl/ut/ya.make
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8804747

Please sign in to comment.