LDBCommand::SelectCommand to use a struct as the parameter
Summary: The function wrapper for LDBCommand::SelectCommand is too long so that Windows build fails with warning "decorated name length exceeded, name was truncated". Shrink the length by using a struct. Test Plan: Build on both of Linux and Windows and make sure the warning doesn't show in either platform. Reviewers: andrewkr, adsharma, IslamAbdelRahman Reviewed By: IslamAbdelRahman Subscribers: leveldb, andrewkr, dhruba Differential Revision: https://reviews.facebook.net/D58965
This commit is contained in:
parent
590e2617ee
commit
c40c4cae14
@ -10,6 +10,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -53,19 +54,21 @@ class LDBCommand {
|
|||||||
static const std::string ARG_CREATE_IF_MISSING;
|
static const std::string ARG_CREATE_IF_MISSING;
|
||||||
static const std::string ARG_NO_VALUE;
|
static const std::string ARG_NO_VALUE;
|
||||||
|
|
||||||
// parameters: cmd, cmdParams, option_map, flags
|
struct ParsedParams {
|
||||||
// The same interface as SelectCommand()
|
std::string cmd;
|
||||||
typedef std::function<LDBCommand*(const std::string&,
|
std::vector<std::string> cmd_params;
|
||||||
const std::vector<std::string>&,
|
std::map<std::string, std::string> option_map;
|
||||||
const std::map<std::string, std::string>&,
|
std::vector<std::string> flags;
|
||||||
const std::vector<std::string>&)>
|
};
|
||||||
RocksDBLDBSelectFunc;
|
|
||||||
|
static LDBCommand* SelectCommand(const ParsedParams& parsed_parms);
|
||||||
|
|
||||||
static LDBCommand* InitFromCmdLineArgs(
|
static LDBCommand* InitFromCmdLineArgs(
|
||||||
const std::vector<std::string>& args, const Options& options,
|
const std::vector<std::string>& args, const Options& options,
|
||||||
const LDBOptions& ldb_options,
|
const LDBOptions& ldb_options,
|
||||||
const std::vector<ColumnFamilyDescriptor>* column_families,
|
const std::vector<ColumnFamilyDescriptor>* column_families,
|
||||||
const RocksDBLDBSelectFunc& selector = SelectCommand);
|
const std::function<LDBCommand*(const ParsedParams&)>& selector =
|
||||||
|
SelectCommand);
|
||||||
|
|
||||||
static LDBCommand* InitFromCmdLineArgs(
|
static LDBCommand* InitFromCmdLineArgs(
|
||||||
int argc, char** argv, const Options& options,
|
int argc, char** argv, const Options& options,
|
||||||
@ -114,11 +117,6 @@ class LDBCommand {
|
|||||||
|
|
||||||
static const char* DELIM;
|
static const char* DELIM;
|
||||||
|
|
||||||
static LDBCommand* SelectCommand(
|
|
||||||
const std::string& cmd, const std::vector<std::string>& cmdParams,
|
|
||||||
const std::map<std::string, std::string>& option_map,
|
|
||||||
const std::vector<std::string>& flags);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LDBCommandExecuteResult exec_state_;
|
LDBCommandExecuteResult exec_state_;
|
||||||
std::string db_path_;
|
std::string db_path_;
|
||||||
|
137
tools/ldb_cmd.cc
137
tools/ldb_cmd.cc
@ -102,12 +102,13 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
|
|||||||
const std::vector<std::string>& args, const Options& options,
|
const std::vector<std::string>& args, const Options& options,
|
||||||
const LDBOptions& ldb_options,
|
const LDBOptions& ldb_options,
|
||||||
const std::vector<ColumnFamilyDescriptor>* column_families,
|
const std::vector<ColumnFamilyDescriptor>* column_families,
|
||||||
const RocksDBLDBSelectFunc& selector) {
|
const std::function<LDBCommand*(const ParsedParams&)>& selector) {
|
||||||
// --x=y command line arguments are added as x->y map entries.
|
// --x=y command line arguments are added as x->y map entries in
|
||||||
std::map<std::string, std::string> option_map;
|
// parsed_params.option_map.
|
||||||
|
//
|
||||||
// Command-line arguments of the form --hex end up in this array as hex
|
// Command-line arguments of the form --hex end up in this array as hex to
|
||||||
std::vector<std::string> flags;
|
// parsed_params.flags
|
||||||
|
ParsedParams parsed_params;
|
||||||
|
|
||||||
// Everything other than option_map and flags. Represents commands
|
// Everything other than option_map and flags. Represents commands
|
||||||
// and their parameters. For eg: put key1 value1 go into this vector.
|
// and their parameters. For eg: put key1 value1 go into this vector.
|
||||||
@ -120,10 +121,10 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
|
|||||||
std::vector<std::string> splits = StringSplit(arg, '=');
|
std::vector<std::string> splits = StringSplit(arg, '=');
|
||||||
if (splits.size() == 2) {
|
if (splits.size() == 2) {
|
||||||
std::string optionKey = splits[0].substr(OPTION_PREFIX.size());
|
std::string optionKey = splits[0].substr(OPTION_PREFIX.size());
|
||||||
option_map[optionKey] = splits[1];
|
parsed_params.option_map[optionKey] = splits[1];
|
||||||
} else {
|
} else {
|
||||||
std::string optionKey = splits[0].substr(OPTION_PREFIX.size());
|
std::string optionKey = splits[0].substr(OPTION_PREFIX.size());
|
||||||
flags.push_back(optionKey);
|
parsed_params.flags.push_back(optionKey);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmdTokens.push_back(arg);
|
cmdTokens.push_back(arg);
|
||||||
@ -135,9 +136,10 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmd = cmdTokens[0];
|
parsed_params.cmd = cmdTokens[0];
|
||||||
std::vector<std::string> cmdParams(cmdTokens.begin() + 1, cmdTokens.end());
|
parsed_params.cmd_params.assign(cmdTokens.begin() + 1, cmdTokens.end());
|
||||||
LDBCommand* command = selector(cmd, cmdParams, option_map, flags);
|
|
||||||
|
LDBCommand* command = selector(parsed_params);
|
||||||
|
|
||||||
if (command) {
|
if (command) {
|
||||||
command->SetDBOptions(options);
|
command->SetDBOptions(options);
|
||||||
@ -146,50 +148,75 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
LDBCommand* LDBCommand::SelectCommand(
|
LDBCommand* LDBCommand::SelectCommand(const ParsedParams& parsed_params) {
|
||||||
const std::string& cmd, const std::vector<std::string>& cmdParams,
|
if (parsed_params.cmd == GetCommand::Name()) {
|
||||||
const std::map<std::string, std::string>& option_map,
|
return new GetCommand(parsed_params.cmd_params, parsed_params.option_map,
|
||||||
const std::vector<std::string>& flags) {
|
parsed_params.flags);
|
||||||
if (cmd == GetCommand::Name()) {
|
} else if (parsed_params.cmd == PutCommand::Name()) {
|
||||||
return new GetCommand(cmdParams, option_map, flags);
|
return new PutCommand(parsed_params.cmd_params, parsed_params.option_map,
|
||||||
} else if (cmd == PutCommand::Name()) {
|
parsed_params.flags);
|
||||||
return new PutCommand(cmdParams, option_map, flags);
|
} else if (parsed_params.cmd == BatchPutCommand::Name()) {
|
||||||
} else if (cmd == BatchPutCommand::Name()) {
|
return new BatchPutCommand(parsed_params.cmd_params,
|
||||||
return new BatchPutCommand(cmdParams, option_map, flags);
|
parsed_params.option_map, parsed_params.flags);
|
||||||
} else if (cmd == ScanCommand::Name()) {
|
} else if (parsed_params.cmd == ScanCommand::Name()) {
|
||||||
return new ScanCommand(cmdParams, option_map, flags);
|
return new ScanCommand(parsed_params.cmd_params, parsed_params.option_map,
|
||||||
} else if (cmd == DeleteCommand::Name()) {
|
parsed_params.flags);
|
||||||
return new DeleteCommand(cmdParams, option_map, flags);
|
} else if (parsed_params.cmd == DeleteCommand::Name()) {
|
||||||
} else if (cmd == ApproxSizeCommand::Name()) {
|
return new DeleteCommand(parsed_params.cmd_params, parsed_params.option_map,
|
||||||
return new ApproxSizeCommand(cmdParams, option_map, flags);
|
parsed_params.flags);
|
||||||
} else if (cmd == DBQuerierCommand::Name()) {
|
} else if (parsed_params.cmd == ApproxSizeCommand::Name()) {
|
||||||
return new DBQuerierCommand(cmdParams, option_map, flags);
|
return new ApproxSizeCommand(parsed_params.cmd_params,
|
||||||
} else if (cmd == CompactorCommand::Name()) {
|
parsed_params.option_map, parsed_params.flags);
|
||||||
return new CompactorCommand(cmdParams, option_map, flags);
|
} else if (parsed_params.cmd == DBQuerierCommand::Name()) {
|
||||||
} else if (cmd == WALDumperCommand::Name()) {
|
return new DBQuerierCommand(parsed_params.cmd_params,
|
||||||
return new WALDumperCommand(cmdParams, option_map, flags);
|
parsed_params.option_map, parsed_params.flags);
|
||||||
} else if (cmd == ReduceDBLevelsCommand::Name()) {
|
} else if (parsed_params.cmd == CompactorCommand::Name()) {
|
||||||
return new ReduceDBLevelsCommand(cmdParams, option_map, flags);
|
return new CompactorCommand(parsed_params.cmd_params,
|
||||||
} else if (cmd == ChangeCompactionStyleCommand::Name()) {
|
parsed_params.option_map, parsed_params.flags);
|
||||||
return new ChangeCompactionStyleCommand(cmdParams, option_map, flags);
|
} else if (parsed_params.cmd == WALDumperCommand::Name()) {
|
||||||
} else if (cmd == DBDumperCommand::Name()) {
|
return new WALDumperCommand(parsed_params.cmd_params,
|
||||||
return new DBDumperCommand(cmdParams, option_map, flags);
|
parsed_params.option_map, parsed_params.flags);
|
||||||
} else if (cmd == DBLoaderCommand::Name()) {
|
} else if (parsed_params.cmd == ReduceDBLevelsCommand::Name()) {
|
||||||
return new DBLoaderCommand(cmdParams, option_map, flags);
|
return new ReduceDBLevelsCommand(parsed_params.cmd_params,
|
||||||
} else if (cmd == ManifestDumpCommand::Name()) {
|
parsed_params.option_map,
|
||||||
return new ManifestDumpCommand(cmdParams, option_map, flags);
|
parsed_params.flags);
|
||||||
} else if (cmd == ListColumnFamiliesCommand::Name()) {
|
} else if (parsed_params.cmd == ChangeCompactionStyleCommand::Name()) {
|
||||||
return new ListColumnFamiliesCommand(cmdParams, option_map, flags);
|
return new ChangeCompactionStyleCommand(parsed_params.cmd_params,
|
||||||
} else if (cmd == CreateColumnFamilyCommand::Name()) {
|
parsed_params.option_map,
|
||||||
return new CreateColumnFamilyCommand(cmdParams, option_map, flags);
|
parsed_params.flags);
|
||||||
} else if (cmd == DBFileDumperCommand::Name()) {
|
} else if (parsed_params.cmd == DBDumperCommand::Name()) {
|
||||||
return new DBFileDumperCommand(cmdParams, option_map, flags);
|
return new DBDumperCommand(parsed_params.cmd_params,
|
||||||
} else if (cmd == InternalDumpCommand::Name()) {
|
parsed_params.option_map, parsed_params.flags);
|
||||||
return new InternalDumpCommand(cmdParams, option_map, flags);
|
} else if (parsed_params.cmd == DBLoaderCommand::Name()) {
|
||||||
} else if (cmd == CheckConsistencyCommand::Name()) {
|
return new DBLoaderCommand(parsed_params.cmd_params,
|
||||||
return new CheckConsistencyCommand(cmdParams, option_map, flags);
|
parsed_params.option_map, parsed_params.flags);
|
||||||
} else if (cmd == RepairCommand::Name()) {
|
} else if (parsed_params.cmd == ManifestDumpCommand::Name()) {
|
||||||
return new RepairCommand(cmdParams, option_map, flags);
|
return new ManifestDumpCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == ListColumnFamiliesCommand::Name()) {
|
||||||
|
return new ListColumnFamiliesCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == CreateColumnFamilyCommand::Name()) {
|
||||||
|
return new CreateColumnFamilyCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == DBFileDumperCommand::Name()) {
|
||||||
|
return new DBFileDumperCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == InternalDumpCommand::Name()) {
|
||||||
|
return new InternalDumpCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == CheckConsistencyCommand::Name()) {
|
||||||
|
return new CheckConsistencyCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == RepairCommand::Name()) {
|
||||||
|
return new RepairCommand(parsed_params.cmd_params, parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user