-
Notifications
You must be signed in to change notification settings - Fork 250
Reject snapshot-less join against primary holding a more recent snapshot #7844
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
Open
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/implement-snapshot-joining-behaviour
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d9df82
Initial plan
Copilot 043687d
Implement primary-side join check against latest on-disk snapshot
Copilot ef73def
Shorten retry_count doc comment per review
Copilot 8e9c582
CHANGELOG: rename Unreleased to 7.0.3, bump pyproject and add PR ref
Copilot 47de9f8
CHANGELOG: shorten 7.0.3 entry
Copilot 730bbb5
node_frontend: distinguish preferred vs required snapshot seqno in er…
Copilot f3d26b8
node_frontend: treat missing retry_count as legacy joiner (value_or(1))
Copilot 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| #include "service/tables/local_sealing.h" | ||
| #include "service/tables/previous_service_identity.h" | ||
| #include "service/tables/snapshot_status.h" | ||
| #include "snapshots/filenames.h" | ||
|
|
||
| #include <llhttp/llhttp.h> | ||
| #include <stdexcept> | ||
|
|
@@ -471,22 +472,76 @@ namespace ccf | |
| // Make sure that the joiner's snapshot is more recent than this node's | ||
| // snapshot. Otherwise, the joiner may not be given all the ledger | ||
| // secrets required to replay historical transactions. | ||
| // | ||
| // On the joiner's first attempt (retry_count == 0), additionally | ||
| // require the joiner's startup_seqno to be at least as recent as the | ||
| // latest committed snapshot file currently held on disk by this node. | ||
| // This prevents a snapshot-less joiner from being accepted by an | ||
| // original (snapshot-less) primary, which would otherwise cause it to | ||
| // replay the entire ledger. On subsequent retries (retry_count > 0), | ||
| // we relax the check back to the primary's startup_seqno only, to | ||
| // avoid the joiner chasing an ever-moving target if a fresher | ||
| // snapshot is committed during the joiner's snapshot fetch. | ||
| // | ||
| // Older joiners which do not populate retry_count are treated as if | ||
| // they were already retrying (value_or(1)), so they keep the legacy | ||
| // "minimum required" behaviour and never fall into the chasing path. | ||
| auto this_startup_seqno = | ||
| this->node_operation.get_startup_snapshot_seqno(); | ||
| ccf::kv::Version required_seqno = this_startup_seqno; | ||
| ccf::kv::Version preferred_seqno = this_startup_seqno; | ||
| const auto retry_count = in.retry_count.value_or(1); | ||
| if (retry_count == 0) | ||
| { | ||
| auto node_configuration_subsystem = | ||
| this->context.get_subsystem<NodeConfigurationSubsystem>(); | ||
| if (node_configuration_subsystem != nullptr) | ||
| { | ||
| const auto& snapshots_config = | ||
| node_configuration_subsystem->get().node_config.snapshots; | ||
| const auto latest_committed_snapshot = | ||
| snapshots::find_latest_committed_snapshot_in_directory( | ||
| snapshots_config.directory); | ||
| if (latest_committed_snapshot.has_value()) | ||
| { | ||
| const auto latest_snapshot_seqno = | ||
| snapshots::get_snapshot_idx_from_file_name( | ||
| latest_committed_snapshot->filename().string()); | ||
| preferred_seqno = std::max( | ||
| preferred_seqno, | ||
| static_cast<ccf::kv::Version>(latest_snapshot_seqno)); | ||
| } | ||
| } | ||
| } | ||
| if ( | ||
|
cjen1-msft marked this conversation as resolved.
|
||
| in.startup_seqno.has_value() && | ||
| this_startup_seqno > in.startup_seqno.value()) | ||
| preferred_seqno > in.startup_seqno.value()) | ||
| { | ||
| if (preferred_seqno > required_seqno) | ||
| { | ||
| return make_error( | ||
| HTTP_STATUS_BAD_REQUEST, | ||
| ccf::errors::StartupSeqnoIsOld, | ||
| fmt::format( | ||
| "Node requested to join from seqno {} which is older than " | ||
| "this node's preferred recent snapshot seqno {} (the latest " | ||
|
Member
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. We should avoid apostrophes/single quotes in error messages and keep them compact: |
||
| "committed snapshot held on disk by this node). A snapshot " | ||
| "at least as recent as {} should be used instead.", | ||
| in.startup_seqno.value(), | ||
| preferred_seqno, | ||
| preferred_seqno)); | ||
| } | ||
| return make_error( | ||
| HTTP_STATUS_BAD_REQUEST, | ||
| ccf::errors::StartupSeqnoIsOld, | ||
| fmt::format( | ||
| "Node requested to join from seqno {} which is older than this " | ||
| "node startup seqno {}. A snapshot at least as recent as {} must " | ||
| "be used instead.", | ||
| "node's required minimum snapshot seqno {} (this node's " | ||
|
Member
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. Same as above. |
||
| "startup seqno). A snapshot at least as recent as {} must be " | ||
| "used instead.", | ||
| in.startup_seqno.value(), | ||
| this_startup_seqno, | ||
| this_startup_seqno)); | ||
| required_seqno, | ||
| required_seqno)); | ||
| } | ||
|
|
||
| auto nodes = args.tx.rw(this->network.nodes); | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.