From: Changyu Bi Date: Mon, 5 Dec 2022 21:46:27 +0000 (-0800) Subject: Fix an assertion failure in `TimestampTablePropertiesCollector` for empty output... X-Git-Tag: v7.10.2~57 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=23af6786a997d3592e8a68f1a8d9e0699a6eae36;p=rocksdb.git Fix an assertion failure in `TimestampTablePropertiesCollector` for empty output (#11015) 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 --- diff --git a/db/db_with_timestamp_compaction_test.cc b/db/db_with_timestamp_compaction_test.cc index d28f67e05..403d9907c 100644 --- a/db/db_with_timestamp_compaction_test.cc +++ b/db/db_with_timestamp_compaction_test.cc @@ -323,6 +323,27 @@ TEST_F(TimestampCompatibleCompactionTest, CompactFilesRangeCheckL1) { static_cast(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 diff --git a/db/table_properties_collector.h b/db/table_properties_collector.h index 9035ba793..968115c3d 100644 --- a/db/table_properties_collector.h +++ b/db/table_properties_collector.h @@ -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();