fix: latestRestorable was incorrect

This commit is contained in:
Evan Tschannen 2017-12-21 17:09:21 -08:00
parent 5ed080721d
commit 69f7409c37
2 changed files with 16 additions and 4 deletions

View File

@ -677,14 +677,20 @@ public:
return configSpace.pack(LiteralStringRef(__FUNCTION__));
}
// The end version of the first complete snapshot
KeyBackedProperty<Version> firstSnapshotEndVersion() {
return configSpace.pack(LiteralStringRef(__FUNCTION__));
}
Future<Optional<Version>> getLatestRestorableVersion(Reference<ReadYourWritesTransaction> tr) {
tr->setOption(FDBTransactionOptions::READ_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::READ_LOCK_AWARE);
auto &copy = *this;
auto lastLog = latestLogEndVersion().get(tr);
auto lastSnapshot = latestSnapshotEndVersion().get(tr);
return map(success(lastLog) && success(lastSnapshot), [=](Void) -> Optional<Version> {
if(lastLog.get().present() && lastSnapshot.get().present()) {
auto firstSnapshot = firstSnapshotEndVersion().get(tr);
return map(success(lastLog) && success(firstSnapshot), [=](Void) -> Optional<Version> {
// The latest log greater than the oldest snapshot is the restorable version
if(lastLog.get().present() && firstSnapshot.get().present() && lastLog.get().get() >= firstSnapshot.get().get()) {
return lastLog.get().get();
}
return {};

View File

@ -1845,10 +1845,16 @@ namespace fileBackup {
state bool stopWhenDone;
state EBackupState backupState;
state Optional<Version> restorableVersion;
state Optional<Version> firstSnapshotEndVersion;
Void _ = wait(store(config.stopWhenDone().getOrThrow(tr), stopWhenDone)
&& store(config.stateEnum().getOrThrow(tr), backupState)
&& store(config.getLatestRestorableVersion(tr), restorableVersion));
&& store(config.getLatestRestorableVersion(tr), restorableVersion)
&& store(config.firstSnapshotEndVersion().get(tr), firstSnapshotEndVersion));
if(!firstSnapshotEndVersion.present()) {
config.firstSnapshotEndVersion().set(tr, Params.endVersion().get(task));
}
// If the backup is restorable and the state isn't differential the set state to differential
if(restorableVersion.present() && backupState != BackupAgentBase::STATE_DIFFERENTIAL)