|
|
@ -10,12 +10,34 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace rocksdb { |
|
|
|
namespace rocksdb { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompactionEventListener::CompactionListenerValueType fromInternalValueType( |
|
|
|
|
|
|
|
ValueType vt) { |
|
|
|
|
|
|
|
switch (vt) { |
|
|
|
|
|
|
|
case kTypeDeletion: |
|
|
|
|
|
|
|
return CompactionEventListener::CompactionListenerValueType::kDelete; |
|
|
|
|
|
|
|
case kTypeValue: |
|
|
|
|
|
|
|
return CompactionEventListener::CompactionListenerValueType::kValue; |
|
|
|
|
|
|
|
case kTypeMerge: |
|
|
|
|
|
|
|
return CompactionEventListener::CompactionListenerValueType:: |
|
|
|
|
|
|
|
kMergeOperand; |
|
|
|
|
|
|
|
case kTypeSingleDeletion: |
|
|
|
|
|
|
|
return CompactionEventListener::CompactionListenerValueType:: |
|
|
|
|
|
|
|
kSingleDelete; |
|
|
|
|
|
|
|
case kTypeRangeDeletion: |
|
|
|
|
|
|
|
return CompactionEventListener::CompactionListenerValueType::kRangeDelete; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
assert(false); |
|
|
|
|
|
|
|
return CompactionEventListener::CompactionListenerValueType::kInvalid; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CompactionIterator::CompactionIterator( |
|
|
|
CompactionIterator::CompactionIterator( |
|
|
|
InternalIterator* input, const Comparator* cmp, MergeHelper* merge_helper, |
|
|
|
InternalIterator* input, const Comparator* cmp, MergeHelper* merge_helper, |
|
|
|
SequenceNumber last_sequence, std::vector<SequenceNumber>* snapshots, |
|
|
|
SequenceNumber last_sequence, std::vector<SequenceNumber>* snapshots, |
|
|
|
SequenceNumber earliest_write_conflict_snapshot, Env* env, |
|
|
|
SequenceNumber earliest_write_conflict_snapshot, Env* env, |
|
|
|
bool expect_valid_internal_key, RangeDelAggregator* range_del_agg, |
|
|
|
bool expect_valid_internal_key, RangeDelAggregator* range_del_agg, |
|
|
|
const Compaction* compaction, const CompactionFilter* compaction_filter, |
|
|
|
const Compaction* compaction, const CompactionFilter* compaction_filter, |
|
|
|
|
|
|
|
CompactionEventListener* compaction_listener, |
|
|
|
const std::atomic<bool>* shutting_down) |
|
|
|
const std::atomic<bool>* shutting_down) |
|
|
|
: CompactionIterator( |
|
|
|
: CompactionIterator( |
|
|
|
input, cmp, merge_helper, last_sequence, snapshots, |
|
|
|
input, cmp, merge_helper, last_sequence, snapshots, |
|
|
@ -23,7 +45,7 @@ CompactionIterator::CompactionIterator( |
|
|
|
range_del_agg, |
|
|
|
range_del_agg, |
|
|
|
std::unique_ptr<CompactionProxy>( |
|
|
|
std::unique_ptr<CompactionProxy>( |
|
|
|
compaction ? new CompactionProxy(compaction) : nullptr), |
|
|
|
compaction ? new CompactionProxy(compaction) : nullptr), |
|
|
|
compaction_filter, shutting_down) {} |
|
|
|
compaction_filter, compaction_listener, shutting_down) {} |
|
|
|
|
|
|
|
|
|
|
|
CompactionIterator::CompactionIterator( |
|
|
|
CompactionIterator::CompactionIterator( |
|
|
|
InternalIterator* input, const Comparator* cmp, MergeHelper* merge_helper, |
|
|
|
InternalIterator* input, const Comparator* cmp, MergeHelper* merge_helper, |
|
|
@ -32,6 +54,7 @@ CompactionIterator::CompactionIterator( |
|
|
|
bool expect_valid_internal_key, RangeDelAggregator* range_del_agg, |
|
|
|
bool expect_valid_internal_key, RangeDelAggregator* range_del_agg, |
|
|
|
std::unique_ptr<CompactionProxy> compaction, |
|
|
|
std::unique_ptr<CompactionProxy> compaction, |
|
|
|
const CompactionFilter* compaction_filter, |
|
|
|
const CompactionFilter* compaction_filter, |
|
|
|
|
|
|
|
CompactionEventListener* compaction_listener, |
|
|
|
const std::atomic<bool>* shutting_down) |
|
|
|
const std::atomic<bool>* shutting_down) |
|
|
|
: input_(input), |
|
|
|
: input_(input), |
|
|
|
cmp_(cmp), |
|
|
|
cmp_(cmp), |
|
|
@ -43,7 +66,9 @@ CompactionIterator::CompactionIterator( |
|
|
|
range_del_agg_(range_del_agg), |
|
|
|
range_del_agg_(range_del_agg), |
|
|
|
compaction_(std::move(compaction)), |
|
|
|
compaction_(std::move(compaction)), |
|
|
|
compaction_filter_(compaction_filter), |
|
|
|
compaction_filter_(compaction_filter), |
|
|
|
|
|
|
|
compaction_listener_(compaction_listener), |
|
|
|
shutting_down_(shutting_down), |
|
|
|
shutting_down_(shutting_down), |
|
|
|
|
|
|
|
ignore_snapshots_(false), |
|
|
|
merge_out_iter_(merge_helper_) { |
|
|
|
merge_out_iter_(merge_helper_) { |
|
|
|
assert(compaction_filter_ == nullptr || compaction_ != nullptr); |
|
|
|
assert(compaction_filter_ == nullptr || compaction_ != nullptr); |
|
|
|
bottommost_level_ = |
|
|
|
bottommost_level_ = |
|
|
@ -62,8 +87,8 @@ CompactionIterator::CompactionIterator( |
|
|
|
earliest_snapshot_ = snapshots_->at(0); |
|
|
|
earliest_snapshot_ = snapshots_->at(0); |
|
|
|
latest_snapshot_ = snapshots_->back(); |
|
|
|
latest_snapshot_ = snapshots_->back(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (compaction_filter_ != nullptr && compaction_filter_->IgnoreSnapshots()) { |
|
|
|
if (compaction_filter_ != nullptr) { |
|
|
|
ignore_snapshots_ = true; |
|
|
|
if (compaction_filter_->IgnoreSnapshots()) ignore_snapshots_ = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ignore_snapshots_ = false; |
|
|
|
ignore_snapshots_ = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -188,6 +213,12 @@ void CompactionIterator::NextFromInput() { |
|
|
|
current_user_key_sequence_ = kMaxSequenceNumber; |
|
|
|
current_user_key_sequence_ = kMaxSequenceNumber; |
|
|
|
current_user_key_snapshot_ = 0; |
|
|
|
current_user_key_snapshot_ = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (compaction_listener_) { |
|
|
|
|
|
|
|
compaction_listener_->OnCompaction(compaction_->level(), ikey_.user_key, |
|
|
|
|
|
|
|
fromInternalValueType(ikey_.type), |
|
|
|
|
|
|
|
value_, ikey_.sequence, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// apply the compaction filter to the first occurrence of the user key
|
|
|
|
// apply the compaction filter to the first occurrence of the user key
|
|
|
|
if (compaction_filter_ != nullptr && ikey_.type == kTypeValue && |
|
|
|
if (compaction_filter_ != nullptr && ikey_.type == kTypeValue && |
|
|
|
(visible_at_tip_ || ikey_.sequence > latest_snapshot_ || |
|
|
|
(visible_at_tip_ || ikey_.sequence > latest_snapshot_ || |
|
|
@ -235,6 +266,12 @@ void CompactionIterator::NextFromInput() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
if (compaction_listener_) { |
|
|
|
|
|
|
|
compaction_listener_->OnCompaction(compaction_->level(), ikey_.user_key, |
|
|
|
|
|
|
|
fromInternalValueType(ikey_.type), |
|
|
|
|
|
|
|
value_, ikey_.sequence, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update the current key to reflect the new sequence number/type without
|
|
|
|
// Update the current key to reflect the new sequence number/type without
|
|
|
|
// copying the user key.
|
|
|
|
// copying the user key.
|
|
|
|
// TODO(rven): Compaction filter does not process keys in this path
|
|
|
|
// TODO(rven): Compaction filter does not process keys in this path
|
|
|
@ -394,7 +431,7 @@ void CompactionIterator::NextFromInput() { |
|
|
|
// is the same as the visibility of a previous instance of the
|
|
|
|
// is the same as the visibility of a previous instance of the
|
|
|
|
// same key, then this kv is not visible in any snapshot.
|
|
|
|
// same key, then this kv is not visible in any snapshot.
|
|
|
|
// Hidden by an newer entry for same user key
|
|
|
|
// Hidden by an newer entry for same user key
|
|
|
|
// TODO: why not > ?
|
|
|
|
// TODO(noetzli): why not > ?
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Note: Dropping this key will not affect TransactionDB write-conflict
|
|
|
|
// Note: Dropping this key will not affect TransactionDB write-conflict
|
|
|
|
// checking since there has already been a record returned for this key
|
|
|
|
// checking since there has already been a record returned for this key
|
|
|
|