Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Slight simplification of configuration rollback logic #409

Merged
merged 8 commits into from
Apr 21, 2023
Merged

Slight simplification of configuration rollback logic #409

merged 8 commits into from
Apr 21, 2023

Conversation

freeekanayaka
Copy link
Contributor

This change removes a bit of code duplication in the logic that handles configuration rollbacks when the last committed configuration is not available anymore in the log and must be retrieved from the last snapshot.

It basically makes the code reflect a bit more this comment from @cole-miller that was made when the fix for configuration rollbacks was implemented.

Please see the commit messages of the individual commits in the PR for more details.

The diff removes more code than it adds, yet test coverage should slightly increase due to reduced code duplication.

@codecov
Copy link

codecov bot commented Apr 18, 2023

Codecov Report

Merging #409 (2ed5d42) into master (9fc0c0b) will increase coverage by 0.11%.
The diff coverage is 74.50%.

@@            Coverage Diff             @@
##           master     #409      +/-   ##
==========================================
+ Coverage   76.44%   76.55%   +0.11%     
==========================================
  Files          50       50              
  Lines        9581     9543      -38     
  Branches     2459     2440      -19     
==========================================
- Hits         7324     7306      -18     
+ Misses       1173     1163      -10     
+ Partials     1084     1074      -10     
Impacted Files Coverage Δ
src/configuration.c 96.27% <ø> (+1.96%) ⬆️
src/replication.c 69.20% <60.00%> (+0.15%) ⬆️
src/start.c 62.72% <70.83%> (+2.22%) ⬆️
src/snapshot.c 89.65% <75.00%> (-1.09%) ⬇️
src/membership.c 74.49% <81.25%> (+0.19%) ⬆️
src/raft.c 78.66% <100.00%> (ø)

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

This new function can be used to fetch the most recent committed configuration,
either from the log or from the last snapshot.

Signed-off-by: Free Ekanayaka <[email protected]>
We need to get the last committed configuration in two cases:

- when aborting a pending configuration change (we'll rollback to the last
  committed configuration)
- when taking a snapshot (we include the last committed configuration in the
  snapshot and save a copy of it)

Use the membershipFetchLastCommittedConfiguration() helper instead of
duplicating the logic.

Signed-off-by: Free Ekanayaka <[email protected]>
Every time we restore a snapshot we must also cache in r->configuration_previous
the configuration contained in the snapshot (which the last known committed
configuration at the time the snapshot was taken). This is necessary in case the
log gets truncated and loses track of the entry that originally contained that
configuration.

We restore a snapshot in two cases:

- when receiving a SnapshotInstall RPC
- when starting up

Instead of duplicating the caching logic in both places, move the caching logic
to the snapshotRestore() utility, which is responsibile for all bookkeeping
needed upon snapshot restore, no matter when and where it happens.

Signed-off-by: Free Ekanayaka <[email protected]>
When we start up we first restore the last persisted snapshot (if any) and then
all persisted entries.

As part of resting the last persisted snapshot, we cache its associated
configuration in r->configuration_previous, for rollbacks.

We don't need to cache it again in restoreConfigurations(), which is called when
persisted entries are restored.

Signed-off-by: Free Ekanayaka <[email protected]>
After successfully taking and persisting a snapshot, we generally cache into
r->configuration_previous the configuration that was included in the snapshot.

Technically speaking we don't need to do that if between the time the snapshot
was started and the time it completed new configuration changes were
committed (those won't be truncated yet).

However, for consistency, change the code to populate r->configuration_previous
no matter what, so we preserve the invariant that r->configuration_previous
always contains a copy of the configuration included in the most recent
snapshot.

Also, make the code slightly less indirect by using configurationCopy() instead
of the configurationBackup() helper, which has now just this one call site and
isn't worth be kept (it will be removed in a follow-up commit).

Signed-off-by: Free Ekanayaka <[email protected]>
The functionality of configurationBackup() is now part of takeSnapshotCb(), and
the one of configurationRestorePrevious() is now part of snapshotRestore().

Signed-off-by: Free Ekanayaka <[email protected]>
Make the logic for restoring the last configuration in the log slightly lighter,
by using r->configuration_index to store the second-to-last configuration entry,
instead of passing around dedicated variables.

Signed-off-by: Free Ekanayaka <[email protected]>
The name "configuration_previous" is a slightly ambiguous, because this field
does not actually store the "previous configuration", but rather a copy of the
configuration contained in the most recent snapshot.

Signed-off-by: Free Ekanayaka <[email protected]>
@cole-miller cole-miller self-assigned this Apr 19, 2023
@cole-miller cole-miller self-requested a review April 19, 2023 15:08
@cole-miller
Copy link
Contributor

Thanks, always happy to see some redundancy removed! To be clear, r->configuration_index still refers to the index of the last committed configuration whether or not it's part of a snapshot, right?

@freeekanayaka
Copy link
Contributor Author

freeekanayaka commented Apr 20, 2023

Thanks, always happy to see some redundancy removed! To be clear, r->configuration_index still refers to the index of the last committed configuration whether or not it's part of a snapshot, right?

Exactly, see the associated comment in the public header, I had improved them here.

@freeekanayaka
Copy link
Contributor Author

Thanks, always happy to see some redundancy removed! To be clear, r->configuration_index still refers to the index of the last committed configuration whether or not it's part of a snapshot, right?

Exactly, see the associated comment in the public header, I had improved them here.

We might even consider renaming configuration_index to configuration_committed_index, if that helps.

@cole-miller
Copy link
Contributor

Thanks, always happy to see some redundancy removed! To be clear, r->configuration_index still refers to the index of the last committed configuration whether or not it's part of a snapshot, right?

Exactly, see the associated comment in the public header, I had improved them here.

We might even consider renaming configuration_index to configuration_committed_index, if that helps.

I'd support that!

@freeekanayaka
Copy link
Contributor Author

Thanks, always happy to see some redundancy removed! To be clear, r->configuration_index still refers to the index of the last committed configuration whether or not it's part of a snapshot, right?

Exactly, see the associated comment in the public header, I had improved them here.

We might even consider renaming configuration_index to configuration_committed_index, if that helps.

I'd support that!

Ok then, I'll make a separate PR for that.

@cole-miller cole-miller merged commit cabe35b into canonical:master Apr 21, 2023
@freeekanayaka freeekanayaka deleted the simplify-configuration-rollback branch April 22, 2023 08:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants