Skip to content
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

SDSTOR-11601 add create_shard implementation #34

Merged
merged 11 commits into from
Sep 19, 2023

Conversation

zichanglai
Copy link
Contributor

@zichanglai zichanglai commented Sep 1, 2023

this is the draft version of create_shard implementation in homeobject and can not build successfully until ReplDev in homestore is finalized.

@zichanglai

This comment was marked as resolved.

@zichanglai zichanglai closed this Sep 4, 2023
@zichanglai zichanglai reopened this Sep 4, 2023
@zichanglai zichanglai force-pushed the create_shard branch 3 times, most recently from 9945e64 to d933d65 Compare September 5, 2023 05:21
@zichanglai zichanglai force-pushed the create_shard branch 3 times, most recently from 9d064e8 to b17a28d Compare September 6, 2023 13:07
szmyd

This comment was marked as resolved.

szmyd

This comment was marked as resolved.

@zichanglai

This comment was marked as resolved.

Copy link
Collaborator

@JacksonYao287 JacksonYao287 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we miss the implement on_precommit and async_alloc_write for now, and will be implemented later?

src/lib/homeobject_impl.hpp Outdated Show resolved Hide resolved
src/lib/homeobject_impl.hpp Outdated Show resolved Hide resolved
src/lib/homeobject_impl.hpp Outdated Show resolved Hide resolved
src/lib/homestore/homeobject.cpp Outdated Show resolved Hide resolved
src/lib/homestore/shard_manager.cpp Outdated Show resolved Hide resolved
src/lib/homestore/shard_manager.cpp Outdated Show resolved Hide resolved
pg_iter->second.shards.push_back(shard_info);

