Skip to content

Commit c90de2b

Browse files
add chunk selector for index
1 parent 9555f6b commit c90de2b

13 files changed

+136
-99
lines changed

conanfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class HomeBlocksConan(ConanFile):
1111
name = "homeblocks"
12-
version = "2.1.2"
12+
version = "2.1.3"
1313
homepage = "https://github.com/eBay/HomeBlocks"
1414
description = "Block Store built on HomeStore"
1515
topics = ("ebay")
@@ -45,7 +45,7 @@ def build_requirements(self):
4545
self.test_requires("gtest/1.14.0")
4646

4747
def requirements(self):
48-
self.requires("homestore/[~6.18]@oss/master", transitive_headers=True)
48+
self.requires("homestore/[~6.20]@oss/master", transitive_headers=True)
4949
self.requires("iomgr/[^11.3]@oss/master", transitive_headers=True)
5050
self.requires("sisl/[^12.2]@oss/master", transitive_headers=True)
5151
self.requires("lz4/1.9.4", override=True)

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
LOGINFO("Filter callback for lba {}, existing value: {}", lba, existing_value_vol_idx.blkid().to_string());
@@ -40,12 +40,8 @@ class VolumeIndexTable {
4040
VolumeIndexKey key{lba};
4141
auto& block_info = blocks_info[lba];
4242
VolumeIndexValue value{block_info.new_blkid, block_info.new_checksum};
43-
auto req = homestore::BtreeSinglePutRequest{
44-
&key,
45-
&value,
46-
homestore::btree_put_type::UPSERT,
47-
nullptr /* existing value, not needed here */,
48-
filter_cb};
43+
auto req = homestore::BtreeSinglePutRequest{&key, &value, homestore::btree_put_type::UPSERT,
44+
nullptr /* existing value, not needed here */, filter_cb};
4945
auto result = hs_index_table_->put(req);
5046
#ifdef _PRERELEASE
5147
if (iomgr_flip::instance()->test_flip("vol_index_partial_put_failure")) {
@@ -59,8 +55,9 @@ class VolumeIndexTable {
5955
value = VolumeIndexValue{blocks_info[lba].old_blkid, blocks_info[lba].old_checksum};
6056
blocks_info[lba].old_blkid = homestore::BlkId{};
6157
blocks_info[lba].old_checksum = 0;
62-
auto req1 = homestore::BtreeSinglePutRequest{&key,&value,homestore::btree_put_type::UPSERT};
63-
if (auto restore_lba_result = hs_index_table_->put(req1); restore_lba_result != homestore::btree_status_t::success) {
58+
auto req1 = homestore::BtreeSinglePutRequest{&key, &value, homestore::btree_put_type::UPSERT};
59+
if (auto restore_lba_result = hs_index_table_->put(req1);
60+
restore_lba_result != homestore::btree_status_t::success) {
6461
LOGERROR("Failed to rollback lba {}, put error={}, NOT EXPECTED!", lba, restore_lba_result);
6562
}
6663
result = homestore::btree_status_t::not_supported;
@@ -78,26 +75,24 @@ class VolumeIndexTable {
7875
return folly::Unit();
7976
}
8077

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

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

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_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);

src/lib/volume/tests/test_volume_io.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class VolumeIOImpl {
158158
return data;
159159
}
160160

161-
void generate_write_io_single(lba_t start_lba = 0, uint32_t nblks = 0,
162-
bool wait = true, bool expect_failure = false) {
161+
void generate_write_io_single(lba_t start_lba = 0, uint32_t nblks = 0, bool wait = true,
162+
bool expect_failure = false) {
163163
// Generate a single io with start lba and nblks.
164164
auto latch = std::make_shared< std::latch >(1);
165165
auto data = build_random_data(start_lba, nblks, !expect_failure /*store the generated data*/);
@@ -330,8 +330,8 @@ class VolumeIOTest : public ::testing::Test {
330330
std::this_thread::sleep_for(std::chrono::seconds(3));
331331
}
332332

333-
void generate_write_io_single(shared< VolumeIOImpl > vol, lba_t start_lba = 0, uint32_t nblks = 0,
334-
bool wait = true, bool expect_failure = false) {
333+
void generate_write_io_single(shared< VolumeIOImpl > vol, lba_t start_lba = 0, uint32_t nblks = 0, bool wait = true,
334+
bool expect_failure = false) {
335335
vol->generate_write_io_single(start_lba, nblks, wait, expect_failure);
336336
}
337337

@@ -604,9 +604,8 @@ TEST_F(VolumeIOTest, LongRunningSequentialIO) {
604604
TEST_F(VolumeIOTest, WriteCrash) {
605605
LOGINFO("WriteCrash test started");
606606
// define all the flips to be set
607-
std::vector< std::string > flip_points = {
608-
"vol_write_crash_after_data_write", "vol_write_crash_after_journal_write"
609-
};
607+
std::vector< std::string > flip_points = {"vol_write_crash_after_data_write",
608+
"vol_write_crash_after_journal_write"};
610609

611610
// Crash after writing to disk but before writing to journal.
612611
// Read should return no data as there is no index.

0 commit comments

Comments
 (0)