@@ -158,17 +158,12 @@ 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+ // except shard footer.
166+ if (exVchunk->available_blks () < get_reserved_blks () + 2 ) {
172167 const auto pchunk_id = exVchunk->get_chunk_id ();
173168 LOGW (" failed to create shard for pg={}, pchunk_id= {} is selected for vchunk_id={} is selected, not enough "
174169 " left space" ,
@@ -471,7 +466,7 @@ void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& h, sha
471466 homestore::BlkAllocStatus alloc_status;
472467 auto gc_mgr = gc_manager ();
473468
474- while ( true ) {
469+ for ( uint8_t i = 0 ; i < 3 ; ++i ) {
475470 alloc_status = homestore::data_service ().alloc_blks (
476471 sisl::round_up (sizeof (shard_info_superblk), repl_dev->get_blk_size ()), hints, blkids);
477472
@@ -500,6 +495,13 @@ void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& h, sha
500495 }
501496 }
502497
498+ if (alloc_status != homestore::BlkAllocStatus::SUCCESS) {
499+ RELEASE_ASSERT (
500+ false ,
501+ " can not allocate blk for shard meta blk after trying for 3 times, fatal error! vchunk={}, pg={}, shard={}" ,
502+ vchunk_id, pg_id, shard_id);
503+ }
504+
503505 ShardInfo shard_info;
504506
505507 switch (header->msg_type ) {
0 commit comments