Skip to content

Commit

Permalink
add is leader checker before any raft write option
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonYao287 committed Nov 26, 2024
1 parent d33b601 commit c4483a8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HomeObjectConan(ConanFile):
name = "homeobject"
version = "2.1.10"
version = "2.1.11"

homepage = "https://github.com/eBay/HomeObject"
description = "Blob Store built on HomeReplication"
Expand Down
5 changes: 5 additions & 0 deletions src/lib/homestore_backend/hs_blob_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ BlobManager::AsyncResult< blob_id_t > HSHomeObject::_put_blob(ShardInfo const& s

RELEASE_ASSERT(repl_dev != nullptr, "Repl dev instance null");

if (!repl_dev->is_leader()) {
LOGW("failed to put blob for pg [{}], not leader", pg_id);
return folly::makeUnexpected(BlobErrorCode::NOT_LEADER);
}

// Create a put_blob request which allocates for header, key and blob_header, user_key. Data sgs are added later
auto req = put_blob_req_ctx::make(sizeof(BlobHeader) + blob.user_key.size());
req->header()->msg_type = ReplicationMessageType::PUT_BLOB_MSG;
Expand Down
15 changes: 15 additions & 0 deletions src/lib/homestore_backend/hs_shard_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ ShardManager::AsyncResult< ShardInfo > HSHomeObject::_create_shard(pg_id_t pg_ow
return folly::makeUnexpected(ShardError::PG_NOT_READY);
}

if (!repl_dev->is_leader()) {
LOGW("failed to create shard for pg [{}], not leader", pg_owner);
return folly::makeUnexpected(ShardError::NOT_LEADER);
}

auto new_shard_id = generate_new_shard_id(pg_owner);
auto create_time = get_current_timestamp();

Expand Down Expand Up @@ -172,6 +177,16 @@ ShardManager::AsyncResult< ShardInfo > HSHomeObject::_seal_shard(ShardInfo const
RELEASE_ASSERT(repl_dev != nullptr, "Repl dev null");
}

if (!repl_dev) {
LOGW("failed to get repl dev instance for pg [{}]", pg_id);
return folly::makeUnexpected(ShardError::PG_NOT_READY);
}

if (!repl_dev->is_leader()) {
LOGW("failed to create shard for pg [{}], not leader", pg_id);
return folly::makeUnexpected(ShardError::NOT_LEADER);
}

ShardInfo tmp_info = info;
tmp_info.state = ShardInfo::State::SEALED;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/replication_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void ReplicationStateMachine::on_replace_member(const homestore::replica_member_
home_object_->on_pg_replace_member(repl_dev()->group_id(), member_out, member_in);
}

void ReplicationStateMachine::on_destroy() {
void ReplicationStateMachine::on_destroy(const homestore::group_id_t& group_id) {
// TODO:: add the logic to handle destroy
LOGI("replica destroyed");
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/homestore_backend/replication_state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ReplicationStateMachine : public homestore::ReplDevListener {
const homestore::replica_member_info& member_in) override;

/// @brief Called when the replica is being destroyed by nuraft;
void on_destroy() override;
void on_destroy(const homestore::group_id_t& group_id) override;

/// Not Implemented
/// @brief Called when the snapshot is being created by nuraft;
Expand Down

0 comments on commit c4483a8

Please sign in to comment.