@@ -309,10 +309,6 @@ class TS3Downloader: public TActorBootstrapped<TS3Downloader> {
309
309
310
310
}; // TUploadRowsRequestBuilder
311
311
312
- enum class EWakeupTag : ui64 {
313
- Restart,
314
- };
315
-
316
312
void AllocateResource () {
317
313
IMPORT_LOG_D (" AllocateResource" );
318
314
@@ -386,7 +382,7 @@ class TS3Downloader: public TActorBootstrapped<TS3Downloader> {
386
382
default :
387
383
IMPORT_LOG_E (" Error at 'HeadObject'"
388
384
<< " : error# " << result);
389
- return RestartOrFinish (result.GetError (). GetMessage (). c_str ());
385
+ return RetryOrFinish (result.GetError ());
390
386
}
391
387
392
388
CompressionCodec = NBackupRestoreTraits::NextCompressionCodec (CompressionCodec);
@@ -578,7 +574,7 @@ class TS3Downloader: public TActorBootstrapped<TS3Downloader> {
578
574
return Finish (false , record.GetErrorDescription ());
579
575
580
576
default :
581
- return RestartOrFinish (record.GetErrorDescription ());
577
+ return RetryOrFinish (record.GetErrorDescription ());
582
578
}
583
579
}
584
580
@@ -590,7 +586,7 @@ class TS3Downloader: public TActorBootstrapped<TS3Downloader> {
590
586
591
587
IMPORT_LOG_E (" Error at '" << marker << " '"
592
588
<< " : error# " << result);
593
- RestartOrFinish (result.GetError (). GetMessage (). c_str ());
589
+ RetryOrFinish (result.GetError ());
594
590
595
591
return false ;
596
592
}
@@ -656,21 +652,35 @@ class TS3Downloader: public TActorBootstrapped<TS3Downloader> {
656
652
return true ;
657
653
}
658
654
659
- void RestartOrFinish (const TString& error) {
660
- if (Attempt++ < Retries) {
661
- Delay = Min (Delay * Attempt, MaxDelay);
662
- const TDuration random = TDuration::FromValue (TAppData::RandomProvider->GenRand64 () % Delay.MicroSeconds ());
655
+ static bool ShouldRetry (const Aws::S3::S3Error& error) {
656
+ return error.ShouldRetry ();
657
+ }
663
658
664
- Schedule (Delay + random, new TEvents::TEvWakeup (static_cast <ui64>(EWakeupTag::Restart)));
665
- } else {
666
- Finish (false , error);
667
- }
659
+ static bool ShouldRetry (const TString&) {
660
+ return true ;
668
661
}
669
662
670
- void Handle (TEvents::TEvWakeup::TPtr& ev) {
671
- switch (static_cast <EWakeupTag>(ev->Get ()->Tag )) {
672
- case EWakeupTag::Restart:
673
- return Restart ();
663
+ template <typename T>
664
+ bool CanRetry (const T& error) const {
665
+ return Attempt < Retries && ShouldRetry (error);
666
+ }
667
+
668
+ void Retry () {
669
+ Delay = Min (Delay * ++Attempt, MaxDelay);
670
+ const TDuration random = TDuration::FromValue (TAppData::RandomProvider->GenRand64 () % Delay.MicroSeconds ());
671
+ Schedule (Delay + random, new TEvents::TEvWakeup ());
672
+ }
673
+
674
+ template <typename T>
675
+ void RetryOrFinish (const T& error) {
676
+ if (CanRetry (error)) {
677
+ Retry ();
678
+ } else {
679
+ if constexpr (std::is_same_v<T, Aws::S3::S3Error>) {
680
+ Finish (false , TStringBuilder () << " S3 error: " << error.GetMessage ().c_str ());
681
+ } else {
682
+ Finish (false , error);
683
+ }
674
684
}
675
685
}
676
686
@@ -754,7 +764,7 @@ class TS3Downloader: public TActorBootstrapped<TS3Downloader> {
754
764
hFunc (TEvDataShard::TEvS3DownloadInfo, Handle);
755
765
hFunc (TEvDataShard::TEvS3UploadRowsResponse, Handle);
756
766
757
- hFunc (TEvents::TEvWakeup, Handle );
767
+ sFunc (TEvents::TEvWakeup, Restart );
758
768
sFunc (TEvents::TEvPoisonPill, NotifyDied);
759
769
}
760
770
}
0 commit comments