//following part is must for follower members or when member is restarted;
auto sequence_num = get_sequence_num_from_shard_id(shard_info->id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the follower apply all the logs correctly, will this happen? or it is just a way to keep safe here

another question, should we flush the pg_sequence_number to metadataservice or somewhere else to make sure will will get the latest sequence_number when restarting, or just set the largest sequence_num(get from shardid)of all the recovered shardid as the latest sequence_number of this pg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.follower will happens, shard is generated from the leader side and sequence num s increased only in leader side, this gives the chance for follower to catch up sequence num with leader.
2. it is better to flush pg_sequence_number to disk but it will cause extra IO and I am trying to avoid it by recovering the lastest sequence num from meta blks, as all commited shard creation is already persisted in meta blks. there are still another two options for this from my side: using raft LSN or combined with (raft term , local sequence num) to be new proposal shard id

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer lastest sequence num from meta blks, that is the source of truth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is the current implementation behaviors.

src/lib/homestore/shard_manager.cpp Show resolved Hide resolved
src/lib/homestore/shard_manager.cpp Outdated Show resolved Hide resolved
src/lib/homestore/shard_manager.cpp Outdated Show resolved Hide resolved
szmyd

This comment was marked as outdated.

@szmyd

This comment was marked as outdated.

@zichanglai
Copy link
Contributor Author

This PR still needs to take the create_shared tests from MemoryShardManager tests so we can get a code-coverage check. The few tests there should cover most paths we care about as is I think.

yes, homestore version ShardManager unit test is added in the latest commit.

src/lib/homestore/shard_manager.cpp Outdated Show resolved Hide resolved
auto iter = _flying_shards.find(lsn);
if (iter != _flying_shards.end()) {
_flying_shards.erase(iter);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, should we delete the block written in on_precommit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think. I think the written shard header will be used for recovery in case of meta blks are lost from the previous discussion meeting.

Copy link
Collaborator

@JacksonYao287 JacksonYao287 Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we rollback the pre_commit, this means this is a canceled create_shard, why to recovery this?

coming to this, i have another question. when rolling back a pre_commit, seems nuraft does not append a log for rollback, what the statemachine does is just call the rollback function(i just only read the nuraft doc, but not deep dive the code for now, so if this is wrong, please correct me). so , if it crashes after we called pre_commit but before or not finish calling statemachie#rollback , who will take the task to finish the rollback job after restart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yes, it is absolutely more clear to truncate/overwrite the shard header which is already written in on_pre_commit(), but homestore DataService is append-only model, I think overwritten is conflict with this model. even this shard header is leaked, I think it will be finalized recycled by chunk compaction, right? because this log is rollbacked and will never be commited, so from the homeobject side, it can not see this shard any more(whether now or after recovery).
  2. I think your mentioned case may happens, restart happens after on_pre_commit() but before on_rollback(), in such case, this shard header is leaked, but same to question 1, it will be recycled finalized.

src/lib/homestore/shard_manager.cpp Outdated Show resolved Hide resolved
src/lib/homestore/shard_manager.cpp Outdated Show resolved Hide resolved
@szmyd

This comment was marked as outdated.

@zichanglai zichanglai requested a review from yamingk September 15, 2023 00:19
@zichanglai
Copy link
Contributor Author

Can you merge main? I think that may be the reason we're not seeing coverage reports...

Also force-pushing makes reviewing incredibly difficult. If we can just merge that'd be best; we can always squash at the end.

sure, I do not realize it before and will take cake of this from now.

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2023

Codecov Report

Patch coverage: 82.69% and project coverage change: +0.40% 🎉

Comparison is base (291b070) 81.04% compared to head (3b9a0a6) 81.44%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #34      +/-   ##
==========================================
+ Coverage   81.04%   81.44%   +0.40%     
==========================================
  Files          16       18       +2     
  Lines         248      469     +221     
  Branches       26       48      +22     
==========================================
+ Hits          201      382     +181     
- Misses         31       57      +26     
- Partials       16       30      +14     
Files Changed Coverage Δ
src/include/homeobject/shard_manager.hpp 0.00% <ø> (ø)
src/lib/homestore/replication_state_machine.cpp 72.00% <72.00%> (ø)
src/lib/blob_manager.cpp 83.33% <75.00%> (ø)
src/lib/homestore/homeobject.cpp 85.00% <80.00%> (-3.47%) ⬇️
src/lib/homestore/shard_manager.cpp 81.11% <81.81%> (+21.11%) ⬆️
src/lib/shard_manager.cpp 87.50% <88.23%> (+0.40%) ⬆️
src/lib/homeobject_impl.hpp 100.00% <100.00%> (ø)
src/lib/homestore/replication_state_machine.hpp 100.00% <100.00%> (ø)
src/lib/memory/shard_manager.cpp 81.81% <100.00%> (+1.81%) ⬆️
src/lib/pg_manager.cpp 76.78% <100.00%> (+2.78%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@szmyd
Copy link
Collaborator

szmyd commented Sep 15, 2023

Nice; I think once we get the CodeCoverage up above 80% we can consider merging this. Let me know if any help is needed to get those unit tests made.

@zichanglai
Copy link
Contributor Author

Nice; I think once we get the CodeCoverage up above 80% we can consider merging this. Let me know if any help is needed to get those unit tests made.

thanks, Brian. I had added some more unit tests to improve code coverage to 81.99% with the latest few commits.

szmyd
szmyd previously approved these changes Sep 19, 2023
Copy link
Collaborator

@szmyd szmyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's merge this and make fixes/api changes later. 👍

@szmyd szmyd added this to the 2 milestone Sep 19, 2023
if (!replica_set->is_leader()) {
LOGWARN("pg [{}] replica set is not a leader, please retry other pg members", pg_owner);
return folly::makeUnexpected(ShardError::NOT_LEADER);
}
Copy link
Collaborator

@szmyd szmyd Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh; shard creation should be able to happen everywhere. We can relax this in M3 I think when we have real replicas. Ideally yes it happens on leader, but it's "best-effort" on a follower (shard id may be invalid).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to follow up; this has to be the case since by the time we actually call append_entries in HomeStore the leadership has changed since it was checked. We can never pre-check leadership...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe let HS return an error in this case? Same situation is also true for write_blob request right?

Copy link
Collaborator

@szmyd szmyd Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; if we want to prevent this we can just turn forwarding off in the raft_server; it will reject append_entries if it's not currently the leader. But I'm not sure why we care about leadership here...we're basically just doing what the DM would retry anyways by forwarding it.
We stick who the leader was in the response in case the DM wants to adjust.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if raft server on follower side support msg forward, then this check will not be necessary. before I do not know this feature is enabled in nuraft.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK yes, only for the optimize_path. DM and GW need to adjust as well.

Actually I was kind of not sure why OM/CM team need that strict regarding sending to leader :

@zichanglai zichanglai merged commit 1cbf09d into eBay:main Sep 19, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants