-
Notifications
You must be signed in to change notification settings - Fork 695
Commit for autopartitioned topics #11629
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
nshestakov
merged 29 commits into
ydb-platform:main
from
niksaveliev:commit-for-autopartitioned-topics
Apr 8, 2025
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
455c733
work in progress
niksaveliev 2b4b32c
return uts
niksaveliev 664bce9
refactoring and ut
niksaveliev f09dc1b
fix
niksaveliev ffc75ac
fix
niksaveliev b625c97
few fixes
niksaveliev 53e5164
distributed tx commit on read session
niksaveliev 1b279d8
work
niksaveliev c117ece
ut
niksaveliev 9b185ac
fix after merge
niksaveliev 45553c2
fix uts
niksaveliev c7dd0fc
fix
niksaveliev 3f898d9
fix
niksaveliev 9ac46b6
fix
niksaveliev 67fdf36
fix after rebase
niksaveliev a5f62e0
fix
niksaveliev a96154f
fix
niksaveliev 2a1a3ad
fix
niksaveliev 2e4b1c0
PQ_V0 comits to autopartitioned topics
niksaveliev f7d192b
rename KQP helper
niksaveliev dc751e8
fix after rebase
niksaveliev ed54e01
clean TODOs
niksaveliev 728f5e2
pq_v0 fixes
niksaveliev 32b821f
ReadSessionId parameter for CommitOffset API
niksaveliev 1874976
add readSessionId to TPartitionSession
niksaveliev e07d7bf
fix for commit to past
niksaveliev 69e9910
remove optional from read_session_id field
niksaveliev 3ea8dd4
fix uts
niksaveliev f18d598
remove kill read session field from TCmdSetClientOffset
niksaveliev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include "kqp_topics.h" | ||
|
||
#include <ydb/core/base/path.h> | ||
#include <ydb/core/protos/kqp.pb.h> | ||
#include <ydb/core/persqueue/utils.h> | ||
#include <ydb/library/actors/core/log.h> | ||
|
||
|
@@ -26,35 +27,73 @@ static void UpdateSupportivePartition(TMaybe<ui32>& lhs, const TMaybe<ui32>& rhs | |
// | ||
bool TConsumerOperations::IsValid() const | ||
{ | ||
return Offsets_.GetNumIntervals() == 1; | ||
return Offsets_.GetNumIntervals() <= 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В случае GetNumIntervals() == 0 функция GetOffsetsCommitRange возвращает {0, 0}? А в каких случаях это нужно? |
||
} | ||
|
||
std::pair<ui64, ui64> TConsumerOperations::GetRange() const | ||
std::pair<ui64, ui64> TConsumerOperations::GetOffsetsCommitRange() const | ||
{ | ||
Y_ABORT_UNLESS(IsValid()); | ||
|
||
return {Offsets_.Min(), Offsets_.Max()}; | ||
if (Offsets_.Empty()) { | ||
return {0,0}; | ||
} else { | ||
return {Offsets_.Min(), Offsets_.Max()}; | ||
} | ||
} | ||
|
||
bool TConsumerOperations::GetForceCommit() const | ||
{ | ||
return ForceCommit_; | ||
} | ||
|
||
bool TConsumerOperations::GetKillReadSession() const | ||
{ | ||
return KillReadSession_; | ||
} | ||
|
||
bool TConsumerOperations::GetOnlyCheckCommitedToFinish() const | ||
niksaveliev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return OnlyCheckCommitedToFinish_; | ||
} | ||
|
||
void TConsumerOperations::AddOperation(const TString& consumer, const Ydb::Topic::OffsetsRange& range) | ||
TString TConsumerOperations::GetReadSessionId() const | ||
{ | ||
return ReadSessionId_; | ||
} | ||
|
||
void TConsumerOperations::AddOperation(const TString& consumer, | ||
const NKikimrKqp::TTopicOperationsRequest_TopicOffsets_PartitionOffsets_OffsetsRange& range, | ||
bool forceCommit, | ||
bool killReadSession, | ||
bool onlyCheckCommitedToFinish, | ||
const TString& readSessionId) | ||
{ | ||
Y_ABORT_UNLESS(Consumer_.Empty() || Consumer_ == consumer); | ||
|
||
AddOperationImpl(consumer, range.start(), range.end()); | ||
AddOperationImpl(consumer, range.start(), range.end(), forceCommit, killReadSession, onlyCheckCommitedToFinish, readSessionId); | ||
} | ||
|
||
void TConsumerOperations::Merge(const TConsumerOperations& rhs) | ||
{ | ||
Y_ABORT_UNLESS(rhs.Consumer_.Defined()); | ||
Y_ABORT_UNLESS(Consumer_.Empty() || Consumer_ == rhs.Consumer_); | ||
|
||
for (auto& range : rhs.Offsets_) { | ||
AddOperationImpl(*rhs.Consumer_, range.first, range.second); | ||
if (!rhs.Offsets_.Empty()) { | ||
for (auto& range : rhs.Offsets_) { | ||
AddOperationImpl(*rhs.Consumer_, range.first, range.second, rhs.GetForceCommit(), rhs.GetKillReadSession(), rhs.GetOnlyCheckCommitedToFinish(), rhs.GetReadSessionId()); | ||
} | ||
} else { | ||
AddOperationImpl(*rhs.Consumer_, 0, 0, rhs.GetForceCommit(), rhs.GetKillReadSession(), rhs.GetOnlyCheckCommitedToFinish(), rhs.GetReadSessionId()); | ||
} | ||
} | ||
|
||
void TConsumerOperations::AddOperationImpl(const TString& consumer, | ||
ui64 begin, ui64 end) | ||
ui64 begin, | ||
ui64 end, | ||
bool forceCommit, | ||
bool killReadSession, | ||
bool onlyCheckCommitedToFinish, | ||
const TString& readSessionId) | ||
{ | ||
if (Offsets_.Intersects(begin, end)) { | ||
ythrow TOffsetsRangeIntersectExpection() << "offset ranges intersect"; | ||
|
@@ -64,7 +103,14 @@ void TConsumerOperations::AddOperationImpl(const TString& consumer, | |
Consumer_ = consumer; | ||
} | ||
|
||
Offsets_.InsertInterval(begin, end); | ||
if (end != 0) { | ||
Offsets_.InsertInterval(begin, end); | ||
} | ||
|
||
ForceCommit_ = forceCommit; | ||
KillReadSession_ = killReadSession; | ||
OnlyCheckCommitedToFinish_ = onlyCheckCommitedToFinish; | ||
ReadSessionId_ = readSessionId; | ||
} | ||
|
||
// | ||
|
@@ -76,9 +122,14 @@ bool TTopicPartitionOperations::IsValid() const | |
[](auto& x) { return x.second.IsValid(); }); | ||
} | ||
|
||
void TTopicPartitionOperations::AddOperation(const TString& topic, ui32 partition, | ||
void TTopicPartitionOperations::AddOperation(const TString& topic, | ||
ui32 partition, | ||
const TString& consumer, | ||
const Ydb::Topic::OffsetsRange& range) | ||
const NKikimrKqp::TTopicOperationsRequest_TopicOffsets_PartitionOffsets_OffsetsRange& range, | ||
bool forceCommit, | ||
bool killReadSession, | ||
bool onlyCheckCommitedToFinish, | ||
const TString& readSessionId) | ||
{ | ||
Y_ABORT_UNLESS(Topic_.Empty() || Topic_ == topic); | ||
Y_ABORT_UNLESS(Partition_.Empty() || Partition_ == partition); | ||
|
@@ -88,7 +139,7 @@ void TTopicPartitionOperations::AddOperation(const TString& topic, ui32 partitio | |
Partition_ = partition; | ||
} | ||
|
||
Operations_[consumer].AddOperation(consumer, range); | ||
Operations_[consumer].AddOperation(consumer, range, forceCommit, killReadSession, onlyCheckCommitedToFinish, readSessionId); | ||
} | ||
|
||
void TTopicPartitionOperations::AddOperation(const TString& topic, ui32 partition, | ||
|
@@ -117,11 +168,15 @@ void TTopicPartitionOperations::BuildTopicTxs(TTopicOperationTransactions& txs) | |
for (auto& [consumer, operations] : Operations_) { | ||
NKikimrPQ::TPartitionOperation* o = t.tx.MutableOperations()->Add(); | ||
o->SetPartitionId(*Partition_); | ||
auto [begin, end] = operations.GetRange(); | ||
o->SetBegin(begin); | ||
o->SetEnd(end); | ||
auto [begin, end] = operations.GetOffsetsCommitRange(); | ||
o->SetCommitOffsetsBegin(begin); | ||
o->SetCommitOffsetsEnd(end); | ||
o->SetConsumer(consumer); | ||
o->SetPath(*Topic_); | ||
o->SetKillReadSession(operations.GetKillReadSession()); | ||
o->SetForceCommit(operations.GetForceCommit()); | ||
o->SetOnlyCheckCommitedToFinish(operations.GetOnlyCheckCommitedToFinish()); | ||
o->SetReadSessionId(operations.GetReadSessionId()); | ||
} | ||
|
||
if (HasWriteOperations_) { | ||
|
@@ -256,14 +311,25 @@ bool TTopicOperations::TabletHasReadOperations(ui64 tabletId) const | |
return false; | ||
} | ||
|
||
void TTopicOperations::AddOperation(const TString& topic, ui32 partition, | ||
void TTopicOperations::AddOperation(const TString& topic, | ||
ui32 partition, | ||
const TString& consumer, | ||
const Ydb::Topic::OffsetsRange& range) | ||
const NKikimrKqp::TTopicOperationsRequest_TopicOffsets_PartitionOffsets_OffsetsRange& range, | ||
bool forceCommit, | ||
bool killReadSession, | ||
bool onlyCheckCommitedToFinish, | ||
const TString& readSessionId | ||
) | ||
{ | ||
TTopicPartition key{topic, partition}; | ||
Operations_[key].AddOperation(topic, partition, | ||
Operations_[key].AddOperation(topic, | ||
partition, | ||
consumer, | ||
range); | ||
range, | ||
forceCommit, | ||
killReadSession, | ||
onlyCheckCommitedToFinish, | ||
readSessionId); | ||
HasReadOperations_ = true; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а почему здесь важно, что FromReqest? Есть не из request?