]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osdc/Striper: rewrite assemble_result without push_front or claim_prepend
authorSage Weil <sage@redhat.com>
Sun, 25 Mar 2018 01:26:37 +0000 (20:26 -0500)
committerSage Weil <sage@redhat.com>
Tue, 3 Apr 2018 15:07:05 +0000 (10:07 -0500)
Make a single forward pass across the map while still avoiding tailing
zeroes in the !zero_tail case.

Signed-off-by: Sage Weil <sage@redhat.com>
src/osdc/Striper.cc

index 8ca4825ec470be83b88e90624b5b556b41ef45f2..66a4e44e35074b65f1eaf1d4ce2851a4177eb100 100644 (file)
@@ -354,36 +354,21 @@ void Striper::StripedReadResult::assemble_result(CephContext *cct,
 {
   ldout(cct, 10) << "assemble_result(" << this << ") zero_tail=" << zero_tail
                 << dendl;
-
-  // go backwards, so that we can efficiently discard zeros
-  map<uint64_t,pair<bufferlist,uint64_t> >::reverse_iterator p
-    = partial.rbegin();
-  if (p == partial.rend())
-    return;
-
-  uint64_t end = p->first + p->second.second;
-  while (p != partial.rend()) {
-    // sanity check
-    ldout(cct, 20) << "assemble_result(" << this << ") " << p->first << "~"
-                  << p->second.second << " " << p->second.first.length()
-                  << " bytes" << dendl;
-    assert(p->first == end - p->second.second);
-    end = p->first;
-
-    size_t len = p->second.first.length();
-    if (len < p->second.second) {
-      if (zero_tail || bl.length()) {
-        bufferptr bp(p->second.second - len);
-        bp.zero();
-        bl.push_front(std::move(bp));
-       bl.claim_prepend(p->second.first);
-      } else {
-       bl.claim_prepend(p->second.first);
+  size_t zeros = 0;  // zeros preceding current position
+  for (auto& p : partial) {
+    size_t got = p.second.first.length();
+    size_t expect = p.second.second;
+    if (got) {
+      if (zeros) {
+       bl.append_zero(zeros);
+       zeros = 0;
       }
-    } else {
-      bl.claim_prepend(p->second.first);
+      bl.claim_append(p.second.first);
     }
-    ++p;
+    zeros += expect - got;
+  }
+  if (zero_tail && zeros) {
+    bl.append_zero(zeros);
   }
   partial.clear();
 }