-
Notifications
You must be signed in to change notification settings - Fork 96
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
Stop checkpoint validation when encountering a valid checkpoint #463
Conversation
2cb471c
to
0b45ffc
Compare
I took some rough measurements with Results...Queue created with Measured with: tprof:profile(fun() -> ra_snapshot:init(<<"uuid">>, ra_log_snapshot, "./snapshots", "./checkpoints", undefined, 3) end, #{type => call_time}). and This branch:
0.28s
main:
|
For a quorum queue were consumers keep up with ingress checkpoints are promoted very often. It would be nice not to to have to do the validation work every time just because we optimised recovery. My thought was that once we'd found a valid checkpoint during recovery we'd assume all prior checkpoints are also valid. That should be roughly as good as promoting any other checkpoint. The most likely way a checkpoint would become corrupted is if the server hard stopped during a write or fsync. Sure there are other ways checkpoints could become corrupted but at least we guard against the most likely one. |
This refactors `ra_snapshot:find_checkpoints/1` to cut down on some work when there are many checkpoints. We scan through the checkpoint directories to find the first (latest) valid checkpoint we can use for recovery. Then we can defer using the `ra_snapshot:validate/1` callback (which can be somewhat expensive) for any older checkpoints. We assume that any checkpoints older than the latest valid checkpoint are valid. We expect that invalid checkpoints would be created when a machine terminates hard and unexpectedly and may stop an in-progress write or leave a checkpoint file unsynced. This should only affect some number of the latest checkpoints though. Once we've found a checkpoint file that is valid, checkpoints older than that should be fully written and synchronized too. We also bail out of the search when we find a checkpoint that has a lower index than the current snapshot index. Those checkpoints cannot be promoted and should be deleted. We scan through the checkpoints from most recent to least recent, so when we find a checkpoint with an older index than the snapshot, we delete that checkpoint and any older checkpoints.
0b45ffc
to
48ecb89
Compare
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.
a few minor things
@mkuratczyk noticed that with many QQs on the qq-v4 branch and each QQ having many checkpoints, we spend a fair amount of effort reading the checkpoints during recovery. This is because
ra_snapshot:find_checkpoints/1
uses thera_snapshot:validate/1
callback to ensure that each snapshot is valid.validate/1
is somewhat expensive inra_log_snapshot
since it fully reads and decodes the checkpoint, discarding the result.Not all of this validation is necessary: we can stop validating checkpoints when we find the latest checkpoint which is valid. This is likely to be good enough. I've also updated
find_checkpoints/1
to stop its search when it finds a checkpoint with a lower index than the current snapshot as any checkpoints lower than the snapshot index won't be used for promotion and should be removed. For many QQs with many checkpoints each this should save some I/O usage and memory.