: coll(_coll), sbid_unloaded(i)
{
ceph_assert(sbid_unloaded > 0);
- if (get_cache()) {
- get_cache()->add_blob();
- }
}
BlueStore::SharedBlob::~SharedBlob()
ceph_assert(!b->shared_blob);
const bluestore_blob_t& blob = b->get_blob();
if (!blob.is_shared()) {
- b->shared_blob = new SharedBlob(this);
+ b->set_shared_blob(new SharedBlob(this));
return;
}
- b->shared_blob = shared_blob_set.lookup(sbid);
- if (b->shared_blob) {
+ SharedBlobRef sb = shared_blob_set.lookup(sbid);
+ if (sb) {
+ b->set_shared_blob(sb);
ldout(store->cct, 10) << __func__ << " sbid 0x" << std::hex << sbid
<< std::dec << " had " << *b->shared_blob << dendl;
} else {
- b->shared_blob = new SharedBlob(sbid, this);
+ b->set_shared_blob(new SharedBlob(sbid, this));
shared_blob_set.add(this, b->shared_blob.get());
ldout(store->cct, 10) << __func__ << " sbid 0x" << std::hex << sbid
<< std::dec << " opened " << *b->shared_blob
// but now those 2 blobs share it.
// This is illegal, as empty shared blobs should be unique.
// Fixing by re-creation.
+
+ // Here we skip set_shared_blob() because e.blob is already in BufferCacheShard
+ // and cannot do add_blob() twice
e.blob->shared_blob = new SharedBlob(c.get());
- dout(20) << __func__ << " recreated empty shared blob " << e << dendl;
}
h->extent_map.dirty_range(e.logical_offset, 1);
}
};
SharedBlob(Collection *_coll) : coll(_coll), sbid_unloaded(0) {
- if (get_cache()) {
- get_cache()->add_blob();
- }
}
SharedBlob(uint64_t i, Collection *_coll);
~SharedBlob();
int16_t id = -1; ///< id, for spanning blobs only, >= 0
int16_t last_encoded_id = -1; ///< (ephemeral) used during encoding only
SharedBlobRef shared_blob; ///< shared blob state (if any)
+
+ void set_shared_blob(SharedBlobRef sb) {
+ ceph_assert((bool)sb);
+ ceph_assert(!shared_blob);
+ shared_blob = sb;
+ ceph_assert(shared_blob->get_cache());
+ shared_blob->get_cache()->add_blob();
+ }
BufferSpace bc;
private:
mutable bluestore_blob_t blob; ///< decoded blob metadata
uint32_t *length0);
void dup(Blob& o) {
- o.shared_blob = shared_blob;
+ o.set_shared_blob(shared_blob);
o.blob = blob;
#ifdef CACHE_BLOB_BL
o.blob_bl = blob_bl;
public:
BufferCacheShard(CephContext* cct) : CacheShard(cct) {}
+ virtual ~BufferCacheShard() {
+ ceph_assert(num_blobs == 0);
+ ceph_assert(num_extents == 0);
+ }
static BufferCacheShard *create(CephContext* cct, std::string type,
PerfCounters *logger);
virtual void _add(Buffer *b, int level, Buffer *near) = 0;
BlobRef new_blob() {
BlobRef b = new Blob();
- b->shared_blob = new SharedBlob(this);
+ b->set_shared_blob(new SharedBlob(this));
return b;
}