Open
Conversation
5113c49 to
5d2b1e6
Compare
We have observed at customer sites various hard-to-replicate cluster instabilities where followers will fail to resync with the rest of the cluster after a restart. In particular, we get a couple of different types of errors from Raft: failed to decode incoming command: error=msgpack decode error [pos 12207]: only encoded map or array can be decoded into a struct This one generally happens when the follower is far enough behind that the leader decides to send a snapshot instead. The second is one that should not be possible: failed to decode incoming command: error=unknown rpc type 125 where the RPC number seems to change almost at random. After many rounds of debugging at a remote customer site, it appears that the root cause of the issue is that the Raft library will send extra data if the file size of the snapshot on disk is larger than the snapshot size indicated in the snapshot metadata. In my particular usecase that can happen because the SnapshotStore we use prefers to recycle older snapshot files rather than deleting them and creating a new file. We do this to make the system more resistant to running out of disk space. On the leader side, alleviate this issue by clamping the maximum amount of snapshot data we will send to the size indicated by the snapshot metadata. On the follower side, rework the RPC event loop to exit after handling an installSnapshot RPC instead of attempting to process the rest of the bytes remaining in the conn. This mirrors what the leader has done for snapshot handling with pooled conns since forever. On the leader side, arrange for pooled connections to discard any outstanding data when a connection is returned to the pool, and arrange for the system to panic if someone ever attempts to use a conn after returning it to the pool.
5d2b1e6 to
c93c886
Compare
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.
Followers can get confused if the leader streams a Snapshot that is larger than indicated by the snapshot metadata. Fix this in a few different ways:
This PR also includes the changes I made while tracking this issue down, including logging the first 100 bytes left over after handling an unknown RPC and being more aggressive about buffer management with pooled conns (including poisoning any conns returned to the pool).