From c40c4cae14615dd42f8c4f03f0373a078b5e214a Mon Sep 17 00:00:00 2001 From: sdong Date: Fri, 27 May 2016 13:04:07 -0700 Subject: [PATCH] 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 --- include/rocksdb/utilities/ldb_cmd.h | 24 +++-- tools/ldb_cmd.cc | 137 +++++++++++++++++----------- 2 files changed, 93 insertions(+), 68 deletions(-) diff --git a/include/rocksdb/utilities/ldb_cmd.h b/include/rocksdb/utilities/ldb_cmd.h index a91505ebe..7df0cd76f 100644 --- a/include/rocksdb/utilities/ldb_cmd.h +++ b/include/rocksdb/utilities/ldb_cmd.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -53,19 +54,21 @@ class LDBCommand { static const std::string ARG_CREATE_IF_MISSING; static const std::string ARG_NO_VALUE; - // parameters: cmd, cmdParams, option_map, flags - // The same interface as SelectCommand() - typedef std::function&, - const std::map&, - const std::vector&)> - RocksDBLDBSelectFunc; + struct ParsedParams { + std::string cmd; + std::vector cmd_params; + std::map option_map; + std::vector flags; + }; + + static LDBCommand* SelectCommand(const ParsedParams& parsed_parms); static LDBCommand* InitFromCmdLineArgs( const std::vector& args, const Options& options, const LDBOptions& ldb_options, const std::vector* column_families, - const RocksDBLDBSelectFunc& selector = SelectCommand); + const std::function& selector = + SelectCommand); static LDBCommand* InitFromCmdLineArgs( int argc, char** argv, const Options& options, @@ -114,11 +117,6 @@ class LDBCommand { static const char* DELIM; - static LDBCommand* SelectCommand( - const std::string& cmd, const std::vector& cmdParams, - const std::map& option_map, - const std::vector& flags); - protected: LDBCommandExecuteResult exec_state_; std::string db_path_; diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index f5758f882..90438af58 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -102,12 +102,13 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( const std::vector& args, const Options& options, const LDBOptions& ldb_options, const std::vector* column_families, - const RocksDBLDBSelectFunc& selector) { - // --x=y command line arguments are added as x->y map entries. - std::map option_map; - - // Command-line arguments of the form --hex end up in this array as hex - std::vector flags; + const std::function& selector) { + // --x=y command line arguments are added as x->y map entries in + // parsed_params.option_map. + // + // Command-line arguments of the form --hex end up in this array as hex to + // parsed_params.flags + ParsedParams parsed_params; // Everything other than option_map and flags. Represents commands // and their parameters. For eg: put key1 value1 go into this vector. @@ -120,10 +121,10 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( std::vector splits = StringSplit(arg, '='); if (splits.size() == 2) { std::string optionKey = splits[0].substr(OPTION_PREFIX.size()); - option_map[optionKey] = splits[1]; + parsed_params.option_map[optionKey] = splits[1]; } else { std::string optionKey = splits[0].substr(OPTION_PREFIX.size()); - flags.push_back(optionKey); + parsed_params.flags.push_back(optionKey); } } else { cmdTokens.push_back(arg); @@ -135,9 +136,10 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( return nullptr; } - std::string cmd = cmdTokens[0]; - std::vector cmdParams(cmdTokens.begin() + 1, cmdTokens.end()); - LDBCommand* command = selector(cmd, cmdParams, option_map, flags); + parsed_params.cmd = cmdTokens[0]; + parsed_params.cmd_params.assign(cmdTokens.begin() + 1, cmdTokens.end()); + + LDBCommand* command = selector(parsed_params); if (command) { command->SetDBOptions(options); @@ -146,50 +148,75 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( return command; } -LDBCommand* LDBCommand::SelectCommand( - const std::string& cmd, const std::vector& cmdParams, - const std::map& option_map, - const std::vector& flags) { - if (cmd == GetCommand::Name()) { - return new GetCommand(cmdParams, option_map, flags); - } else if (cmd == PutCommand::Name()) { - return new PutCommand(cmdParams, option_map, flags); - } else if (cmd == BatchPutCommand::Name()) { - return new BatchPutCommand(cmdParams, option_map, flags); - } else if (cmd == ScanCommand::Name()) { - return new ScanCommand(cmdParams, option_map, flags); - } else if (cmd == DeleteCommand::Name()) { - return new DeleteCommand(cmdParams, option_map, flags); - } else if (cmd == ApproxSizeCommand::Name()) { - return new ApproxSizeCommand(cmdParams, option_map, flags); - } else if (cmd == DBQuerierCommand::Name()) { - return new DBQuerierCommand(cmdParams, option_map, flags); - } else if (cmd == CompactorCommand::Name()) { - return new CompactorCommand(cmdParams, option_map, flags); - } else if (cmd == WALDumperCommand::Name()) { - return new WALDumperCommand(cmdParams, option_map, flags); - } else if (cmd == ReduceDBLevelsCommand::Name()) { - return new ReduceDBLevelsCommand(cmdParams, option_map, flags); - } else if (cmd == ChangeCompactionStyleCommand::Name()) { - return new ChangeCompactionStyleCommand(cmdParams, option_map, flags); - } else if (cmd == DBDumperCommand::Name()) { - return new DBDumperCommand(cmdParams, option_map, flags); - } else if (cmd == DBLoaderCommand::Name()) { - return new DBLoaderCommand(cmdParams, option_map, flags); - } else if (cmd == ManifestDumpCommand::Name()) { - return new ManifestDumpCommand(cmdParams, option_map, flags); - } else if (cmd == ListColumnFamiliesCommand::Name()) { - return new ListColumnFamiliesCommand(cmdParams, option_map, flags); - } else if (cmd == CreateColumnFamilyCommand::Name()) { - return new CreateColumnFamilyCommand(cmdParams, option_map, flags); - } else if (cmd == DBFileDumperCommand::Name()) { - return new DBFileDumperCommand(cmdParams, option_map, flags); - } else if (cmd == InternalDumpCommand::Name()) { - return new InternalDumpCommand(cmdParams, option_map, flags); - } else if (cmd == CheckConsistencyCommand::Name()) { - return new CheckConsistencyCommand(cmdParams, option_map, flags); - } else if (cmd == RepairCommand::Name()) { - return new RepairCommand(cmdParams, option_map, flags); +LDBCommand* LDBCommand::SelectCommand(const ParsedParams& parsed_params) { + if (parsed_params.cmd == GetCommand::Name()) { + return new GetCommand(parsed_params.cmd_params, parsed_params.option_map, + parsed_params.flags); + } else if (parsed_params.cmd == PutCommand::Name()) { + return new PutCommand(parsed_params.cmd_params, parsed_params.option_map, + parsed_params.flags); + } else if (parsed_params.cmd == BatchPutCommand::Name()) { + return new BatchPutCommand(parsed_params.cmd_params, + parsed_params.option_map, parsed_params.flags); + } else if (parsed_params.cmd == ScanCommand::Name()) { + return new ScanCommand(parsed_params.cmd_params, parsed_params.option_map, + parsed_params.flags); + } else if (parsed_params.cmd == DeleteCommand::Name()) { + return new DeleteCommand(parsed_params.cmd_params, parsed_params.option_map, + parsed_params.flags); + } else if (parsed_params.cmd == ApproxSizeCommand::Name()) { + return new ApproxSizeCommand(parsed_params.cmd_params, + parsed_params.option_map, parsed_params.flags); + } else if (parsed_params.cmd == DBQuerierCommand::Name()) { + return new DBQuerierCommand(parsed_params.cmd_params, + parsed_params.option_map, parsed_params.flags); + } else if (parsed_params.cmd == CompactorCommand::Name()) { + return new CompactorCommand(parsed_params.cmd_params, + parsed_params.option_map, parsed_params.flags); + } else if (parsed_params.cmd == WALDumperCommand::Name()) { + return new WALDumperCommand(parsed_params.cmd_params, + parsed_params.option_map, parsed_params.flags); + } else if (parsed_params.cmd == ReduceDBLevelsCommand::Name()) { + return new ReduceDBLevelsCommand(parsed_params.cmd_params, + parsed_params.option_map, + parsed_params.flags); + } else if (parsed_params.cmd == ChangeCompactionStyleCommand::Name()) { + return new ChangeCompactionStyleCommand(parsed_params.cmd_params, + parsed_params.option_map, + parsed_params.flags); + } else if (parsed_params.cmd == DBDumperCommand::Name()) { + return new DBDumperCommand(parsed_params.cmd_params, + parsed_params.option_map, parsed_params.flags); + } else if (parsed_params.cmd == DBLoaderCommand::Name()) { + return new DBLoaderCommand(parsed_params.cmd_params, + parsed_params.option_map, parsed_params.flags); + } else if (parsed_params.cmd == ManifestDumpCommand::Name()) { + 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; }