mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-16 02:42:23 +08:00
Add begin and end version filtering for files
This commit is contained in:
parent
b35c5b31c6
commit
c21fadeaea
@ -41,6 +41,10 @@ enum {
|
|||||||
OPT_TRACE_LOG_GROUP,
|
OPT_TRACE_LOG_GROUP,
|
||||||
OPT_INPUT_FILE,
|
OPT_INPUT_FILE,
|
||||||
OPT_BUILD_FLAGS,
|
OPT_BUILD_FLAGS,
|
||||||
|
OPT_LIST_ONLY,
|
||||||
|
OPT_KEY_PREFIX,
|
||||||
|
OPT_BEGIN_VERSION_FILTER,
|
||||||
|
OPT_END_VERSION_FILTER,
|
||||||
OPT_HELP
|
OPT_HELP
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,6 +66,10 @@ CSimpleOpt::SOption gConverterOptions[] = { { OPT_CONTAINER, "-r", SO_REQ_SEP },
|
|||||||
TLS_OPTION_FLAGS
|
TLS_OPTION_FLAGS
|
||||||
#endif
|
#endif
|
||||||
{ OPT_BUILD_FLAGS, "--build_flags", SO_NONE },
|
{ OPT_BUILD_FLAGS, "--build_flags", SO_NONE },
|
||||||
|
{ OPT_LIST_ONLY, "--list_only", SO_NONE },
|
||||||
|
{ OPT_KEY_PREFIX, "-k", SO_REQ_SEP },
|
||||||
|
{ OPT_BEGIN_VERSION_FILTER, "--begin_version_filter", SO_REQ_SEP },
|
||||||
|
{ OPT_END_VERSION_FILTER, "--end_version_filter", SO_REQ_SEP },
|
||||||
{ OPT_HELP, "-?", SO_NONE },
|
{ OPT_HELP, "-?", SO_NONE },
|
||||||
{ OPT_HELP, "-h", SO_NONE },
|
{ OPT_HELP, "-h", SO_NONE },
|
||||||
{ OPT_HELP, "--help", SO_NONE },
|
{ OPT_HELP, "--help", SO_NONE },
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "fdbbackup/BackupTLSConfig.h"
|
#include "fdbbackup/BackupTLSConfig.h"
|
||||||
@ -65,6 +68,12 @@ void printDecodeUsage() {
|
|||||||
TLS_HELP
|
TLS_HELP
|
||||||
#endif
|
#endif
|
||||||
" --build_flags Print build information and exit.\n"
|
" --build_flags Print build information and exit.\n"
|
||||||
|
" --list_only Print file list and exit.\n"
|
||||||
|
" -k KEY_PREFIX Use the prefix for filtering mutations\n"
|
||||||
|
" --begin_version_filter BEGIN_VERSION\n"
|
||||||
|
" The version range's begin version (inclusive) for filtering.\n"
|
||||||
|
" --end_version_filter END_VERSION\n"
|
||||||
|
" The version range's end version (exclusive) for filtering.\n"
|
||||||
"\n";
|
"\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -79,6 +88,16 @@ struct DecodeParams {
|
|||||||
bool log_enabled = false;
|
bool log_enabled = false;
|
||||||
std::string log_dir, trace_format, trace_log_group;
|
std::string log_dir, trace_format, trace_log_group;
|
||||||
BackupTLSConfig tlsConfig;
|
BackupTLSConfig tlsConfig;
|
||||||
|
bool list_only = false;
|
||||||
|
std::string prefix; // Key prefix for filtering
|
||||||
|
Version beginVersionFilter = 0;
|
||||||
|
Version endVersionFilter = std::numeric_limits<Version>::max();
|
||||||
|
|
||||||
|
// Returns if [begin, end) overlap with the filter range
|
||||||
|
bool overlap(Version begin, Version end) const {
|
||||||
|
// Filter [100, 200), [50,75) [200, 300)
|
||||||
|
return !(begin >= endVersionFilter || end <= beginVersionFilter);
|
||||||
|
}
|
||||||
|
|
||||||
std::string toString() {
|
std::string toString() {
|
||||||
std::string s;
|
std::string s;
|
||||||
@ -97,6 +116,13 @@ struct DecodeParams {
|
|||||||
s.append(" LogGroup:").append(trace_log_group);
|
s.append(" LogGroup:").append(trace_log_group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.append(", list_only: ").append(list_only ? "true" : "false");
|
||||||
|
if (beginVersionFilter != 0) {
|
||||||
|
s.append(", beginVersionFilter: ").append(std::to_string(beginVersionFilter));
|
||||||
|
}
|
||||||
|
if (endVersionFilter < std::numeric_limits<Version>::max()) {
|
||||||
|
s.append(", endVersionFilter: ").append(std::to_string(endVersionFilter));
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +150,22 @@ int parseDecodeCommandLine(DecodeParams* param, CSimpleOpt* args) {
|
|||||||
param->container_url = args->OptionArg();
|
param->container_url = args->OptionArg();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPT_LIST_ONLY:
|
||||||
|
param->list_only = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_KEY_PREFIX:
|
||||||
|
ASSERT(false); // TODO
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_BEGIN_VERSION_FILTER:
|
||||||
|
param->beginVersionFilter = std::atoll(args->OptionArg());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_END_VERSION_FILTER:
|
||||||
|
param->endVersionFilter = std::atoll(args->OptionArg());
|
||||||
|
break;
|
||||||
|
|
||||||
case OPT_CRASHONERROR:
|
case OPT_CRASHONERROR:
|
||||||
g_crashOnError = true;
|
g_crashOnError = true;
|
||||||
break;
|
break;
|
||||||
@ -202,7 +244,8 @@ void printLogFiles(std::string msg, const std::vector<LogFile>& files) {
|
|||||||
std::vector<LogFile> getRelevantLogFiles(const std::vector<LogFile>& files, const DecodeParams& params) {
|
std::vector<LogFile> getRelevantLogFiles(const std::vector<LogFile>& files, const DecodeParams& params) {
|
||||||
std::vector<LogFile> filtered;
|
std::vector<LogFile> filtered;
|
||||||
for (const auto& file : files) {
|
for (const auto& file : files) {
|
||||||
if (file.fileName.find(params.fileFilter) != std::string::npos) {
|
if (file.fileName.find(params.fileFilter) != std::string::npos &&
|
||||||
|
params.overlap(file.beginVersion, file.endVersion + 1)) {
|
||||||
filtered.push_back(file);
|
filtered.push_back(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -520,6 +563,8 @@ ACTOR Future<Void> decode_logs(DecodeParams params) {
|
|||||||
state std::vector<LogFile> logs = getRelevantLogFiles(listing.logs, params);
|
state std::vector<LogFile> logs = getRelevantLogFiles(listing.logs, params);
|
||||||
printLogFiles("Relevant files are: ", logs);
|
printLogFiles("Relevant files are: ", logs);
|
||||||
|
|
||||||
|
if (params.list_only) return Void();
|
||||||
|
|
||||||
state int i = 0;
|
state int i = 0;
|
||||||
// Previous file's unfinished version data
|
// Previous file's unfinished version data
|
||||||
state std::vector<VersionedKVPart> left;
|
state std::vector<VersionedKVPart> left;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user