mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-28 15:33:54 +00:00
c0be6a4b90
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/13079 The patch adds support for the new read option `allow_unprepared_value` to the multi-column-family iterators `CoalescingIterator` and `AttributeGroupIterator`. When this option is set, these iterators populate their value (`value()` + `columns()` or `attribute_groups()`) in an on-demand fashion when `PrepareValue()` is called. Calling `PrepareValue()` on the child iterators is similarly deferred until `PrepareValue()` is called on the main iterator. Reviewed By: jowlyzhang Differential Revision: D64570587 fbshipit-source-id: 783c8d408ad10074417dabca7b82c5e1fe5cab36
105 lines
2.9 KiB
C++
105 lines
2.9 KiB
C++
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#pragma once
|
|
|
|
#include "db/multi_cf_iterator_impl.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
// EXPERIMENTAL
|
|
class CoalescingIterator : public Iterator {
|
|
public:
|
|
CoalescingIterator(const Comparator* comparator, bool allow_unprepared_value,
|
|
const std::vector<ColumnFamilyHandle*>& column_families,
|
|
const std::vector<Iterator*>& child_iterators)
|
|
: impl_(comparator, allow_unprepared_value, column_families,
|
|
child_iterators, ResetFunc(this), PopulateFunc(this)) {}
|
|
~CoalescingIterator() override {}
|
|
|
|
// No copy allowed
|
|
CoalescingIterator(const CoalescingIterator&) = delete;
|
|
CoalescingIterator& operator=(const CoalescingIterator&) = delete;
|
|
|
|
bool Valid() const override { return impl_.Valid(); }
|
|
void SeekToFirst() override { impl_.SeekToFirst(); }
|
|
void SeekToLast() override { impl_.SeekToLast(); }
|
|
void Seek(const Slice& target) override { impl_.Seek(target); }
|
|
void SeekForPrev(const Slice& target) override { impl_.SeekForPrev(target); }
|
|
void Next() override { impl_.Next(); }
|
|
void Prev() override { impl_.Prev(); }
|
|
Slice key() const override { return impl_.key(); }
|
|
Status status() const override { return impl_.status(); }
|
|
|
|
Slice value() const override {
|
|
assert(Valid());
|
|
return value_;
|
|
}
|
|
const WideColumns& columns() const override {
|
|
assert(Valid());
|
|
return wide_columns_;
|
|
}
|
|
|
|
void Reset() {
|
|
value_.clear();
|
|
wide_columns_.clear();
|
|
}
|
|
|
|
bool PrepareValue() override { return impl_.PrepareValue(); }
|
|
|
|
private:
|
|
class ResetFunc {
|
|
public:
|
|
explicit ResetFunc(CoalescingIterator* iter) : iter_(iter) {}
|
|
|
|
void operator()() const {
|
|
assert(iter_);
|
|
iter_->Reset();
|
|
}
|
|
|
|
private:
|
|
CoalescingIterator* iter_;
|
|
};
|
|
|
|
class PopulateFunc {
|
|
public:
|
|
explicit PopulateFunc(CoalescingIterator* iter) : iter_(iter) {}
|
|
|
|
void operator()(const autovector<MultiCfIteratorInfo>& items) const {
|
|
assert(iter_);
|
|
iter_->Coalesce(items);
|
|
}
|
|
|
|
private:
|
|
CoalescingIterator* iter_;
|
|
};
|
|
|
|
MultiCfIteratorImpl<ResetFunc, PopulateFunc> impl_;
|
|
Slice value_;
|
|
WideColumns wide_columns_;
|
|
|
|
struct WideColumnWithOrder {
|
|
const WideColumn* column;
|
|
int order;
|
|
};
|
|
|
|
class WideColumnWithOrderComparator {
|
|
public:
|
|
explicit WideColumnWithOrderComparator() {}
|
|
bool operator()(const WideColumnWithOrder& a,
|
|
const WideColumnWithOrder& b) const {
|
|
int c = a.column->name().compare(b.column->name());
|
|
return c == 0 ? a.order - b.order > 0 : c > 0;
|
|
}
|
|
};
|
|
|
|
using MinHeap =
|
|
BinaryHeap<WideColumnWithOrder, WideColumnWithOrderComparator>;
|
|
|
|
void Coalesce(const autovector<MultiCfIteratorInfo>& items);
|
|
};
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|