From a13d4e9bb6b0611cc5831c94ea72ef8716d44a2a Mon Sep 17 00:00:00 2001 From: Jingyu Zhou Date: Mon, 10 Feb 2020 13:44:08 -0800 Subject: [PATCH] Attempt to fix: remove dead code and add a unit test --- fdbserver/BackupWorker.actor.cpp | 46 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/fdbserver/BackupWorker.actor.cpp b/fdbserver/BackupWorker.actor.cpp index 5a7fc30a1c..8105e01e5f 100644 --- a/fdbserver/BackupWorker.actor.cpp +++ b/fdbserver/BackupWorker.actor.cpp @@ -64,21 +64,10 @@ struct BackupData { PerBackupInfo() = default; PerBackupInfo(BackupData* data, Version v) : self(data), startVersion(v) {} - ACTOR static Future _waitReady(PerBackupInfo* info, UID backupUid) { - wait(success(info->container) && success(info->ranges)); - info->ready = true; - const auto& ranges = info->ranges.get(); - TraceEvent("BackupWorkerInsertRanges", info->self->myId) - .detail("BackupID", backupUid) - .detail("URL", info->container.get()->getURL()) - .detail("Ranges", ranges.present() ? describe(ranges.get()) : "[empty]"); - return Void(); + bool isRunning() { + return container.isReady() && ranges.isReady() && !stopped; } - Future waitReady(UID backupUid) { return _waitReady(this, backupUid); } - - bool isRunning() { return ready && !stopped; } - BackupData* self = nullptr; Version startVersion = invalidVersion; Version lastSavedVersion = invalidVersion; @@ -86,7 +75,6 @@ struct BackupData { Future>> ranges; // Key ranges of this backup bool allWorkerStarted = false; // Only worker with Tag(-2,0) uses & sets this field bool stopped = false; // Is the backup stopped? - bool ready = false; // Change to true when container and ranges are ready }; std::map backups; // Backup UID to infos @@ -416,6 +404,7 @@ ACTOR Future saveMutationsToFile(BackupData* self, Version popVersion, int state std::vector blockEnds; state std::set activeUids; // active Backups' UIDs state KeyRangeMap> keyRangeMap; // range to index in logFileFutures, logFiles, & blockEnds + state MutationRef m; for (auto it = self->backups.begin(); it != self->backups.end();) { if (!it->second.isRunning()) { @@ -436,6 +425,7 @@ ACTOR Future saveMutationsToFile(BackupData* self, Version popVersion, int it->second.lastSavedVersion, popVersion + 1, blockSize, self->tag.id)); it++; } + keyRangeMap.coalesce(allKeys); wait(waitForAll(logFileFutures)); std::transform(logFileFutures.begin(), logFileFutures.end(), std::back_inserter(logFiles), @@ -450,7 +440,6 @@ ACTOR Future saveMutationsToFile(BackupData* self, Version popVersion, int state int idx = 0; blockEnds = std::vector(logFiles.size(), 0); for (; idx < numMsg; idx++) { - state MutationRef m; if (!isBackupMessage(self->messages[idx], &m)) continue; std::vector> adds; @@ -701,4 +690,31 @@ ACTOR Future backupWorker(BackupInterface interf, InitializeBackupRequest } } return Void(); +} + +#include "flow/UnitTest.h" + +TEST_CASE("/BackupWorker/Range") { + KeyRangeMap> rangeMap; + + for (int index : rangeMap[LiteralStringRef("1")]) { + ASSERT(false); + printf("index %d\n", index); + } + + for (auto& logRange : rangeMap.modify(normalKeys)) { + logRange->value().insert(1); + } + for (auto& logRange : rangeMap.modify(singleKeyRange(metadataVersionKey))) { + logRange->value().insert(1); + } + for (auto& logRange : rangeMap.modify(KeyRange(KeyRangeRef(LiteralStringRef("0"), LiteralStringRef("5"))))) { + logRange->value().insert(2); + } + // rangeMap.coalesce(allKeys); + + for (int index : rangeMap[LiteralStringRef("1")]) { + printf("index %d\n", index); + } + return Void(); } \ No newline at end of file