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. 62
      db/merge_helper.cc

@ -290,22 +290,28 @@ 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.
std::string merge_result;
if (range_del_agg &&
range_del_agg->ShouldDelete(
ikey, RangeDelPositioningMode::kForwardTraversal)) {
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);
} else if (ikey.type == kTypeValue) {
const Slice val = iter->value(); const Slice val = iter->value();
PinnableSlice blob_value;
const Slice* val_ptr; s = TimedFullMerge(user_merge_operator_, ikey.user_key, &val,
if ((kTypeValue == ikey.type || kTypeBlobIndex == ikey.type || merge_context_.GetOperands(), &merge_result, logger_,
kTypeWideColumnEntity == ikey.type) && stats_, clock_,
(range_del_agg == nullptr || /* result_operand */ nullptr,
!range_del_agg->ShouldDelete( /* update_num_ops_stats */ false);
ikey, RangeDelPositioningMode::kForwardTraversal))) {
if (ikey.type == kTypeWideColumnEntity) {
// TODO: support wide-column entities
return Status::NotSupported(
"Merge currently not supported for wide-column entities");
} else if (ikey.type == kTypeBlobIndex) { } else if (ikey.type == kTypeBlobIndex) {
BlobIndex blob_index; BlobIndex blob_index;
s = blob_index.DecodeFrom(val); s = blob_index.DecodeFrom(iter->value());
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
@ -319,30 +325,34 @@ Status MergeHelper::MergeUntil(InternalIterator* iter,
assert(blob_fetcher); assert(blob_fetcher);
s = blob_fetcher->FetchBlob(ikey.user_key, blob_index, PinnableSlice blob_value;
prefetch_buffer, &blob_value, s = blob_fetcher->FetchBlob(ikey.user_key, blob_index, prefetch_buffer,
&bytes_read); &blob_value, &bytes_read);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
val_ptr = &blob_value;
if (c_iter_stats) { if (c_iter_stats) {
++c_iter_stats->num_blobs_read; ++c_iter_stats->num_blobs_read;
c_iter_stats->total_blob_bytes_read += bytes_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 = &val; s = TimedFullMerge(user_merge_operator_, ikey.user_key, nullptr,
} merge_context_.GetOperands(), &merge_result, logger_,
} else { stats_, clock_,
val_ptr = nullptr; /* 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