Skip watch of backup task's started key if it's already set
The backup task may be restarted multiple times so the started key for the backup task may already be set. In this case, the wait on watch should be skipped.
This commit is contained in:
parent
7cf2881fe8
commit
19ef7f6bdb
|
@ -2366,15 +2366,19 @@ namespace fileBackup {
|
||||||
tr->reset();
|
tr->reset();
|
||||||
state BackupConfig config(task);
|
state BackupConfig config(task);
|
||||||
loop {
|
loop {
|
||||||
|
state Future<Void> watchFuture;
|
||||||
try {
|
try {
|
||||||
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
||||||
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
||||||
state Future<Void> keepRunning = taskBucket->keepRunning(tr, task);
|
state Future<Void> keepRunning = taskBucket->keepRunning(tr, task);
|
||||||
|
|
||||||
Optional<Value> value = wait(tr->get(backupStartedKey));
|
state Future<Optional<Value>> started = tr->get(backupStartedKey);
|
||||||
|
state Future<Optional<Value>> taskStarted = tr->get(config.allWorkerStarted().key);
|
||||||
|
wait(success(started) && success(taskStarted));
|
||||||
|
|
||||||
std::vector<std::pair<UID, Version>> ids;
|
std::vector<std::pair<UID, Version>> ids;
|
||||||
if (value.present()) {
|
if (started.get().present()) {
|
||||||
ids = decodeBackupStartedValue(value.get());
|
ids = decodeBackupStartedValue(started.get().get());
|
||||||
}
|
}
|
||||||
const UID uid = config.getUid();
|
const UID uid = config.getUid();
|
||||||
auto it = std::find_if(ids.begin(), ids.end(),
|
auto it = std::find_if(ids.begin(), ids.end(),
|
||||||
|
@ -2389,10 +2393,17 @@ namespace fileBackup {
|
||||||
}
|
}
|
||||||
|
|
||||||
tr->set(backupStartedKey, encodeBackupStartedValue(ids));
|
tr->set(backupStartedKey, encodeBackupStartedValue(ids));
|
||||||
state Future<Void> watchFuture = tr->watch(config.allWorkerStarted().key);
|
|
||||||
|
// The task may be restarted. Set the watch if started key has NOT been set.
|
||||||
|
if (!taskStarted.get().present()) {
|
||||||
|
watchFuture = tr->watch(config.allWorkerStarted().key);
|
||||||
|
}
|
||||||
|
|
||||||
wait(keepRunning);
|
wait(keepRunning);
|
||||||
wait(tr->commit());
|
wait(tr->commit());
|
||||||
wait(watchFuture);
|
if (!taskStarted.get().present()) {
|
||||||
|
wait(watchFuture);
|
||||||
|
}
|
||||||
return Void();
|
return Void();
|
||||||
} catch (Error &e) {
|
} catch (Error &e) {
|
||||||
wait(tr->onError(e));
|
wait(tr->onError(e));
|
||||||
|
|
Loading…
Reference in New Issue