Support single delete in ldb (#9469)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9469 Reviewed By: riversand963 Differential Revision: D33953484 fbshipit-source-id: f4e84a2d9865957d744c7e84ff02ffbb0a62b0a8
This commit is contained in:
parent
0d1613aad6
commit
26768edb65
@ -214,6 +214,10 @@ LDBCommand* LDBCommand::SelectCommand(const ParsedParams& parsed_params) {
|
|||||||
} else if (parsed_params.cmd == DeleteCommand::Name()) {
|
} else if (parsed_params.cmd == DeleteCommand::Name()) {
|
||||||
return new DeleteCommand(parsed_params.cmd_params, parsed_params.option_map,
|
return new DeleteCommand(parsed_params.cmd_params, parsed_params.option_map,
|
||||||
parsed_params.flags);
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == SingleDeleteCommand::Name()) {
|
||||||
|
return new SingleDeleteCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
} else if (parsed_params.cmd == DeleteRangeCommand::Name()) {
|
} else if (parsed_params.cmd == DeleteRangeCommand::Name()) {
|
||||||
return new DeleteRangeCommand(parsed_params.cmd_params,
|
return new DeleteRangeCommand(parsed_params.cmd_params,
|
||||||
parsed_params.option_map,
|
parsed_params.option_map,
|
||||||
@ -3063,6 +3067,42 @@ void DeleteCommand::DoCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SingleDeleteCommand::SingleDeleteCommand(
|
||||||
|
const std::vector<std::string>& params,
|
||||||
|
const std::map<std::string, std::string>& options,
|
||||||
|
const std::vector<std::string>& flags)
|
||||||
|
: LDBCommand(options, flags, false,
|
||||||
|
BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX})) {
|
||||||
|
if (params.size() != 1) {
|
||||||
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
||||||
|
"KEY must be specified for the single delete command");
|
||||||
|
} else {
|
||||||
|
key_ = params.at(0);
|
||||||
|
if (is_key_hex_) {
|
||||||
|
key_ = HexToString(key_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SingleDeleteCommand::Help(std::string& ret) {
|
||||||
|
ret.append(" ");
|
||||||
|
ret.append(SingleDeleteCommand::Name() + " <key>");
|
||||||
|
ret.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SingleDeleteCommand::DoCommand() {
|
||||||
|
if (!db_) {
|
||||||
|
assert(GetExecuteState().IsFailed());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status st = db_->SingleDelete(WriteOptions(), GetCfHandle(), key_);
|
||||||
|
if (st.ok()) {
|
||||||
|
fprintf(stdout, "OK\n");
|
||||||
|
} else {
|
||||||
|
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DeleteRangeCommand::DeleteRangeCommand(
|
DeleteRangeCommand::DeleteRangeCommand(
|
||||||
const std::vector<std::string>& params,
|
const std::vector<std::string>& params,
|
||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
|
@ -24,7 +24,7 @@ class CompactorCommand : public LDBCommand {
|
|||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool null_from_;
|
bool null_from_;
|
||||||
@ -43,7 +43,7 @@ class DBFileDumperCommand : public LDBCommand {
|
|||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool decode_blob_index_;
|
bool decode_blob_index_;
|
||||||
@ -61,7 +61,7 @@ class DBLiveFilesMetadataDumperCommand : public LDBCommand {
|
|||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool sort_by_filename_;
|
bool sort_by_filename_;
|
||||||
@ -79,7 +79,7 @@ class DBDumperCommand : public LDBCommand {
|
|||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@ -127,7 +127,7 @@ class InternalDumpCommand : public LDBCommand {
|
|||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool has_from_;
|
bool has_from_;
|
||||||
@ -160,9 +160,10 @@ class DBLoaderCommand : public LDBCommand {
|
|||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
virtual void DoCommand() override;
|
|
||||||
|
|
||||||
virtual void OverrideBaseOptions() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
|
void OverrideBaseOptions() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool disable_wal_;
|
bool disable_wal_;
|
||||||
@ -183,9 +184,10 @@ class ManifestDumpCommand : public LDBCommand {
|
|||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
virtual void DoCommand() override;
|
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return true; }
|
void DoCommand() override;
|
||||||
|
|
||||||
|
bool NoDBOpen() override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool verbose_;
|
bool verbose_;
|
||||||
@ -263,9 +265,10 @@ class ListColumnFamiliesCommand : public LDBCommand {
|
|||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
virtual void DoCommand() override;
|
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return true; }
|
void DoCommand() override;
|
||||||
|
|
||||||
|
bool NoDBOpen() override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CreateColumnFamilyCommand : public LDBCommand {
|
class CreateColumnFamilyCommand : public LDBCommand {
|
||||||
@ -277,9 +280,10 @@ class CreateColumnFamilyCommand : public LDBCommand {
|
|||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
virtual void DoCommand() override;
|
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return false; }
|
void DoCommand() override;
|
||||||
|
|
||||||
|
bool NoDBOpen() override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string new_cf_name_;
|
std::string new_cf_name_;
|
||||||
@ -294,9 +298,10 @@ class DropColumnFamilyCommand : public LDBCommand {
|
|||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
virtual void DoCommand() override;
|
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return false; }
|
void DoCommand() override;
|
||||||
|
|
||||||
|
bool NoDBOpen() override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string cf_name_to_drop_;
|
std::string cf_name_to_drop_;
|
||||||
@ -310,11 +315,11 @@ class ReduceDBLevelsCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void OverrideBaseCFOptions(ColumnFamilyOptions* cf_opts) override;
|
void OverrideBaseCFOptions(ColumnFamilyOptions* cf_opts) override;
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return true; }
|
bool NoDBOpen() override { return true; }
|
||||||
|
|
||||||
static void Help(std::string& msg);
|
static void Help(std::string& msg);
|
||||||
|
|
||||||
@ -342,9 +347,9 @@ class ChangeCompactionStyleCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void OverrideBaseCFOptions(ColumnFamilyOptions* cf_opts) override;
|
void OverrideBaseCFOptions(ColumnFamilyOptions* cf_opts) override;
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& msg);
|
static void Help(std::string& msg);
|
||||||
|
|
||||||
@ -364,10 +369,11 @@ class WALDumperCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return true; }
|
bool NoDBOpen() override { return true; }
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
virtual void DoCommand() override;
|
|
||||||
|
void DoCommand() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool print_header_;
|
bool print_header_;
|
||||||
@ -389,7 +395,7 @@ class GetCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -405,7 +411,7 @@ class ApproxSizeCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -422,11 +428,11 @@ class BatchPutCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void OverrideBaseOptions() override;
|
void OverrideBaseOptions() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@ -443,7 +449,7 @@ class ScanCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -464,7 +470,23 @@ class DeleteCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string key_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SingleDeleteCommand : public LDBCommand {
|
||||||
|
public:
|
||||||
|
static std::string Name() { return "singledelete"; }
|
||||||
|
|
||||||
|
SingleDeleteCommand(const std::vector<std::string>& params,
|
||||||
|
const std::map<std::string, std::string>& options,
|
||||||
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -480,7 +502,7 @@ class DeleteRangeCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -497,11 +519,11 @@ class PutCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void OverrideBaseOptions() override;
|
void OverrideBaseOptions() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string key_;
|
std::string key_;
|
||||||
@ -522,7 +544,7 @@ class DBQuerierCommand : public LDBCommand {
|
|||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char* HELP_CMD;
|
static const char* HELP_CMD;
|
||||||
@ -539,9 +561,9 @@ class CheckConsistencyCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return true; }
|
bool NoDBOpen() override { return true; }
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
};
|
};
|
||||||
@ -554,7 +576,7 @@ class CheckPointCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -571,11 +593,11 @@ class RepairCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return true; }
|
bool NoDBOpen() override { return true; }
|
||||||
|
|
||||||
virtual void OverrideBaseOptions() override;
|
void OverrideBaseOptions() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -615,7 +637,7 @@ class BackupCommand : public BackupEngineCommand {
|
|||||||
BackupCommand(const std::vector<std::string>& params,
|
BackupCommand(const std::vector<std::string>& params,
|
||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -625,8 +647,8 @@ class RestoreCommand : public BackupEngineCommand {
|
|||||||
RestoreCommand(const std::vector<std::string>& params,
|
RestoreCommand(const std::vector<std::string>& params,
|
||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
virtual bool NoDBOpen() override { return true; }
|
bool NoDBOpen() override { return true; }
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -638,11 +660,11 @@ class WriteExternalSstFilesCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return false; }
|
bool NoDBOpen() override { return false; }
|
||||||
|
|
||||||
virtual void OverrideBaseOptions() override;
|
void OverrideBaseOptions() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -658,11 +680,11 @@ class IngestExternalSstFilesCommand : public LDBCommand {
|
|||||||
const std::map<std::string, std::string>& options,
|
const std::map<std::string, std::string>& options,
|
||||||
const std::vector<std::string>& flags);
|
const std::vector<std::string>& flags);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return false; }
|
bool NoDBOpen() override { return false; }
|
||||||
|
|
||||||
virtual void OverrideBaseOptions() override;
|
void OverrideBaseOptions() override;
|
||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
@ -710,9 +732,9 @@ class UnsafeRemoveSstFileCommand : public LDBCommand {
|
|||||||
|
|
||||||
static void Help(std::string& ret);
|
static void Help(std::string& ret);
|
||||||
|
|
||||||
virtual void DoCommand() override;
|
void DoCommand() override;
|
||||||
|
|
||||||
virtual bool NoDBOpen() override { return true; }
|
bool NoDBOpen() override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t sst_file_number_;
|
uint64_t sst_file_number_;
|
||||||
|
Loading…
Reference in New Issue
Block a user