FAB-18244 single node catches up with snapshot - #1964
Merged
Conversation
Support.WriteBlock commits block to ledger asynchronously and can have up to one block in-flight. And there's possibility a node crashes before such block is persisted successfully. Normally when node restarts, Raft loads entries from WAL and attempts to re-apply them. However, when a snapshot is taken at this block, only entries after (if any) the snapshot are loaded, and we end up hanging here forever waiting for missing blocks to be pulled from nowhere in single node situation. A straightforward solution would be to peek into ledger tip first, and decide whether to load some "old" entries from WAL, instead of blindly load data after latest snapshot. Although it's trickier than it sounds: - today, we don't strictly respect the contract between Raft and state machine, where applied data should not be lossy and it's safe to prune data in WAL after snapshots. For example, in extreme case, if we lose the entire ledger, we should not expect it to be recoverable from WAL - etcd/raft persistence library does not provide friendly interfaces to control what data to load in fine-grained manner. For example, snap.Load() simply looks for latest snapshot available, and loads entries after that. If we'd like to, for example, load older data prior to that snapshot, we'll need to come up with our own utilities This commit aims to provide a quick fix for bug described in FAB-18244, leveraging the fact that we can have only one async block in-flight, and leave the "correct" solution to future work. Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
jyellick
approved these changes
Oct 5, 2020
jyellick
left a comment
Contributor
There was a problem hiding this comment.
Although this solution isn't ideal, it's definitely simple, and fixes a real bug, so merging. I'm certainly not eager to re-implement any of etcd's WAL parsing/loading, especially if the issue is fixed. I'll continue to think on whether there's a nicer solution, and I'd appreciate it if you would was well.
| if c.lastBlock.Header.Number >= b.Header.Number { | ||
| c.logger.Warnf("Snapshot is at block [%d], local block number is %d, no sync needed", b.Header.Number, c.lastBlock.Header.Number) | ||
| return nil | ||
| } else if b.Header.Number == c.lastBlock.Header.Number+1 { |
Contributor
There was a problem hiding this comment.
I definitely don't love this, though it is fairly obviously correct, it injects knowledge of the sync properties of the WriteBlock call into the Raft implementation.
guoger
added a commit
to guoger/fabric
that referenced
this pull request
Oct 19, 2020
Support.WriteBlock commits block to ledger asynchronously and can have up to one block in-flight. And there's possibility a node crashes before such block is persisted successfully. Normally when node restarts, Raft loads entries from WAL and attempts to re-apply them. However, when a snapshot is taken at this block, only entries after (if any) the snapshot are loaded, and we end up hanging here forever waiting for missing blocks to be pulled from nowhere in single node situation. A straightforward solution would be to peek into ledger tip first, and decide whether to load some "old" entries from WAL, instead of blindly load data after latest snapshot. Although it's trickier than it sounds: - today, we don't strictly respect the contract between Raft and state machine, where applied data should not be lossy and it's safe to prune data in WAL after snapshots. For example, in extreme case, if we lose the entire ledger, we should not expect it to be recoverable from WAL - etcd/raft persistence library does not provide friendly interfaces to control what data to load in fine-grained manner. For example, snap.Load() simply looks for latest snapshot available, and loads entries after that. If we'd like to, for example, load older data prior to that snapshot, we'll need to come up with our own utilities This commit aims to provide a quick fix for bug described in FAB-18244, leveraging the fact that we can have only one async block in-flight, and leave the "correct" solution to future work. Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
C0rWin
pushed a commit
that referenced
this pull request
Oct 19, 2020
Support.WriteBlock commits block to ledger asynchronously and can have up to one block in-flight. And there's possibility a node crashes before such block is persisted successfully. Normally when node restarts, Raft loads entries from WAL and attempts to re-apply them. However, when a snapshot is taken at this block, only entries after (if any) the snapshot are loaded, and we end up hanging here forever waiting for missing blocks to be pulled from nowhere in single node situation. A straightforward solution would be to peek into ledger tip first, and decide whether to load some "old" entries from WAL, instead of blindly load data after latest snapshot. Although it's trickier than it sounds: - today, we don't strictly respect the contract between Raft and state machine, where applied data should not be lossy and it's safe to prune data in WAL after snapshots. For example, in extreme case, if we lose the entire ledger, we should not expect it to be recoverable from WAL - etcd/raft persistence library does not provide friendly interfaces to control what data to load in fine-grained manner. For example, snap.Load() simply looks for latest snapshot available, and loads entries after that. If we'd like to, for example, load older data prior to that snapshot, we'll need to come up with our own utilities This commit aims to provide a quick fix for bug described in FAB-18244, leveraging the fact that we can have only one async block in-flight, and leave the "correct" solution to future work. Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Support.WriteBlock commits block to ledger asynchronously and can have
up to one block in-flight. And there's possibility a node crashes before
such block is persisted successfully. Normally when node restarts, Raft
loads entries from WAL and attempts to re-apply them. However, when a
snapshot is taken at this block, only entries after (if any) the
snapshot are loaded, and we end up hanging here forever waiting for
missing blocks to be pulled from nowhere in single node situation.
A straightforward solution would be to peek into ledger tip first, and
decide whether to load some "old" entries from WAL, instead of blindly
load data after latest snapshot. Although it's trickier than it sounds:
today, we don't strictly respect the contract between Raft and state
machine, where applied data should not be lossy and it's safe to prune
data in WAL after snapshots. For example, in extreme case, if we lose
the entire ledger, we should not expect it to be recoverable from WAL
etcd/raft persistence library does not provide friendly interfaces
to control what data to load in fine-grained manner. For example,
snap.Load() simply looks for latest snapshot available, and loads
entries after that. If we'd like to, for example, load older data prior
to that snapshot, we'll need to come up with our own utilities
This commit aims to provide a quick fix for bug described in FAB-18244,
leveraging the fact that we can have only one async block in-flight, and
leave the "correct" solution to future work.
Signed-off-by: Jay Guo guojiannan1101@gmail.com