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
main
Changyu Bi 2 years ago committed by Facebook GitHub Bot
parent 8ffabdc226
commit 23af6786a9
  1. 21
      db/db_with_timestamp_compaction_test.cc
  2. 4
      db/table_properties_collector.h

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

@ -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();

Loading…
Cancel
Save