diff --git a/src/include/homestore/chunk_selector.h b/src/include/homestore/chunk_selector.h new file mode 100644 index 000000000..5c3a21a20 --- /dev/null +++ b/src/include/homestore/chunk_selector.h @@ -0,0 +1,30 @@ +/********************************************************************************* + * Modifications Copyright 2017-2023 eBay Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + *********************************************************************************/ +#pragma once + +#include + +namespace homestore { +class Chunk; +class ChunkSelector { +public: + ChunkSelector() = default; + virtual void add_chunk(cshared< Chunk >&) = 0; + virtual void foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) = 0; + virtual cshared< Chunk > select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) = 0; + + virtual ~ChunkSelector() = default; +}; +} // namespace homestore diff --git a/src/include/homestore/vchunk.h b/src/include/homestore/vchunk.h new file mode 100644 index 000000000..ed58a99a3 --- /dev/null +++ b/src/include/homestore/vchunk.h @@ -0,0 +1,39 @@ +/********************************************************************************* + * Modifications Copyright 2017-2023 eBay Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + *********************************************************************************/ +#pragma once + +#include +#include +#include + +namespace homestore { +class Chunk; + +class VChunk { +public: + VChunk(cshared< Chunk > const&); + + ~VChunk() = default; + + void set_user_private(const sisl::blob& data); + 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; + +private: + cshared< Chunk > internalChunk; +}; +}// namespace homestore diff --git a/src/lib/blkdata_svc/blkdata_service.cpp b/src/lib/blkdata_svc/blkdata_service.cpp index da8d23941..3c52f89de 100644 --- a/src/lib/blkdata_svc/blkdata_service.cpp +++ b/src/lib/blkdata_svc/blkdata_service.cpp @@ -15,9 +15,9 @@ *********************************************************************************/ #include #include +#include "device/chunk.h" #include "device/virtual_dev.hpp" #include "device/physical_dev.hpp" // vdev_info_block -#include "device/chunk.h" #include "common/homestore_config.hpp" // is_data_drive_hdd #include "common/homestore_assert.hpp" #include "common/error.h" diff --git a/src/lib/device/CMakeLists.txt b/src/lib/device/CMakeLists.txt index 9296a3107..ccd4f9030 100644 --- a/src/lib/device/CMakeLists.txt +++ b/src/lib/device/CMakeLists.txt @@ -11,5 +11,6 @@ target_sources(hs_device PRIVATE journal_vdev.cpp chunk.cpp round_robin_chunk_selector.cpp + vchunk.cpp ) target_link_libraries(hs_device hs_common ${COMMON_DEPS}) diff --git a/src/lib/device/chunk.h b/src/lib/device/chunk.h index 8ca71a6c1..71150b521 100644 --- a/src/lib/device/chunk.h +++ b/src/lib/device/chunk.h @@ -53,7 +53,7 @@ class Chunk { uint16_t chunk_id() const { return static_cast< uint16_t >(m_chunk_info.chunk_id); } uint64_t end_of_chunk() const { return m_chunk_info.end_of_chunk_size; } uint32_t pdev_ordinal() const { return m_chunk_info.chunk_ordinal; } - uint8_t* user_private() { return &m_chunk_info.user_private[0]; } + const uint8_t* user_private() { return &m_chunk_info.user_private[0]; } uint32_t stream_id() const { return m_stream_id; } uint32_t slot_number() const { return m_chunk_slot; } uint32_t vdev_ordinal() const { return m_vdev_ordinal; } diff --git a/src/lib/device/device_manager.cpp b/src/lib/device/device_manager.cpp index e9e16b550..1b06d2fd9 100644 --- a/src/lib/device/device_manager.cpp +++ b/src/lib/device/device_manager.cpp @@ -21,9 +21,9 @@ #include #include +#include "device/chunk.h" #include "device/device.h" #include "device/physical_dev.hpp" -#include "device/chunk.h" #include "device/virtual_dev.hpp" #include "common/homestore_utils.hpp" #include "common/homestore_assert.hpp" diff --git a/src/lib/device/journal_vdev.cpp b/src/lib/device/journal_vdev.cpp index 3ae7937dc..4240fc223 100644 --- a/src/lib/device/journal_vdev.cpp +++ b/src/lib/device/journal_vdev.cpp @@ -23,10 +23,10 @@ #include #include #include +#include "device/chunk.h" #include "device/device.h" #include "device/physical_dev.hpp" #include "device/journal_vdev.hpp" -#include "device/chunk.h" #include "common/error.h" #include "common/homestore_assert.hpp" #include "common/homestore_utils.hpp" diff --git a/src/lib/device/physical_dev.cpp b/src/lib/device/physical_dev.cpp index f44de8d21..163162efd 100644 --- a/src/lib/device/physical_dev.cpp +++ b/src/lib/device/physical_dev.cpp @@ -25,9 +25,9 @@ #include #include +#include "device/chunk.h" #include "device/physical_dev.hpp" #include "device/device.h" -#include "device/chunk.h" #include "common/homestore_utils.hpp" #include "common/homestore_assert.hpp" diff --git a/src/lib/device/round_robin_chunk_selector.cpp b/src/lib/device/round_robin_chunk_selector.cpp index 50937668c..aa73f7b56 100644 --- a/src/lib/device/round_robin_chunk_selector.cpp +++ b/src/lib/device/round_robin_chunk_selector.cpp @@ -12,8 +12,7 @@ * specific language governing permissions and limitations under the License. * *********************************************************************************/ -#include "device/chunk_selector.hpp" -#include "device/chunk.h" +#include "round_robin_chunk_selector.h" namespace homestore { RoundRobinChunkSelector::RoundRobinChunkSelector(bool dynamic_chunk_add) : m_dynamic_chunk_add{dynamic_chunk_add} { @@ -21,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(cshared< Chunk >& chunk) { m_chunks.push_back(chunk); } +void RoundRobinChunkSelector::add_chunk(cshared< Chunk >& chunk) { m_chunks.emplace_back(std::move(chunk)); } -Chunk* RoundRobinChunkSelector::select(blk_count_t, const blk_alloc_hints&) { +cshared< Chunk > 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(); + return m_chunks[(*m_next_chunk_index)++]; } void RoundRobinChunkSelector::foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) { diff --git a/src/lib/device/chunk_selector.hpp b/src/lib/device/round_robin_chunk_selector.h similarity index 75% rename from src/lib/device/chunk_selector.hpp rename to src/lib/device/round_robin_chunk_selector.h index af0736053..5a8f7a530 100644 --- a/src/lib/device/chunk_selector.hpp +++ b/src/lib/device/round_robin_chunk_selector.h @@ -14,26 +14,16 @@ *********************************************************************************/ #pragma once +#include + #include #include #include -#include -#include +#include +#include "device/chunk.h" namespace homestore { -class Chunk; - -class ChunkSelector { -public: - ChunkSelector() = default; - virtual void add_chunk(cshared< Chunk >& chunk) = 0; - virtual void foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) = 0; - virtual Chunk* select(blk_count_t nblks, const blk_alloc_hints& hints) = 0; - - virtual ~ChunkSelector() = default; -}; - class RoundRobinChunkSelector : public ChunkSelector { public: RoundRobinChunkSelector(bool dynamic_chunk_add = false); @@ -43,10 +33,8 @@ class RoundRobinChunkSelector : public ChunkSelector { RoundRobinChunkSelector& operator=(RoundRobinChunkSelector&&) noexcept = delete; ~RoundRobinChunkSelector() = default; - void add_chunk(cshared< Chunk >& chunk) override; - - Chunk* select(blk_count_t nblks, const blk_alloc_hints& hints) override; - + void add_chunk(cshared< Chunk >&) override; + cshared< Chunk > select_chunk(blk_count_t nblks, const blk_alloc_hints& hints) override; void foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) override; private: diff --git a/src/lib/device/vchunk.cpp b/src/lib/device/vchunk.cpp new file mode 100644 index 000000000..31860b446 --- /dev/null +++ b/src/lib/device/vchunk.cpp @@ -0,0 +1,39 @@ +/********************************************************************************* + * Modifications Copyright 2017-2023 eBay Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + *********************************************************************************/ +#include +#include "blkalloc/blk_allocator.h" +#include "device/chunk.h" + +namespace homestore { + VChunk::VChunk(cshared< Chunk >& chunk) : internalChunk(chunk){} + + void VChunk::set_user_private(const sisl::blob& data){ + internalChunk->set_user_private(data); + } + + const uint8_t* VChunk::get_user_private() const { + return internalChunk->user_private(); + }; + + blk_cap_t VChunk::available_blks() const { + return internalChunk->blk_allocator()->available_blks(); + } + + uint32_t VChunk::get_pdev_id() const { + return internalChunk->physical_dev()->pdev_id(); + } + + cshared< Chunk > VChunk::get_internal_chunk() const {return internalChunk;} +}// namespace homestore diff --git a/src/lib/device/virtual_dev.cpp b/src/lib/device/virtual_dev.cpp index 4580471c9..0d771d4ab 100644 --- a/src/lib/device/virtual_dev.cpp +++ b/src/lib/device/virtual_dev.cpp @@ -34,15 +34,15 @@ #include #include -// #include +#include "device/chunk.h" #include "device/physical_dev.hpp" #include "device/device.h" #include "device/virtual_dev.hpp" -#include "device/chunk.h" #include "common/error.h" #include "common/homestore_assert.hpp" #include "common/homestore_utils.hpp" #include "blkalloc/varsize_blk_allocator.h" +#include "device/round_robin_chunk_selector.h" #include "blkalloc/append_blk_allocator.h" SISL_LOGGING_DECL(device) @@ -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(nblks, hints); + chunk = m_chunk_selector->select_chunk(nblks, hints).get(); if (chunk == nullptr) { status = BlkAllocStatus::SPACE_FULL; } status = alloc_blk_from_chunk(nblks, hints, out_blkid, chunk); diff --git a/src/lib/device/virtual_dev.hpp b/src/lib/device/virtual_dev.hpp index 5de36905f..fe0e61ac5 100644 --- a/src/lib/device/virtual_dev.hpp +++ b/src/lib/device/virtual_dev.hpp @@ -34,7 +34,7 @@ #include #include #include "device/device.h" -#include "device/chunk_selector.hpp" +#include namespace homestore { class PhysicalDev; diff --git a/src/lib/index/wb_cache.cpp b/src/lib/index/wb_cache.cpp index 86e9a50f1..5b117ca03 100644 --- a/src/lib/index/wb_cache.cpp +++ b/src/lib/index/wb_cache.cpp @@ -17,12 +17,12 @@ #include #include #include +#include "device/chunk.h" #include "common/homestore_assert.hpp" #include "wb_cache.hpp" #include "index_cp.hpp" #include "device/virtual_dev.hpp" -#include "device/chunk.h" #include "common/resource_mgr.hpp" SISL_LOGGING_DECL(wbcache) diff --git a/src/lib/logstore/log_store_service.cpp b/src/lib/logstore/log_store_service.cpp index fa2cdf60e..ec3be9da9 100644 --- a/src/lib/logstore/log_store_service.cpp +++ b/src/lib/logstore/log_store_service.cpp @@ -23,13 +23,12 @@ #include #include #include +#include "device/chunk.h" #include "common/homestore_assert.hpp" #include "common/homestore_status_mgr.hpp" -#include "device/device.h" #include "device/journal_vdev.hpp" #include "device/physical_dev.hpp" -#include "device/chunk.h" #include "log_store_family.hpp" #include "log_dev.hpp" diff --git a/src/lib/logstore/log_stream.cpp b/src/lib/logstore/log_stream.cpp index 9a198927a..d7c0ce8e2 100644 --- a/src/lib/logstore/log_stream.cpp +++ b/src/lib/logstore/log_stream.cpp @@ -15,12 +15,13 @@ *********************************************************************************/ #include +#include "device/chunk.h" #include "common/homestore_assert.hpp" #include "common/homestore_config.hpp" #include "common/homestore_utils.hpp" #include "log_dev.hpp" #include "device/journal_vdev.hpp" -#include "device/chunk.h" + namespace homestore { SISL_LOGGING_DECL(logstore) diff --git a/src/lib/meta/meta_blk_service.cpp b/src/lib/meta/meta_blk_service.cpp index eda967e14..ac9268e5f 100644 --- a/src/lib/meta/meta_blk_service.cpp +++ b/src/lib/meta/meta_blk_service.cpp @@ -29,13 +29,13 @@ #include #include +#include "device/chunk.h" +#include #include "common/homestore_flip.hpp" #include "common/homestore_utils.hpp" #include "device/device.h" #include "device/virtual_dev.hpp" #include "device/physical_dev.hpp" -#include "device/chunk.h" -#include "device/chunk_selector.hpp" #include "blkalloc/blk_allocator.h" #include "meta_sb.hpp" diff --git a/src/tests/test_device_manager.cpp b/src/tests/test_device_manager.cpp index c6b1b32c1..d54e31a65 100644 --- a/src/tests/test_device_manager.cpp +++ b/src/tests/test_device_manager.cpp @@ -28,10 +28,11 @@ #include #include +#include "device/chunk.h" + #include "device/device.h" #include "device/physical_dev.hpp" #include "device/virtual_dev.hpp" -#include "device/chunk.h" using namespace homestore; SISL_LOGGING_INIT(HOMESTORE_LOG_MODS) diff --git a/src/tests/test_pdev.cpp b/src/tests/test_pdev.cpp index a90f584af..d5670abaf 100644 --- a/src/tests/test_pdev.cpp +++ b/src/tests/test_pdev.cpp @@ -28,9 +28,10 @@ #include #include +#include "device/chunk.h" + #include "device/device.h" #include "device/physical_dev.hpp" -#include "device/chunk.h" using namespace homestore; SISL_LOGGING_INIT(HOMESTORE_LOG_MODS)