Skip to content

Commit 4fd93bd

Browse files
committed
refactor_create/seal_shard
1 parent 9bc58d9 commit 4fd93bd

File tree

11 files changed

+277
-345
lines changed

11 files changed

+277
-345
lines changed

conanfile.py

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

1111
class HomeObjectConan(ConanFile):
1212
name = "homeobject"
13-
version = "2.7.3"
13+
version = "2.7.4"
1414

1515
homepage = "https://github.com/eBay/HomeObject"
1616
description = "Blob Store built on HomeReplication"

src/lib/homestore_backend/gc_manager.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -556,27 +556,6 @@ bool GCManager::pdev_gc_actor::replace_blob_index(
556556
return true;
557557
}
558558

559-
sisl::sg_list GCManager::pdev_gc_actor::generate_shard_super_blk_sg_list(shard_id_t shard_id) {
560-
// TODO: do the buffer check before using it.
561-
auto raw_shard_sb = m_hs_home_object->_get_hs_shard(shard_id);
562-
RELEASE_ASSERT(raw_shard_sb, "can not find shard super blk for shard_id={} !!!", shard_id);
563-
564-
const auto shard_sb =
565-
const_cast< HSHomeObject::HS_Shard* >(d_cast< const HSHomeObject::HS_Shard* >(raw_shard_sb))->sb_.get();
566-
567-
auto blk_size = homestore::data_service().get_blk_size();
568-
auto shard_sb_size = sizeof(HSHomeObject::shard_info_superblk);
569-
auto total_size = sisl::round_up(shard_sb_size, blk_size);
570-
auto shard_sb_buf = iomanager.iobuf_alloc(blk_size, total_size);
571-
572-
std::memcpy(shard_sb_buf, shard_sb, shard_sb_size);
573-
574-
sisl::sg_list shard_sb_sgs;
575-
shard_sb_sgs.size = total_size;
576-
shard_sb_sgs.iovs.emplace_back(iovec{.iov_base = shard_sb_buf, .iov_len = total_size});
577-
return shard_sb_sgs;
578-
}
579-
580559
// note that, when we copy data, there is not create shard or put blob in this chunk, only delete blob might happen.
581560
bool GCManager::pdev_gc_actor::copy_valid_data(chunk_id_t move_from_chunk, chunk_id_t move_to_chunk,
582561
const uint64_t task_id) {
@@ -696,7 +675,7 @@ bool GCManager::pdev_gc_actor::copy_valid_data(chunk_id_t move_from_chunk, chunk
696675
}
697676

698677
// prepare a shard header for this shard in move_to_chunk
699-
sisl::sg_list header_sgs = generate_shard_super_blk_sg_list(shard_id);
678+
sisl::sg_list header_sgs = m_hs_home_object->generate_shard_super_blk_sg_list(shard_id);
700679

701680
// we ignore the state in shard header blk. we never read a shard header since we don`t know where it is(nor
702681
// record the pba in indextable)
@@ -841,7 +820,7 @@ bool GCManager::pdev_gc_actor::copy_valid_data(chunk_id_t move_from_chunk, chunk
841820
}
842821

843822
// 3 write a shard footer for this shard
844-
sisl::sg_list footer_sgs = generate_shard_super_blk_sg_list(shard_id);
823+
sisl::sg_list footer_sgs = m_hs_home_object->generate_shard_super_blk_sg_list(shard_id);
845824
return folly::collectAllUnsafe(futs)
846825
.thenValue([this, &is_last_shard, &shard_id, &blk_size, &hints, &move_to_chunk,
847826
&last_shard_state, task_id, &data_service, footer_sgs](auto&& results) {

src/lib/homestore_backend/gc_manager.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,6 @@ class GCManager {
237237

238238
pdev_gc_metrics& metrics() { return metrics_; }
239239

240-
private:
241-
// utils
242-
sisl::sg_list generate_shard_super_blk_sg_list(shard_id_t shard_id);
243-
244240
private:
245241
uint32_t m_pdev_id;
246242
std::shared_ptr< HeapChunkSelector > m_chunk_selector;

src/lib/homestore_backend/heap_chunk_selector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ std::optional< homestore::chunk_num_t > HeapChunkSelector::get_most_available_bl
533533
LOGWARNMOD(homeobject, "No available chunk for pg={}, ctx=0x{:x}", pg_id, ctx);
534534
return std::nullopt;
535535
}
536+
536537
auto v_chunk_id = std::distance(pg_chunks.begin(), max_it);
537538
LOGDEBUGMOD(homeobject, "Picked v_chunk_id={} : [p_chunk_id={}, avail={}], ctx=0x{:x}", v_chunk_id,
538539
pg_chunks[v_chunk_id]->get_chunk_id(), pg_chunks[v_chunk_id]->available_blks(), ctx);

src/lib/homestore_backend/hs_blob_manager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ HSHomeObject::blob_put_get_blk_alloc_hints(sisl::blob const& header, cintrusive<
401401
return folly::makeUnexpected(homestore::ReplServiceError::FAILED);
402402
}
403403

404+
if (msg_header->msg_type != ReplicationMessageType::PUT_BLOB_MSG) {
405+
LOGW("traceID={}, shardID=0x{:x}, pg={}, shard=0x{:x}, unsupported message type {}, reject it!", tid,
406+
msg_header->shard_id, (msg_header->shard_id >> homeobject::shard_width),
407+
(msg_header->shard_id & homeobject::shard_mask), msg_header->pg_id, msg_header->msg_type);
408+
if (ctx) { ctx->promise_.setValue(folly::makeUnexpected(BlobError(BlobErrorCode::UNSUPPORTED_OP))); }
409+
return folly::makeUnexpected(homestore::ReplServiceError::RESULT_NOT_EXIST_YET);
410+
}
411+
404412
auto hs_pg = get_hs_pg(msg_header->pg_id);
405413
if (hs_pg == nullptr) {
406414
LOGW("traceID={}, shardID=0x{:x}, pg={}, shard=0x{:x}, Received a blob_put on an unknown pg={}, underlying "
@@ -425,6 +433,14 @@ HSHomeObject::blob_put_get_blk_alloc_hints(sisl::blob const& header, cintrusive<
425433

426434
auto hs_shard = d_cast< HS_Shard* >((*shard_iter->second).get());
427435

436+
if (hs_shard->sb_->info.state != ShardInfo::State::OPEN) {
437+
LOGW("traceID={}, shardID=0x{:x}, pg={}, shard=0x{:x}, Received a blob_put on an unopen shard, reject it!", tid,
438+
msg_header->shard_id, (msg_header->shard_id >> homeobject::shard_width),
439+
(msg_header->shard_id & homeobject::shard_mask));
440+
if (ctx) { ctx->promise_.setValue(folly::makeUnexpected(BlobError(BlobErrorCode::SEALED_SHARD))); }
441+
return folly::makeUnexpected(homestore::ReplServiceError::RESULT_NOT_EXIST_YET);
442+
}
443+
428444
homestore::blk_alloc_hints hints;
429445
hints.chunk_id_hint = hs_shard->sb_->p_chunk_id;
430446
if (hs_ctx->is_proposer()) { hints.reserved_blks = get_reserved_blks(); }

src/lib/homestore_backend/hs_homeobject.hpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ class HSHomeObject : public HomeObjectImpl {
800800
* @param repl_dev The replication device.
801801
* @param hs_ctx The replication request context.
802802
*/
803-
void on_shard_message_commit(int64_t lsn, sisl::blob const& header, homestore::MultiBlkId const& blkids,
804-
shared< homestore::ReplDev > repl_dev, cintrusive< homestore::repl_req_ctx >& hs_ctx);
803+
void on_shard_message_commit(int64_t lsn, sisl::blob const& header, shared< homestore::ReplDev > repl_dev,
804+
cintrusive< homestore::repl_req_ctx >& hs_ctx);
805805

806806
bool on_shard_message_pre_commit(int64_t lsn, sisl::blob const& header, sisl::blob const& key,
807807
cintrusive< homestore::repl_req_ctx >& hs_ctx);
@@ -841,16 +841,6 @@ class HSHomeObject : public HomeObjectImpl {
841841
*/
842842
void on_replica_restart();
843843

844-
/**
845-
* @brief Extracts the physical chunk ID for create shard from the message.
846-
*
847-
* @param header The message header that includes the shard_info_superblk, which contains the data necessary for
848-
* extracting and mapping the chunk ID.
849-
* @return An optional virtual chunk id if the extraction and mapping process is successful, otherwise an empty
850-
* optional.
851-
*/
852-
std::optional< homestore::chunk_num_t > resolve_v_chunk_id_from_msg(sisl::blob const& header);
853-
854844
/**
855845
* @brief Releases a chunk based on the information provided in a CREATE_SHARD message.
856846
*
@@ -904,6 +894,8 @@ class HSHomeObject : public HomeObjectImpl {
904894
void update_pg_meta_after_gc(const pg_id_t pg_id, const homestore::chunk_num_t move_from_chunk,
905895
const homestore::chunk_num_t move_to_chunk, const uint64_t task_id);
906896

897+
sisl::sg_list generate_shard_super_blk_sg_list(shard_id_t shard_id);
898+
907899
uint32_t get_pg_tombstone_blob_count(pg_id_t pg_id) const;
908900

909901
// Snapshot persistence related

0 commit comments

Comments
 (0)