Skip to content

NRG (2.11): When term matches, simply truncate and store append entry#6073

Merged
derekcollison merged 1 commit intomainfrom
maurice/truncate-down-to-commit
Nov 11, 2024
Merged

NRG (2.11): When term matches, simply truncate and store append entry#6073
derekcollison merged 1 commit intomainfrom
maurice/truncate-down-to-commit

Conversation

@MauriceVanVeen
Copy link
Copy Markdown
Member

@MauriceVanVeen MauriceVanVeen commented Nov 4, 2024

If we are leader and store two entries, the first having quorum and being committed/applied and the second not having quorum. A new leader should be able to truncate the second entry.

That was not possible before as the n.loadEntry(ae.pindex) and n.truncateWAL(eae.pterm, eae.pindex) combination would remove two entries, not just one.

We now check if the entry stored at ae.pindex has a matching term with ae.pterm, if so we can truncate entries past that point and then simply continue storing that append entry. Instead of needing to truncate, stop, get a heartbeat, start catchup, get the same append entry again, store it, get the next entry, stop catchup, etc. In this case we can now just, truncate and store.

Signed-off-by: Maurice van Veen github@mauricevanveen.com

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/truncate-down-to-commit branch 2 times, most recently from 91eae7f to bb57925 Compare November 4, 2024 16:48
require_Equal(t, n.commit, 3)
}

func TestNRGNewLeaderWithIncorrectPtermDoesNotTruncateIfCommitted(t *testing.T) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two tests that have been removed asserted that n.pterm = n.term could still be executed, resulting in a situation where we should recover from the possibility of having an incorrect pterm.

Since its removal in #6060, these tests should be removed. We should never have this situation occur anymore.

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/truncate-down-to-commit branch from bb57925 to 998d7d0 Compare November 4, 2024 16:59
@MauriceVanVeen MauriceVanVeen changed the title NRG (2.11): Truncate down to commit NRG (2.11): Use correct sequence when truncating to previous pterm/pindex Nov 4, 2024
@MauriceVanVeen MauriceVanVeen force-pushed the maurice/truncate-down-to-commit branch from 998d7d0 to a9c30c3 Compare November 6, 2024 09:39
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen force-pushed the maurice/truncate-down-to-commit branch from a9c30c3 to 7a10f66 Compare November 11, 2024 09:10
@MauriceVanVeen MauriceVanVeen changed the title NRG (2.11): Use correct sequence when truncating to previous pterm/pindex NRG (2.11): When term matches, simply truncate and store append entry Nov 11, 2024
@MauriceVanVeen MauriceVanVeen marked this pull request as ready for review November 11, 2024 16:13
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner November 11, 2024 16:13
Copy link
Copy Markdown
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this is effectively the approach Maurice and I were talking about at the end of last week, where we can avoid having to wait for a heartbeat to apply an entry after a truncation, and additionally where we can prune the log back step-by-step if needed until we can resolve a pterm mismatch.

Copy link
Copy Markdown
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekcollison derekcollison merged commit 626603c into main Nov 11, 2024
@derekcollison derekcollison deleted the maurice/truncate-down-to-commit branch November 11, 2024 17:05
neilalexander added a commit that referenced this pull request Nov 25, 2024
Includes the following:

- #5661
- #5666
- #5671
- #5344
- #5684
- #5689
- #5691
- #5714
- #5717
- #5707
- #5792
- #5912
- #5957
- #5700
- #5975
- #5991
- #5987
- #6027
- #6038
- #6053
- #5848
- #6055
- #6056
- #6060
- #6061
- #6072
- #5832
- #6073
- #6107

Signed-off-by: Neil Twigg <neil@nats.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants