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 1 commit
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-2019 eBay Inc.
JacksonYao287 marked this conversation as resolved.
Show resolved Hide resolved
*
* 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;
JacksonYao287 marked this conversation as resolved.
Show resolved Hide resolved
virtual void foreach_chunks(std::function< void(VChunk&) >&& cb) = 0;
virtual Chunk* select(blk_count_t nblks, const blk_alloc_hints& hints) = 0;
JacksonYao287 marked this conversation as resolved.
Show resolved Hide resolved
hkadayam marked this conversation as resolved.
Show resolved Hide resolved

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 >&);
szmyd marked this conversation as resolved.
Show resolved Hide resolved
~VChunk() = default;

void set_user_private(const sisl::blob& data);
uint8_t* get_user_private();
blk_cap_t available_blks();
uint32_t getPdevID();
JacksonYao287 marked this conversation as resolved.
Show resolved Hide resolved
cshared< Chunk > getInternalChunk();

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.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); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do std::move(chunk) instead of copy VChunk, which does increment and decrement of atomic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is back to the https://ebay-eng.slack.com/archives/CAVQXEAKS/p1694203171225199 discussion, vchunk only has single member <cshared_ptr>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure


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

void RoundRobinChunkSelector::foreach_chunks(std::function< void(cshared< Chunk >&) >&& cb) {
void RoundRobinChunkSelector::foreach_chunks(std::function< void(VChunk&) >&& cb) {
yamingk marked this conversation as resolved.
Show resolved Hide resolved
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to avoid std::function, to auto& and make use of lambda. If not, we don't want to call foreach_chunks on very critical path. I know it is a micro optimization, but one that accumulates over time.

Copy link
Contributor Author

@JacksonYao287 JacksonYao287 Sep 12, 2023

Choose a reason for hiding this comment

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

it is declared in a virtual class as a param of a virtual function. it tried , but the compiler throws an error that we can not use auto& or auto&& as parameter in a virtual function declaration.
we can keep it like this for now , and find another method to change it to lambda until it is necessary in the critical path


private:
std::vector< shared< Chunk > > m_chunks;
std::vector< VChunk > m_chunks;
hkadayam marked this conversation as resolved.
Show resolved Hide resolved
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){}
hkadayam marked this conversation as resolved.
Show resolved Hide resolved

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

uint8_t* VChunk::get_user_private() {
return internalChunk->user_private();
JacksonYao287 marked this conversation as resolved.
Show resolved Hide resolved
};

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