From 930b175c4cb3ece3f82a8ec79dd4989ca688d9e1 Mon Sep 17 00:00:00 2001 From: Jingyu Zhou Date: Thu, 16 Apr 2020 15:11:09 -0700 Subject: [PATCH] Add range files' key ranges to RestorableFileSet Also add continuous logs' begin and end version in RestorableFileSet. --- fdbclient/BackupContainer.actor.cpp | 41 ++++++++++++++++++++++++----- fdbclient/BackupContainer.h | 7 +++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/fdbclient/BackupContainer.actor.cpp b/fdbclient/BackupContainer.actor.cpp index fe2e1b79f0..965042f627 100644 --- a/fdbclient/BackupContainer.actor.cpp +++ b/fdbclient/BackupContainer.actor.cpp @@ -20,6 +20,7 @@ #include "fdbclient/BackupContainer.h" #include "fdbclient/BackupAgent.actor.h" +#include "fdbclient/FDBTypes.h" #include "fdbclient/JsonBuilder.h" #include "flow/Trace.h" #include "flow/UnitTest.h" @@ -424,9 +425,11 @@ public: } // TODO: Do this more efficiently, as the range file list for a snapshot could potentially be hundreds of megabytes. - ACTOR static Future> readKeyspaceSnapshot_impl(Reference bc, KeyspaceSnapshotFile snapshot) { + ACTOR static Future, std::map>> readKeyspaceSnapshot_impl( + Reference bc, KeyspaceSnapshotFile snapshot) { // Read the range file list for the specified version range, and then index them by fileName. - // This is so we can verify that each of the files listed in the manifest file are also in the container at this time. + // This is so we can verify that each of the files listed in the manifest file are also in the container at this + // time. std::vector files = wait(bc->listRangeFiles(snapshot.beginVersion, snapshot.endVersion)); state std::map rangeIndex; for(auto &f : files) @@ -482,10 +485,30 @@ public: throw restore_missing_data(); } - return results; + // Check key ranges for files + std::map fileKeyRanges; + JSONDoc ranges = doc.subDoc("keyRanges"); // Create an empty doc if not existed + for (auto i : ranges.obj()) { + const std::string& filename = i.first; + JSONDoc fields(i.second); + std::string begin, end; + if (fields.tryGet("beginKey", begin) && fields.tryGet("endKey", end)) { + TraceEvent("ManifestFields") + .detail("File", filename) + .detail("Begin", printable(StringRef(begin))) + .detail("End", printable(StringRef(end))); + fileKeyRanges.emplace(filename, KeyRange(KeyRangeRef(StringRef(begin), StringRef(end)))); + } else { + TraceEvent("MalFormattedManifest").detail("Key", filename); + throw restore_corrupted_data(); + } + } + + return std::make_pair(results, fileKeyRanges); } - Future> readKeyspaceSnapshot(KeyspaceSnapshotFile snapshot) { + Future, std::map>> readKeyspaceSnapshot( + KeyspaceSnapshotFile snapshot) { return readKeyspaceSnapshot_impl(Reference::addRef(this), snapshot); } @@ -1322,8 +1345,10 @@ public: restorable.snapshot = snapshot.get(); restorable.targetVersion = targetVersion; - std::vector ranges = wait(bc->readKeyspaceSnapshot(snapshot.get())); - restorable.ranges = std::move(ranges); + std::pair, std::map> results = + wait(bc->readKeyspaceSnapshot(snapshot.get())); + restorable.ranges = std::move(results.first); + restorable.keyRanges = std::move(results.second); // No logs needed if there is a complete key space snapshot at the target version. if (snapshot.get().beginVersion == snapshot.get().endVersion && @@ -1352,6 +1377,8 @@ public: // sort by version order again for continuous analysis std::sort(restorable.logs.begin(), restorable.logs.end()); if (isPartitionedLogsContinuous(restorable.logs, snapshot.get().beginVersion, targetVersion)) { + restorable.continuousBeginVersion = snapshot.get().beginVersion; + restorable.continuousEndVersion = targetVersion + 1; // not inclusive return Optional(restorable); } return Optional(); @@ -1365,6 +1392,8 @@ public: Version end = logs.begin()->endVersion; computeRestoreEndVersion(logs, &restorable.logs, &end, targetVersion); if (end >= targetVersion) { + restorable.continuousBeginVersion = logs.begin()->beginVersion; + restorable.continuousEndVersion = end; return Optional(restorable); } } diff --git a/fdbclient/BackupContainer.h b/fdbclient/BackupContainer.h index c843fb65e7..e68e29b014 100644 --- a/fdbclient/BackupContainer.h +++ b/fdbclient/BackupContainer.h @@ -193,6 +193,13 @@ struct RestorableFileSet { Version targetVersion; std::vector logs; std::vector ranges; + + // Range file's key ranges. Can be empty for backups generated before 6.3. + std::map keyRanges; + + // Mutation logs continuous range [begin, end) + Version continuousBeginVersion, continuousEndVersion; + KeyspaceSnapshotFile snapshot; // Info. for debug purposes };