Skip to content

Commit

Permalink
crimson/onode-staged-tree: implement fast Node::get_name()
Browse files Browse the repository at this point in the history
Signed-off-by: Yingxin Cheng <[email protected]>
  • Loading branch information
cyx1231st committed Apr 29, 2021
1 parent 2cebba5 commit 630babc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/crimson/os/seastore/onode_manager/staged-fltree/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ std::ostream& Node::dump_brief(std::ostream& os) const
return impl->dump_brief(os);
}

const std::string& Node::get_name() const
{
return impl->get_name();
}

void Node::test_make_destructable(
context_t c, NodeExtentMutable& mut, Super::URef&& _super)
{
Expand Down
3 changes: 3 additions & 0 deletions src/crimson/os/seastore/onode_manager/staged-fltree/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ class Node
/// Returns an ostream containing an one-line summary of this node.
std::ostream& dump_brief(std::ostream&) const;

/// Print the node name
const std::string& get_name() const;

/// Initializes the tree by allocating an empty root node.
static node_future<> mkfs(context_t, RootNodeTracker&);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class NodeImpl {
virtual node_stats_t get_stats() const = 0;
virtual std::ostream& dump(std::ostream&) const = 0;
virtual std::ostream& dump_brief(std::ostream&) const = 0;
virtual const std::string& get_name() const = 0;
virtual void validate_layout() const = 0;

virtual void test_copy_to(NodeExtentMutable&) const = 0;
Expand Down
36 changes: 26 additions & 10 deletions src/crimson/os/seastore/onode_manager/staged-fltree/node_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,14 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
}

std::ostream& dump_brief(std::ostream& os) const override {
auto& node_stage = extent.read();
os << "Node" << NODE_TYPE << FIELD_TYPE
<< "@0x" << std::hex << extent.get_laddr()
<< "+" << node_stage_t::EXTENT_SIZE << std::dec
<< (node_stage.is_level_tail() ? "$" : "")
<< "(level=" << (unsigned)node_stage.level()
<< ", filled=" << filled_size() << "B"
<< ", free=" << node_stage.free_size() << "B"
<< ")";
os << name
<< "(filled=" << filled_size() << "B"
<< ", free=" << extent.read().free_size() << "B)";
return os;
}

const std::string& get_name() const override { return name; }

void validate_layout() const override {
#ifndef NDEBUG
STAGE_T::validate(extent.read());
Expand All @@ -196,6 +192,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {

void test_set_tail(NodeExtentMutable& mut) override {
node_stage_t::update_is_level_tail(mut, extent.read(), true);
build_name();
}

/*
Expand Down Expand Up @@ -536,6 +533,10 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
#endif
extent.split_replayable(split_at);
}
if (right_impl.is_level_tail()) {
// is_level_tail of left is changed by split/split_insert
build_name();
}
if (unlikely(logger().is_enabled(seastar::log_level::debug))) {
std::ostringstream sos;
dump(sos);
Expand Down Expand Up @@ -653,7 +654,9 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
}

private:
NodeLayoutT(NodeExtentRef extent) : extent{extent} {}
NodeLayoutT(NodeExtentRef extent) : extent{extent} {
build_name();
}

node_offset_t filled_size() const {
auto& node_stage = extent.read();
Expand All @@ -662,11 +665,24 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
return ret;
}

// rebuild the name whenever addr, type, level, tail is changed
void build_name() {
// XXX: maybe also include the extent state
std::ostringstream sos;
sos << "Node" << NODE_TYPE << FIELD_TYPE
<< "@0x" << std::hex << extent.get_laddr()
<< "+" << node_stage_t::EXTENT_SIZE << std::dec
<< "Lv" << (unsigned)level()
<< (is_level_tail() ? "$" : "");
name = sos.str();
}

static seastar::logger& logger() {
return crimson::get_logger(ceph_subsys_filestore);
}

extent_t extent;
std::string name = "Node-N/A";
};

using InternalNode0 = NodeLayoutT<node_fields_0_t, node_type_t::INTERNAL>;
Expand Down
14 changes: 14 additions & 0 deletions src/test/crimson/seastore/onode_tree/test_staged_fltree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ class DummyChildPool {
DummyChildImpl(const std::set<ghobject_t>& keys, bool is_level_tail, laddr_t laddr)
: keys{keys}, _is_level_tail{is_level_tail}, _laddr{laddr} {
std::tie(key_view, p_mem_key_view) = build_key_view(*keys.crbegin());
build_name();
}
~DummyChildImpl() override {
std::free(p_mem_key_view);
Expand All @@ -698,12 +699,14 @@ class DummyChildPool {
_is_level_tail = level_tail;
std::free(p_mem_key_view);
std::tie(key_view, p_mem_key_view) = build_key_view(*keys.crbegin());
build_name();
}

public:
laddr_t laddr() const override { return _laddr; }
bool is_level_tail() const override { return _is_level_tail; }
std::optional<key_view_t> get_pivot_index() const override { return {key_view}; }
const std::string& get_name() const override { return name; }

protected:
node_type_t node_type() const override { return node_type_t::LEAF; }
Expand Down Expand Up @@ -735,9 +738,20 @@ class DummyChildPool {
ceph_abort("impossible path"); }

private:
void build_name() {
std::ostringstream sos;
sos << "DummyNode"
<< "@0x" << std::hex << laddr() << std::dec
<< "Lv" << (unsigned)level()
<< (is_level_tail() ? "$" : "")
<< "(" << key_view << ")";
name = sos.str();
}

std::set<ghobject_t> keys;
bool _is_level_tail;
laddr_t _laddr;
std::string name;

key_view_t key_view;
void* p_mem_key_view;
Expand Down

0 comments on commit 630babc

Please sign in to comment.