PragmaTwice commented on code in PR #2845:
URL: https://github.com/apache/kvrocks/pull/2845#discussion_r2011181944


##########
src/storage/storage.cc:
##########
@@ -769,6 +775,65 @@ rocksdb::Status Storage::FlushScripts(engine::Context 
&ctx, const rocksdb::Write
   return Write(ctx, options, batch->GetWriteBatch());
 }
 
+rocksdb::Status Storage::IngestSST(const std::string &sst_dir, int* 
files_loaded) {
+  std::vector<std::string> sst_files;
+  DIR *dir = opendir(sst_dir.c_str());
+  if (!dir) {
+    return rocksdb::Status::IOError("Failed to open directory " + sst_dir);
+  }
+
+  struct dirent *entry;
+  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 rocksdb::Status::OK();
+  }
+
+  std::vector<std::string> default_files;
+  std::vector<std::string> metadata_files;
+
+  // Sort files into appropriate vectors based on filename
+  for (const auto &file : sst_files) {
+    if (file.find("metadata") != std::string::npos) {
+      metadata_files.push_back(file);
+    } else {
+      default_files.push_back(file);
+    }
+  }
+
+  // Process each set of files with the appropriate column family
+  // By importing the Default column family SST files first, we avoid data 
corruption -
+  // if import fails, no data is made available or corrupted in either column 
family
+  // if the metadata import fails, the imported data will be deleted by the 
compaction.
+  rocksdb::Status status;
+  // Process default files with no specific column family
+  if (!default_files.empty()) {
+    status = ingestSST(db_->DefaultColumnFamily(), default_ingest_opts_, 
default_files);
+    if (!status.ok()) {
+      return status;
+    }
+  }
+  // Process metadata files
+  if (!metadata_files.empty()) {
+    status = ingestSST(GetCFHandle(ColumnFamilyID::Metadata), 
default_ingest_opts_, metadata_files);
+  }

Review Comment:
   I think we have other column families besides these two.



-- 
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]

Reply via email to