@@ -132,7 +132,8 @@ PGManager::NullAsyncResult HSHomeObject::_create_pg(PGInfo&& pg_info, std::set<
132132 });
133133}
134134
135- PGManager::NullAsyncResult HSHomeObject::do_create_pg (cshared< homestore::ReplDev > repl_dev, PGInfo&& pg_info, trace_id_t tid) {
135+ PGManager::NullAsyncResult HSHomeObject::do_create_pg (cshared< homestore::ReplDev > repl_dev, PGInfo&& pg_info,
136+ trace_id_t tid) {
136137 auto serailized_pg_info = serialize_pg_info (pg_info);
137138 auto info_size = serailized_pg_info.size ();
138139
@@ -168,8 +169,8 @@ folly::Expected< HSHomeObject::HS_PG*, PGError > HSHomeObject::local_create_pg(s
168169
169170 auto local_chunk_size = chunk_selector ()->get_chunk_size ();
170171 if (pg_info.chunk_size != local_chunk_size) {
171- LOGE (" Chunk sizes are inconsistent, leader_chunk_size={}, local_chunk_size={}, trace_id: {}" , pg_info. chunk_size ,
172- local_chunk_size, tid);
172+ LOGE (" Chunk sizes are inconsistent, leader_chunk_size={}, local_chunk_size={}, trace_id: {}" ,
173+ pg_info. chunk_size , local_chunk_size, tid);
173174 return folly::makeUnexpected< PGError >(PGError::UNKNOWN);
174175 }
175176
@@ -218,7 +219,8 @@ void HSHomeObject::on_create_pg_message_commit(int64_t lsn, sisl::blob const& he
218219 auto const * msg_header = r_cast< ReplicationMessageHeader const * >(header.cbytes ());
219220
220221 if (msg_header->corrupted ()) {
221- LOGE (" create PG message header is corrupted , lsn:{}; header: {}, trace_id: {}" , lsn, msg_header->to_string (), tid);
222+ LOGE (" create PG message header is corrupted , lsn:{}; header: {}, trace_id: {}" , lsn, msg_header->to_string (),
223+ tid);
222224 if (ctx) { ctx->promise_ .setValue (folly::makeUnexpected (PGError::CRC_MISMATCH)); }
223225 return ;
224226 }
@@ -361,23 +363,28 @@ void HSHomeObject::mark_pg_destroyed(pg_id_t pg_id) {
361363 LOGD (" PG {} is marked as destroyed" , pg_id);
362364}
363365
364- void HSHomeObject::destroy_hs_resources (pg_id_t pg_id) {
365- chunk_selector_->reset_pg_chunks (pg_id);
366- }
366+ void HSHomeObject::destroy_hs_resources (pg_id_t pg_id) { chunk_selector_->reset_pg_chunks (pg_id); }
367367
368368void HSHomeObject::destroy_pg_index_table (pg_id_t pg_id) {
369- auto lg = std::scoped_lock (_pg_lock);
370- auto hs_pg = _get_hs_pg_unlocked (pg_id);
371- if (hs_pg == nullptr ) {
372- LOGW (" destroy pg index table with unknown pg_id {}" , pg_id);
373- return ;
369+ std::shared_ptr< BlobIndexTable > index_table;
370+
371+ {
372+ // index_table->destroy() will trigger a cp_flush, which will call homeobject#cp_flush and try to acquire
373+ // `_pg_lock`, so we need to release the lock here to avoid a dead lock
374+ auto lg = std::scoped_lock (_pg_lock);
375+ auto hs_pg = _get_hs_pg_unlocked (pg_id);
376+ if (hs_pg == nullptr ) {
377+ LOGW (" destroy pg index table with unknown pg_id {}" , pg_id);
378+ return ;
379+ }
380+ index_table = hs_pg->index_table_ ;
374381 }
375382
376- if (nullptr != hs_pg-> index_table_ ) {
377- auto uuid_str = boost::uuids::to_string (hs_pg-> index_table_ ->uuid ());
383+ if (nullptr != index_table ) {
384+ auto uuid_str = boost::uuids::to_string (index_table ->uuid ());
378385 index_table_pg_map_.erase (uuid_str);
379- hs ()->index_service ().remove_index_table (hs_pg-> index_table_ );
380- hs_pg-> index_table_ ->destroy ();
386+ hs ()->index_service ().remove_index_table (index_table );
387+ index_table ->destroy ();
381388 LOGD (" PG {} index table is destroyed" , pg_id);
382389 } else {
383390 LOGD (" PG {} index table is not found, skip destroy" , pg_id);
0 commit comments