add create_column_family and drop_column_family cmd to ldb tool (#5503)
Summary: `create_column_family` cmd already exists but was somehow missed in the help message. also add `drop_column_family` cmd which can drop a cf without opening db. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5503 Test Plan: Updated existing ldb_test.py to test deleting a column family. Differential Revision: D16018414 Pulled By: lightmark fbshipit-source-id: 1fc33680b742104fea86b10efc8499f79e722301
This commit is contained in:
parent
15fd3be07b
commit
5c2f13fb14
@ -223,6 +223,10 @@ LDBCommand* LDBCommand::SelectCommand(const ParsedParams& parsed_params) {
|
|||||||
return new CreateColumnFamilyCommand(parsed_params.cmd_params,
|
return new CreateColumnFamilyCommand(parsed_params.cmd_params,
|
||||||
parsed_params.option_map,
|
parsed_params.option_map,
|
||||||
parsed_params.flags);
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == DropColumnFamilyCommand::Name()) {
|
||||||
|
return new DropColumnFamilyCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
} else if (parsed_params.cmd == DBFileDumperCommand::Name()) {
|
} else if (parsed_params.cmd == DBFileDumperCommand::Name()) {
|
||||||
return new DBFileDumperCommand(parsed_params.cmd_params,
|
return new DBFileDumperCommand(parsed_params.cmd_params,
|
||||||
parsed_params.option_map,
|
parsed_params.option_map,
|
||||||
@ -1125,6 +1129,44 @@ void CreateColumnFamilyCommand::DoCommand() {
|
|||||||
CloseDB();
|
CloseDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DropColumnFamilyCommand::Help(std::string& ret) {
|
||||||
|
ret.append(" ");
|
||||||
|
ret.append(DropColumnFamilyCommand::Name());
|
||||||
|
ret.append(" --db=<db_path> <column_family_name_to_drop>");
|
||||||
|
ret.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
DropColumnFamilyCommand::DropColumnFamilyCommand(
|
||||||
|
const std::vector<std::string>& params,
|
||||||
|
const std::map<std::string, std::string>& options,
|
||||||
|
const std::vector<std::string>& flags)
|
||||||
|
: LDBCommand(options, flags, true, {ARG_DB}) {
|
||||||
|
if (params.size() != 1) {
|
||||||
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
||||||
|
"The name of column family to drop must be specified");
|
||||||
|
} else {
|
||||||
|
cf_name_to_drop_ = params[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DropColumnFamilyCommand::DoCommand() {
|
||||||
|
auto iter = cf_handles_.find(cf_name_to_drop_);
|
||||||
|
if (iter == cf_handles_.end()) {
|
||||||
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
||||||
|
"Column family: " + cf_name_to_drop_ + " doesn't exist in db.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ColumnFamilyHandle* cf_handle_to_drop = iter->second;
|
||||||
|
Status st = db_->DropColumnFamily(cf_handle_to_drop);
|
||||||
|
if (st.ok()) {
|
||||||
|
fprintf(stdout, "OK\n");
|
||||||
|
} else {
|
||||||
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
||||||
|
"Fail to drop column family: " + st.ToString());
|
||||||
|
}
|
||||||
|
CloseDB();
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -205,6 +205,23 @@ class CreateColumnFamilyCommand : public LDBCommand {
|
|||||||
std::string new_cf_name_;
|
std::string new_cf_name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DropColumnFamilyCommand : public LDBCommand {
|
||||||
|
public:
|
||||||
|
static std::string Name() { return "drop_column_family"; }
|
||||||
|
|
||||||
|
DropColumnFamilyCommand(const std::vector<std::string>& params,
|
||||||
|
const std::map<std::string, std::string>& options,
|
||||||
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
|
static void Help(std::string& ret);
|
||||||
|
virtual void DoCommand() override;
|
||||||
|
|
||||||
|
virtual bool NoDBOpen() override { return false; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string cf_name_to_drop_;
|
||||||
|
};
|
||||||
|
|
||||||
class ReduceDBLevelsCommand : public LDBCommand {
|
class ReduceDBLevelsCommand : public LDBCommand {
|
||||||
public:
|
public:
|
||||||
static std::string Name() { return "reduce_levels"; }
|
static std::string Name() { return "reduce_levels"; }
|
||||||
|
@ -553,8 +553,10 @@ class LDBTestCase(unittest.TestCase):
|
|||||||
"1")
|
"1")
|
||||||
self.assertRunOK("get cf3_1 --column_family=three",
|
self.assertRunOK("get cf3_1 --column_family=three",
|
||||||
"3")
|
"3")
|
||||||
|
self.assertRunOK("drop_column_family three", "OK")
|
||||||
# non-existing column family.
|
# non-existing column family.
|
||||||
self.assertRunFAIL("get cf3_1 --column_family=four")
|
self.assertRunFAIL("get cf3_1 --column_family=four")
|
||||||
|
self.assertRunFAIL("drop_column_family four")
|
||||||
|
|
||||||
def testIngestExternalSst(self):
|
def testIngestExternalSst(self):
|
||||||
print "Running testIngestExternalSst..."
|
print "Running testIngestExternalSst..."
|
||||||
|
@ -82,6 +82,8 @@ void LDBCommandRunner::PrintHelp(const LDBOptions& ldb_options,
|
|||||||
DBLoaderCommand::Help(ret);
|
DBLoaderCommand::Help(ret);
|
||||||
ManifestDumpCommand::Help(ret);
|
ManifestDumpCommand::Help(ret);
|
||||||
ListColumnFamiliesCommand::Help(ret);
|
ListColumnFamiliesCommand::Help(ret);
|
||||||
|
CreateColumnFamilyCommand::Help(ret);
|
||||||
|
DropColumnFamilyCommand::Help(ret);
|
||||||
DBFileDumperCommand::Help(ret);
|
DBFileDumperCommand::Help(ret);
|
||||||
InternalDumpCommand::Help(ret);
|
InternalDumpCommand::Help(ret);
|
||||||
RepairCommand::Help(ret);
|
RepairCommand::Help(ret);
|
||||||
|
Loading…
Reference in New Issue
Block a user