Skip to content

Commit

Permalink
os/bluestore: improve ExtentMap::reshard() readability a little
Browse files Browse the repository at this point in the history
As ep, sp and esp can be a little confusing.

Signed-off-by: xiexingguo <xie.xingguo@zte.com.cn>
  • Loading branch information
xiexingguo committed Oct 11, 2016
1 parent 4e33747 commit d410573
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -1569,19 +1569,17 @@ void BlueStore::ExtentMap::reshard(Onode *o, uint64_t min_alloc_size)
<< " target " << target << " slop " << slop << dendl;

// reshard
auto ep = extent_map.begin();
auto sp = o->onode.extent_map_shards.begin();
auto esp = o->onode.extent_map_shards.end();
unsigned shard_end = 0;
unsigned estimate = 0;
unsigned offset = 0;
vector<bluestore_onode_t::shard_info> new_shard_info;
unsigned max_blob_end = 0;
while (ep != extent_map.end()) {
dout(30) << " ep " << *ep << dendl;
assert(!ep->blob->is_spanning());
if (shard_end == 0 ||
ep->logical_offset >= shard_end) {
for (auto& e: extent_map) {
dout(30) << " extent " << e << dendl;
assert(!e.blob->is_spanning());
if (shard_end == 0 || e.logical_offset >= shard_end) {
if (sp == esp) {
// inline case
shard_end = o->onode.size;
Expand All @@ -1599,7 +1597,7 @@ void BlueStore::ExtentMap::reshard(Onode *o, uint64_t min_alloc_size)
<< std::dec << dendl;
}
// disfavor shard boundaries that span a blob
bool would_span = (ep->logical_offset < max_blob_end) || ep->blob_offset;
bool would_span = (e.logical_offset < max_blob_end) || e.blob_offset;
if (estimate &&
estimate + extent_avg > target + (would_span ? slop : 0)) {
// new shard
Expand All @@ -1609,19 +1607,18 @@ void BlueStore::ExtentMap::reshard(Onode *o, uint64_t min_alloc_size)
dout(20) << __func__ << " new shard 0x" << std::hex << offset
<< std::dec << dendl;
}
offset = ep->logical_offset;
offset = e.logical_offset;
new_shard_info.emplace_back(bluestore_onode_t::shard_info());
new_shard_info.back().offset = offset;
dout(20) << __func__ << " new shard 0x" << std::hex << offset << std::dec
<< dendl;
estimate = 0;
}
estimate += extent_avg;
uint32_t be = ep->blob_end();
uint32_t be = e.blob_end();
if (be > max_blob_end) {
max_blob_end = be;
}
++ep;
}
o->onode.extent_map_shards.swap(new_shard_info);

Expand All @@ -1632,7 +1629,6 @@ void BlueStore::ExtentMap::reshard(Onode *o, uint64_t min_alloc_size)
// identify spanning blobs
if (!o->onode.extent_map_shards.empty()) {
dout(20) << __func__ << " checking for spanning blobs" << dendl;
auto ep = extent_map.begin();
auto sp = o->onode.extent_map_shards.begin();
auto esp = o->onode.extent_map_shards.end();
unsigned shard_start = 0;
Expand All @@ -1644,9 +1640,9 @@ void BlueStore::ExtentMap::reshard(Onode *o, uint64_t min_alloc_size)
shard_end = sp->offset;
}
int bid = 0;
while (ep != extent_map.end()) {
dout(30) << " ep " << *ep << dendl;
while (ep->logical_offset >= shard_end) {
for (auto& e : extent_map) {
dout(30) << " extent " << e << dendl;
while (e.logical_offset >= shard_end) {
shard_start = shard_end;
++sp;
if (sp == esp) {
Expand All @@ -1657,17 +1653,17 @@ void BlueStore::ExtentMap::reshard(Onode *o, uint64_t min_alloc_size)
dout(30) << __func__ << " shard 0x" << std::hex << shard_start
<< " to 0x" << shard_end << std::dec << dendl;
}
if (ep->blob->id < 0 &&
ep->blob_escapes_range(shard_start, shard_end - shard_start)) {
if (e.blob->id < 0 &&
e.blob_escapes_range(shard_start, shard_end - shard_start)) {
// We have two options: (1) split the blob into pieces at the
// shard boundaries (and adjust extents accordingly), or (2)
// mark it spanning. We prefer to cut the blob if we can. Note that
// we may have to split it multiple times--potentially at every
// shard boundary.
bool must_span = false;
BlobRef b = ep->blob;
BlobRef b = e.blob;
if (b->can_split()) {
uint32_t bstart = ep->logical_offset - ep->blob_offset;
uint32_t bstart = e.logical_offset - e.blob_offset;
uint32_t bend = bstart + b->get_blob().get_logical_length();
for (const auto& sh : shards) {
if (bstart < sh.offset && bend > sh.offset) {
Expand Down Expand Up @@ -1697,7 +1693,6 @@ void BlueStore::ExtentMap::reshard(Onode *o, uint64_t min_alloc_size)
dout(20) << __func__ << " adding spanning " << *b << dendl;
}
}
++ep;
}
}
}
Expand Down

0 comments on commit d410573

Please sign in to comment.