]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Fix an assertion failure in `TimestampTablePropertiesCollector` for empty output...
authorChangyu Bi <changyubi@meta.com>
Mon, 5 Dec 2022 21:46:27 +0000 (13:46 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 5 Dec 2022 21:46:27 +0000 (13:46 -0800)
Summary:
when the compaction output file is empty, the assertion in `TimestampTablePropertiesCollector::Finish()` breaks. This PR fixes this assert and added unit test.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/11015

Test Plan: added UT.

Reviewed By: ajkr

Differential Revision: D41716719

Pulled By: cbi42

fbshipit-source-id: d891d46be4c4805e3d49be6b80c9d75f1bd51080

db/db_with_timestamp_compaction_test.cc
db/table_properties_collector.h

index d28f67e05a75ce834fd3301fe71a7a351f10a8ba..403d9907c57a701eb829265132e28b4c44bb2f8b 100644 (file)
@@ -323,6 +323,27 @@ TEST_F(TimestampCompatibleCompactionTest, CompactFilesRangeCheckL1) {
               static_cast<int>(compaction_job_info.input_files.size()));
   }
 }
+
+TEST_F(TimestampCompatibleCompactionTest, EmptyCompactionOutput) {
+  Options options = CurrentOptions();
+  options.env = env_;
+  options.comparator = test::BytewiseComparatorWithU64TsWrapper();
+  DestroyAndReopen(options);
+
+  std::string ts_str = Timestamp(1);
+  WriteOptions wopts;
+  ASSERT_OK(
+      db_->DeleteRange(wopts, db_->DefaultColumnFamily(), "k1", "k3", ts_str));
+  ASSERT_OK(Flush());
+
+  ts_str = Timestamp(3);
+  Slice ts = ts_str;
+  CompactRangeOptions cro;
+  // range tombstone will be dropped during compaction
+  cro.full_history_ts_low = &ts;
+  cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
+  ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr));
+}
 #endif  // !ROCKSDB_LITE
 
 }  // namespace ROCKSDB_NAMESPACE
index 9035ba793b32a2db4188dbdf53b71993d8277e53..968115c3d7a348ba71441f19d56bf1ed1a94f69a 100644 (file)
@@ -150,8 +150,10 @@ class TimestampTablePropertiesCollector : public IntTblPropCollector {
   }
 
   Status Finish(UserCollectedProperties* properties) override {
+    // timestamp is empty is table is empty
     assert(timestamp_min_.size() == timestamp_max_.size() &&
-           timestamp_max_.size() == cmp_->timestamp_size());
+           (timestamp_min_.empty() ||
+            timestamp_max_.size() == cmp_->timestamp_size()));
     properties->insert({"rocksdb.timestamp_min", timestamp_min_});
     properties->insert({"rocksdb.timestamp_max", timestamp_max_});
     return Status::OK();