Skip to content

Commit 518ec23

Browse files
add chunk selector for index (#125)
1 parent 8ac39f4 commit 518ec23

15 files changed

+247
-206
lines changed

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class HomeBlocksConan(ConanFile):
1111
name = "homeblocks"
12-
version = "2.1.4"
12+
version = "2.1.5"
1313
homepage = "https://github.com/eBay/HomeBlocks"
1414
description = "Block Store built on HomeStore"
1515
topics = ("ebay")

src/include/homeblks/volume_mgr.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ struct vol_interface_req : public sisl::ObjLifeCounter< vol_interface_req > {
2727
sisl::atomic_counter< int > refcount;
2828
bool part_of_batch{false};
2929
uint64_t request_id;
30-
VolumePtr vol{nullptr}; // back ref to the volume this request is associated with.
31-
Clock::time_point io_start_time; // time when the request reaches homeblks.
30+
VolumePtr vol{nullptr}; // back ref to the volume this request is associated with.
31+
Clock::time_point io_start_time; // time when the request reaches homeblks.
3232
Clock::time_point data_svc_start_time; // time when the request to data service starts.
33-
Clock::time_point index_start_time; // time when the request to index service starts.
33+
Clock::time_point index_start_time; // time when the request to index service starts.
3434

3535
friend void intrusive_ptr_add_ref(vol_interface_req* req) { req->refcount.increment(1); }
3636
friend void intrusive_ptr_release(vol_interface_req* req);

src/lib/homeblks_impl.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,24 @@ void HomeBlocksImpl::init_homestore() {
273273

274274
RELEASE_ASSERT(device_info.size() != 0, "No supported devices found!");
275275

276-
chunk_selector_ = std::make_shared< VolumeChunkSelector >(
277-
[this](uint64_t volume_ordinal, const std::vector< chunk_num_t >& chunk_ids) {
276+
volume_chunk_selector_ = std::make_shared< VolumeChunkSelector >(
277+
"volume", [this](uint64_t volume_ordinal, const std::vector< chunk_num_t >& chunk_ids) {
278278
update_vol_sb_cb(volume_ordinal, chunk_ids);
279279
});
280+
LOGI("Initialize index chunk selector");
281+
index_chunk_selector_ = std::make_shared< VolumeChunkSelector >(
282+
"index", [this](uint64_t volume_ordinal, const std::vector< chunk_num_t >& chunk_ids) {
283+
// Todo: decide it later whether needed for index
284+
});
285+
280286
using namespace homestore;
281287
// Note: timeline_consistency doesn't matter as we are using solo repl dev;
282288
auto repl_app =
283289
std::make_shared< HBReplApp >(repl_impl_type::solo, false /*timeline_consistency*/, this, _application);
284290
bool need_format = homestore::hs()
285-
->with_index_service(std::make_unique< HBIndexSvcCB >(this))
286-
.with_repl_data_service(repl_app, chunk_selector_) // custom volume chunk selector
291+
->with_index_service(std::make_unique< HBIndexSvcCB >(this),
292+
index_chunk_selector_) // custom index chunk selector
293+
.with_repl_data_service(repl_app, volume_chunk_selector_) // custom volume chunk selector
287294
.start(hs_input_params{.devices = device_info, .app_mem_size = app_mem_size},
288295
[this]() { register_metablk_cb(); });
289296
if (need_format) {
@@ -299,7 +306,11 @@ void HomeBlocksImpl::init_homestore() {
299306
{HS_SERVICE::LOG,
300307
hs_format_params{
301308
.dev_type = HSDevType::Fast, .size_pct = 45.0, .num_chunks = 0, .chunk_size = 32 * Mi}},
302-
{HS_SERVICE::INDEX, hs_format_params{.dev_type = HSDevType::Fast, .size_pct = 45.0}},
309+
{HS_SERVICE::INDEX,
310+
hs_format_params{.dev_type = HSDevType::Fast,
311+
.size_pct = 45.0,
312+
.num_chunks = 100,
313+
.chunk_sel_type = chunk_selector_type_t::CUSTOM}},
303314
{HS_SERVICE::REPLICATION,
304315
hs_format_params{.dev_type = HSDevType::Data,
305316
.size_pct = 95.0,
@@ -315,7 +326,11 @@ void HomeBlocksImpl::init_homestore() {
315326
{HS_SERVICE::META, hs_format_params{.dev_type = run_on_type, .size_pct = 5.0}},
316327
{HS_SERVICE::LOG,
317328
hs_format_params{.dev_type = run_on_type, .size_pct = 10.0, .num_chunks = 0, .chunk_size = 32 * Mi}},
318-
{HS_SERVICE::INDEX, hs_format_params{.dev_type = run_on_type, .size_pct = 5.0}},
329+
{HS_SERVICE::INDEX,
330+
hs_format_params{.dev_type = run_on_type,
331+
.size_pct = 5.0,
332+
.num_chunks = 100,
333+
.chunk_sel_type = chunk_selector_type_t::CUSTOM}},
319334
{HS_SERVICE::REPLICATION,
320335
hs_format_params{.dev_type = run_on_type,
321336
.size_pct = 75.0,

src/lib/homeblks_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
7474
bool recovery_done_{false};
7575
superblk< homeblks_sb_t > sb_;
7676
peer_id_t our_uuid_;
77-
shared< VolumeChunkSelector > chunk_selector_;
77+
shared< VolumeChunkSelector > volume_chunk_selector_;
78+
shared< VolumeChunkSelector > index_chunk_selector_;
7879
std::unique_ptr< sisl::IDReserver > ordinal_reserver_;
7980

8081
public:

src/lib/volume/index_fixed_kv.hpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class VolumeIndexKey : public homestore::BtreeKey {
7575

7676
static uint32_t get_fixed_size() { return sizeof(VolumeIndexKey); }
7777

78-
7978
/////////////////// Local methods for helping tests //////////////////
8079
bool operator<(const VolumeIndexKey& o) const { return (compare(o) < 0); }
8180
bool operator==(const VolumeIndexKey& other) const { return (compare(other) == 0); }
@@ -101,28 +100,22 @@ class VolumeIndexKey : public homestore::BtreeKey {
101100
class VolumeIndexValue : public homestore::BtreeValue {
102101
private:
103102
#pragma pack(1)
104-
// Store blkid and checksum as the value.
103+
// Store blkid and checksum as the value.
105104
BlkId m_blkid;
106105
homestore::csum_t m_checksum;
107106
#pragma pack()
108107

109108
public:
110-
VolumeIndexValue(const BlkId& base_blkid, homestore::csum_t csum) :
111-
homestore::BtreeValue(),
112-
m_blkid(base_blkid),
113-
m_checksum(csum) {}
109+
VolumeIndexValue(const BlkId& base_blkid, homestore::csum_t csum) :
110+
homestore::BtreeValue(), m_blkid(base_blkid), m_checksum(csum) {}
114111
VolumeIndexValue(const BlkId& base_blkid) : VolumeIndexValue(base_blkid, 0) {}
115112
VolumeIndexValue() = default;
116113
VolumeIndexValue(const VolumeIndexValue& other) :
117-
homestore::BtreeValue(),
118-
m_blkid(other.m_blkid),
119-
m_checksum(other.m_checksum) {}
114+
homestore::BtreeValue(), m_blkid(other.m_blkid), m_checksum(other.m_checksum) {}
120115
VolumeIndexValue(const sisl::blob& b, bool copy) : homestore::BtreeValue() { this->deserialize(b, copy); }
121116
virtual ~VolumeIndexValue() = default;
122117

123-
homestore::BlkId blkid() const {
124-
return m_blkid;
125-
}
118+
homestore::BlkId blkid() const { return m_blkid; }
126119

127120
homestore::csum_t checksum() const { return m_checksum; }
128121

src/lib/volume/index_fixed_table.hpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ using hs_index_table_t = homestore::IndexTable< VolumeIndexKey, VolumeIndexValue
1212

1313
class VolumeIndexTable {
1414
std::shared_ptr< hs_index_table_t > hs_index_table_;
15+
1516
public:
16-
template <typename... Args>
17-
VolumeIndexTable(Args&&... args) : hs_index_table_(std::make_shared< hs_index_table_t >(std::forward<Args>(args)...)) {
17+
template < typename... Args >
18+
VolumeIndexTable(Args&&... args) :
19+
hs_index_table_(std::make_shared< hs_index_table_t >(std::forward< Args >(args)...)) {
1820
LOGINFO("Created Fixed Index table, uuid {}", boost::uuids::to_string(hs_index_table_->uuid()));
1921
}
2022

21-
std::shared_ptr< hs_index_table_t > index_table() {
22-
return hs_index_table_;
23-
}
24-
23+
std::shared_ptr< hs_index_table_t > index_table() { return hs_index_table_; }
24+
2525
VolumeManager::Result< folly::Unit > write_to_index(lba_t start_lba, lba_t end_lba,
2626
std::unordered_map< lba_t, BlockInfo >& blocks_info) {
2727
// Use filter callback to get the old blkid.
2828
homestore::put_filter_cb_t filter_cb = [&blocks_info](BtreeKey const& key, BtreeValue const& existing_value,
29-
BtreeValue const& value) {
29+
BtreeValue const& value) {
3030
auto lba = r_cast< const VolumeIndexKey& >(key).lba();
3131
auto& existing_value_vol_idx = r_cast< const VolumeIndexValue& >(existing_value);
3232
blocks_info[lba].old_blkid = existing_value_vol_idx.blkid();
@@ -39,12 +39,8 @@ class VolumeIndexTable {
3939
VolumeIndexKey key{lba};
4040
auto& block_info = blocks_info[lba];
4141
VolumeIndexValue value{block_info.new_blkid, block_info.new_checksum};
42-
auto req = homestore::BtreeSinglePutRequest{
43-
&key,
44-
&value,
45-
homestore::btree_put_type::UPSERT,
46-
nullptr /* existing value, not needed here */,
47-
filter_cb};
42+
auto req = homestore::BtreeSinglePutRequest{&key, &value, homestore::btree_put_type::UPSERT,
43+
nullptr /* existing value, not needed here */, filter_cb};
4844
auto result = hs_index_table_->put(req);
4945
#ifdef _PRERELEASE
5046
if (iomgr_flip::instance()->test_flip("vol_index_partial_put_failure")) {
@@ -58,8 +54,9 @@ class VolumeIndexTable {
5854
value = VolumeIndexValue{blocks_info[lba].old_blkid, blocks_info[lba].old_checksum};
5955
blocks_info[lba].old_blkid = homestore::BlkId{};
6056
blocks_info[lba].old_checksum = 0;
61-
auto req1 = homestore::BtreeSinglePutRequest{&key,&value,homestore::btree_put_type::UPSERT};
62-
if (auto restore_lba_result = hs_index_table_->put(req1); restore_lba_result != homestore::btree_status_t::success) {
57+
auto req1 = homestore::BtreeSinglePutRequest{&key, &value, homestore::btree_put_type::UPSERT};
58+
if (auto restore_lba_result = hs_index_table_->put(req1);
59+
restore_lba_result != homestore::btree_status_t::success) {
6360
LOGERROR("Failed to rollback lba {}, put error={}, NOT EXPECTED!", lba, restore_lba_result);
6461
}
6562
result = homestore::btree_status_t::not_supported;
@@ -77,26 +74,24 @@ class VolumeIndexTable {
7774
return folly::Unit();
7875
}
7976

80-
VolumeManager::Result< folly::Unit > read_from_index(const vol_interface_req_ptr& req,
81-
index_kv_list_t& index_kvs) {
77+
VolumeManager::Result< folly::Unit > read_from_index(const vol_interface_req_ptr& req, index_kv_list_t& index_kvs) {
8278
homestore::BtreeQueryRequest< VolumeIndexKey > qreq{
8379
homestore::BtreeKeyRange< VolumeIndexKey >{VolumeIndexKey{req->lba}, VolumeIndexKey{req->end_lba()}},
8480
homestore::BtreeQueryType::SWEEP_NON_INTRUSIVE_PAGINATION_QUERY};
8581
if (auto ret = hs_index_table_->query(qreq, index_kvs); ret != homestore::btree_status_t::success) {
8682
return folly::makeUnexpected(VolumeError::INDEX_ERROR);
8783
}
88-
return folly::Unit();
84+
return folly::Unit();
8985
}
9086

91-
void rollback_write(lba_t start_lba, lba_t end_lba,
92-
std::unordered_map< lba_t, BlockInfo >& blocks_info) {
87+
void rollback_write(lba_t start_lba, lba_t end_lba, std::unordered_map< lba_t, BlockInfo >& blocks_info) {
9388
for (auto lba = start_lba; lba <= end_lba; ++lba) {
9489
VolumeIndexKey key{lba};
9590
VolumeIndexValue value;
9691
// If old_blk_id is valid, we need to restore it, otherwise remove the entry.
9792
if (blocks_info[lba].old_blkid.is_valid()) {
9893
value = VolumeIndexValue{blocks_info[lba].old_blkid, blocks_info[lba].old_checksum};
99-
auto req = homestore::BtreeSinglePutRequest{&key, &value, homestore::btree_put_type::UPSERT};
94+
auto req = homestore::BtreeSinglePutRequest{&key, &value, homestore::btree_put_type::UPSERT};
10095
if (auto result = hs_index_table_->put(req); result != homestore::btree_status_t::success) {
10196
LOGERROR("Failed to rollback lba {}, put error={}", lba, result);
10297
}

src/lib/volume/index_prefix_table.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ using hs_index_table_t = homestore::IndexTable< VolumeIndexKey, VolumeIndexValue
1212

1313
class VolumeIndexTable {
1414
std::shared_ptr< hs_index_table_t > hs_index_table_;
15+
1516
public:
16-
template <typename... Args>
17-
VolumeIndexTable(Args&&... args) : hs_index_table_(std::make_shared< hs_index_table_t >(std::forward<Args>(args)...)) {
17+
template < typename... Args >
18+
VolumeIndexTable(Args&&... args) :
19+
hs_index_table_(std::make_shared< hs_index_table_t >(std::forward< Args >(args)...)) {
1820
LOGINFO("Created Prefix Index table, uuid {}", boost::uuids::to_string(hs_index_table_->uuid()));
1921
}
2022

21-
std::shared_ptr< hs_index_table_t > index_table() {
22-
return hs_index_table_;
23-
}
24-
23+
std::shared_ptr< hs_index_table_t > index_table() { return hs_index_table_; }
24+
2525
VolumeManager::Result< folly::Unit > write_to_index(lba_t start_lba, lba_t end_lba,
2626
std::unordered_map< lba_t, BlockInfo >& blocks_info) {
2727
// Use filter callback to get the old blkid.
2828
homestore::put_filter_cb_t filter_cb = [&blocks_info](BtreeKey const& key, BtreeValue const& existing_value,
29-
BtreeValue const& value) {
29+
BtreeValue const& value) {
3030
auto lba = r_cast< const VolumeIndexKey& >(key).key();
3131
blocks_info[lba].old_blkid = r_cast< const VolumeIndexValue& >(existing_value).blkid();
3232
return homestore::put_filter_decision::replace;
@@ -54,15 +54,14 @@ class VolumeIndexTable {
5454
return folly::Unit();
5555
}
5656

57-
VolumeManager::Result< folly::Unit > read_from_index(const vol_interface_req_ptr& req,
58-
index_kv_list_t& index_kvs) {
57+
VolumeManager::Result< folly::Unit > read_from_index(const vol_interface_req_ptr& req, index_kv_list_t& index_kvs) {
5958
homestore::BtreeQueryRequest< VolumeIndexKey > qreq{
6059
homestore::BtreeKeyRange< VolumeIndexKey >{VolumeIndexKey{req->lba}, VolumeIndexKey{req->end_lba()}},
6160
homestore::BtreeQueryType::SWEEP_NON_INTRUSIVE_PAGINATION_QUERY};
6261
if (auto ret = hs_index_table_->query(qreq, index_kvs); ret != homestore::btree_status_t::success) {
6362
return folly::makeUnexpected(VolumeError::INDEX_ERROR);
6463
}
65-
return folly::Unit();
64+
return folly::Unit();
6665
}
6766

6867
void destroy() {

src/lib/volume/tests/test_common.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ using namespace homeblocks;
6262
class test_http_server {
6363
public:
6464
void get_prometheus_metrics(const Pistache::Rest::Request&, Pistache::Http::ResponseWriter response) {
65-
response.send(Pistache::Http::Code::Ok, sisl::MetricsFarm::getInstance().report(sisl::ReportFormat::kTextFormat));
65+
response.send(Pistache::Http::Code::Ok,
66+
sisl::MetricsFarm::getInstance().report(sisl::ReportFormat::kTextFormat));
6667
}
6768

6869
void start() {
6970
auto http_server_ptr = ioenvironment.get_http_server();
7071

7172
std::vector< iomgr::http_route > routes = {
72-
{Pistache::Http::Method::Get, "/metrics", Pistache::Rest::Routes::bind(&test_http_server::get_prometheus_metrics, this),
73-
iomgr::url_t::safe}
74-
};
73+
{Pistache::Http::Method::Get, "/metrics",
74+
Pistache::Rest::Routes::bind(&test_http_server::get_prometheus_metrics, this), iomgr::url_t::safe}};
7575
try {
7676
http_server_ptr->setup_routes(routes);
7777
LOGINFO("Started http server ");

src/lib/volume/tests/test_volume_chunk_selector.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class ChunkSelectorTest : public ::testing::Test {
122122
};
123123

124124
TEST_F(ChunkSelectorTest, AllocateReleaseChunksTest) {
125-
auto chunk_sel = std::make_shared< VolumeChunkSelector >([this](uint64_t, const std::vector< chunk_num_t >&) {});
125+
auto chunk_sel =
126+
std::make_shared< VolumeChunkSelector >("test", [this](uint64_t, const std::vector< chunk_num_t >&) {});
126127

127128
uint32_t pdevs = 3, num_chunks_per_pdev = 20, pdev_id;
128129
// Add chunks to chunk selector, each chunk is 16KB, so 3 * 20 * 16KB = 960KB
@@ -154,7 +155,8 @@ TEST_F(ChunkSelectorTest, AllocateReleaseChunksTest) {
154155
}
155156

156157
TEST_F(ChunkSelectorTest, SelectChunksTest) {
157-
auto chunk_sel = std::make_shared< VolumeChunkSelector >([this](uint64_t, const std::vector< chunk_num_t >&) {});
158+
auto chunk_sel =
159+
std::make_shared< VolumeChunkSelector >("test", [this](uint64_t, const std::vector< chunk_num_t >&) {});
158160
uint32_t pdevs = 3, num_chunks_per_pdev = 20, pdev_id;
159161
// Add chunks to chunk selector, each chunk is 16KB, so 3 * 20 * 16KB = 960KB
160162
add_chunks_per_pdev(chunk_sel, pdevs, num_chunks_per_pdev);
@@ -183,7 +185,7 @@ TEST_F(ChunkSelectorTest, SelectChunksTest) {
183185
TEST_F(ChunkSelectorTest, ResizeNumChunksTest) {
184186
auto latch = std::make_shared< std::latch >(1);
185187
auto chunk_sel = std::make_shared< VolumeChunkSelector >(
186-
[latch, this](uint64_t vol_ord, const std::vector< chunk_num_t >& chunk_ids) {
188+
"test", [latch, this](uint64_t vol_ord, const std::vector< chunk_num_t >& chunk_ids) {
187189
RELEASE_ASSERT(!chunk_ids.empty(), "Empty chunk ids");
188190
latch->count_down();
189191
});
@@ -213,7 +215,8 @@ TEST_F(ChunkSelectorTest, ResizeNumChunksTest) {
213215
#endif
214216

215217
TEST_F(ChunkSelectorTest, RecoverChunksTest) {
216-
auto chunk_sel = std::make_shared< VolumeChunkSelector >([this](uint64_t, const std::vector< chunk_num_t >&) {});
218+
auto chunk_sel =
219+
std::make_shared< VolumeChunkSelector >("test", [this](uint64_t, const std::vector< chunk_num_t >&) {});
217220
uint32_t pdevs = 3, num_chunks_per_pdev = 20;
218221
// Add chunks to chunk selector, each chunk is 16KB, so 3 * 20 * 16KB = 960KB
219222
add_chunks_per_pdev(chunk_sel, pdevs, num_chunks_per_pdev);

0 commit comments

Comments
 (0)