1
1
#include " restore_import_data.h"
2
2
3
3
#include < ydb/public/lib/ydb_cli/common/retry_func.h>
4
+ #include < ydb/public/lib/ydb_cli/dump/util/log.h>
4
5
#include < ydb/public/lib/ydb_cli/dump/util/util.h>
5
6
6
7
#include < library/cpp/string_utils/quote/quote.h>
@@ -662,29 +663,29 @@ class TTableRows {
662
663
return false ;
663
664
}
664
665
665
- TString GetData (ui64 memLimit, ui64 batchSize, bool force = false ) {
666
+ TString GetData (ui64 memLimit, ui64 batchSize, bool force = false ) {
666
667
Y_ENSURE (HasData (memLimit, batchSize, force));
667
668
Y_ENSURE (!ByMemSize.empty ());
668
669
Y_ENSURE (!ByRecordsSize.empty ());
669
670
Y_ENSURE (!ByMemSize.begin ()->second .empty ());
670
671
Y_ENSURE (!ByRecordsSize.begin ()->second .empty ());
671
672
672
673
auto get = [this , batchSize](TRowsBy& from) {
673
- auto it = from.begin ()->second .begin ();
674
- auto & rows = (*it) ->second ;
674
+ auto it = * from.begin ()->second .begin ();
675
+ auto & rows = it ->second ;
675
676
676
- RemoveFromSizeTracker (ByMemSize, rows.MemSize (), * it);
677
- RemoveFromSizeTracker (ByRecordsSize, rows.RecordsSize (), * it);
677
+ RemoveFromSizeTracker (ByMemSize, rows.MemSize (), it);
678
+ RemoveFromSizeTracker (ByRecordsSize, rows.RecordsSize (), it);
678
679
679
680
MemSize -= rows.MemSize ();
680
681
auto ret = rows.Serialize (batchSize);
681
682
MemSize += rows.MemSize ();
682
683
683
684
if (rows.MemSize ()) {
684
- Y_ENSURE (ByMemSize[rows.MemSize ()].insert (* it).second );
685
+ Y_ENSURE (ByMemSize[rows.MemSize ()].insert (it).second );
685
686
}
686
687
if (rows.RecordsSize ()) {
687
- Y_ENSURE (ByRecordsSize[rows.RecordsSize ()].insert (* it).second );
688
+ Y_ENSURE (ByRecordsSize[rows.RecordsSize ()].insert (it).second );
688
689
}
689
690
690
691
return ret;
@@ -739,9 +740,16 @@ class TDataAccumulator: public NPrivate::IDataAccumulator {
739
740
return Rows.GetData (MemLimit, BatchSize, force);
740
741
}
741
742
742
- void Reshard (const TVector<TKeyRange>& keyRanges) {
743
+ void Reshard (const TVector<TKeyRange>& keyRanges, const TString& data ) {
743
744
TGuard<TMutex> lock (Mutex);
744
745
Rows.Reshard (keyRanges);
746
+
747
+ TStringInput input (data);
748
+ TString line;
749
+
750
+ while (input.ReadLine (line)) {
751
+ Rows.Add (KeyBuilder.Build (line), std::move (line));
752
+ }
745
753
}
746
754
747
755
private:
@@ -792,6 +800,7 @@ class TDataWriter: public NPrivate::IDataWriter {
792
800
}
793
801
794
802
if (retryNumber == maxRetries) {
803
+ LOG_E (" There is no retries left, last result: " << importResult.GetIssues ().ToOneLineString ());
795
804
return false ;
796
805
}
797
806
@@ -801,19 +810,12 @@ class TDataWriter: public NPrivate::IDataWriter {
801
810
TMaybe<TTableDescription> desc;
802
811
auto descResult = DescribeTable (TableClient, Path, desc);
803
812
if (!descResult.IsSuccess ()) {
813
+ LOG_E (" Describe table " << Path.Quote () << " failed: " << descResult.GetIssues ().ToOneLineString ());
804
814
return false ;
805
815
}
806
816
807
- Accumulator->Reshard (desc->GetKeyRanges ());
808
-
809
- TStringInput input (data);
810
- TString line;
811
-
812
- while (input.ReadLine (line)) {
813
- Accumulator->Feed (std::move (line));
814
- }
815
-
816
- break ;
817
+ Accumulator->Reshard (desc->GetKeyRanges (), data);
818
+ return true ;
817
819
}
818
820
819
821
case EStatus::ABORTED:
@@ -855,12 +857,14 @@ class TDataWriter: public NPrivate::IDataWriter {
855
857
const TRestoreSettings& settings,
856
858
TImportClient& importClient,
857
859
TTableClient& tableClient,
858
- NPrivate::IDataAccumulator* accumulator)
860
+ NPrivate::IDataAccumulator* accumulator,
861
+ const std::shared_ptr<TLog>& log)
859
862
: Path(path)
860
863
, Settings(MakeSettings(settings, desc))
861
864
, ImportClient(importClient)
862
865
, TableClient(tableClient)
863
866
, Accumulator(dynamic_cast <TDataAccumulator*>(accumulator))
867
+ , Log(log)
864
868
, RateLimiterSettings(settings.RateLimiterSettings_)
865
869
, RequestLimiter(RateLimiterSettings.GetRps(), RateLimiterSettings.GetRps())
866
870
{
@@ -871,7 +875,10 @@ class TDataWriter: public NPrivate::IDataWriter {
871
875
}
872
876
873
877
bool Push (TString&& data) override {
874
- Y_ENSURE (data.size () < TRestoreSettings::MaxBytesPerRequest, " Data is too long" );
878
+ if (data.size () >= TRestoreSettings::MaxBytesPerRequest) {
879
+ LOG_E (" Data is too long" );
880
+ return false ;
881
+ }
875
882
876
883
if (IsStopped ()) {
877
884
return false ;
@@ -896,6 +903,7 @@ class TDataWriter: public NPrivate::IDataWriter {
896
903
TImportClient& ImportClient;
897
904
TTableClient& TableClient;
898
905
TDataAccumulator* Accumulator;
906
+ const std::shared_ptr<TLog> Log;
899
907
900
908
const TRateLimiterSettings RateLimiterSettings;
901
909
@@ -922,8 +930,9 @@ NPrivate::IDataWriter* CreateImportDataWriter(
922
930
TImportClient& importClient,
923
931
TTableClient& tableClient,
924
932
NPrivate::IDataAccumulator* accumulator,
925
- const TRestoreSettings& settings) {
926
- return new TDataWriter (path, desc, settings, importClient, tableClient, accumulator);
933
+ const TRestoreSettings& settings,
934
+ const std::shared_ptr<TLog>& log) {
935
+ return new TDataWriter (path, desc, settings, importClient, tableClient, accumulator, log );
927
936
}
928
937
929
938
} // NDump
0 commit comments