2019-10-01 04:16:28 +08:00
|
|
|
#include "fdbserver/BackupProgress.actor.h"
|
|
|
|
|
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
|
|
|
#include "fdbclient/SystemData.h"
|
2019-10-02 00:44:57 +08:00
|
|
|
#include "flow/UnitTest.h"
|
2019-10-01 04:16:28 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
|
|
|
void BackupProgress::addBackupStatus(const WorkerBackupStatus& status) {
|
|
|
|
auto& it = progress[status.epoch];
|
|
|
|
auto lb = it.lower_bound(status.tag);
|
|
|
|
if (lb != it.end() && status.tag == lb->first) {
|
|
|
|
if (lb->second < status.version) {
|
|
|
|
lb->second = status.version;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
it.insert(lb, { status.tag, status.version });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::pair<LogEpoch, Version>, std::map<Tag, Version>> BackupProgress::getUnfinishedBackup() {
|
|
|
|
std::map<std::pair<LogEpoch, Version>, std::map<Tag, Version>> toRecruit;
|
|
|
|
|
2020-01-05 06:33:50 +08:00
|
|
|
if (!backupStartedValue.present()) return toRecruit; // No active backups
|
|
|
|
|
2019-10-02 05:55:08 +08:00
|
|
|
for (const auto& [epoch, info] : epochInfos) {
|
|
|
|
std::set<Tag> tags = enumerateLogRouterTags(info.logRouterTags);
|
2019-10-01 04:16:28 +08:00
|
|
|
std::map<Tag, Version> tagVersions;
|
|
|
|
auto progressIt = progress.find(epoch);
|
|
|
|
if (progressIt != progress.end()) {
|
|
|
|
for (const auto& [tag, savedVersion] : progressIt->second) {
|
|
|
|
tags.erase(tag);
|
2019-10-02 05:55:08 +08:00
|
|
|
if (savedVersion < info.epochEnd - 1) {
|
2019-12-17 05:50:52 +08:00
|
|
|
tagVersions.insert({ tag, savedVersion + 1 });
|
2019-10-01 04:16:28 +08:00
|
|
|
TraceEvent("BW", dbgid)
|
|
|
|
.detail("OldEpoch", epoch)
|
|
|
|
.detail("Tag", tag.toString())
|
2019-12-17 05:50:52 +08:00
|
|
|
.detail("BeginVersion", savedVersion + 1)
|
2019-10-02 05:55:08 +08:00
|
|
|
.detail("EndVersion", info.epochEnd);
|
2019-10-01 04:16:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const Tag tag : tags) { // tags without progress data
|
2019-12-17 05:50:52 +08:00
|
|
|
tagVersions.insert({ tag, info.epochBegin });
|
2019-10-01 04:16:28 +08:00
|
|
|
TraceEvent("BW", dbgid)
|
|
|
|
.detail("OldEpoch", epoch)
|
|
|
|
.detail("Tag", tag.toString())
|
2019-12-17 05:50:52 +08:00
|
|
|
.detail("BeginVersion", info.epochBegin)
|
2019-10-02 05:55:08 +08:00
|
|
|
.detail("EndVersion", info.epochEnd);
|
2019-10-01 04:16:28 +08:00
|
|
|
}
|
|
|
|
if (!tagVersions.empty()) {
|
2019-10-02 05:55:08 +08:00
|
|
|
toRecruit[{ epoch, info.epochEnd }] = tagVersions;
|
2019-10-01 04:16:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return toRecruit;
|
|
|
|
}
|
|
|
|
|
2019-12-17 05:50:52 +08:00
|
|
|
// Save each tag's savedVersion for all epochs into "bStatus".
|
2019-10-01 04:16:28 +08:00
|
|
|
ACTOR Future<Void> getBackupProgress(Database cx, UID dbgid, Reference<BackupProgress> bStatus) {
|
|
|
|
state Transaction tr(cx);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr.setOption(FDBTransactionOptions::PRIORITY_SYSTEM_IMMEDIATE);
|
2020-01-05 06:33:50 +08:00
|
|
|
state Optional<Value> value = wait(tr.get(backupStartedKey));
|
2019-10-01 04:16:28 +08:00
|
|
|
Standalone<RangeResultRef> results = wait(tr.getRange(backupProgressKeys, CLIENT_KNOBS->TOO_MANY));
|
|
|
|
ASSERT(!results.more && results.size() < CLIENT_KNOBS->TOO_MANY);
|
|
|
|
|
2020-01-05 06:33:50 +08:00
|
|
|
bStatus->setBackupStartedValue(value);
|
2019-10-01 04:16:28 +08:00
|
|
|
for (auto& it : results) {
|
|
|
|
const UID workerID = decodeBackupProgressKey(it.key);
|
|
|
|
const WorkerBackupStatus status = decodeBackupProgressValue(it.value);
|
|
|
|
bStatus->addBackupStatus(status);
|
|
|
|
TraceEvent("GotBackupProgress", dbgid)
|
|
|
|
.detail("W", workerID)
|
|
|
|
.detail("Epoch", status.epoch)
|
|
|
|
.detail("Version", status.version)
|
|
|
|
.detail("Tag", status.tag.toString());
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr.onError(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 00:44:57 +08:00
|
|
|
TEST_CASE("/BackupProgress/Unfinished") {
|
2019-10-02 05:55:08 +08:00
|
|
|
std::map<LogEpoch, ILogSystem::EpochTagsVersionsInfo> epochInfos;
|
2019-10-01 04:16:28 +08:00
|
|
|
|
2019-10-02 05:55:08 +08:00
|
|
|
const int epoch1 = 2, begin1 = 1, end1 = 100;
|
2019-10-02 00:44:57 +08:00
|
|
|
const Tag tag1(tagLocalityLogRouter, 0);
|
2019-10-02 05:55:08 +08:00
|
|
|
epochInfos.insert({ epoch1, ILogSystem::EpochTagsVersionsInfo(1, begin1, end1) });
|
|
|
|
BackupProgress progress(UID(0, 0), epochInfos);
|
2020-01-05 06:33:50 +08:00
|
|
|
progress.setBackupStartedValue(Optional<Value>(LiteralStringRef("1")));
|
2019-10-01 04:16:28 +08:00
|
|
|
|
2019-10-02 00:44:57 +08:00
|
|
|
std::map<std::pair<LogEpoch, Version>, std::map<Tag, Version>> unfinished = progress.getUnfinishedBackup();
|
|
|
|
|
|
|
|
ASSERT(unfinished.size() == 1);
|
|
|
|
for (const auto [epochVersion, tagVersion] : unfinished) {
|
|
|
|
ASSERT(epochVersion.first == epoch1 && epochVersion.second == end1);
|
2019-12-17 05:50:52 +08:00
|
|
|
ASSERT(tagVersion.size() == 1 && tagVersion.begin()->first == tag1 && tagVersion.begin()->second == begin1);
|
2019-10-02 00:44:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const int saved1 = 50;
|
2019-12-17 05:50:52 +08:00
|
|
|
WorkerBackupStatus status1(epoch1, saved1, tag1);
|
2019-10-02 00:44:57 +08:00
|
|
|
progress.addBackupStatus(status1);
|
|
|
|
unfinished = progress.getUnfinishedBackup();
|
|
|
|
ASSERT(unfinished.size() == 1);
|
|
|
|
for (const auto [epochVersion, tagVersion] : unfinished) {
|
|
|
|
ASSERT(epochVersion.first == epoch1 && epochVersion.second == end1);
|
2019-12-17 05:50:52 +08:00
|
|
|
ASSERT(tagVersion.size() == 1 && tagVersion.begin()->first == tag1 && tagVersion.begin()->second == saved1 + 1);
|
2019-10-02 00:44:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|