Skip to content

YDB C++ SDK Import 7 #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/ydb-cpp-sdk/client/rate_limiter/rate_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ struct TCreateResourceSettings
: public TOperationRequestSettings<TCreateResourceSettings>
, public THierarchicalDrrSettings<TCreateResourceSettings>
{
using TSelf = TCreateResourceSettings;

TCreateResourceSettings() = default;
TCreateResourceSettings(const Ydb::RateLimiter::CreateResourceRequest&);

Expand All @@ -187,6 +189,8 @@ struct TAlterResourceSettings
: public TOperationRequestSettings<TAlterResourceSettings>
, public THierarchicalDrrSettings<TAlterResourceSettings>
{
using TSelf = TAlterResourceSettings;

FLUENT_SETTING_OPTIONAL(TMeteringConfig, MeteringConfig);
};

Expand Down
1 change: 0 additions & 1 deletion src/client/topic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ target_link_libraries(client-ydb_topic PUBLIC
)

target_sources(client-ydb_topic PRIVATE
proto_accessor.cpp
out.cpp
)

Expand Down
1 change: 1 addition & 0 deletions src/client/topic/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_sources(client-ydb_topic-impl
deferred_commit.cpp
event_handlers.cpp
offsets_collector.cpp
proto_accessor.cpp
read_session_event.cpp
read_session.cpp
topic_impl.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/client/topic/impl/read_session_impl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ void TPartitionStreamImpl<UseMigrationProtocol>::RequestStatus() {
template<bool UseMigrationProtocol>
void TPartitionStreamImpl<UseMigrationProtocol>::ConfirmCreate(std::optional<ui64> readOffset, std::optional<ui64> commitOffset) {
if (auto sessionShared = CbContext->LockShared()) {
if (commitOffset.has_value()) {
SetFirstNotReadOffset(commitOffset.value());
}
sessionShared->ConfirmPartitionStreamCreate(this, readOffset, commitOffset);
}
}
Expand Down
60 changes: 59 additions & 1 deletion src/client/topic/ut/basic_usage_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <src/client/persqueue_public/ut/ut_utils/ut_utils.h>

#include <ydb-cpp-sdk/client/topic/client.h>

#include <src/client/persqueue_public/persqueue.h>

#include <src/client/topic/impl/common.h>
Expand Down Expand Up @@ -661,6 +661,64 @@ Y_UNIT_TEST_SUITE(BasicUsage) {
Sleep(TDuration::Seconds(5));
}

Y_UNIT_TEST(ConfirmPartitionSessionWithCommitOffset) {
// TStartPartitionSessionEvent::Confirm(readOffset, commitOffset) should work,
// if commitOffset passed to Confirm is greater than the offset committed previously by the consumer.
// https://st.yandex-team.ru/KIKIMR-23015

auto setup = TTopicSdkTestSetup(TEST_CASE_NAME);

{
// Write 2 messages:
auto settings = NTopic::TWriteSessionSettings()
.Path(setup.GetTopicPath())
.MessageGroupId(TEST_MESSAGE_GROUP_ID)
.ProducerId(TEST_MESSAGE_GROUP_ID);
auto client = setup.MakeClient();
auto writer = client.CreateSimpleBlockingWriteSession(settings);
writer->Write("message");
writer->Write("message");
writer->Close();
}

{
// Read messages:
auto settings = NTopic::TReadSessionSettings()
.ConsumerName(TEST_CONSUMER)
.AppendTopics(std::string(setup.GetTopicPath()));

auto client = setup.MakeClient();
auto reader = client.CreateReadSession(settings);

{
// Start partition session and request to read from offset 1 and commit offset 1:
auto event = reader->GetEvent(true);
UNIT_ASSERT(event.has_value());
UNIT_ASSERT(std::holds_alternative<TReadSessionEvent::TStartPartitionSessionEvent>(*event));
auto& startPartitionSession = std::get<TReadSessionEvent::TStartPartitionSessionEvent>(*event);
startPartitionSession.Confirm(/*readOffset=*/ 1, /*commitOffset=*/ 1);
}

{
// Receive a message with offset 1 and commit it:
auto event = reader->GetEvent(true);
UNIT_ASSERT(event.has_value());
UNIT_ASSERT(std::holds_alternative<TReadSessionEvent::TDataReceivedEvent>(*event));
auto& dataReceived = std::get<TReadSessionEvent::TDataReceivedEvent>(*event);

// Here we should commit range [1, 2), not [0, 2):
dataReceived.Commit();
}

{
// And then get a TCommitOffsetAcknowledgementEvent:
auto event = reader->GetEvent(true);
UNIT_ASSERT(event.has_value());
UNIT_ASSERT(std::holds_alternative<TReadSessionEvent::TCommitOffsetAcknowledgementEvent>(*event));
}
}
}

Y_UNIT_TEST(ConflictingWrites) {

TTopicSdkTestSetup setup(TEST_CASE_NAME);
Expand Down
Loading