Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDSTOR-11579. expose chunk and chunkSelector Header #157

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/include/homestore/chunk_selector.h
Original file line number Diff line number Diff line change
@@ -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 <homestore/vchunk.h>

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
39 changes: 39 additions & 0 deletions src/include/homestore/vchunk.h
Original file line number Diff line number Diff line change
@@ -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 <sisl/fds/buffer.hpp>
#include <homestore/blk.h>
#include <homestore/homestore_decl.hpp>

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;
hkadayam marked this conversation as resolved.
Show resolved Hide resolved
};
}// namespace homestore
2 changes: 1 addition & 1 deletion src/lib/blkdata_svc/blkdata_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*********************************************************************************/
#include <homestore/blkdata_service.hpp>
#include <homestore/homestore.hpp>
#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"
Expand Down
1 change: 1 addition & 0 deletions src/lib/device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
2 changes: 1 addition & 1 deletion src/lib/device/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/lib/device/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <boost/uuid/random_generator.hpp>

#include <homestore/homestore_decl.hpp>
#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"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/device/journal_vdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include <sisl/logging/logging.h>
#include <iomgr/iomgr_flip.hpp>
#include <homestore/homestore.hpp>
#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"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/device/physical_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <isa-l/crc.h>

#include <homestore/homestore_decl.hpp>
#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"

Expand Down
9 changes: 4 additions & 5 deletions src/lib/device/round_robin_chunk_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@
* 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} {
RELEASE_ASSERT_EQ(dynamic_chunk_add, false,
"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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,16 @@
*********************************************************************************/
#pragma once

#include <homestore/chunk_selector.h>

#include <vector>
#include <folly/ThreadLocal.h>
#include <sisl/logging/logging.h>

#include <homestore/homestore_decl.hpp>
#include <homestore/blk.h>
#include <homestore/vchunk.h>
#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);
Expand All @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions src/lib/device/vchunk.cpp
Original file line number Diff line number Diff line change
@@ -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 <homestore/vchunk.h>
#include "blkalloc/blk_allocator.h"
#include "device/chunk.h"

namespace homestore {
VChunk::VChunk(cshared< Chunk >& chunk) : internalChunk(chunk){}
hkadayam marked this conversation as resolved.
Show resolved Hide resolved

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();
JacksonYao287 marked this conversation as resolved.
Show resolved Hide resolved
};

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
6 changes: 3 additions & 3 deletions src/lib/device/virtual_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
#include <sisl/utility/atomic_counter.hpp>
#include <iomgr/iomgr_flip.hpp>

// #include <homestore/homestore.hpp>
#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)
Expand Down Expand Up @@ -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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkadayam This is dangerous as raw ptr/shared ptr are mixed used.

The cshare was born in PhysicalDev::create_chunks and all the way pass to chunkSelector, however the consumer part(allocator, etc) use raw ptr get from the cshare.

It is functioning fine as a reference to every chunk was kept at m_chunks_map but it is a bad practice. Maybe lets have a ticket to move those *chunk to cshare ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with this change of doing a .get() and select_chunk() returning a shared_ptr. Why incrementing atomic reference when all you are doing is accessing an in-memory member. I am not asking to change now, but will change in next PR.

I would rather return a chunk_id and look it up on the all chunks in vdev. If vdev doesn't maintain all chunks, then I would rather ask it to return a reference to chunks. This is a critical path for homestore, don't want unneccessary atomic reference increment and decrements.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the upstream (PhysicalDev::create_chunks ) use shared_ptr, if we dont want ref counting we can change the interface of add/select to ref/raw_ptr. It could work as pdev holds the shared_ptr that ensuring the chunks will not be de-construct, just not safe.

if (chunk == nullptr) { status = BlkAllocStatus::SPACE_FULL; }

status = alloc_blk_from_chunk(nblks, hints, out_blkid, chunk);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/device/virtual_dev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <homestore/checkpoint/cp_mgr.hpp>
#include <homestore/homestore_decl.hpp>
#include "device/device.h"
#include "device/chunk_selector.hpp"
#include <homestore/chunk_selector.h>

namespace homestore {
class PhysicalDev;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index/wb_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include <homestore/btree/detail/btree_node.hpp>
#include <homestore/index_service.hpp>
#include <homestore/homestore.hpp>
#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)
Expand Down
3 changes: 1 addition & 2 deletions src/lib/logstore/log_store_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
#include <homestore/meta_service.hpp>
#include <homestore/logstore_service.hpp>
#include <homestore/homestore.hpp>
#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"

Expand Down
3 changes: 2 additions & 1 deletion src/lib/logstore/log_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*********************************************************************************/
#include <isa-l/crc.h>

#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)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/meta/meta_blk_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

#include <homestore/meta_service.hpp>
#include <homestore/homestore.hpp>
#include "device/chunk.h"
#include <homestore/chunk_selector.h>
#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"

Expand Down
3 changes: 2 additions & 1 deletion src/tests/test_device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
#include <sisl/logging/logging.h>
#include <sisl/options/options.h>

#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)
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test_pdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#include <sisl/logging/logging.h>
#include <sisl/options/options.h>

#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)
Expand Down