Skip to content

Commit ac67e14

Browse files
authored
Reserve space in a chunk (eBay#279)
1 parent 899f29e commit ac67e14

File tree

8 files changed

+26
-7
lines changed

8 files changed

+26
-7
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 HomeObjectConan(ConanFile):
1111
name = "homeobject"
12-
version = "2.3.7"
12+
version = "2.3.8"
1313

1414
homepage = "https://github.com/eBay/HomeObject"
1515
description = "Blob Store built on HomeReplication"
@@ -49,7 +49,7 @@ def build_requirements(self):
4949

5050
def requirements(self):
5151
self.requires("sisl/[^12.2]@oss/master", transitive_headers=True)
52-
self.requires("homestore/[>=6.8.0]@oss/master")
52+
self.requires("homestore/[>=6.9.0]@oss/master")
5353
self.requires("iomgr/[^11.3]@oss/master")
5454
self.requires("lz4/1.9.4", override=True)
5555
self.requires("openssl/3.3.1", override=True)

src/lib/homestore_backend/hs_backend_config.fbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ table HSBackendSettings {
1515

1616
//Snapshot blob load retry count
1717
snapshot_blob_load_retry: uint8 = 3 (hotswap);
18+
19+
//Reserved space in a chunk
20+
reserved_bytes_in_chunk: uint64 = 16777216 (hotswap);
1821
}
1922

2023
root_type HSBackendSettings;

src/lib/homestore_backend/hs_blob_manager.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "hs_backend_config.hpp"
12
#include "hs_homeobject.hpp"
23
#include "replication_message.hpp"
34
#include "replication_state_machine.hpp"
@@ -408,14 +409,18 @@ HSHomeObject::blob_put_get_blk_alloc_hints(sisl::blob const& header, cintrusive<
408409
homestore::blk_alloc_hints hints;
409410

410411
auto hs_shard = d_cast< HS_Shard* >((*shard_iter->second).get());
411-
BLOGD(tid, msg_header->shard_id, msg_header->blob_id, "Picked p_chunk_id=[{}]", hs_shard->sb_->p_chunk_id);
412412
hints.chunk_id_hint = hs_shard->sb_->p_chunk_id;
413+
if (hs_ctx->is_proposer()) { hints.reserved_blks = get_reserved_blks(); }
414+
BLOGD(tid, msg_header->shard_id, msg_header->blob_id, "Picked p_chunk_id={}, reserved_blks={}",
415+
hs_shard->sb_->p_chunk_id, get_reserved_blks());
413416

414417
if (msg_header->blob_id != 0) {
415418
// check if the blob already exists, if yes, return the blk id
416419
auto r = get_blob_from_index_table(hs_pg->index_table_, msg_header->shard_id, msg_header->blob_id);
417420
if (r.hasValue()) {
418-
BLOGT(tid, msg_header->shard_id, msg_header->blob_id, "Blob has already been persisted");
421+
BLOGT(tid, msg_header->shard_id, msg_header->blob_id,
422+
"Blob has already been persisted, blk_num={}, blk_count={}", r.value().blk_num(),
423+
r.value().blk_count());
419424
hints.committed_blk_id = r.value();
420425
}
421426
}

src/lib/homestore_backend/hs_homeobject.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ void HSHomeObject::init_homestore() {
123123
RELEASE_ASSERT(app_mem_size > 0, "Invalid app_mem_size");
124124
LOGI("Initialize and start HomeStore with app_mem_size = {}", homestore::in_bytes(app_mem_size));
125125

126+
if (HS_BACKEND_DYNAMIC_CONFIG(reserved_bytes_in_chunk) > 0) {
127+
_hs_reserved_blks = sisl::round_up(HS_BACKEND_DYNAMIC_CONFIG(reserved_bytes_in_chunk) / _data_block_size, 1);
128+
LOGI("will reserve {} blks in each chunk", _hs_reserved_blks);
129+
}
126130
std::vector< homestore::dev_info > device_info;
127131
bool has_data_dev = false;
128132
bool has_fast_dev = false;

src/lib/homestore_backend/hs_homeobject.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class HSHomeObject : public HomeObjectImpl {
4747
static constexpr uint64_t HS_CHUNK_SIZE = 2 * Gi;
4848
static constexpr uint32_t _data_block_size = 1024;
4949
static uint64_t _hs_chunk_size;
50+
uint32_t _hs_reserved_blks = 0;
5051
///
5152

5253
/// Overridable Helpers
@@ -792,6 +793,8 @@ class HSHomeObject : public HomeObjectImpl {
792793

793794
bool pg_exists(pg_id_t pg_id) const;
794795

796+
uint32_t get_reserved_blks() const { return _hs_reserved_blks; }
797+
795798
void on_create_pg_message_rollback(int64_t lsn, sisl::blob const& header, sisl::blob const& key,
796799
cintrusive< homestore::repl_req_ctx >& hs_ctx);
797800

src/lib/homestore_backend/hs_pg_manager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "hs_backend_config.hpp"
2+
13
#include <boost/uuid/random_generator.hpp>
24
#include <boost/uuid/string_generator.hpp>
35
#include <homestore/replication_service.hpp>
@@ -190,6 +192,7 @@ folly::Expected< HSHomeObject::HS_PG*, PGError > HSHomeObject::local_create_pg(s
190192
auto index_table = create_index_table();
191193
auto uuid_str = boost::uuids::to_string(index_table->uuid());
192194

195+
repl_dev->set_custom_rdev_name(fmt::format("rdev{}", pg_info.id));
193196
auto hs_pg = std::make_unique< HS_PG >(std::move(pg_info), std::move(repl_dev), index_table, chunk_ids);
194197
auto ret = hs_pg.get();
195198
{

src/lib/homestore_backend/replication_state_machine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void ReplicationStateMachine::on_error(ReplServiceError error, const sisl::blob&
149149
}
150150

151151
homestore::ReplResult< homestore::blk_alloc_hints >
152-
ReplicationStateMachine::get_blk_alloc_hints(sisl::blob const& header, uint32_t data_size) {
152+
ReplicationStateMachine::get_blk_alloc_hints(sisl::blob const& header, uint32_t data_size, cintrusive< homestore::repl_req_ctx >& hs_ctx) {
153153
const ReplicationMessageHeader* msg_header = r_cast< const ReplicationMessageHeader* >(header.cbytes());
154154
switch (msg_header->msg_type) {
155155
case ReplicationMessageType::CREATE_SHARD_MSG: {
@@ -172,6 +172,7 @@ ReplicationStateMachine::get_blk_alloc_hints(sisl::blob const& header, uint32_t
172172
static_assert(std::is_same< homestore::chunk_num_t, uint16_t >::value, "chunk_num_t is not uint16_t");
173173
homestore::chunk_num_t v_chunk_id = v_chunkID.value();
174174
hints.application_hint = ((uint64_t)pg_id << 16) | v_chunk_id;
175+
if (hs_ctx->is_proposer()) { hints.reserved_blks = home_object_->get_reserved_blks(); }
175176
return hints;
176177
}
177178

@@ -187,7 +188,7 @@ ReplicationStateMachine::get_blk_alloc_hints(sisl::blob const& header, uint32_t
187188
}
188189

189190
case ReplicationMessageType::PUT_BLOB_MSG:
190-
return home_object_->blob_put_get_blk_alloc_hints(header, nullptr);
191+
return home_object_->blob_put_get_blk_alloc_hints(header, hs_ctx);
191192

192193
case ReplicationMessageType::DEL_BLOB_MSG:
193194
default:

src/lib/homestore_backend/replication_state_machine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class ReplicationStateMachine : public homestore::ReplDevListener {
166166
/// @param header Header originally passed with repl_dev::write() api on the leader
167167
/// @return Expected to return blk_alloc_hints for this write
168168
homestore::ReplResult< homestore::blk_alloc_hints > get_blk_alloc_hints(sisl::blob const& header,
169-
uint32_t data_size) override;
169+
uint32_t data_size, cintrusive< homestore::repl_req_ctx >& hs_ctx) override;
170170

171171
/// @brief Called when replication module is replacing an existing member with a new member
172172
void on_replace_member(const homestore::replica_member_info& member_out,

0 commit comments

Comments
 (0)