Refactor MergeHelper::MergeUntil a bit (#10943)

Summary:
The patch untangles some nested ifs in `MergeHelper::MergeUntil`. This will come in handy when extending the compaction logic to support `Merge` for wide-column entities, and also enables us to eliminate some repeated branching on value type and to decrease the scope of some variables.

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

Test Plan: `make check`

Reviewed By: riversand963

Differential Revision: D41201946

Pulled By: ltamasi

fbshipit-source-id: 890bd3d4e31cdccadca614489a94686d76485ba9
main
Levi Tamasi 2 years ago committed by Facebook GitHub Bot
parent 2ea109521f
commit 9460d4b77e
  1. 110
      db/merge_helper.cc

@ -290,59 +290,69 @@ Status MergeHelper::MergeUntil(InternalIterator* iter,
// (almost) silently dropping the put/delete. That's probably not what we // (almost) silently dropping the put/delete. That's probably not what we
// want. Also if we're in compaction and it's a put, it would be nice to // want. Also if we're in compaction and it's a put, it would be nice to
// run compaction filter on it. // run compaction filter on it.
const Slice val = iter->value(); std::string merge_result;
PinnableSlice blob_value;
const Slice* val_ptr; if (range_del_agg &&
if ((kTypeValue == ikey.type || kTypeBlobIndex == ikey.type || range_del_agg->ShouldDelete(
kTypeWideColumnEntity == ikey.type) && ikey, RangeDelPositioningMode::kForwardTraversal)) {
(range_del_agg == nullptr || s = TimedFullMerge(user_merge_operator_, ikey.user_key, nullptr,
!range_del_agg->ShouldDelete( merge_context_.GetOperands(), &merge_result, logger_,
ikey, RangeDelPositioningMode::kForwardTraversal))) { stats_, clock_,
if (ikey.type == kTypeWideColumnEntity) { /* result_operand */ nullptr,
// TODO: support wide-column entities /* update_num_ops_stats */ false);
return Status::NotSupported( } else if (ikey.type == kTypeValue) {
"Merge currently not supported for wide-column entities"); const Slice val = iter->value();
} else if (ikey.type == kTypeBlobIndex) {
BlobIndex blob_index; s = TimedFullMerge(user_merge_operator_, ikey.user_key, &val,
merge_context_.GetOperands(), &merge_result, logger_,
s = blob_index.DecodeFrom(val); stats_, clock_,
if (!s.ok()) { /* result_operand */ nullptr,
return s; /* update_num_ops_stats */ false);
} } else if (ikey.type == kTypeBlobIndex) {
BlobIndex blob_index;
FilePrefetchBuffer* prefetch_buffer =
prefetch_buffers ? prefetch_buffers->GetOrCreatePrefetchBuffer( s = blob_index.DecodeFrom(iter->value());
blob_index.file_number()) if (!s.ok()) {
: nullptr; return s;
uint64_t bytes_read = 0;
assert(blob_fetcher);
s = blob_fetcher->FetchBlob(ikey.user_key, blob_index,
prefetch_buffer, &blob_value,
&bytes_read);
if (!s.ok()) {
return s;
}
val_ptr = &blob_value;
if (c_iter_stats) {
++c_iter_stats->num_blobs_read;
c_iter_stats->total_blob_bytes_read += bytes_read;
}
} else {
val_ptr = &val;
} }
FilePrefetchBuffer* prefetch_buffer =
prefetch_buffers ? prefetch_buffers->GetOrCreatePrefetchBuffer(
blob_index.file_number())
: nullptr;
uint64_t bytes_read = 0;
assert(blob_fetcher);
PinnableSlice blob_value;
s = blob_fetcher->FetchBlob(ikey.user_key, blob_index, prefetch_buffer,
&blob_value, &bytes_read);
if (!s.ok()) {
return s;
}
if (c_iter_stats) {
++c_iter_stats->num_blobs_read;
c_iter_stats->total_blob_bytes_read += bytes_read;
}
s = TimedFullMerge(user_merge_operator_, ikey.user_key, &blob_value,
merge_context_.GetOperands(), &merge_result, logger_,
stats_, clock_,
/* result_operand */ nullptr,
/* update_num_ops_stats */ false);
} else if (ikey.type == kTypeWideColumnEntity) {
// TODO: support wide-column entities
return Status::NotSupported(
"Merge currently not supported for wide-column entities");
} else { } else {
val_ptr = nullptr; s = TimedFullMerge(user_merge_operator_, ikey.user_key, nullptr,
merge_context_.GetOperands(), &merge_result, logger_,
stats_, clock_,
/* result_operand */ nullptr,
/* update_num_ops_stats */ false);
} }
std::string merge_result;
s = TimedFullMerge(
user_merge_operator_, ikey.user_key, val_ptr,
merge_context_.GetOperands(), &merge_result, logger_, stats_, clock_,
/* result_operand */ nullptr, /* update_num_ops_stats */ false);
// We store the result in keys_.back() and operands_.back() // We store the result in keys_.back() and operands_.back()
// if nothing went wrong (i.e.: no operand corruption on disk) // if nothing went wrong (i.e.: no operand corruption on disk)

Loading…
Cancel
Save