This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 0ea85d42 Add column family parameter to Compact methon (#1878)
0ea85d42 is described below

commit 0ea85d42ddcb7ad22347f5b19672a30762f765ac
Author: raffertyyu <[email protected]>
AuthorDate: Mon Nov 6 17:58:07 2023 +0800

    Add column family parameter to Compact methon (#1878)
---
 src/server/server.cc              |  2 +-
 src/storage/compaction_checker.cc |  6 +++---
 src/storage/storage.cc            |  5 +++--
 src/storage/storage.h             |  3 ++-
 tests/cppunit/compact_test.cc     | 10 +++++-----
 5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/server/server.cc b/src/server/server.cc
index 4f860152..03f2eae7 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -1253,7 +1253,7 @@ Status Server::AsyncCompactDB(const std::string 
&begin_key, const std::string &e
     if (!begin_key.empty()) begin = std::make_unique<Slice>(begin_key);
     if (!end_key.empty()) end = std::make_unique<Slice>(end_key);
 
-    auto s = storage->Compact(begin.get(), end.get());
+    auto s = storage->Compact(nullptr, begin.get(), end.get());
     if (!s.ok()) {
       LOG(ERROR) << "[task runner] Failed to do compaction: " << s.ToString();
     }
diff --git a/src/storage/compaction_checker.cc 
b/src/storage/compaction_checker.cc
index 17f9e87c..55502b2a 100644
--- a/src/storage/compaction_checker.cc
+++ b/src/storage/compaction_checker.cc
@@ -59,7 +59,7 @@ void CompactionChecker::PickCompactionFiles(const std::string 
&cf_name) {
 
   auto force_compact_file_age = storage_->GetConfig()->force_compact_file_age;
   auto force_compact_min_ratio =
-      
static_cast<double>(storage_->GetConfig()->force_compact_file_min_deleted_percentage
 / 100);
+      
static_cast<double>(storage_->GetConfig()->force_compact_file_min_deleted_percentage)
 / 100.0;
 
   std::string best_filename;
   double best_delete_ratio = 0;
@@ -112,7 +112,7 @@ void CompactionChecker::PickCompactionFiles(const 
std::string &cf_name) {
     if (file_creation_time < static_cast<uint64_t>(now - 
force_compact_file_age) &&
         delete_ratio >= force_compact_min_ratio) {
       LOG(INFO) << "[compaction checker] Going to compact the key in file 
(force compact policy): " << iter.first;
-      auto s = storage_->Compact(&start_key, &stop_key);
+      auto s = storage_->Compact(cf, &start_key, &stop_key);
       LOG(INFO) << "[compaction checker] Compact the key in file (force 
compact policy): " << iter.first
                 << " finished, result: " << s.ToString();
       max_files_to_compact--;
@@ -135,7 +135,7 @@ void CompactionChecker::PickCompactionFiles(const 
std::string &cf_name) {
   if (best_delete_ratio > 0.1 && !best_start_key.empty() && 
!best_stop_key.empty()) {
     LOG(INFO) << "[compaction checker] Going to compact the key in file: " << 
best_filename
               << ", delete ratio: " << best_delete_ratio;
-    auto s = storage_->Compact(&best_start_key, &best_stop_key);
+    auto s = storage_->Compact(cf, &best_start_key, &best_stop_key);
     if (!s.ok()) {
       LOG(ERROR) << "[compaction checker] Failed to do compaction: " << 
s.ToString();
     }
diff --git a/src/storage/storage.cc b/src/storage/storage.cc
index 70855dcb..5710823c 100644
--- a/src/storage/storage.cc
+++ b/src/storage/storage.cc
@@ -640,13 +640,14 @@ rocksdb::ColumnFamilyHandle *Storage::GetCFHandle(const 
std::string &name) {
   return cf_handles_[0];
 }
 
-rocksdb::Status Storage::Compact(const Slice *begin, const Slice *end) {
+rocksdb::Status Storage::Compact(rocksdb::ColumnFamilyHandle *cf, const Slice 
*begin, const Slice *end) {
   rocksdb::CompactRangeOptions compact_opts;
   compact_opts.change_level = true;
   // For the manual compaction, we would like to force the bottommost level to 
be compacted.
   // Or it may use the trivial mode and some expired key-values were still 
exist in the bottommost level.
   compact_opts.bottommost_level_compaction = 
rocksdb::BottommostLevelCompaction::kForceOptimized;
-  for (const auto &cf_handle : cf_handles_) {
+  const auto &cf_handles = cf ? std::vector<rocksdb::ColumnFamilyHandle *>{cf} 
: cf_handles_;
+  for (const auto &cf_handle : cf_handles) {
     rocksdb::Status s = db_->CompactRange(compact_opts, cf_handle, begin, end);
     if (!s.ok()) return s;
   }
diff --git a/src/storage/storage.h b/src/storage/storage.h
index 902f7e76..e8d6562a 100644
--- a/src/storage/storage.h
+++ b/src/storage/storage.h
@@ -125,7 +125,8 @@ class Storage {
   Status InWALBoundary(rocksdb::SequenceNumber seq);
   Status WriteToPropagateCF(const std::string &key, const std::string &value);
 
-  [[nodiscard]] rocksdb::Status Compact(const rocksdb::Slice *begin, const 
rocksdb::Slice *end);
+  [[nodiscard]] rocksdb::Status Compact(rocksdb::ColumnFamilyHandle *cf, const 
rocksdb::Slice *begin,
+                                        const rocksdb::Slice *end);
   rocksdb::DB *GetDB();
   bool IsClosing() const { return db_closing_; }
   std::string GetName() const { return config_->db_name; }
diff --git a/tests/cppunit/compact_test.cc b/tests/cppunit/compact_test.cc
index 42ae3907..c482173f 100644
--- a/tests/cppunit/compact_test.cc
+++ b/tests/cppunit/compact_test.cc
@@ -49,11 +49,11 @@ TEST(Compact, Filter) {
   hash->Set(live_hash_key, "f1", "v1", &ret);
   hash->Set(live_hash_key, "f2", "v2", &ret);
 
-  auto status = storage->Compact(nullptr, nullptr);
+  auto status = storage->Compact(nullptr, nullptr, nullptr);
   assert(status.ok());
   // Compact twice to workaround issue fixed by: 
https://github.com/facebook/rocksdb/pull/11468
   // before rocksdb/speedb 8.1.1. This line can be removed after speedb 
upgraded above 8.1.1.
-  status = storage->Compact(nullptr, nullptr);
+  status = storage->Compact(nullptr, nullptr, nullptr);
   assert(status.ok());
 
   rocksdb::DB* db = storage->GetDB();
@@ -85,9 +85,9 @@ TEST(Compact, Filter) {
   usleep(10000);
 
   // Same as the above compact, need to compact twice here
-  status = storage->Compact(nullptr, nullptr);
+  status = storage->Compact(nullptr, nullptr, nullptr);
   assert(status.ok());
-  status = storage->Compact(nullptr, nullptr);
+  status = storage->Compact(nullptr, nullptr, nullptr);
   assert(status.ok());
 
   iter = new_iterator("default");
@@ -107,7 +107,7 @@ TEST(Compact, Filter) {
 
   int retry = 2;
   while (retry-- > 0) {
-    status = storage->Compact(nullptr, nullptr);
+    status = storage->Compact(nullptr, nullptr, nullptr);
     assert(status.ok());
     std::vector<FieldValue> fieldvalues;
     auto get_res = hash->GetAll(mk_with_ttl, &fieldvalues);

Reply via email to