}
- FixedKVNodeLayout(char *buf) :
- buf(buf) {}
+ FixedKVNodeLayout() : buf(nullptr) {}
virtual ~FixedKVNodeLayout() = default;
+ void set_layout_buf(char *_buf) {
+ assert(buf == nullptr);
+ assert(_buf != nullptr);
+ buf = _buf;
+ }
+
const_iterator begin() const {
return const_iterator(
this,
: ChildableCachedExtent(std::move(ptr)),
children(capacity, nullptr),
capacity(capacity) {}
+ // Must be identical with FixedKVNode(capacity, ptr) after on_fully_loaded()
+ explicit FixedKVNode(uint16_t capacity, extent_len_t length)
+ : ChildableCachedExtent(length),
+ children(capacity, nullptr),
+ capacity(capacity) {}
FixedKVNode(const FixedKVNode &rhs)
: ChildableCachedExtent(rhs),
range(rhs.range),
node_size,
node_type_t>;
- FixedKVInternalNode(ceph::bufferptr &&ptr)
- : FixedKVNode<NODE_KEY>(CAPACITY, std::move(ptr)),
- node_layout_t(this->get_bptr().c_str()) {}
+ explicit FixedKVInternalNode(ceph::bufferptr &&ptr)
+ : FixedKVNode<NODE_KEY>(CAPACITY, std::move(ptr)) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+ // Must be identical with FixedKVInternalNode(ptr) after on_fully_loaded()
+ explicit FixedKVInternalNode(extent_len_t length)
+ : FixedKVNode<NODE_KEY>(CAPACITY, length) {}
FixedKVInternalNode(const FixedKVInternalNode &rhs)
- : FixedKVNode<NODE_KEY>(rhs),
- node_layout_t(this->get_bptr().c_str()) {}
+ : FixedKVNode<NODE_KEY>(rhs) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
bool have_children() const final {
return true;
pivot);
}
+ void on_fully_loaded() final {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+
/**
* Internal relative addresses on read or in memory prior to commit
* are either record or block relative depending on whether this
node_type_t,
has_children>;
using base_t = FixedKVNode<NODE_KEY>;
- FixedKVLeafNode(ceph::bufferptr &&ptr)
- : FixedKVNode<NODE_KEY>(has_children ? CAPACITY : 0, std::move(ptr)),
- node_layout_t(this->get_bptr().c_str()) {}
+ explicit FixedKVLeafNode(ceph::bufferptr &&ptr)
+ : FixedKVNode<NODE_KEY>(has_children ? CAPACITY : 0, std::move(ptr)) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+ // Must be identical with FixedKVLeafNode(ptr) after on_fully_loaded()
+ explicit FixedKVLeafNode(extent_len_t length)
+ : FixedKVNode<NODE_KEY>(has_children ? CAPACITY : 0, length) {}
FixedKVLeafNode(const FixedKVLeafNode &rhs)
: FixedKVNode<NODE_KEY>(rhs),
- node_layout_t(this->get_bptr().c_str()),
- modifications(rhs.modifications) {}
+ modifications(rhs.modifications) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
static constexpr bool do_has_children = has_children;
// for the stable extent, modifications is always 0;
}
}
+ void on_fully_loaded() final {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+
void prepare_commit() final {
if constexpr (has_children) {
if (this->is_initial_pending()) {
*/
virtual void on_initial_write() {}
+ /**
+ * on_fully_loaded
+ *
+ * Called when ptr is ready. Normally this should be used to initiate
+ * the extent to be identical to CachedExtent(ptr).
+ *
+ * Note this doesn't mean the content is fully read, use on_clean_read for
+ * this purpose.
+ */
+ virtual void on_fully_loaded() {}
+
/**
* on_clean_read
*
CachedExtent(CachedExtent &&other) = delete;
/// construct a fully loaded CachedExtent
- CachedExtent(ceph::bufferptr &&_ptr)
+ explicit CachedExtent(ceph::bufferptr &&_ptr)
: length(_ptr.length()),
loaded_length(_ptr.length()) {
ptr = std::move(_ptr);
}
/// construct a partially loaded CachedExtent
- CachedExtent(extent_len_t _length)
+ /// must be identical with CachedExtent(ptr) after on_fully_loaded()
+ explicit CachedExtent(extent_len_t _length)
: length(_length),
loaded_length(0),
buffer_space(std::in_place) {
loaded_length = _length;
buffer_space.reset();
assert(is_fully_loaded());
+ on_fully_loaded();
load_ranges_t ret;
ret.push_back(offset, *ptr);
return ret;
ptr = buffer_space->to_full_ptr(length);
buffer_space.reset();
assert(is_fully_loaded());
+ on_fully_loaded();
// adjust ret since the ptr has been rebuild
for (load_range_t& range : ret.ranges) {
auto range_length = range.ptr.length();
explicit CollectionNode(ceph::bufferptr &&ptr)
: LogicalCachedExtent(std::move(ptr)) {}
+ explicit CollectionNode(extent_len_t length)
+ : LogicalCachedExtent(length) {}
explicit CollectionNode(const CollectionNode &other)
: LogicalCachedExtent(other),
decoded(other.decoded) {}
need_merge(n_merge) {}
};
- OMapNode(ceph::bufferptr &&ptr) : LogicalCachedExtent(std::move(ptr)) {}
+ explicit OMapNode(ceph::bufferptr &&ptr) : LogicalCachedExtent(std::move(ptr)) {}
+ explicit OMapNode(extent_len_t length) : LogicalCachedExtent(length) {}
OMapNode(const OMapNode &other)
: LogicalCachedExtent(other) {}
StringKVInnerNodeLayout {
using OMapInnerNodeRef = TCachedExtentRef<OMapInnerNode>;
using internal_iterator_t = const_iterator;
- template <typename... T>
- OMapInnerNode(T&&... t) :
- OMapNode(std::forward<T>(t)...),
- StringKVInnerNodeLayout(get_bptr().c_str()) {}
+
+ explicit OMapInnerNode(ceph::bufferptr &&ptr)
+ : OMapNode(std::move(ptr)) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+ // Must be identical with OMapInnerNode(ptr) after on_fully_loaded()
+ explicit OMapInnerNode(extent_len_t length)
+ : OMapNode(length) {}
+ OMapInnerNode(const OMapInnerNode &rhs)
+ : OMapNode(rhs) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
omap_node_meta_t get_node_meta() const final { return get_meta(); }
bool extent_will_overflow(size_t ksize, std::optional<size_t> vsize) const {
bool extent_is_below_min() const { return below_min(); }
uint32_t get_node_size() { return get_size(); }
+ void on_fully_loaded() final {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+
CachedExtentRef duplicate_for_write(Transaction&) final {
assert(delta_buffer.empty());
return CachedExtentRef(new OMapInnerNode(*this));
using OMapLeafNodeRef = TCachedExtentRef<OMapLeafNode>;
using internal_iterator_t = const_iterator;
- template <typename... T>
- OMapLeafNode(T&&... t) :
- OMapNode(std::forward<T>(t)...),
- StringKVLeafNodeLayout(get_bptr().c_str()) {}
+
+ explicit OMapLeafNode(ceph::bufferptr &&ptr)
+ : OMapNode(std::move(ptr)) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+ // Must be identical with OMapLeafNode(ptr) after on_fully_loaded()
+ explicit OMapLeafNode(extent_len_t length)
+ : OMapNode(length) {}
+ OMapLeafNode(const OMapLeafNode &rhs)
+ : OMapNode(rhs) {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
omap_node_meta_t get_node_meta() const final { return get_meta(); }
bool extent_will_overflow(
bool extent_is_below_min() const { return below_min(); }
uint32_t get_node_size() { return get_size(); }
+ void on_fully_loaded() final {
+ this->set_layout_buf(this->get_bptr().c_str());
+ }
+
CachedExtentRef duplicate_for_write(Transaction&) final {
assert(delta_buffer.empty());
return CachedExtentRef(new OMapLeafNode(*this));
inner_remove(iter);
}
- StringKVInnerNodeLayout(char *buf) :
- buf(buf) {}
+ StringKVInnerNodeLayout() : buf(nullptr) {}
+
+ void set_layout_buf(char *_buf) {
+ assert(buf == nullptr);
+ assert(_buf != nullptr);
+ buf = _buf;
+ }
uint32_t get_size() const {
ceph_le32 &size = *layout.template Pointer<0>(buf);
leaf_remove(iter);
}
- StringKVLeafNodeLayout(char *buf) :
- buf(buf) {}
+ StringKVLeafNodeLayout() : buf(nullptr) {}
+
+ void set_layout_buf(char *_buf) {
+ assert(buf == nullptr);
+ assert(_buf != nullptr);
+ buf = _buf;
+ }
const_iterator iter_begin() const {
return const_iterator(
class SeastoreNodeExtent final: public NodeExtent {
public:
- SeastoreNodeExtent(ceph::bufferptr &&ptr)
+ explicit SeastoreNodeExtent(ceph::bufferptr &&ptr)
: NodeExtent(std::move(ptr)) {}
+ explicit SeastoreNodeExtent(extent_len_t length)
+ : NodeExtent(length) {}
SeastoreNodeExtent(const SeastoreNodeExtent& other)
: NodeExtent(other) {}
~SeastoreNodeExtent() override = default;
interval_set<extent_len_t> modified_region;
- TestBlock(ceph::bufferptr &&ptr)
+ explicit TestBlock(ceph::bufferptr &&ptr)
: LogicalCachedExtent(std::move(ptr)) {}
+ explicit TestBlock(extent_len_t length)
+ : LogicalCachedExtent(length) {}
TestBlock(const TestBlock &other)
: LogicalCachedExtent(other), modified_region(other.modified_region) {}
- TestBlock(extent_len_t length)
- : LogicalCachedExtent(length) {}
CachedExtentRef duplicate_for_write(Transaction&) final {
return CachedExtentRef(new TestBlock(*this));
void on_rewrite(Transaction&, CachedExtent&, extent_len_t) final {}
- TestBlockPhysical(ceph::bufferptr &&ptr)
+ explicit TestBlockPhysical(ceph::bufferptr &&ptr)
: CachedExtent(std::move(ptr)) {}
+ explicit TestBlockPhysical(extent_len_t length)
+ : CachedExtent(length) {}
TestBlockPhysical(const TestBlockPhysical &other)
: CachedExtent(other) {}
uint32_t, ceph_le32,
test_val_t, test_val_le_t> {
char buf[4096];
- TestNode() : FixedKVNodeLayout(buf) {
+ TestNode() : FixedKVNodeLayout() {
+ set_layout_buf(buf);
memset(buf, 0, sizeof(buf));
set_meta({0, std::numeric_limits<uint32_t>::max()});
}
TestNode(const TestNode &rhs)
- : FixedKVNodeLayout(buf) {
+ : FixedKVNodeLayout() {
+ set_layout_buf(buf);
::memcpy(buf, rhs.buf, sizeof(buf));
}