@@ -94,7 +94,7 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload {
9494 shareLogRange = getOption (options, " shareLogRange" _sr, false );
9595 defaultBackup = getOption (options, " defaultBackup" _sr, false );
9696 backupURL = getOption (options, " backupURL" _sr, " file://simfdb/backups/" _sr).toString ();
97- skipDirtyRestore = getOption (options, " skipDirtyRestore" _sr, true );
97+ skipDirtyRestore = getOption (options, " skipDirtyRestore" _sr, false );
9898 initSnapshotInterval = getOption (options, " initSnapshotInterval" _sr, 0 );
9999 snapshotInterval = getOption (options, " snapshotInterval" _sr, 30 );
100100
@@ -610,6 +610,8 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload {
610610 }
611611
612612 try {
613+ state Future<Void> startRestore = delay (self->restoreAfter );
614+
613615 // backup
614616 wait (delay (self->backupAfter ));
615617
@@ -653,11 +655,8 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload {
653655 UidAndAbortedFlagT uidFlag = wait (keyBackedTag.getOrThrow (cx.getReference ()));
654656 state UID logUid = uidFlag.first ;
655657 state Key destUidValue = wait (BackupConfig (logUid).destUidValue ().getD (cx.getReference ()));
656- // Ensure backup reached a restorable/completed state and fetch its container
657- state Reference<IBackupContainer> lastBackupContainer;
658- state UID lastBackupUID;
659- state EBackupState waitState = wait (backupAgent.waitBackup (
660- cx, self->backupTag .toString (), StopWhenDone::True, &lastBackupContainer, &lastBackupUID));
658+ state Reference<IBackupContainer> lastBackupContainer =
659+ wait (BackupConfig (logUid).backupContainer ().getD (cx.getReference ()));
661660
662661 // Occasionally start yet another backup that might still be running when we restore
663662 if (!self->locked && BUGGIFY) {
@@ -681,11 +680,8 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload {
681680 }
682681 }
683682
684- // Wait for backup to complete, then add a small delay before restore
685- TraceEvent (" BARW_WaitingForBackupBeforeRestore" , randomID).detail (" BackupTag" , printable (self->backupTag ));
686-
687- // Add a small delay after backup completion to ensure all metadata is written
688- wait (delay (5.0 ));
683+ CODE_PROBE (!startRestore.isReady (), " Restore starts at specified time" );
684+ wait (startRestore);
689685
690686 if (lastBackupContainer && self->performRestore ) {
691687 if (!self->skipDirtyRestore && deterministicRandom ()->random01 () < 0.5 ) {
@@ -706,36 +702,25 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload {
706702 .detail (" BackupTag" , printable (self->backupTag ));
707703 TraceEvent (" BARW_RestoreBegin" , randomID).detail (" BackupTag" , printable (self->backupTag ));
708704
709- state Reference<IBackupContainer> restoreContainer =
710- IBackupContainer::openContainer (lastBackupContainer->getURL (),
711- lastBackupContainer->getProxy (),
712- lastBackupContainer->getEncryptionKeyFileName ());
713- state BackupDescription restoreDesc;
714- state BackupDescription _initialRestoreDesc = wait (restoreContainer->describeBackup ());
715- restoreDesc = _initialRestoreDesc;
716- // Wait until backup becomes restorable to avoid restore_invalid_version
717- state int attempts = 0 ;
718- loop {
719- if (restoreDesc.maxRestorableVersion .present () || attempts >= 10000 )
720- break ;
721- wait (delay (1.0 ));
722- state BackupDescription _loopRestoreDesc = wait (restoreContainer->describeBackup ());
723- restoreDesc = _loopRestoreDesc;
724- attempts++;
725- }
726- if (!restoreDesc.maxRestorableVersion .present ()) {
727- TraceEvent (" BARW_SkipRestoreNotRestorable" ).detail (" BackupTag" , printable (self->backupTag ));
728- return Void ();
729- }
730-
731- // Double-check to prevent race condition
732- if (!restoreDesc.maxRestorableVersion .present ()) {
733- TraceEvent (" BARW_SkipRestoreNotRestorableRace" ).detail (" BackupTag" , printable (self->backupTag ));
734- return Void ();
705+ auto container = IBackupContainer::openContainer (lastBackupContainer->getURL (),
706+ lastBackupContainer->getProxy (),
707+ lastBackupContainer->getEncryptionKeyFileName ());
708+ BackupDescription desc = wait (container->describeBackup ());
709+
710+ state Version targetVersion = -1 ;
711+ if (desc.maxRestorableVersion .present ()) {
712+ if (deterministicRandom ()->random01 () < 0.1 ) {
713+ targetVersion = desc.minRestorableVersion .get ();
714+ } else if (deterministicRandom ()->random01 () < 0.1 ) {
715+ targetVersion = desc.maxRestorableVersion .get ();
716+ } else if (deterministicRandom ()->random01 () < 0.5 ) {
717+ targetVersion = (desc.minRestorableVersion .get () != desc.maxRestorableVersion .get ())
718+ ? deterministicRandom ()->randomInt64 (desc.minRestorableVersion .get (),
719+ desc.maxRestorableVersion .get ())
720+ : desc.maxRestorableVersion .get ();
721+ }
735722 }
736723
737- state Version targetVersion = restoreDesc.maxRestorableVersion .get ();
738-
739724 TraceEvent (" BARW_RestoreDebug" ).detail (" TargetVersion" , targetVersion);
740725
741726 state std::vector<Future<Version>> restores;
@@ -895,13 +880,6 @@ struct BackupAndRestoreCorrectnessWorkload : TestWorkload {
895880 for (auto & restore : restores) {
896881 ASSERT (!restore.isError ());
897882 }
898-
899- // Re-describe the same container instance to print final description
900- {
901- state BackupDescription finalDesc = wait (restoreContainer->describeBackup ());
902- wait (finalDesc.resolveVersionTimes (cx));
903- printf (" BackupDescription:\n %s\n " , finalDesc.toString ().c_str ());
904- }
905883 }
906884
907885 if (extraBackup.isValid ()) {
0 commit comments