From a48da26ea944520c784852e267482a3ddbe1de8f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 19 Jul 2019 14:39:19 -0500 Subject: [PATCH] osd/osd_types: add pg_lease[_ack]_t Signed-off-by: Sage Weil --- src/osd/osd_types.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++ src/osd/osd_types.h | 63 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index a505c6fa81f..d15da4222e9 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -4251,6 +4251,71 @@ void pg_query_t::generate_test_instances(list& o) *h.back(), 5)); } +// -- pg_lease_t -- + +void pg_lease_t::encode(bufferlist& bl) const +{ + ENCODE_START(1, 1, bl); + encode(readable_until, bl); + encode(readable_until_ub, bl); + encode(interval, bl); + ENCODE_FINISH(bl); +} + +void pg_lease_t::decode(bufferlist::const_iterator& p) +{ + DECODE_START(1, p); + decode(readable_until, p); + decode(readable_until_ub, p); + decode(interval, p); + DECODE_FINISH(p); +} + +void pg_lease_t::dump(Formatter *f) const +{ + f->dump_stream("readable_until") << readable_until; + f->dump_stream("readable_until_ub") << readable_until_ub; + f->dump_stream("interval") << interval; +} + +void pg_lease_t::generate_test_instances(std::list& o) +{ + o.push_back(new pg_lease_t()); + o.push_back(new pg_lease_t()); + o.back()->readable_until = make_timespan(1.5); + o.back()->readable_until_ub = make_timespan(3.4); + o.back()->interval = make_timespan(1.0); +} + +// -- pg_lease_ack_t -- + +void pg_lease_ack_t::encode(bufferlist& bl) const +{ + ENCODE_START(1, 1, bl); + encode(readable_until_ub, bl); + ENCODE_FINISH(bl); +} + +void pg_lease_ack_t::decode(bufferlist::const_iterator& p) +{ + DECODE_START(1, p); + decode(readable_until_ub, p); + DECODE_FINISH(p); +} + +void pg_lease_ack_t::dump(Formatter *f) const +{ + f->dump_stream("readable_until_ub") << readable_until_ub; +} + +void pg_lease_ack_t::generate_test_instances(std::list& o) +{ + o.push_back(new pg_lease_ack_t()); + o.push_back(new pg_lease_ack_t()); + o.back()->readable_until_ub = make_timespan(3.4); +} + + // -- ObjectModDesc -- void ObjectModDesc::visit(Visitor *visitor) const { diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 78881d5c939..90a9a746bfe 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -3629,6 +3629,69 @@ inline std::ostream& operator<<(std::ostream& out, const pg_query_t& q) { return out; } +/** + * pg_lease_t - readable lease metadata, from primary -> non-primary + * + * This metadata serves to increase either or both of the lease expiration + * and upper bound on the non-primary. + */ +struct pg_lease_t { + /// pg readable_until value; replicas must not be readable beyond this + ceph::signedspan readable_until = ceph::signedspan::zero(); + + /// upper bound on any acting osd's readable_until + ceph::signedspan readable_until_ub = ceph::signedspan::zero(); + + /// duration of the lease (in case clock deltas aren't available) + ceph::signedspan interval = ceph::signedspan::zero(); + + pg_lease_t() {} + pg_lease_t(ceph::signedspan ru, ceph::signedspan ruub, + ceph::signedspan i) + : readable_until(ru), + readable_until_ub(ruub), + interval(i) {} + + void encode(ceph::buffer::list &bl) const; + void decode(ceph::buffer::list::const_iterator &bl); + void dump(ceph::Formatter *f) const; + static void generate_test_instances(std::list& o); + + friend ostream& operator<<(ostream& out, const pg_lease_t& l) { + return out << "pg_lease(ru " << l.readable_until + << " ub " << l.readable_until_ub + << " int " << l.interval << ")"; + } +}; +WRITE_CLASS_ENCODER(pg_lease_t) + +/** + * pg_lease_ack_t - lease ack, from non-primary -> primary + * + * This metadata acknowledges to the primary what a non-primary's noted + * upper bound is. + */ +struct pg_lease_ack_t { + /// highest upper bound non-primary has recorded (primary's clock) + ceph::signedspan readable_until_ub = ceph::signedspan::zero(); + + pg_lease_ack_t() {} + pg_lease_ack_t(ceph::signedspan ub) + : readable_until_ub(ub) {} + + void encode(ceph::buffer::list &bl) const; + void decode(ceph::buffer::list::const_iterator &bl); + void dump(ceph::Formatter *f) const; + static void generate_test_instances(std::list& o); + + friend ostream& operator<<(ostream& out, const pg_lease_ack_t& l) { + return out << "pg_lease_ack(ruub " << l.readable_until_ub << ")"; + } +}; +WRITE_CLASS_ENCODER(pg_lease_ack_t) + + + class PGBackend; class ObjectModDesc { bool can_local_rollback; -- 2.39.5