git-hulk commented on code in PR #2845:
URL: https://github.com/apache/kvrocks/pull/2845#discussion_r2043587483
##########
src/commands/cmd_server.cc:
##########
@@ -1370,6 +1370,49 @@ class CommandPollUpdates : public Commander {
Format format_ = Format::Raw;
};
+class CommandSST : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ CommandParser parser(args, 1);
+ std::string cmd = GET_OR_RET(parser.TakeStr());
+ if (!util::EqualICase(cmd, "load")) {
+ return {Status::RedisParseErr, "unknown subcommand:" + args[1]};
+ }
+ folder_ = GET_OR_RET(parser.TakeStr());
+ // Parse optional movefiles flag
+ while (parser.Good()) {
+ if (parser.EatEqICase("movefiles")) {
+ std::string move_files = GET_OR_RET(parser.TakeStr());
+ if (util::EqualICase(move_files, "yes")) {
+ ingest_options_.move_files = true;
+ } else if (util::EqualICase(move_files, "no")) {
+ ingest_options_.move_files = false;
+ } else {
+ return {Status::RedisParseErr, "movefiles value must be 'yes' or
'no'"};
+ }
+ } else {
+ return {Status::RedisParseErr, "unknown option: " +
parser.TakeStr().GetValue()};
+ }
+ }
+ return Commander::Parse(args);
+ }
+
+ Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv,
[[maybe_unused]] Connection *conn,
+ std::string *output) override {
Review Comment:
We could check the following conditions and not allow the load:
- The instance is in cluster mode
- The instance has any replicas or is in replica mode.
##########
src/storage/storage.cc:
##########
@@ -769,6 +770,101 @@ rocksdb::Status Storage::FlushScripts(engine::Context
&ctx, const rocksdb::Write
return Write(ctx, options, batch->GetWriteBatch());
}
+StatusOr<int> Storage::IngestSST(const std::string &sst_dir, const
rocksdb::IngestExternalFileOptions &ingest_options) {
+ if (config_->cluster_enabled) {
+ return {Status::NotOK, "SST command is not supported in cluster mode"};
+ }
+ std::vector<std::string> sst_files;
+ DIR *dir = opendir(sst_dir.c_str());
+ if (!dir) {
+ return {Status::NotOK, "Failed to open directory " + sst_dir};
+ }
+
+ struct dirent *entry = nullptr;
+ while ((entry = readdir(dir)) != nullptr) {
+ std::string filename = entry->d_name;
+ if (filename.length() >= 4 && filename.substr(filename.length() - 4) ==
".sst") {
+ sst_files.push_back(sst_dir + "/" + filename);
+ }
+ }
+ closedir(dir);
+
+ if (sst_files.empty()) {
+ LOG(WARNING) << "No SST files found in " << sst_dir;
+ return 0;
+ }
+
+ // Create a map to store SST files for each column family
+ std::unordered_map<std::string_view, std::vector<std::string>> cf_files;
+
+ // Initialize vectors for each column family
+ std::vector<std::string> cf_names;
+ for (const auto &cf : ColumnFamilyConfigs::ListAllColumnFamilies()) {
+ cf_names.emplace_back(cf.Name());
+ }
+
+ // Initialize vectors for each column family
+ for (const auto &cf_name : cf_names) {
+ cf_files[cf_name] = std::vector<std::string>();
+ }
+
+ // Sort files into appropriate vectors based on filename
+ for (const auto &file : sst_files) {
+ bool matched = false;
+ for (const auto &cf_name : cf_names) {
+ if (file.find(cf_name) != std::string::npos) {
+ cf_files[cf_name].push_back(file);
+ matched = true;
+ break;
+ }
+ }
+ // If no match found, assume it belongs to default CF
+ if (!matched) {
+ cf_files[rocksdb::kDefaultColumnFamilyName].push_back(file);
Review Comment:
It would be better to return an error if the column family is mismatched.
##########
.github/workflows/kvrocks.yaml:
##########
@@ -162,11 +163,13 @@ jobs:
without_jemalloc: -DDISABLE_JEMALLOC=ON
with_sanitizer: -DENABLE_ASAN=ON
compiler: gcc
+ ignore_when_asan: -tags="ignore_when_asan"
Review Comment:
Where's using this tag?
##########
src/commands/cmd_server.cc:
##########
@@ -1370,6 +1370,49 @@ class CommandPollUpdates : public Commander {
Format format_ = Format::Raw;
};
+class CommandSST : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
Review Comment:
Can remove this check since this command has required at least 3 parameters
when building attributes, so it will be checked before executing.
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]