From eb3df0b8e48dd22ae7c4bee11be3c455ff66dafb Mon Sep 17 00:00:00 2001 From: Jie Yao Date: Sun, 17 Sep 2023 04:43:32 -0700 Subject: [PATCH] update --- src/lib/homestore/heap_chunk_selector.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/homestore/heap_chunk_selector.cpp b/src/lib/homestore/heap_chunk_selector.cpp index ed28cfa6..6e2db4e1 100644 --- a/src/lib/homestore/heap_chunk_selector.cpp +++ b/src/lib/homestore/heap_chunk_selector.cpp @@ -29,10 +29,14 @@ csharedChunk HeapChunkSelector::select_chunk(homestore::blk_count_t count, const if(pdevID == homestore::INVALID_DEV_ID) { // this is the first shard of this pg, select a pdev with the most available blocks for it std::lock_guard l(lock); - auto it = std::max_element(m_pdev_avalable_blk_map.begin(), m_pdev_avalable_blk_map.end(), + auto& it = std::max_element(m_pdev_avalable_blk_map.begin(), m_pdev_avalable_blk_map.end(), [](const std::pair& lhs, const std::pair& rhs) { return lhs.second < rhs.second; } ); + if(it == m_pdev_avalable_blk_map.end()) { + LOGINFO("No pdev found for pg"); + return nullptr; + } pdevID = it->first; } @@ -41,13 +45,13 @@ csharedChunk HeapChunkSelector::select_chunk(homestore::blk_count_t count, const LOGINFO("No pdev found for pdev {}", pdevID); return nullptr; } - it->second->first.lock(); if(it->second->second.empty()) { LOGINFO("No more available chunks found for pdev {}", pdevID); return nullptr; } + auto& vchunk = it->second->second.top(); it->second->second.pop(); it->second->first.unlock();