From 3b4cec7ec6259b3899a6a9ed2539b673c7bb59e5 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Thu, 26 Oct 2017 11:04:33 +0800 Subject: [PATCH 1/3] osd/PrimaryLogPG: make oi.extents handle 0-length write/write_full properly Signed-off-by: xie xingguo --- src/osd/PrimaryLogPG.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 8b9beedba7b..d7f37292d86 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -7205,17 +7205,21 @@ void PrimaryLogPG::write_update_size_and_usage(object_stat_sum_t& delta_stats, o } oi.size = new_size; } - if (length && oi.has_extents()) { - delta_stats.num_bytes -= oi.extents.size(); - if (write_full) { - // oi.size may shrink - oi.extents.clear(); - assert(offset == 0); - oi.extents.insert(0, length); - } else { - oi.extents.union_of(ch); // deduplicated - } - delta_stats.num_bytes += oi.extents.size(); + if (oi.has_extents()) { + delta_stats.num_bytes -= oi.extents.size(); + if (write_full) { + // oi.size may shrink + oi.extents.clear(); + assert(offset == 0); + if (length) { + oi.extents.insert(0, length); + } + } else { + if (length) { + oi.extents.union_of(ch); // deduplicated + } + } + delta_stats.num_bytes += oi.extents.size(); } delta_stats.num_wr++; delta_stats.num_wr_kb += SHIFT_ROUND_UP(length, 10); From 83594df164a1d858e1248fdbb217a6c5568e63b1 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Thu, 26 Oct 2017 11:27:41 +0800 Subject: [PATCH 2/3] osd/osd_type.cc: use "<<" directly for oi.extents there's already a builtin operator<< for interval_set, which is simpler. Signed-off-by: xie xingguo --- src/osd/osd_types.cc | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 1e67517e79c..cde0490145c 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -5122,16 +5122,7 @@ ostream& operator<<(ostream& out, const object_info_t& oi) if (oi.has_manifest()) out << " " << oi.manifest; if (oi.has_extents()) { - out << " extents ["; - for (interval_set::const_iterator p = oi.extents.begin(); - p != oi.extents.end();) { - out << p.get_start() << "~" << p.get_len(); - ++p; - if (p != oi.extents.end()) { - out << ", "; - } - } - out << "]"; + out << " extents " << oi.extents; } out << ")"; return out; From 8c630a040eb616d50ced921a5b7e73b1770c9418 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Thu, 26 Oct 2017 15:54:27 +0800 Subject: [PATCH 3/3] osd/PrimaryLogPG: add_object_context_to_pg_stat - fix stat There might be holes in the extents map, thus it is not always consistent to calc the clone bytes this way. Instead we could switch to its own (simpler and consistent) way to count used bytes for head-object and clone respectively. Signed-off-by: xie xingguo --- src/osd/PrimaryLogPG.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index d7f37292d86..d7c5ab3e961 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -9992,8 +9992,6 @@ void PrimaryLogPG::add_object_context_to_pg_stat(ObjectContextRef obc, pg_stat_t assert(!oi.soid.is_snapdir()); object_stat_sum_t stat; - stat.num_bytes += oi.has_extents() ? - oi.extents.size() : oi.size; stat.num_objects++; if (oi.is_dirty()) stat.num_objects_dirty++; @@ -10010,12 +10008,10 @@ void PrimaryLogPG::add_object_context_to_pg_stat(ObjectContextRef obc, pg_stat_t if (!obc->ssc) obc->ssc = get_snapset_context(oi.soid, false); assert(obc->ssc); - - // subtract off clone overlap - auto it = obc->ssc->snapset.clone_overlap.find(oi.soid.snap); - if (it != obc->ssc->snapset.clone_overlap.end()) { - stat.num_bytes -= it->second.size(); - } + stat.num_bytes += obc->ssc->snapset.get_clone_bytes(oi.soid.snap); + } else { + stat.num_bytes += oi.has_extents() ? + oi.extents.size() : oi.size; } // add it in