-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SealShard state change in pre-commit #120
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,90 @@ ShardManager::AsyncResult< ShardInfo > HSHomeObject::_seal_shard(ShardInfo const | |
return req->result(); | ||
} | ||
|
||
// move seal_shard to pre_commit can not fundamentally solve the conflict between seal_shard and put_blob, since | ||
// put_blob handler will only check the shard state at the very beginning and will not check again before proposing to | ||
// raft, so we need a callback to check whether we can handle this request before appending log, which is previous to | ||
// pre_commit. | ||
|
||
// FIXME after we have the callback, which is coming in homestore. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. an issue in HS and HO respectively, pls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
|
||
bool HSHomeObject::on_shard_message_pre_commit(int64_t lsn, sisl::blob const& header, sisl::blob const& key, | ||
cintrusive< homestore::repl_req_ctx >& hs_ctx) { | ||
repl_result_ctx< ShardManager::Result< ShardInfo > >* ctx{nullptr}; | ||
if (hs_ctx && hs_ctx->is_proposer) { | ||
ctx = boost::static_pointer_cast< repl_result_ctx< ShardManager::Result< ShardInfo > > >(hs_ctx).get(); | ||
} | ||
const ReplicationMessageHeader* msg_header = r_cast< const ReplicationMessageHeader* >(header.cbytes()); | ||
if (msg_header->corrupted()) { | ||
LOGW("replication message header is corrupted with crc error, lsn:{}", lsn); | ||
if (ctx) { ctx->promise_.setValue(folly::makeUnexpected(ShardError::CRC_MISMATCH)); } | ||
return false; | ||
} | ||
switch (msg_header->msg_type) { | ||
case ReplicationMessageType::SEAL_SHARD_MSG: { | ||
auto sb = r_cast< shard_info_superblk const* >(header.cbytes() + sizeof(ReplicationMessageHeader)); | ||
auto const shard_info = sb->info; | ||
|
||
{ | ||
std::scoped_lock lock_guard(_shard_lock); | ||
auto iter = _shard_map.find(shard_info.id); | ||
RELEASE_ASSERT(iter != _shard_map.end(), "Missing shard info"); | ||
auto& state = (*iter->second)->info.state; | ||
// we just change the state to SEALED, so that it will fail the later coming put_blob on this shard and will | ||
// be easy for rollback. | ||
// the update of superblk will be done in on_shard_message_commit; | ||
if (state == ShardInfo::State::OPEN) { | ||
state = ShardInfo::State::SEALED; | ||
} else { | ||
LOGW("try to seal an unopen shard, shard_id: {}", shard_info.id); | ||
} | ||
} | ||
} | ||
default: { | ||
break; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
void HSHomeObject::on_shard_message_rollback(int64_t lsn, sisl::blob const& header, sisl::blob const& key, | ||
cintrusive< homestore::repl_req_ctx >& hs_ctx) { | ||
repl_result_ctx< ShardManager::Result< ShardInfo > >* ctx{nullptr}; | ||
if (hs_ctx && hs_ctx->is_proposer) { | ||
ctx = boost::static_pointer_cast< repl_result_ctx< ShardManager::Result< ShardInfo > > >(hs_ctx).get(); | ||
} | ||
const ReplicationMessageHeader* msg_header = r_cast< const ReplicationMessageHeader* >(header.cbytes()); | ||
if (msg_header->corrupted()) { | ||
LOGW("replication message header is corrupted with crc error, lsn:{}", lsn); | ||
if (ctx) { ctx->promise_.setValue(folly::makeUnexpected(ShardError::CRC_MISMATCH)); } | ||
return; | ||
} | ||
|
||
switch (msg_header->msg_type) { | ||
case ReplicationMessageType::SEAL_SHARD_MSG: { | ||
auto sb = r_cast< shard_info_superblk const* >(header.cbytes() + sizeof(ReplicationMessageHeader)); | ||
auto const shard_info = sb->info; | ||
{ | ||
std::scoped_lock lock_guard(_shard_lock); | ||
auto iter = _shard_map.find(shard_info.id); | ||
RELEASE_ASSERT(iter != _shard_map.end(), "Missing shard info"); | ||
auto& state = (*iter->second)->info.state; | ||
// we just change the state to SEALED, since it will be easy for rollback | ||
// the update of superblk will be done in on_shard_message_commit; | ||
if (state == ShardInfo::State::SEALED) { | ||
state = ShardInfo::State::OPEN; | ||
} else { | ||
LOGW("try to rollback seal_shard message , but the shard state is not sealed. shard_id: {}", | ||
shard_info.id); | ||
} | ||
} | ||
} | ||
default: { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& h, homestore::MultiBlkId const& blkids, | ||
shared< homestore::ReplDev > repl_dev, | ||
cintrusive< homestore::repl_req_ctx >& hs_ctx) { | ||
|
@@ -259,12 +343,13 @@ void HSHomeObject::on_shard_message_commit(int64_t lsn, sisl::blob const& h, hom | |
state = (*iter->second)->info.state; | ||
} | ||
|
||
if (state == ShardInfo::State::OPEN) { | ||
if (state == ShardInfo::State::SEALED) { | ||
auto chunk_id = get_shard_chunk(shard_info.id); | ||
RELEASE_ASSERT(chunk_id.has_value(), "Chunk id not found"); | ||
chunk_selector()->release_chunk(chunk_id.value()); | ||
update_shard_in_map(shard_info); | ||
} | ||
} else | ||
LOGW("try to commit SEAL_SHARD_MSG but shard state is not sealed, shard_id: {}", shard_info.id); | ||
if (ctx) { ctx->promise_.setValue(ShardManager::Result< ShardInfo >(shard_info)); } | ||
break; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prior to the pre_commit of put_blob
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for pointing out this misusing , will be careful!