If we are adding up the shards, and race with some allocations and
deallocations, we might get a negative sum. E.g., with 2 shards, intially
[0,0],
- A: read shard 0 (0)
- B: allocate object on shard 0 (now 1)
- C: dallocate object on shard 1 (now -1)
- A: read shard 1 (-1)
- A: sum is -1
Signed-off-by: Sage Weil <sage@redhat.com>
for (size_t i = 0; i < num_shards; ++i) {
result += shard[i].bytes;
}
- ceph_assert(result >= 0);
+ if (result < 0) {
+ // we raced with some unbalanced allocations/deallocations
+ result = 0;
+ }
return (size_t) result;
}
for (size_t i = 0; i < num_shards; ++i) {
result += shard[i].items;
}
- ceph_assert(result >= 0);
+ if (result < 0) {
+ // we raced with some unbalanced allocations/deallocations
+ result = 0;
+ }
return (size_t) result;
}