Skip to content

Commit c7e7dfd

Browse files
committed
address comments
1 parent 7ed3511 commit c7e7dfd

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/lib/homestore_backend/hs_shard_manager.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,11 @@ ShardManager::AsyncResult< ShardInfo > HSHomeObject::_create_shard(pg_id_t pg_ow
158158
// now, we put allocate blk for shard head/footer in on_commit of create/seal shard, so we have to make sure that
159159
// the blk can be successfully allocated immediately(or after emergent gc). otherwise, on_commit can not go ahead
160160
// and the whole raft group will be blocked forever.
161-
162-
// +1 here means the created shard should have the capacity to hold at least one blob, otherwise we refuse this
163-
// request.
164161
const auto v_chunk_id = v_chunkID.value();
165-
const static uint64_t shard_super_blk_count{
166-
sisl::round_up(sizeof(shard_info_superblk), homestore::data_service().get_blk_size()) /
167-
homestore::data_service().get_blk_size()};
168-
169-
const static auto least_available_blk_count = 2 * shard_super_blk_count + 1;
170162
const auto exVchunk = chunk_selector()->get_pg_vchunk(pg_owner, v_chunk_id);
171-
if (exVchunk->available_blks() < least_available_blk_count) {
163+
164+
// only seal_shard(footer) can used reserved space, so +2 here means we can at least write a shard header and a blob
165+
if (exVchunk->available_blks() < get_reserved_blks() + 2) {
172166
const auto pchunk_id = exVchunk->get_chunk_id();
173167
LOGW("failed to create shard for pg={}, pchunk_id= {} is selected for vchunk_id={} is selected, not enough "
174168
"left space",
@@ -471,7 +465,7 @@ void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& h, sha
471465
homestore::BlkAllocStatus alloc_status;
472466
auto gc_mgr = gc_manager();
473467

474-
while (true) {
468+
for (uint8_t i = 0; i < 3; ++i) {
475469
alloc_status = homestore::data_service().alloc_blks(
476470
sisl::round_up(sizeof(shard_info_superblk), repl_dev->get_blk_size()), hints, blkids);
477471

@@ -500,6 +494,13 @@ void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& h, sha
500494
}
501495
}
502496

497+
if (alloc_status != homestore::BlkAllocStatus::SUCCESS) {
498+
RELEASE_ASSERT(
499+
false,
500+
"can not allocate blk for shard meta blk after trying for 3 times, fatal error! vchunk={}, pg={}, shard={}",
501+
vchunk_id, pg_id, shard_id);
502+
}
503+
503504
ShardInfo shard_info;
504505

505506
switch (header->msg_type) {

0 commit comments

Comments
 (0)