From 44eaa0277265543afba17c62c042fbfdf4d6585f Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Sat, 19 Nov 2016 13:46:33 +0800 Subject: [PATCH] os/bluestore: refactor ctor of SharedBlob Signed-off-by: xie xingguo --- src/os/bluestore/BlueStore.cc | 10 ++--- src/os/bluestore/BlueStore.h | 5 ++- src/test/objectstore/test_bluestore_types.cc | 44 ++++++++++---------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 25b5a63c54982..3225a3a0a86dd 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1280,11 +1280,12 @@ ostream& operator<<(ostream& out, const BlueStore::SharedBlob& sb) return out << ")"; } -BlueStore::SharedBlob::SharedBlob(uint64_t i, const string& k, Cache *c) +BlueStore::SharedBlob::SharedBlob(uint64_t i, Cache *c) : sbid(i), - key(k), bc(c) { + assert(sbid > 0); + get_shared_blob_key(sbid, &key); } BlueStore::SharedBlob::~SharedBlob() @@ -2294,7 +2295,7 @@ void BlueStore::Collection::open_shared_blob(BlobRef b) assert(!b->shared_blob); const bluestore_blob_t& blob = b->get_blob(); if (!blob.is_shared()) { - b->shared_blob = new SharedBlob(0, string(), cache); + b->shared_blob = new SharedBlob(cache); return; } @@ -2303,8 +2304,7 @@ void BlueStore::Collection::open_shared_blob(BlobRef b) dout(10) << __func__ << " sbid 0x" << std::hex << blob.sbid << std::dec << " had " << *b->shared_blob << dendl; } else { - b->shared_blob = new SharedBlob(blob.sbid, string(), cache); - get_shared_blob_key(blob.sbid, &b->shared_blob->key); + b->shared_blob = new SharedBlob(blob.sbid, cache); shared_blob_set.add(b->shared_blob.get()); dout(10) << __func__ << " sbid 0x" << std::hex << blob.sbid << std::dec << " opened " << *b->shared_blob << dendl; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 02b30b73926ac..b3995b96fa6a8 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -338,7 +338,8 @@ public: BufferSpace bc; ///< buffer cache - SharedBlob(uint64_t i, const string& k, Cache *c); + SharedBlob(Cache *c) : bc(c) {} + SharedBlob(uint64_t i, Cache *c); ~SharedBlob(); friend void intrusive_ptr_add_ref(SharedBlob *b) { b->get(); } @@ -1117,7 +1118,7 @@ public: BlobRef new_blob() { BlobRef b = new Blob; - b->shared_blob = new SharedBlob(0, string(), cache); + b->shared_blob = new SharedBlob(cache); return b; } diff --git a/src/test/objectstore/test_bluestore_types.cc b/src/test/objectstore/test_bluestore_types.cc index 56e9c1f253582..ea6613c5e8429 100644 --- a/src/test/objectstore/test_bluestore_types.cc +++ b/src/test/objectstore/test_bluestore_types.cc @@ -335,7 +335,7 @@ TEST(Blob, put_ref) { { BlueStore::Blob b; - b.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + b.shared_blob = new BlueStore::SharedBlob(nullptr); b.shared_blob->get(); // hack to avoid dtor from running b.dirty_blob().extents.push_back(bluestore_pextent_t(0x40715000, 0x2000)); b.dirty_blob().extents.push_back( @@ -361,7 +361,7 @@ TEST(Blob, put_ref) { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -381,7 +381,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -402,7 +402,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -437,7 +437,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -475,7 +475,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -504,7 +504,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -539,7 +539,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -589,7 +589,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -639,7 +639,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -677,7 +677,7 @@ TEST(Blob, put_ref) // verify csum chunk size if factored in properly { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); vector r; @@ -694,7 +694,7 @@ TEST(Blob, put_ref) } { BlueStore::Blob B; - B.shared_blob = new BlueStore::SharedBlob(-1, string(), nullptr); + B.shared_blob = new BlueStore::SharedBlob(nullptr); B.shared_blob->get(); // hack to avoid dtor from running bluestore_blob_t& b = B.dirty_blob(); B.get_ref(0x0, 0x3800); @@ -780,9 +780,9 @@ TEST(Blob, split) BlueStore::Cache *cache = BlueStore::Cache::create("lru", NULL); { BlueStore::Blob L, R; - L.shared_blob = new BlueStore::SharedBlob(-1, string(), cache); + L.shared_blob = new BlueStore::SharedBlob(cache); L.shared_blob->get(); // hack to avoid dtor from running - R.shared_blob = new BlueStore::SharedBlob(-1, string(), cache); + R.shared_blob = new BlueStore::SharedBlob(cache); R.shared_blob->get(); // hack to avoid dtor from running L.dirty_blob().extents.emplace_back(bluestore_pextent_t(0x2000, 0x2000)); L.dirty_blob().init_csum(Checksummer::CSUM_CRC32C, 12, 0x2000); @@ -800,9 +800,9 @@ TEST(Blob, split) } { BlueStore::Blob L, R; - L.shared_blob = new BlueStore::SharedBlob(-1, string(), cache); + L.shared_blob = new BlueStore::SharedBlob(cache); L.shared_blob->get(); // hack to avoid dtor from running - R.shared_blob = new BlueStore::SharedBlob(-1, string(), cache); + R.shared_blob = new BlueStore::SharedBlob(cache); R.shared_blob->get(); // hack to avoid dtor from running L.dirty_blob().extents.emplace_back(bluestore_pextent_t(0x2000, 0x1000)); L.dirty_blob().extents.emplace_back(bluestore_pextent_t(0x12000, 0x1000)); @@ -826,7 +826,7 @@ TEST(ExtentMap, find_lextent) BlueStore::LRUCache cache; BlueStore::ExtentMap em(nullptr); BlueStore::BlobRef br(new BlueStore::Blob); - br->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); + br->shared_blob = new BlueStore::SharedBlob(&cache); ASSERT_EQ(em.extent_map.end(), em.find_lextent(0)); ASSERT_EQ(em.extent_map.end(), em.find_lextent(100)); @@ -872,7 +872,7 @@ TEST(ExtentMap, seek_lextent) BlueStore::LRUCache cache; BlueStore::ExtentMap em(nullptr); BlueStore::BlobRef br(new BlueStore::Blob); - br->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); + br->shared_blob = new BlueStore::SharedBlob(&cache); ASSERT_EQ(em.extent_map.end(), em.seek_lextent(0)); ASSERT_EQ(em.extent_map.end(), em.seek_lextent(100)); @@ -918,7 +918,7 @@ TEST(ExtentMap, has_any_lextents) BlueStore::LRUCache cache; BlueStore::ExtentMap em(nullptr); BlueStore::BlobRef b(new BlueStore::Blob); - b->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); + b->shared_blob = new BlueStore::SharedBlob(&cache); ASSERT_FALSE(em.has_any_lextents(0, 0)); ASSERT_FALSE(em.has_any_lextents(0, 1000)); @@ -964,9 +964,9 @@ TEST(ExtentMap, compress_extent_map) BlueStore::BlobRef b1(new BlueStore::Blob); BlueStore::BlobRef b2(new BlueStore::Blob); BlueStore::BlobRef b3(new BlueStore::Blob); - b1->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); - b2->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); - b3->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); + b1->shared_blob = new BlueStore::SharedBlob(&cache); + b2->shared_blob = new BlueStore::SharedBlob(&cache); + b3->shared_blob = new BlueStore::SharedBlob(&cache); em.extent_map.insert(*new BlueStore::Extent(0, 0, 100, b1)); em.extent_map.insert(*new BlueStore::Extent(100, 0, 100, b2)); -- 2.39.5