@@ -511,15 +511,28 @@ NTable::TBulkUpsertResult LoadOrderLines(
511
511
template <typename LoadFunc>
512
512
void ExecuteWithRetry (const TString& operationName, LoadFunc loadFunc, TLog* Log) {
513
513
for (int retryCount = 0 ; retryCount < MAX_RETRIES; ++retryCount) {
514
+ if (GetGlobalInterruptSource ().stop_requested ()) {
515
+ break ;
516
+ }
517
+
514
518
auto result = loadFunc ();
515
519
if (result.IsSuccess ()) {
516
520
return ;
517
521
}
518
522
523
+ const auto status = result.GetStatus ();
524
+ bool shouldFail = status == EStatus::NOT_FOUND || status == EStatus::UNDETERMINED
525
+ || status == EStatus::UNAUTHORIZED || status == EStatus::SCHEME_ERROR;
526
+ if (shouldFail) {
527
+ LOG_E (operationName << " failed: " << result.GetIssues ().ToOneLineString ());
528
+ RequestStop ();
529
+ return ;
530
+ }
531
+
519
532
if (retryCount < MAX_RETRIES - 1 ) {
520
533
int waitMs = GetBackoffWaitMs (retryCount);
521
534
LOG_T (" Retrying " << operationName << " after " << waitMs << " ms due to: "
522
- << result.GetIssues ().ToOneLineString ());
535
+ << result.GetStatus () << " , " << result. GetIssues ().ToOneLineString ());
523
536
Sleep (TDuration::MilliSeconds (waitMs));
524
537
} else {
525
538
LOG_E (operationName << " failed after " << MAX_RETRIES << " retries: "
@@ -757,10 +770,8 @@ std::expected<double, std::string> GetIndexProgress(
757
770
758
771
// -----------------------------------------------------------------------------
759
772
760
- std::stop_source StopByInterrupt;
761
-
762
773
void InterruptHandler (int ) {
763
- StopByInterrupt .request_stop ();
774
+ GetGlobalInterruptSource () .request_stop ();
764
775
}
765
776
766
777
// -----------------------------------------------------------------------------
@@ -787,7 +798,7 @@ class TPCCLoader {
787
798
, Log(std::make_unique<TLog>(THolder(static_cast <TLogBackend*>(LogBackend))))
788
799
, PreviousDataSizeLoaded(0 )
789
800
, StartTime(Clock::now())
790
- , LoadState(StopByInterrupt .get_token())
801
+ , LoadState(GetGlobalInterruptSource() .get_token())
791
802
{
792
803
}
793
804
@@ -812,18 +823,17 @@ class TPCCLoader {
812
823
Config.LoadThreadCount = DEFAULT_LOAD_THREAD_COUNT;
813
824
}
814
825
815
- // in particular this log message
816
- LOG_I (" Starting TPC-C data import for " << Config.WarehouseCount << " warehouses using " <<
817
- Config.LoadThreadCount << " threads. Approximate data size: "
818
- << GetFormattedSize (LoadState.ApproximateDataSize ));
819
-
820
826
// TODO: detect number of threads
821
827
size_t threadCount = std::min (Config.WarehouseCount , Config.LoadThreadCount );
822
828
threadCount = std::max (threadCount, size_t (1 ));
823
829
824
830
// TODO: calculate optimal number of drivers (but per thread looks good)
825
831
size_t driverCount = threadCount;
826
832
833
+ LOG_I (" Starting TPC-C data import for " << Config.WarehouseCount << " warehouses using " <<
834
+ threadCount << " threads and " << driverCount << " YDB drivers. Approximate data size: "
835
+ << GetFormattedSize (LoadState.ApproximateDataSize ));
836
+
827
837
std::vector<TDriver> drivers;
828
838
drivers.reserve (driverCount);
829
839
for (size_t i = 0 ; i < driverCount; ++i) {
@@ -849,6 +859,8 @@ class TPCCLoader {
849
859
auto & driver = drivers[threadId % driverCount];
850
860
if (threadId == 0 ) {
851
861
LoadSmallTables (driver, Config.Path , Config.WarehouseCount , Log.get ());
862
+ } else {
863
+ std::this_thread::sleep_for (std::chrono::milliseconds (threadId));
852
864
}
853
865
LoadRange (driver, Config.Path , whStart, whEnd, LoadState, Log.get ());
854
866
});
@@ -859,7 +871,7 @@ class TPCCLoader {
859
871
Clock::time_point lastIndexProgressCheck = Clock::time_point::min ();
860
872
861
873
while (true ) {
862
- if (StopByInterrupt .stop_requested ()) {
874
+ if (GetGlobalInterruptSource () .stop_requested ()) {
863
875
break ;
864
876
}
865
877
@@ -876,6 +888,16 @@ class TPCCLoader {
876
888
size_t indexedRangesLoaded = LoadState.IndexedRangesLoaded .load (std::memory_order_relaxed);
877
889
if (indexedRangesLoaded >= threadCount) {
878
890
CreateIndices (drivers[0 ], Config.Path , LoadState, Log.get ());
891
+ for (const auto & state: LoadState.IndexBuildStates ) {
892
+ if (state.Id .GetKind () == TOperation::TOperationId::UNUSED) {
893
+ GetGlobalInterruptSource ().request_stop ();
894
+ break ;
895
+ }
896
+ }
897
+ if (GetGlobalInterruptSource ().stop_requested ()) {
898
+ break ;
899
+ }
900
+
879
901
LOG_I (" Indexed tables loaded, indices are being built in background. Continuing with remaining tables" );
880
902
LoadState.State = TLoadState::ELOAD_TABLES_BUILD_INDICES;
881
903
lastIndexProgressCheck = now;
@@ -932,7 +954,7 @@ class TPCCLoader {
932
954
ExitTuiMode ();
933
955
}
934
956
935
- if (StopByInterrupt .stop_requested ()) {
957
+ if (GetGlobalInterruptSource () .stop_requested ()) {
936
958
LOG_I (" Stop requested, waiting for threads to finish" );
937
959
}
938
960
0 commit comments