Skip to content

Commit

Permalink
os/bluestore: do not precalculate/cache shard keys
Browse files Browse the repository at this point in the history
Note that we are generating it on demand now.  We can
probably do better, especially when in a loop.

Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Dec 23, 2016
1 parent 566ad2d commit f5f16ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -1629,7 +1629,7 @@ bool BlueStore::ExtentMap::update(KeyValueDB::Transaction t,
} else {

struct dirty_shard_t{
string* key = nullptr;
uint32_t offset = 0;
bufferlist bl;
boost::intrusive::list_member_hook<> dirty_list_item;
};
Expand Down Expand Up @@ -1683,7 +1683,7 @@ bool BlueStore::ExtentMap::update(KeyValueDB::Transaction t,
p->shard_info->bytes = len;
p->shard_info->extents = nn;

encoded_shards[pos].key = &p->key;
encoded_shards[pos].offset = p->offset;
dirty_shards.push_back(encoded_shards[pos]);
p->dirty = false;
}
Expand All @@ -1692,8 +1692,10 @@ bool BlueStore::ExtentMap::update(KeyValueDB::Transaction t,
}
//schedule DB update for dirty shards
auto it = dirty_shards.begin();
while(it != dirty_shards.end()) {
t->set(PREFIX_OBJ, *(it->key), it->bl);
while (it != dirty_shards.end()) {
string key;
get_extent_shard_key(onode->key, it->offset, &key);
t->set(PREFIX_OBJ, key, it->bl);
++it;
}
}
Expand Down Expand Up @@ -2049,7 +2051,6 @@ void BlueStore::ExtentMap::init_shards(bool loaded, bool dirty)
shards.resize(onode->onode.extent_map_shards.size());
unsigned i = 0;
for (auto &s : onode->onode.extent_map_shards) {
get_extent_shard_key(onode->key, s.offset, &shards[i].key);
shards[i].offset = s.offset;
shards[i].shard_info = &s;
shards[i].loaded = loaded;
Expand Down Expand Up @@ -4460,7 +4461,8 @@ int BlueStore::fsck(bool deep)
}
for (auto& s : o->extent_map.shards) {
dout(20) << __func__ << " shard " << *s.shard_info << dendl;
expecting_shards.push_back(s.key);
expecting_shards.push_back(string());
get_extent_shard_key(o->key, s.offset, &expecting_shards.back());
}
// lextents
uint64_t pos = 0;
Expand Down Expand Up @@ -6432,7 +6434,9 @@ void BlueStore::_txc_write_nodes(TransContext *txc, KeyValueDB::Transaction t)
if (reshard) {
dout(20) << __func__ << " resharding extents for " << o->oid << dendl;
for (auto &s : o->extent_map.shards) {
t->rmkey(PREFIX_OBJ, s.key);
string key;
get_extent_shard_key(o->key, s.offset, &key);
t->rmkey(PREFIX_OBJ, key);
}
o->extent_map.fault_range(db, 0, o->onode.size);
o->extent_map.reshard(min_alloc_size);
Expand Down Expand Up @@ -8393,7 +8397,9 @@ int BlueStore::_do_remove(
o->onode = bluestore_onode_t();
txc->removed(o);
for (auto &s : o->extent_map.shards) {
txc->t->rmkey(PREFIX_OBJ, s.key);
string key;
get_extent_shard_key(o->key, s.offset, &key);
txc->t->rmkey(PREFIX_OBJ, key);
}
txc->t->rmkey(PREFIX_OBJ, o->key);
o->extent_map.clear();
Expand Down Expand Up @@ -8935,8 +8941,9 @@ int BlueStore::_rename(TransContext *txc,
oldo->extent_map.fault_range(db, 0, oldo->onode.size);
get_object_key(new_oid, &new_okey);
for (auto &s : oldo->extent_map.shards) {
txc->t->rmkey(PREFIX_OBJ, s.key);
get_extent_shard_key(new_okey, s.offset, &s.key);
string key;
get_extent_shard_key(oldo->key, s.offset, &key);
txc->t->rmkey(PREFIX_OBJ, key);
s.dirty = true;
}

Expand Down
3 changes: 1 addition & 2 deletions src/os/bluestore/BlueStore.h
Expand Up @@ -644,9 +644,8 @@ class BlueStore : public ObjectStore,
blob_map_t spanning_blob_map; ///< blobs that span shards

struct Shard {
string key; ///< kv key
uint32_t offset; ///< starting logical offset
bluestore_onode_t::shard_info *shard_info;
uint32_t offset = 0; ///< starting logical offset
bool loaded = false; ///< true if shard is loaded
bool dirty = false; ///< true if shard is dirty and needs reencoding
};
Expand Down

0 comments on commit f5f16ce

Please sign in to comment.