22#include " range_ops.h"
33#include " scan_common.h"
44#include " upload_stats.h"
5+ #include " buffer_data.h"
56
67#include < ydb/core/base/appdata.h>
78#include < ydb/core/base/counters.h>
@@ -27,31 +28,6 @@ namespace NKikimr::NDataShard {
2728#define LOG_W (stream ) LOG_WARN_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD, stream)
2829#define LOG_E (stream ) LOG_ERROR_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD, stream)
2930
30- using TColumnsTypes = THashMap<TString, NScheme::TTypeInfo>;
31- using TTypes = NTxProxy::TUploadTypes;
32- using TRows = NTxProxy::TUploadRows;
33-
34- static TColumnsTypes GetAllTypes (const TUserTable& tableInfo) {
35- TColumnsTypes result;
36-
37- for (const auto & it : tableInfo.Columns ) {
38- result[it.second .Name ] = it.second .Type ;
39- }
40-
41- return result;
42- }
43-
44- static void ProtoYdbTypeFromTypeInfo (Ydb::Type* type, const NScheme::TTypeInfo typeInfo) {
45- if (typeInfo.GetTypeId () == NScheme::NTypeIds::Pg) {
46- auto * typeDesc = typeInfo.GetTypeDesc ();
47- auto * pg = type->mutable_pg_type ();
48- pg->set_type_name (NPg::PgTypeNameFromTypeDesc (typeDesc));
49- pg->set_oid (NPg::PgTypeIdFromTypeDesc (typeDesc));
50- } else {
51- type->set_type_id ((Ydb::Type::PrimitiveTypeId)typeInfo.GetTypeId ());
52- }
53- }
54-
5531static std::shared_ptr<TTypes> BuildTypes (const TUserTable& tableInfo, const NKikimrIndexBuilder::TColumnBuildSettings& buildSettings) {
5632 auto types = GetAllTypes (tableInfo);
5733
@@ -119,74 +95,6 @@ bool BuildExtraColumns(TVector<TCell>& cells, const NKikimrIndexBuilder::TColumn
11995 return true ;
12096}
12197
122- class TBufferData : public IStatHolder , public TNonCopyable {
123- public:
124- TBufferData ()
125- : Rows(new TRows)
126- {
127- }
128-
129- ui64 GetRows () const override final {
130- return Rows->size ();
131- }
132-
133- std::shared_ptr<TRows> GetRowsData () const {
134- return Rows;
135- }
136-
137- ui64 GetBytes () const override final {
138- return ByteSize;
139- }
140-
141- void FlushTo (TBufferData& other) {
142- if (this == &other) {
143- return ;
144- }
145-
146- Y_ABORT_UNLESS (other.Rows );
147- Y_ABORT_UNLESS (other.IsEmpty ());
148-
149- other.Rows .swap (Rows);
150- other.ByteSize = ByteSize;
151- other.LastKey = std::move (LastKey);
152-
153- Clear ();
154- }
155-
156- void Clear () {
157- Rows->clear ();
158- ByteSize = 0 ;
159- LastKey = {};
160- }
161-
162- void AddRow (TSerializedCellVec&& key, TSerializedCellVec&& targetPk, TString&& targetValue) {
163- Rows->emplace_back (std::move (targetPk), std::move (targetValue));
164- ByteSize += Rows->back ().first .GetBuffer ().size () + Rows->back ().second .size ();
165- LastKey = std::move (key);
166- }
167-
168- bool IsEmpty () const {
169- return Rows->empty ();
170- }
171-
172- bool IsReachLimits (const TUploadLimits& Limits) {
173- return Rows->size () >= Limits.BatchRowsLimit || ByteSize > Limits.BatchBytesLimit ;
174- }
175-
176- void ExtractLastKey (TSerializedCellVec& out) {
177- out = std::move (LastKey);
178- }
179-
180- const TSerializedCellVec& GetLastKey () const {
181- return LastKey;
182- }
183-
184- private:
185- std::shared_ptr<TRows> Rows;
186- ui64 ByteSize = 0 ;
187- TSerializedCellVec LastKey;
188- };
189-
19098template <NKikimrServices::TActivity::EType Activity>
19199class TBuildScanUpload : public TActor <TBuildScanUpload<Activity>>, public NTable::IScan {
192100 using TThis = TBuildScanUpload<Activity>;
@@ -382,11 +290,7 @@ class TBuildScanUpload: public TActor<TBuildScanUpload<Activity>>, public NTable
382290 << " WriteBuf empty: " << WriteBuf.IsEmpty ()
383291 << " " << Debug ());
384292
385- if (ReadBuf.IsEmpty ()) {
386- return EScan::Feed;
387- }
388-
389- if (WriteBuf.IsEmpty ()) {
293+ if (!ReadBuf.IsEmpty () && WriteBuf.IsEmpty ()) {
390294 ReadBuf.FlushTo (WriteBuf);
391295 Upload ();
392296 }
@@ -433,7 +337,7 @@ class TBuildScanUpload: public TActor<TBuildScanUpload<Activity>>, public NTable
433337
434338 if (UploadStatus.IsSuccess ()) {
435339 Stats.Aggr (&WriteBuf);
436- WriteBuf.ExtractLastKey (LastUploadedKey );
340+ LastUploadedKey = WriteBuf.ExtractLastKey ();
437341
438342 // send progress
439343 TAutoPtr<TEvDataShard::TEvBuildIndexProgressResponse> progress = new TEvDataShard::TEvBuildIndexProgressResponse;
0 commit comments