Skip to content

Commit

Permalink
add chunk and chunkSelector Header
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonYao287 committed Sep 7, 2023
1 parent 8065a05 commit 1a0db6d
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 40 deletions.
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-2019 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(VChunk chunk) = 0;
virtual void foreach_chunks(std::function< void(VChunk&) >&& cb) = 0;
virtual Chunk* select(blk_count_t nblks, const blk_alloc_hints& hints) = 0;

virtual ~ChunkSelector() = default;
};
} // namespace homestore
38 changes: 38 additions & 0 deletions src/include/homestore/vchunk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*********************************************************************************
* Modifications Copyright 2017-2019 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 >&);
~VChunk() = default;

void set_user_private(const sisl::blob& data);
uint8_t* get_user_private();
blk_cap_t available_blks();
uint32_t getPdevID();
cshared< Chunk > getInternalChunk();

private:
cshared< Chunk > internalChunk;
};
}// 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.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ nlohmann::json Chunk::get_status([[maybe_unused]] int log_level) const {
j["slot_alloced?"] = is_busy();
return j;
}
} // namespace homestore
} // namespace homestore
2 changes: 1 addition & 1 deletion src/lib/device/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ class Chunk {
private:
void write_chunk_info();
};
} // namespace homestore
} // namespace homestore
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,23 +12,22 @@
* 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(VChunk chunk) { m_chunks.push_back(chunk); }

Chunk* RoundRobinChunkSelector::select(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)++].getInternalChunk().get();
}

void RoundRobinChunkSelector::foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) {
void RoundRobinChunkSelector::foreach_chunks(std::function< void(VChunk&) >&& cb) {
for (auto& chunk : m_chunks) {
cb(chunk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@
*********************************************************************************/
#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,14 +35,12 @@ class RoundRobinChunkSelector : public ChunkSelector {
RoundRobinChunkSelector& operator=(RoundRobinChunkSelector&&) noexcept = delete;
~RoundRobinChunkSelector() = default;

void add_chunk(cshared< Chunk >& chunk) override;

void add_chunk(VChunk chunk) override;
Chunk* select(blk_count_t nblks, const blk_alloc_hints& hints) override;

void foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) override;
void foreach_chunks(std::function< void(VChunk&) >&& cb) override;

private:
std::vector< shared< Chunk > > m_chunks;
std::vector< VChunk > m_chunks;
folly::ThreadLocal< uint32_t > m_next_chunk_index;
bool m_dynamic_chunk_add; // Can we add chunk dynamically
};
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-2019 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){}

void VChunk::set_user_private(const sisl::blob& data){
internalChunk->set_user_private(data);
}

uint8_t* VChunk::get_user_private() {
return internalChunk->user_private();
};

blk_cap_t VChunk::available_blks() {
return internalChunk->blk_allocator()->available_blks();
}

uint32_t VChunk::getPdevID() {
return internalChunk->physical_dev()->pdev_id();
}

cshared< Chunk > VChunk::getInternalChunk() {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"

SISL_LOGGING_DECL(device)

Expand Down Expand Up @@ -435,7 +435,7 @@ uint64_t VirtualDev::used_size() const {
}

void VirtualDev::cp_flush() {
m_chunk_selector->foreach_chunks([this](cshared< Chunk >& chunk) { chunk->cp_flush(); });
m_chunk_selector->foreach_chunks([this](VChunk& vchunk) { vchunk.getInternalChunk()->cp_flush(); });
}

std::vector< shared< Chunk > > VirtualDev::get_chunks() const { return m_all_chunks; }
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 @@ -33,7 +33,7 @@

#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

0 comments on commit 1a0db6d

Please sign in to comment.