diff --git a/HISTORY.md b/HISTORY.md index 161b2597a..113381d8c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,7 @@ ### Public API Change * Transaction::GetForUpdate is extended with a do_validate parameter with default value of true. If false it skips validating the snapshot before doing the read. Similarly ::Merge, ::Put, ::Delete, and ::SingleDelete are extended with assume_tracked with default value of false. If true it indicates that call is assumed to be after a ::GetForUpdate. +* `TableProperties::num_entries` and `TableProperties::num_deletions` now also account for number of range tombstones. ### Bug Fixes * Fix a deadlock caused by compaction and file ingestion waiting for each other in the event of write stalls. diff --git a/db/db_properties_test.cc b/db/db_properties_test.cc index f8733934f..711b961a1 100644 --- a/db/db_properties_test.cc +++ b/db/db_properties_test.cc @@ -245,15 +245,14 @@ void GetExpectedTableProperties( const int kDeletionCount = kTableCount * kDeletionsPerTable; const int kMergeCount = kTableCount * kMergeOperandsPerTable; const int kRangeDeletionCount = kTableCount * kRangeDeletionsPerTable; - const int kKeyCount = kPutCount + kDeletionCount + kMergeCount; + const int kKeyCount = kPutCount + kDeletionCount + kMergeCount + kRangeDeletionCount; const int kAvgSuccessorSize = kKeySize / 5; const int kEncodingSavePerKey = kKeySize / 4; - expected_tp->raw_key_size = - (kKeyCount + kRangeDeletionCount) * (kKeySize + 8); + expected_tp->raw_key_size = kKeyCount * (kKeySize + 8); expected_tp->raw_value_size = (kPutCount + kMergeCount + kRangeDeletionCount) * kValueSize; expected_tp->num_entries = kKeyCount; - expected_tp->num_deletions = kDeletionCount; + expected_tp->num_deletions = kDeletionCount + kRangeDeletionCount; expected_tp->num_merge_operands = kMergeCount; expected_tp->num_range_deletions = kRangeDeletionCount; expected_tp->num_data_blocks = diff --git a/table/block_based_table_builder.cc b/table/block_based_table_builder.cc index 2ef40a2cf..097f4dba4 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -417,9 +417,11 @@ void BlockBasedTableBuilder::Add(const Slice& key, const Slice& value) { if (!ok()) return; ValueType value_type = ExtractValueType(key); if (IsValueType(value_type)) { - if (r->props.num_entries > 0) { +#ifndef NDEBUG + if (r->props.num_entries > r->props.num_range_deletions) { assert(r->internal_comparator.Compare(key, Slice(r->last_key)) > 0); } +#endif // NDEBUG auto should_flush = r->flush_block_policy->Update(key, value); if (should_flush) { @@ -447,15 +449,6 @@ void BlockBasedTableBuilder::Add(const Slice& key, const Slice& value) { r->last_key.assign(key.data(), key.size()); r->data_block.Add(key, value); - r->props.num_entries++; - r->props.raw_key_size += key.size(); - r->props.raw_value_size += value.size(); - if (value_type == kTypeDeletion || value_type == kTypeSingleDeletion) { - r->props.num_deletions++; - } else if (value_type == kTypeMerge) { - r->props.num_merge_operands++; - } - r->index_builder->OnKeyAdded(key); NotifyCollectTableCollectorsOnAdd(key, value, r->offset, r->table_properties_collectors, @@ -463,15 +456,24 @@ void BlockBasedTableBuilder::Add(const Slice& key, const Slice& value) { } else if (value_type == kTypeRangeDeletion) { r->range_del_block.Add(key, value); - ++r->props.num_range_deletions; - r->props.raw_key_size += key.size(); - r->props.raw_value_size += value.size(); NotifyCollectTableCollectorsOnAdd(key, value, r->offset, r->table_properties_collectors, r->ioptions.info_log); } else { assert(false); } + + r->props.num_entries++; + r->props.raw_key_size += key.size(); + r->props.raw_value_size += value.size(); + if (value_type == kTypeDeletion || value_type == kTypeSingleDeletion) { + r->props.num_deletions++; + } else if (value_type == kTypeRangeDeletion) { + r->props.num_deletions++; + r->props.num_range_deletions++; + } else if (value_type == kTypeMerge) { + r->props.num_merge_operands++; + } } void BlockBasedTableBuilder::Flush() { diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 2d3870683..f84594987 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -1286,7 +1286,8 @@ class DbStressListener : public EventListener { } assert(info.job_id > 0 || FLAGS_compact_files_one_in > 0); if (info.status.ok() && info.file_size > 0) { - assert(info.table_properties.data_size > 0); + assert(info.table_properties.data_size > 0 || + info.table_properties.num_range_deletions > 0); assert(info.table_properties.raw_key_size > 0); assert(info.table_properties.num_entries > 0); }