@@ -624,146 +624,112 @@ ACTOR Future<Void> applyMutations(Database cx, Key uid, Key addPrefix, Key remov
624
624
}
625
625
}
626
626
627
- ACTOR Future<Void> _clearLogRanges (Reference<ReadYourWritesTransaction> tr, bool clearVersionHistory, Key logUidValue, Key destUidValue, Version beginVersion, Version endVersion ) {
627
+ ACTOR static Future<Void> _eraseLogData (Database cx, Key logUidValue, Key destUidValue, Optional< Version> endVersion, bool checkBackupUid, Version backupUid ) {
628
628
state Key backupLatestVersionsPath = destUidValue.withPrefix (backupLatestVersionsPrefix);
629
629
state Key backupLatestVersionsKey = logUidValue.withPrefix (backupLatestVersionsPath);
630
- tr->setOption (FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
631
- tr->setOption (FDBTransactionOptions::LOCK_AWARE);
632
-
633
- state Standalone<RangeResultRef> backupVersions = wait (tr->getRange (KeyRangeRef (backupLatestVersionsPath, strinc (backupLatestVersionsPath)), CLIENT_KNOBS->TOO_MANY ));
634
-
635
- // Make sure version history key does exist and lower the beginVersion if needed
636
- bool foundSelf = false ;
637
- for (auto backupVersion : backupVersions) {
638
- Key currLogUidValue = backupVersion.key .removePrefix (backupLatestVersionsPrefix).removePrefix (destUidValue);
639
-
640
- if (currLogUidValue == logUidValue) {
641
- foundSelf = true ;
642
- beginVersion = std::min (beginVersion, BinaryReader::fromStringRef<Version>(backupVersion.value , Unversioned ()));
643
- }
644
- }
645
630
646
- // Do not clear anything if version history key cannot be found
647
- if (!foundSelf) {
631
+ if (!destUidValue.size ()) {
648
632
return Void ();
649
633
}
650
634
651
- Version nextSmallestVersion = endVersion;
652
- bool clearLogRangesRequired = true ;
653
-
654
- // More than one backup/DR with the same range
655
- if (backupVersions.size () > 1 ) {
656
- for (auto backupVersion : backupVersions) {
657
- Key currLogUidValue = backupVersion.key .removePrefix (backupLatestVersionsPrefix).removePrefix (destUidValue);
658
- Version currVersion = BinaryReader::fromStringRef<Version>(backupVersion.value , Unversioned ());
635
+ state Reference<ReadYourWritesTransaction> tr (new ReadYourWritesTransaction (cx));
636
+ loop{
637
+ try {
638
+ tr->setOption (FDBTransactionOptions::LOCK_AWARE);
639
+ tr->setOption (FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
659
640
660
- if (currLogUidValue == logUidValue) {
661
- continue ;
662
- } else if (currVersion > beginVersion) {
663
- nextSmallestVersion = std::min (currVersion, nextSmallestVersion);
664
- } else {
665
- // If we can find a version less than or equal to beginVersion, clearing log ranges is not required
666
- clearLogRangesRequired = false ;
667
- break ;
641
+ if (checkBackupUid) {
642
+ Subspace sourceStates = Subspace (databaseBackupPrefixRange.begin ).get (BackupAgentBase::keySourceStates).get (logUidValue);
643
+ Optional<Value> v = wait ( tr->get ( sourceStates.pack (DatabaseBackupAgent::keyFolderId) ) );
644
+ if (v.present () && BinaryReader::fromStringRef<Version>(v.get (), Unversioned ()) > backupUid)
645
+ return Void ();
668
646
}
669
- }
670
- }
671
-
672
- if (clearVersionHistory && backupVersions.size () == 1 ) {
673
- // Clear version history
674
- tr->clear (prefixRange (backupLatestVersionsPath));
675
647
676
- // Clear everything under blog/[destUid]
677
- tr->clear (prefixRange (destUidValue.withPrefix (backupLogKeys.begin )));
648
+ state Standalone<RangeResultRef> backupVersions = wait (tr->getRange (KeyRangeRef (backupLatestVersionsPath, strinc (backupLatestVersionsPath)), CLIENT_KNOBS->TOO_MANY ));
678
649
679
- // Disable committing mutations into blog
680
- tr->clear (prefixRange (destUidValue.withPrefix (logRangesRange.begin )));
681
- } else {
682
- if (clearVersionHistory) {
683
- // Clear current backup version history
684
- tr->clear (backupLatestVersionsKey);
685
- } else {
686
- // Update current backup latest version
687
- tr->set (backupLatestVersionsKey, BinaryWriter::toValue<Version>(endVersion, Unversioned ()));
688
- }
650
+ // Make sure version history key does exist and lower the beginVersion if needed
651
+ state Version currBeginVersion = invalidVersion;
652
+ for (auto backupVersion : backupVersions) {
653
+ Key currLogUidValue = backupVersion.key .removePrefix (backupLatestVersionsPrefix).removePrefix (destUidValue);
689
654
690
- // Clear log ranges if needed
691
- if (clearLogRangesRequired) {
692
- Standalone<VectorRef<KeyRangeRef>> ranges = getLogRanges (beginVersion, nextSmallestVersion, destUidValue);
693
- for (auto & range : ranges) {
694
- tr->clear (range);
655
+ if (currLogUidValue == logUidValue) {
656
+ currBeginVersion = BinaryReader::fromStringRef<Version>(backupVersion.value , Unversioned ());
657
+ break ;
658
+ }
695
659
}
696
- }
697
- }
698
-
699
- return Void ();
700
- }
701
660
702
- // The difference between beginVersion and endVersion should not be too large
703
- Future<Void> clearLogRanges (Reference<ReadYourWritesTransaction> tr, bool clearVersionHistory, Key logUidValue, Key destUidValue, Version beginVersion, Version endVersion ) {
704
- return _clearLogRanges (tr, clearVersionHistory, logUidValue, destUidValue, beginVersion, endVersion );
705
- }
661
+ // Do not clear anything if version history key cannot be found
662
+ if (currBeginVersion == invalidVersion ) {
663
+ return Void ( );
664
+ }
706
665
707
- ACTOR static Future<Void> _eraseLogData (Database cx, Key logUidValue, Key destUidValue, Optional<Version> beginVersion, Optional<Version> endVersion, bool checkBackupUid, Version backupUid) {
708
- if ((beginVersion.present () && endVersion.present () && endVersion.get () <= beginVersion.get ()) || !destUidValue.size ())
709
- return Void ();
666
+ state Version currEndVersion = currBeginVersion + CLIENT_KNOBS->CLEAR_LOG_RANGE_COUNT * CLIENT_KNOBS->LOG_RANGE_BLOCK_SIZE ;
667
+ if (endVersion.present ()) {
668
+ currEndVersion = std::min (currEndVersion, endVersion.get ());
669
+ }
710
670
711
- state Version currBeginVersion;
712
- state Version endVersionValue;
713
- state Version currEndVersion;
714
- state bool clearVersionHistory;
715
-
716
- ASSERT (beginVersion.present () == endVersion.present ());
717
- if (beginVersion.present ()) {
718
- currBeginVersion = beginVersion.get ();
719
- endVersionValue = endVersion.get ();
720
- clearVersionHistory = false ;
721
- } else {
722
- // If beginVersion and endVersion are not presented, it means backup is done and we need to clear version history.
723
- // Set currBeginVersion to INTMAX_MAX and it will be set to the correct version in clearLogRanges().
724
- // Set endVersionValue to INTMAX_MAX since we need to clear log ranges up to next smallest version.
725
- currBeginVersion = endVersionValue = currEndVersion = INTMAX_MAX;
726
- clearVersionHistory = true ;
727
- }
671
+ state Version nextSmallestVersion = currEndVersion;
672
+ bool clearLogRangesRequired = true ;
673
+
674
+ // More than one backup/DR with the same range
675
+ if (backupVersions.size () > 1 ) {
676
+ for (auto backupVersion : backupVersions) {
677
+ Key currLogUidValue = backupVersion.key .removePrefix (backupLatestVersionsPrefix).removePrefix (destUidValue);
678
+ Version currVersion = BinaryReader::fromStringRef<Version>(backupVersion.value , Unversioned ());
679
+
680
+ if (currLogUidValue == logUidValue) {
681
+ continue ;
682
+ } else if (currVersion > currBeginVersion) {
683
+ nextSmallestVersion = std::min (currVersion, nextSmallestVersion);
684
+ } else {
685
+ // If we can find a version less than or equal to beginVersion, clearing log ranges is not required
686
+ clearLogRangesRequired = false ;
687
+ break ;
688
+ }
689
+ }
690
+ }
728
691
692
+ if (!endVersion.present () && backupVersions.size () == 1 ) {
693
+ // Clear version history
694
+ tr->clear (prefixRange (backupLatestVersionsPath));
729
695
730
- while (currBeginVersion < endVersionValue || clearVersionHistory) {
731
- state Reference<ReadYourWritesTransaction> tr (new ReadYourWritesTransaction (cx));
732
-
733
- loop{
734
- try {
735
- tr->setOption (FDBTransactionOptions::LOCK_AWARE);
736
- tr->setOption (FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
737
-
738
- if (checkBackupUid) {
739
- Subspace sourceStates = Subspace (databaseBackupPrefixRange.begin ).get (BackupAgentBase::keySourceStates).get (logUidValue);
740
- Optional<Value> v = wait ( tr->get ( sourceStates.pack (DatabaseBackupAgent::keyFolderId) ) );
741
- if (v.present () && BinaryReader::fromStringRef<Version>(v.get (), Unversioned ()) > backupUid)
742
- return Void ();
743
- }
696
+ // Clear everything under blog/[destUid]
697
+ tr->clear (prefixRange (destUidValue.withPrefix (backupLogKeys.begin )));
744
698
745
- if (!clearVersionHistory) {
746
- currEndVersion = std::min (currBeginVersion + CLIENT_KNOBS->CLEAR_LOG_RANGE_COUNT * CLIENT_KNOBS->LOG_RANGE_BLOCK_SIZE , endVersionValue);
699
+ // Disable committing mutations into blog
700
+ tr->clear (prefixRange (destUidValue.withPrefix (logRangesRange.begin )));
701
+ } else {
702
+ if (!endVersion.present () && currEndVersion >= nextSmallestVersion) {
703
+ // Clear current backup version history
704
+ tr->clear (backupLatestVersionsKey);
705
+ } else {
706
+ // Update current backup latest version
707
+ tr->set (backupLatestVersionsKey, BinaryWriter::toValue<Version>(currEndVersion, Unversioned ()));
747
708
}
748
709
749
- Void _ = wait (clearLogRanges (tr, clearVersionHistory, logUidValue, destUidValue, currBeginVersion, currEndVersion));
750
- Void _ = wait (tr->commit ());
751
-
752
- if (clearVersionHistory) {
753
- return Void ();
710
+ // Clear log ranges if needed
711
+ if (clearLogRangesRequired) {
712
+ Standalone<VectorRef<KeyRangeRef>> ranges = getLogRanges (currBeginVersion, nextSmallestVersion, destUidValue);
713
+ for (auto & range : ranges) {
714
+ tr->clear (range);
715
+ }
754
716
}
717
+ }
718
+ Void _ = wait (tr->commit ());
755
719
756
- currBeginVersion = currEndVersion;
757
- break ;
758
- } catch (Error &e) {
759
- Void _ = wait (tr->onError (e));
720
+ if (!endVersion.present () && (backupVersions.size () == 1 || currEndVersion >= nextSmallestVersion)) {
721
+ return Void ();
760
722
}
723
+ if (endVersion.present () && currEndVersion == endVersion.get ()) {
724
+ return Void ();
725
+ }
726
+ tr->reset ();
727
+ } catch (Error &e) {
728
+ Void _ = wait (tr->onError (e));
761
729
}
762
730
}
763
-
764
- return Void ();
765
731
}
766
732
767
- Future<Void> eraseLogData (Database cx, Key logUidValue, Key destUidValue, Optional<Version> beginVersion, Optional<Version> endVersion, bool checkBackupUid, Version backupUid) {
768
- return _eraseLogData (cx, logUidValue, destUidValue, beginVersion, endVersion, checkBackupUid, backupUid);
769
- }
733
+ Future<Void> eraseLogData (Database cx, Key logUidValue, Key destUidValue, Optional<Version> endVersion, bool checkBackupUid, Version backupUid) {
734
+ return _eraseLogData (cx, logUidValue, destUidValue, endVersion, checkBackupUid, backupUid);
735
+ }
0 commit comments