From 2e40d4e10f25d4c77527889fce620291300cf1ff Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Fri, 29 Apr 2022 16:17:46 +0800 Subject: [PATCH] crimson/os/seastore/segment_cleaner: fix journal tail calculations Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/seastore_types.h | 31 +++++++++++++++++++++-- src/crimson/os/seastore/segment_cleaner.h | 18 ++++++++----- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index 31a503a7863de..7e8eece8bd4c5 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -772,9 +772,36 @@ struct journal_seq_t { denc(v.offset, p); DENC_FINISH(p); } + + bool operator==(const journal_seq_t &o) const { return cmp(o) == 0; } + bool operator!=(const journal_seq_t &o) const { return cmp(o) != 0; } + bool operator<(const journal_seq_t &o) const { return cmp(o) < 0; } + bool operator<=(const journal_seq_t &o) const { return cmp(o) <= 0; } + bool operator>(const journal_seq_t &o) const { return cmp(o) > 0; } + bool operator>=(const journal_seq_t &o) const { return cmp(o) >= 0; } + +private: + int cmp(const journal_seq_t &other) const { + if (segment_seq > other.segment_seq) { + return 1; + } else if (segment_seq < other.segment_seq) { + return -1; + } + auto &seg_paddr = offset.as_seg_paddr(); + auto &o_seg_paddr = other.offset.as_seg_paddr(); + if (seg_paddr.get_segment_off() > o_seg_paddr.get_segment_off()) { + return 1; + } else if (seg_paddr.get_segment_off() < o_seg_paddr.get_segment_off()) { + return -1; + } + if (seg_paddr.get_segment_id() > o_seg_paddr.get_segment_id()) { + return 1; + } else if (seg_paddr.get_segment_id() < o_seg_paddr.get_segment_id()) { + return -1; + } + return 0; + } }; -WRITE_CMP_OPERATORS_2(journal_seq_t, segment_seq, offset) -WRITE_EQ_OPERATORS_2(journal_seq_t, segment_seq, offset) std::ostream &operator<<(std::ostream &out, const journal_seq_t &seq); diff --git a/src/crimson/os/seastore/segment_cleaner.h b/src/crimson/os/seastore/segment_cleaner.h index 6a55f8ebb0695..dc66de43e9c4e 100644 --- a/src/crimson/os/seastore/segment_cleaner.h +++ b/src/crimson/os/seastore/segment_cleaner.h @@ -883,17 +883,23 @@ private: journal_seq_t get_dirty_tail() const { auto ret = journal_head; - ret.segment_seq -= std::min( - static_cast(ret.segment_seq), - config.target_journal_segments); + if (ret.segment_seq >= config.target_journal_segments) { + ret.segment_seq -= config.target_journal_segments; + } else { + ret.segment_seq = 0; + ret.offset = P_ADDR_MIN; + } return ret; } journal_seq_t get_dirty_tail_limit() const { auto ret = journal_head; - ret.segment_seq -= std::min( - static_cast(ret.segment_seq), - config.max_journal_segments); + if (ret.segment_seq >= config.max_journal_segments) { + ret.segment_seq -= config.max_journal_segments; + } else { + ret.segment_seq = 0; + ret.offset = P_ADDR_MIN; + } return ret; } -- 2.39.5