From 849de5f7ee3f9d63fe4a94fddd039aaf36c021c0 Mon Sep 17 00:00:00 2001 From: Jie Yao Date: Tue, 12 Sep 2023 00:47:26 -0700 Subject: [PATCH] fix comments --- src/include/homestore/chunk_selector.h | 3 +-- src/include/homestore/vchunk.h | 2 +- src/lib/device/round_robin_chunk_selector.cpp | 6 +++--- src/lib/device/round_robin_chunk_selector.h | 4 +--- src/lib/device/virtual_dev.cpp | 4 ++-- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/include/homestore/chunk_selector.h b/src/include/homestore/chunk_selector.h index 818ea5e69..4cd53635c 100644 --- a/src/include/homestore/chunk_selector.h +++ b/src/include/homestore/chunk_selector.h @@ -17,13 +17,12 @@ #include namespace homestore { -class Chunk; class ChunkSelector { public: ChunkSelector() = default; virtual void add_chunk(VChunk chunk) = 0; virtual void foreach_chunks(std::function< void(VChunk&) >&& cb) = 0; - virtual Chunk* select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) = 0; + virtual VChunk select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) = 0; virtual ~ChunkSelector() = default; }; diff --git a/src/include/homestore/vchunk.h b/src/include/homestore/vchunk.h index a6ff0eb48..ed58a99a3 100644 --- a/src/include/homestore/vchunk.h +++ b/src/include/homestore/vchunk.h @@ -31,7 +31,7 @@ class VChunk { const uint8_t* get_user_private() const; blk_cap_t available_blks() const; uint32_t get_pdev_id() const; - cshared< Chunk > get_internal_chunk () const; + cshared< Chunk > get_internal_chunk() const; private: cshared< Chunk > internalChunk; diff --git a/src/lib/device/round_robin_chunk_selector.cpp b/src/lib/device/round_robin_chunk_selector.cpp index 3edc9ae3a..cbabbb864 100644 --- a/src/lib/device/round_robin_chunk_selector.cpp +++ b/src/lib/device/round_robin_chunk_selector.cpp @@ -20,11 +20,11 @@ RoundRobinChunkSelector::RoundRobinChunkSelector(bool dynamic_chunk_add) : m_dyn "Dynamically adding chunk to chunkselector is not supported, need RCU to make it thread safe"); } -void RoundRobinChunkSelector::add_chunk(VChunk chunk) { m_chunks.push_back(chunk); } +void RoundRobinChunkSelector::add_chunk(VChunk chunk) { m_chunks.emplace_back(std::move(chunk)); } -Chunk* RoundRobinChunkSelector::select_chunk(blk_count_t, const blk_alloc_hints&) { +VChunk RoundRobinChunkSelector::select_chunk(blk_count_t, const blk_alloc_hints&) { if (*m_next_chunk_index >= m_chunks.size()) { *m_next_chunk_index = 0; } - return m_chunks[(*m_next_chunk_index)++].get_internal_chunk().get(); + return m_chunks[(*m_next_chunk_index)++]; } void RoundRobinChunkSelector::foreach_chunks(std::function< void(VChunk&) >&& cb) { diff --git a/src/lib/device/round_robin_chunk_selector.h b/src/lib/device/round_robin_chunk_selector.h index cc916c9d3..58530d68e 100644 --- a/src/lib/device/round_robin_chunk_selector.h +++ b/src/lib/device/round_robin_chunk_selector.h @@ -24,8 +24,6 @@ #include "device/chunk.h" namespace homestore { -class Chunk; - class RoundRobinChunkSelector : public ChunkSelector { public: RoundRobinChunkSelector(bool dynamic_chunk_add = false); @@ -36,7 +34,7 @@ class RoundRobinChunkSelector : public ChunkSelector { ~RoundRobinChunkSelector() = default; void add_chunk(VChunk chunk) override; - Chunk* select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) override; + VChunk select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) override; void foreach_chunks(std::function< void(VChunk&) >&& cb) override; private: diff --git a/src/lib/device/virtual_dev.cpp b/src/lib/device/virtual_dev.cpp index cedf21e64..f969fe147 100644 --- a/src/lib/device/virtual_dev.cpp +++ b/src/lib/device/virtual_dev.cpp @@ -197,7 +197,7 @@ BlkAllocStatus VirtualDev::do_alloc_blk(blk_count_t nblks, const blk_alloc_hints size_t attempt{0}; do { - chunk = m_chunk_selector->select_chunk(nblks, hints); + chunk = m_chunk_selector->select_chunk(nblks, hints).get_internal_chunk().get(); if (chunk == nullptr) { status = BlkAllocStatus::SPACE_FULL; } status = alloc_blk_from_chunk(nblks, hints, out_blkid, chunk); @@ -532,7 +532,7 @@ std::unique_ptr< CPContext > VirtualDev::create_cp_context(cp_id_t cp_id) { void VirtualDev::cp_flush(CP* cp) { // pass down cp so that underlying componnents can get their customized CP context if needed; - m_chunk_selector->foreach_chunks([this, cp](cshared< Chunk >& chunk) { chunk->cp_flush(cp); }); + m_chunk_selector->foreach_chunks([this, cp](VChunk& chunk) { (chunk.get_internal_chunk())->cp_flush(cp); }); } // sync-ops during cp_flush, so return 100;