]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: decode blobs on demand 10768/head
authorSage Weil <sage@redhat.com>
Wed, 24 Aug 2016 21:41:53 +0000 (17:41 -0400)
committerSage Weil <sage@redhat.com>
Wed, 24 Aug 2016 21:41:53 +0000 (17:41 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 4d9d0e8a69128bfe3cb869ca0c8bc40f552e74c8..029aa8724cf81b97398b883e4cbf945b6319691d 100644 (file)
@@ -1145,6 +1145,7 @@ bool BlueStore::OnodeSpace::map_any(std::function<bool(OnodeRef)> f)
 
 void BlueStore::Blob::discard_unallocated()
 {
+  get_blob();
   size_t pos = 0;
   if (blob.is_compressed()) {
     bool discard = false;
@@ -5857,8 +5858,10 @@ void BlueStore::_dump_blob_map(BlobMap &bm, int log_level)
 {
   for (auto& b : bm.blob_map) {
     dout(log_level) << __func__ << "  " << b
-                   << " blob_bl " << b.blob_bl.length()
-                   << (b.blob_bl.length() ? "" : " (dirty)") << dendl;
+                   << " blob_bl " << b.get_encoded_length()
+                   << (b.is_dirty() ? " (dirty)" : "")
+                   << (b.is_undecoded() ? " (was undecoded)" : "")
+                   << dendl;
     if (b.get_blob().has_csum()) {
       vector<uint64_t> v;
       unsigned n = b.get_blob().get_csum_count();
index 93ec4da5477996c47c822285115700a4076edd38..11c124f5bb0c9611b980a1bc01f626ada53b3a13 100644 (file)
@@ -291,9 +291,10 @@ public:
     BufferSpace bc;          ///< buffer cache
 
   private:
-    bluestore_blob_t blob;        ///< decoded blob metadata
-    mutable bool dirty = true;    ///< true if blob != blob_bl
-    mutable bufferlist blob_bl;   ///< cached encoded blob
+    mutable bluestore_blob_t blob;  ///< decoded blob metadata
+    mutable bool undecoded = false; ///< true if blob_bl is newer than blob
+    mutable bool dirty = true;      ///< true if blob is newer than blob_bl
+    mutable bufferlist blob_bl;     ///< cached encoded blob
 
   public:
     Blob(int64_t i, Cache *c) : nref(0), id(i), bc(c) {}
@@ -316,19 +317,38 @@ public:
     }
 
     friend ostream& operator<<(ostream& out, const Blob &b) {
-      return out << b.id << ":" << b.blob;
+      return out << b.id << ":" << b.get_blob();
     }
 
     const bluestore_blob_t& get_blob() const {
+      if (undecoded) {
+       bufferlist::iterator p = blob_bl.begin();
+       ::decode(blob, p);
+       undecoded = false;
+      }
       return blob;
     }
     bluestore_blob_t& dirty_blob() {
+      if (undecoded) {
+       bufferlist::iterator p = blob_bl.begin();
+       ::decode(blob, p);
+       undecoded = false;
+      }
       if (!dirty) {
        dirty = true;
        blob_bl.clear();
       }
       return blob;
     }
+    size_t get_encoded_length() const {
+      return blob_bl.length();
+    }
+    bool is_dirty() const {
+      return dirty;
+    }
+    bool is_undecoded() const {
+      return undecoded;
+    }
 
     /// discard buffers for unallocated regions
     void discard_unallocated();
@@ -348,12 +368,11 @@ public:
       } else {
        assert(blob_bl.length());
       }
-      bl.append(blob_bl);
+      ::encode(blob_bl, bl);
     }
     void decode(bufferlist::iterator& p) {
-      bufferlist::iterator start = p;
-      ::decode(blob, p);
-      start.copy(p.get_off() - start.get_off(), blob_bl);
+      ::decode(blob_bl, p);
+      undecoded = true;
       dirty = false;
     }
   };