@@ -24,7 +24,7 @@ TBlobIterator::TBlobIterator(const TKey& key, const TString& blob)
24
24
void TBlobIterator::ParseBatch () {
25
25
Y_ABORT_UNLESS (Data < End);
26
26
Header = ExtractHeader (Data, End - Data);
27
- Y_ABORT_UNLESS (Header.GetOffset () == Offset);
27
+ // Y_ABORT_UNLESS(Header.GetOffset() == Offset);
28
28
Count += Header.GetCount ();
29
29
Offset += Header.GetCount ();
30
30
InternalPartsCount += Header.GetInternalPartsCount ();
@@ -686,6 +686,13 @@ ui32 THead::FindPos(const ui64 offset, const ui16 partNo) const {
686
686
return i - 1 ;
687
687
}
688
688
689
+ TPartitionedBlob::TRenameFormedBlobInfo::TRenameFormedBlobInfo (const TKey& oldKey, const TKey& newKey, ui32 size) :
690
+ OldKey (oldKey),
691
+ NewKey (newKey),
692
+ Size (size)
693
+ {
694
+ }
695
+
689
696
TPartitionedBlob& TPartitionedBlob::operator =(const TPartitionedBlob& x)
690
697
{
691
698
Partition = x.Partition ;
@@ -737,7 +744,8 @@ TPartitionedBlob::TPartitionedBlob(const TPartitionedBlob& x)
737
744
{}
738
745
739
746
TPartitionedBlob::TPartitionedBlob (const TPartitionId& partition, const ui64 offset, const TString& sourceId, const ui64 seqNo, const ui16 totalParts,
740
- const ui32 totalSize, THead& head, THead& newHead, bool headCleared, bool needCompactHead, const ui32 maxBlobSize)
747
+ const ui32 totalSize, THead& head, THead& newHead, bool headCleared, bool needCompactHead, const ui32 maxBlobSize,
748
+ const ui16 nextPartNo)
741
749
: Partition(partition)
742
750
, Offset(offset)
743
751
, InternalPartsCount(0 )
@@ -747,7 +755,7 @@ TPartitionedBlob::TPartitionedBlob(const TPartitionId& partition, const ui64 off
747
755
, SeqNo(seqNo)
748
756
, TotalParts(totalParts)
749
757
, TotalSize(totalSize)
750
- , NextPartNo(0 )
758
+ , NextPartNo(nextPartNo )
751
759
, HeadPartNo(0 )
752
760
, BlobsSize(0 )
753
761
, Head(head)
@@ -773,7 +781,7 @@ TPartitionedBlob::TPartitionedBlob(const TPartitionId& partition, const ui64 off
773
781
if (HeadSize == 0 ) {
774
782
StartOffset = offset;
775
783
NewHead.Offset = offset;
776
- Y_ABORT_UNLESS (StartPartNo == 0 );
784
+ // Y_ABORT_UNLESS(StartPartNo == 0);
777
785
}
778
786
}
779
787
@@ -804,58 +812,93 @@ TString TPartitionedBlob::CompactHead(bool glueHead, THead& head, bool glueNewHe
804
812
return valueD;
805
813
}
806
814
807
- std::optional<std::pair<TKey, TString>> TPartitionedBlob::Add (TClientBlob&& blob)
815
+ auto TPartitionedBlob::CreateFormedBlob (ui32 size, bool useRename) -> std::optional<TFormedBlobInfo>
816
+ {
817
+ HeadPartNo = NextPartNo;
818
+ ui32 count = (GlueHead ? Head.GetCount () : 0 ) + (GlueNewHead ? NewHead.GetCount () : 0 );
819
+
820
+ Y_ABORT_UNLESS (Offset >= (GlueHead ? Head.Offset : NewHead.Offset ));
821
+
822
+ Y_ABORT_UNLESS (NewHead.GetNextOffset () >= (GlueHead ? Head.Offset : NewHead.Offset ));
823
+
824
+ TKey tmpKey (TKeyPrefix::TypeTmpData, Partition, StartOffset, StartPartNo, count, InternalPartsCount, false );
825
+ TKey dataKey (TKeyPrefix::TypeData, Partition, StartOffset, StartPartNo, count, InternalPartsCount, false );
826
+
827
+ StartOffset = Offset;
828
+ StartPartNo = NextPartNo;
829
+ InternalPartsCount = 0 ;
830
+
831
+ TString valueD = CompactHead (GlueHead, Head, GlueNewHead, NewHead, HeadSize + BlobsSize + (BlobsSize > 0 ? GetMaxHeaderSize () : 0 ));
832
+
833
+ GlueHead = GlueNewHead = false ;
834
+ if (!Blobs.empty ()) {
835
+ TBatch batch{Offset, Blobs.front ().GetPartNo (), std::move (Blobs)};
836
+ Blobs.clear ();
837
+ batch.Pack ();
838
+ Y_ABORT_UNLESS (batch.Packed );
839
+ batch.SerializeTo (valueD);
840
+ }
841
+
842
+ Y_ABORT_UNLESS (valueD.size () <= MaxBlobSize && (valueD.size () + size + 1_MB > MaxBlobSize || HeadSize + BlobsSize + size + GetMaxHeaderSize () <= MaxBlobSize));
843
+ HeadSize = 0 ;
844
+ BlobsSize = 0 ;
845
+ TClientBlob::CheckBlob (tmpKey, valueD);
846
+ if (useRename) {
847
+ FormedBlobs.emplace_back (tmpKey, dataKey, valueD.size ());
848
+ }
849
+ Blobs.clear ();
850
+
851
+ return {{useRename ? tmpKey : dataKey, valueD}};
852
+ }
853
+
854
+ auto TPartitionedBlob::Add (TClientBlob&& blob) -> std::optional<TFormedBlobInfo>
808
855
{
809
856
Y_ABORT_UNLESS (NewHead.Offset >= Head.Offset );
810
857
ui32 size = blob.GetBlobSize ();
811
858
Y_ABORT_UNLESS (InternalPartsCount < 1000 ); // just check for future packing
812
- if (HeadSize + BlobsSize + size + GetMaxHeaderSize () > MaxBlobSize)
859
+ if (HeadSize + BlobsSize + size + GetMaxHeaderSize () > MaxBlobSize) {
813
860
NeedCompactHead = true ;
861
+ }
814
862
if (HeadSize + BlobsSize == 0 ) { // if nothing to compact at all
815
863
NeedCompactHead = false ;
816
864
}
817
865
818
- std::optional<std::pair<TKey, TString> > res;
866
+ std::optional<TFormedBlobInfo > res;
819
867
if (NeedCompactHead) { // need form blob without last chunk, on start or in case of big head
820
868
NeedCompactHead = false ;
821
- HeadPartNo = NextPartNo;
822
- ui32 count = (GlueHead ? Head.GetCount () : 0 ) + (GlueNewHead ? NewHead.GetCount () : 0 );
823
-
824
- Y_ABORT_UNLESS (Offset >= (GlueHead ? Head.Offset : NewHead.Offset ));
825
-
826
- Y_ABORT_UNLESS (NewHead.GetNextOffset () >= (GlueHead ? Head.Offset : NewHead.Offset ));
827
-
828
- TKey key (TKeyPrefix::TypeTmpData, Partition, StartOffset, StartPartNo, count, InternalPartsCount, false );
829
-
830
- StartOffset = Offset;
831
- StartPartNo = NextPartNo;
832
- InternalPartsCount = 0 ;
833
-
834
- TString valueD = CompactHead (GlueHead, Head, GlueNewHead, NewHead, HeadSize + BlobsSize + (BlobsSize > 0 ? GetMaxHeaderSize () : 0 ));
835
-
836
- GlueHead = GlueNewHead = false ;
837
- if (!Blobs.empty ()) {
838
- TBatch batch{Offset, Blobs.front ().GetPartNo (), std::move (Blobs)};
839
- Blobs.clear ();
840
- batch.Pack ();
841
- Y_ABORT_UNLESS (batch.Packed );
842
- batch.SerializeTo (valueD);
843
- }
844
-
845
- Y_ABORT_UNLESS (valueD.size () <= MaxBlobSize && (valueD.size () + size + 1_MB > MaxBlobSize || HeadSize + BlobsSize + size + GetMaxHeaderSize () <= MaxBlobSize));
846
- HeadSize = 0 ;
847
- BlobsSize = 0 ;
848
- TClientBlob::CheckBlob (key, valueD);
849
- FormedBlobs.emplace_back (key, valueD.size ());
850
- Blobs.clear ();
851
-
852
- res = {key, valueD};
869
+ res = CreateFormedBlob (size, true );
853
870
}
854
871
BlobsSize += size + GetMaxHeaderSize ();
855
872
++NextPartNo;
856
873
Blobs.push_back (blob);
857
- if (!IsComplete ())
874
+ if (!IsComplete ()) {
858
875
++InternalPartsCount;
876
+ }
877
+ return res;
878
+ }
879
+
880
+ auto TPartitionedBlob::Add (const TKey& oldKey, ui32 size) -> std::optional<TFormedBlobInfo>
881
+ {
882
+ std::optional<TFormedBlobInfo> res;
883
+ if (NeedCompactHead) {
884
+ NeedCompactHead = false ;
885
+ GlueNewHead = false ;
886
+ res = CreateFormedBlob (0 , false );
887
+ }
888
+
889
+ TKey newKey (TKeyPrefix::TypeData,
890
+ Partition,
891
+ NewHead.Offset + oldKey.GetOffset (),
892
+ oldKey.GetPartNo (),
893
+ oldKey.GetCount (),
894
+ oldKey.GetInternalPartsCount (),
895
+ oldKey.IsHead ());
896
+
897
+ FormedBlobs.emplace_back (oldKey, newKey, size);
898
+
899
+ StartOffset += oldKey.GetCount ();
900
+ // NewHead.Offset += oldKey.GetOffset() + oldKey.GetCount();
901
+
859
902
return res;
860
903
}
861
904
0 commit comments