diff options
author | azevaykin <azevaykin@yandex-team.com> | 2023-05-29 10:07:21 +0300 |
---|---|---|
committer | azevaykin <azevaykin@yandex-team.com> | 2023-05-29 10:07:21 +0300 |
commit | bc30b7302696803f29eb5f80bb662a259791a0e8 (patch) | |
tree | ef87092ef024d17ace3cfa9eb5eb2b2bf875c1d1 | |
parent | abe2f152c113b3b8a7dbd6843c378214ed7b540d (diff) | |
download | ydb-bc30b7302696803f29eb5f80bb662a259791a0e8.tar.gz |
Make result optional

Убрал холостое создание std::pair<TKey, TString> в https://a.yandex-team.ru/review/3914273/files/b77e3d7a98463098bb5e0e1ef176d5fd2339c054#file-ydb/core/persqueue/blob.cpp:L783
-rw-r--r-- | ydb/core/persqueue/blob.cpp | 19 | ||||
-rw-r--r-- | ydb/core/persqueue/blob.h | 3 | ||||
-rw-r--r-- | ydb/core/persqueue/partition_write.cpp | 20 | ||||
-rw-r--r-- | ydb/core/persqueue/ut/internals_ut.cpp | 4 |
4 files changed, 23 insertions, 23 deletions
diff --git a/ydb/core/persqueue/blob.cpp b/ydb/core/persqueue/blob.cpp index 859eafa43bc..60f2f967089 100644 --- a/ydb/core/persqueue/blob.cpp +++ b/ydb/core/persqueue/blob.cpp @@ -783,11 +783,10 @@ TString TPartitionedBlob::CompactHead(bool glueHead, THead& head, bool glueNewHe return valueD; } -std::pair<TKey, TString> TPartitionedBlob::Add(TClientBlob&& blob) +std::optional<std::pair<TKey, TString>> TPartitionedBlob::Add(TClientBlob&& blob) { Y_VERIFY(NewHead.Offset >= Head.Offset); ui32 size = blob.GetBlobSize(); - std::pair<TKey, TString> res; Y_VERIFY(InternalPartsCount < 1000); //just check for future packing if (HeadSize + BlobsSize + size + GetMaxHeaderSize() > MaxBlobSize) NeedCompactHead = true; @@ -795,7 +794,8 @@ std::pair<TKey, TString> TPartitionedBlob::Add(TClientBlob&& blob) NeedCompactHead = false; } - if (NeedCompactHead) { //need form blob without last chunk, on start or in case of big head + std::optional<std::pair<TKey, TString>> res; + if (NeedCompactHead) { // need form blob without last chunk, on start or in case of big head NeedCompactHead = false; HeadPartNo = NextPartNo; ui32 count = (GlueHead ? Head.GetCount() : 0) + (GlueNewHead ? NewHead.GetCount() : 0); @@ -804,7 +804,7 @@ std::pair<TKey, TString> TPartitionedBlob::Add(TClientBlob&& blob) Y_VERIFY(NewHead.GetNextOffset() >= (GlueHead ? Head.Offset : NewHead.Offset)); - res.first = TKey(TKeyPrefix::TypeTmpData, Partition, StartOffset, StartPartNo, count, InternalPartsCount, false); + TKey key(TKeyPrefix::TypeTmpData, Partition, StartOffset, StartPartNo, count, InternalPartsCount, false); StartOffset = Offset; StartPartNo = NextPartNo; @@ -820,14 +820,15 @@ std::pair<TKey, TString> TPartitionedBlob::Add(TClientBlob&& blob) Y_VERIFY(batch.Packed); batch.SerializeTo(valueD); } - res.second = valueD; - Y_VERIFY(res.second.size() <= MaxBlobSize && (res.second.size() + size + 1_MB > MaxBlobSize - || HeadSize + BlobsSize + size + GetMaxHeaderSize() <= MaxBlobSize)); + + Y_VERIFY(valueD.size() <= MaxBlobSize && (valueD.size() + size + 1_MB > MaxBlobSize || HeadSize + BlobsSize + size + GetMaxHeaderSize() <= MaxBlobSize)); HeadSize = 0; BlobsSize = 0; - CheckBlob(res.first, res.second); - FormedBlobs.push_back(std::make_pair(res.first, res.second.size())); + CheckBlob(key, valueD); + FormedBlobs.emplace_back(key, valueD.size()); Blobs.clear(); + + res = {key, valueD}; } BlobsSize += size + GetMaxHeaderSize(); ++NextPartNo; diff --git a/ydb/core/persqueue/blob.h b/ydb/core/persqueue/blob.h index 5f9ef43914f..6573ee4720f 100644 --- a/ydb/core/persqueue/blob.h +++ b/ydb/core/persqueue/blob.h @@ -267,8 +267,7 @@ public: TPartitionedBlob(const ui32 partition, const ui64 offset, const TString& sourceId, const ui64 seqNo, const ui16 totalParts, const ui32 totalSize, THead& head, THead& newHead, bool headCleared, bool needCompactHead, const ui32 maxBlobSize); - - std::pair<TKey, TString> Add(TClientBlob&& blob); + std::optional<std::pair<TKey, TString>> Add(TClientBlob&& blob); bool IsInited() const { return !SourceId.empty(); } diff --git a/ydb/core/persqueue/partition_write.cpp b/ydb/core/persqueue/partition_write.cpp index c9910b8d4f9..05b335fd804 100644 --- a/ydb/core/persqueue/partition_write.cpp +++ b/ydb/core/persqueue/partition_write.cpp @@ -966,21 +966,21 @@ bool TPartition::AppendHeadWithNewWrites(TEvKeyValue::TEvRequest* request, const bool lastBlobPart = blob.IsLastPart(); //will return compacted tmp blob - std::pair<TKey, TString> newWrite = PartitionedBlob.Add(std::move(blob)); + auto newWrite = PartitionedBlob.Add(std::move(blob)); - if (!newWrite.second.empty()) { + if (newWrite && !newWrite->second.empty()) { auto write = request->Record.AddCmdWrite(); - write->SetKey(newWrite.first.Data(), newWrite.first.Size()); - write->SetValue(newWrite.second); - Y_VERIFY(!newWrite.first.IsHead()); - auto channel = GetChannel(NextChannel(newWrite.first.IsHead(), newWrite.second.Size())); + write->SetKey(newWrite->first.Data(), newWrite->first.Size()); + write->SetValue(newWrite->second); + Y_VERIFY(!newWrite->first.IsHead()); + auto channel = GetChannel(NextChannel(newWrite->first.IsHead(), newWrite->second.Size())); write->SetStorageChannel(channel); write->SetTactic(AppData(ctx)->PQConfig.GetTactic()); - TKey resKey = newWrite.first; + TKey resKey = newWrite->first; resKey.SetType(TKeyPrefix::TypeData); write->SetKeyToCache(resKey.Data(), resKey.Size()); - WriteCycleSize += newWrite.second.size(); + WriteCycleSize += newWrite->second.size(); LOG_DEBUG_S( ctx, NKikimrServices::PERSQUEUE, @@ -988,8 +988,8 @@ bool TPartition::AppendHeadWithNewWrites(TEvKeyValue::TEvRequest* request, const "' partition " << Partition << " part blob sourceId '" << EscapeC(p.Msg.SourceId) << "' seqNo " << p.Msg.SeqNo << " partNo " << p.Msg.PartNo << - " result is " << TStringBuf(newWrite.first.Data(), newWrite.first.Size()) << - " size " << newWrite.second.size() + " result is " << TStringBuf(newWrite->first.Data(), newWrite->first.Size()) << + " size " << newWrite->second.size() ); } diff --git a/ydb/core/persqueue/ut/internals_ut.cpp b/ydb/core/persqueue/ut/internals_ut.cpp index 22db0517609..7f953e042d5 100644 --- a/ydb/core/persqueue/ut/internals_ut.cpp +++ b/ydb/core/persqueue/ut/internals_ut.cpp @@ -88,8 +88,8 @@ void Test(bool headCompacted, ui32 parts, ui32 partSize, ui32 leftInHead) ); all.push_back(clientBlob); auto res = blob.Add(std::move(clientBlob)); - if (!res.second.empty()) - formed.push_back(res); + if (res && !res->second.empty()) + formed.push_back(*res); } UNIT_ASSERT(blob.IsComplete()); UNIT_ASSERT(formed.size() == blob.GetFormedBlobs().size()); |