Skip to content

Commit bdd6b9d

Browse files
Alek5andr-KotovGazizonoki
authored andcommitted
Moved "The TxUsage::WriteTopic_Demo_8 test is flashing" commit from ydb repo
1 parent 5e27150 commit bdd6b9d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/client/topic/impl/write_session_impl.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ const TDuration UPDATE_TOKEN_PERIOD = TDuration::Hours(1);
2020
// Error code from file ydb/public/api/protos/persqueue_error_codes_v1.proto
2121
const ui64 WRITE_ERROR_PARTITION_INACTIVE = 500029;
2222

23+
namespace {
24+
25+
using TTxId = std::pair<std::string_view, std::string_view>;
26+
using TTxIdOpt = std::optional<TTxId>;
27+
28+
TTxIdOpt GetTransactionId(const Ydb::Topic::StreamWriteMessage_WriteRequest& request)
29+
{
30+
Y_ABORT_UNLESS(request.messages_size());
31+
32+
if (!request.has_tx()) {
33+
return std::nullopt;
34+
}
35+
36+
const Ydb::Topic::TransactionIdentity& tx = request.tx();
37+
return TTxId(tx.session(), tx.id());
38+
}
39+
40+
TTxIdOpt GetTransactionId(const NTable::TTransaction* tx)
41+
{
42+
if (!tx) {
43+
return std::nullopt;
44+
}
45+
46+
return TTxId(tx->GetSession().GetId(), tx->GetId());
47+
}
48+
49+
}
50+
2351
namespace NCompressionDetails {
2452
THolder<IOutputStream> CreateCoder(ECodec codec, TBuffer& result, int quality);
2553
}
@@ -1308,6 +1336,19 @@ void TWriteSessionImpl::UpdateTokenIfNeededImpl() {
13081336
Processor->Write(std::move(clientMessage));
13091337
}
13101338

1339+
bool TWriteSessionImpl::TxIsChanged(const Ydb::Topic::StreamWriteMessage_WriteRequest* writeRequest) const
1340+
{
1341+
Y_ABORT_UNLESS(writeRequest);
1342+
1343+
if (!writeRequest->messages_size()) {
1344+
return false;
1345+
}
1346+
1347+
Y_ABORT_UNLESS(!OriginalMessagesToSend.empty());
1348+
1349+
return GetTransactionId(*writeRequest) != GetTransactionId(OriginalMessagesToSend.front().Tx);
1350+
}
1351+
13111352
void TWriteSessionImpl::SendImpl() {
13121353
Y_ABORT_UNLESS(Lock.IsLocked());
13131354

@@ -1324,6 +1365,9 @@ void TWriteSessionImpl::SendImpl() {
13241365
if (writeRequest->messages_size() > 0 && prevCodec != block.CodecID) {
13251366
break;
13261367
}
1368+
if (TxIsChanged(writeRequest)) {
1369+
break;
1370+
}
13271371
prevCodec = block.CodecID;
13281372
writeRequest->set_codec(static_cast<i32>(block.CodecID));
13291373
Y_ABORT_UNLESS(block.MessageCount == 1);

src/client/topic/impl/write_session_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ class TWriteSessionImpl : public TContinuationTokenIssuer,
418418

419419
std::optional<TEndpointKey> GetPreferredEndpointImpl(ui32 partitionId, ui64 partitionNodeId);
420420

421+
bool TxIsChanged(const Ydb::Topic::StreamWriteMessage_WriteRequest* writeRequest) const;
422+
421423
private:
422424
TWriteSessionSettings Settings;
423425
std::shared_ptr<TTopicClient::TImpl> Client;

0 commit comments

Comments
 (0)