MCPcopy Create free account
hub / github.com/apple/foundationdb / finishRangeFile

Method finishRangeFile

fdbclient/FileBackupAgent.actor.cpp:1081–1129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1079 // - save/extend the task with the new params
1080 // Returns whether or not the caller should continue executing the task.
1081 ACTOR static Future<bool> finishRangeFile(Reference<IBackupFile> file,
1082 Database cx,
1083 Reference<Task> task,
1084 Reference<TaskBucket> taskBucket,
1085 KeyRange range,
1086 Version version) {
1087 wait(file->finish());
1088
1089 // Ignore empty ranges.
1090 if (range.empty())
1091 return false;
1092
1093 state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
1094 state BackupConfig backup(task);
1095 state bool usedFile = false;
1096
1097 // Avoid unnecessary conflict by prevent taskbucket's automatic timeout extension
1098 // because the following transaction loop extends and updates the task.
1099 wait(task->extendMutex.take());
1100 state FlowLock::Releaser releaser(task->extendMutex, 1);
1101
1102 loop {
1103 try {
1104 tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
1105 tr->setOption(FDBTransactionOptions::LOCK_AWARE);
1106
1107 // Update the start key of the task so if this transaction completes but the task then fails
1108 // when it is restarted it will continue where this execution left off.
1109 Params.beginKey().set(task, range.end);
1110
1111 // Save and extend the task with the new begin parameter
1112 state Version newTimeout = wait(taskBucket->extendTimeout(tr, task, UpdateParams::True));
1113
1114 // Update the range bytes written in the backup config
1115 backup.rangeBytesWritten().atomicOp(tr, file->size(), MutationRef::AddValue);
1116 backup.snapshotRangeFileCount().atomicOp(tr, 1, MutationRef::AddValue);
1117
1118 // See if there is already a file for this key which has an earlier begin, update the map if not.
1119 Optional<BackupConfig::RangeSlice> s = wait(backup.snapshotRangeFileMap().get(tr, range.end));
1120 if (!s.present() || s.get().begin >= range.begin) {
1121 backup.snapshotRangeFileMap().set(
1122 tr, range.end, { range.begin, version, file->getFileName(), file->size() });
1123 usedFile = true;
1124 }
1125
1126 wait(tr->commit());
1127 task->timeoutVersion = newTimeout;
1128 break;
1129 } catch (Error& e) {
1130 wait(tr->onError(e));
1131 }
1132 }

Callers

nothing calls this directly

Calls 15

snapshotRangeFileMapMethod · 0.80
commitMethod · 0.65
setOptionMethod · 0.65
setMethod · 0.65
getMethod · 0.65
finishMethod · 0.45
emptyMethod · 0.45
takeMethod · 0.45
beginKeyMethod · 0.45
extendTimeoutMethod · 0.45
atomicOpMethod · 0.45

Tested by

no test coverage detected