From e7e3baebd6d5d9e3dfbddc77a2312e9f8e4e9da8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 Mar 2012 14:29:42 -0800 Subject: [PATCH] osd: add zero_to field to PG::OndiskLog; track zeroed region of pg log Track which region of the log has been zeroed on disk. This may be different from tail if 'osd preserved trimmed log = false' in the config. Only zero the portion of the log we need to. This avoids rezeroing regions or missing bits when 'osd preserved trimmed log' was off and is then turned on. Signed-off-by: Sage Weil Reviewed-by: Samuel Just --- src/osd/PG.cc | 11 +++++++++-- src/osd/PG.h | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/osd/PG.cc b/src/osd/PG.cc index d48db381f77..28277d0dcc0 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -1911,8 +1911,15 @@ void PG::trim_ondisklog(ObjectStore::Transaction& t) ondisklog.tail = new_tail; - if (!g_conf->osd_preserve_trimmed_log) - t.zero(coll_t::META_COLL, log_oid, 0, ondisklog.tail & ~4095); + if (!g_conf->osd_preserve_trimmed_log) { + uint64_t zt = new_tail & ~4095; + if (zt > ondisklog.zero_to) { + t.zero(coll_t::META_COLL, log_oid, ondisklog.zero_to, zt); + dout(15) << "trim_ondisklog zeroing from " << ondisklog.zero_to + << " to " << zt << dendl; + ondisklog.zero_to = zt; + } + } bufferlist blb(sizeof(ondisklog)); ::encode(ondisklog, blb); diff --git a/src/osd/PG.h b/src/osd/PG.h index 3ab265dc8ba..8d56ddeec8f 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -280,10 +280,11 @@ public: public: // ok uint64_t tail; // first byte of log. - uint64_t head; // byte following end of log. + uint64_t head; // byte following end of log. + uint64_t zero_to; // first non-zeroed byte of log. bool has_checksums; - OndiskLog() : tail(0), head(0) {} + OndiskLog() : tail(0), head(0), zero_to(0) {} uint64_t length() { return head - tail; } bool trim_to(eversion_t v, ObjectStore::Transaction& t); @@ -291,12 +292,14 @@ public: void zero() { tail = 0; head = 0; + zero_to = 0; } void encode(bufferlist& bl) const { - ENCODE_START(3, 3, bl); + ENCODE_START(4, 3, bl); ::encode(tail, bl); ::encode(head, bl); + ::encode(zero_to, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { @@ -304,17 +307,23 @@ public: has_checksums = (struct_v >= 2); ::decode(tail, bl); ::decode(head, bl); + if (struct_v >= 4) + ::decode(zero_to, bl); + else + zero_to = 0; DECODE_FINISH(bl); } void dump(Formatter *f) const { f->dump_unsigned("head", head); f->dump_unsigned("tail", tail); + f->dump_unsigned("zero_to", zero_to); } static void generate_test_instances(list& o) { o.push_back(new OndiskLog); o.push_back(new OndiskLog); - o.back()->tail = 1; - o.back()->head = 2; + o.back()->tail = 2; + o.back()->head = 3; + o.back()->zero_to = 1; } }; WRITE_CLASS_ENCODER(OndiskLog)