Skip to content
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

NRG (2.11): Start catchup from n.commit & fix AppendEntry is stored at seq=ae.pindex+1 #5987

Merged
merged 7 commits into from
Oct 15, 2024

Conversation

MauriceVanVeen
Copy link
Member

@MauriceVanVeen MauriceVanVeen commented Oct 10, 2024

This PR makes three complementary fixes to the way how catchup and truncating is handled.
Specifically:

  • when doing n.loadEntry(index) we need to pass where the AppendEntry is in terms of stream sequence, this is equal to ae.pindex+1 since the ae.pindex is the value before it's stored in the stream.
  • start catchup from n.commit, we could have messages past our commit that have been invalidated and need to be truncated since there was a switch between leaders
  • because we catchup from n.commit, we check if our local AppendEntry matches terms with the incoming AppendEntry, we only need to truncate if the terms don't match

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

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/truncate-entries-without-quorum branch from 848e1d2 to 5bd3d7e Compare October 10, 2024 19:10
@derekcollison
Copy link
Member

LMK when ready for review.

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
…e.pindex+1

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen force-pushed the maurice/truncate-entries-without-quorum branch from 4fff9ec to b62c058 Compare October 14, 2024 15:48
Copy link
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.

I think this looks good, let's mark for review.

Copy link
Contributor

@mprimi mprimi left a comment

Choose a reason for hiding this comment

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

Minor style comments on tests

followerServer2.WaitForShutdown()

// Although this request will time out, it will be added to the stream leader's WAL.
_, err = js.Publish("foo", []byte("first"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could set a shorter timeout to make the test faster? (not sure what the default is)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, default seemed to be 5 seconds, lowered to 1s.

streamLeaderServer.WaitForShutdown()

// Only restart the (previous) followers.
followerServer1 = c.restartServer(followerServer1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is one server variable reassigned and not the other?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used below to have a connection to that server:

nc, js = jsClientConnect(t, followerServer1)

The connection could be to either server, as long as it's not the (previous) leader. So only this one variable is used to setup the connection.

rs := c.randomNonStreamLeader(globalAccountName, "TEST")
ts := time.Now().UnixNano()

var scratch [1024]byte
Copy link
Contributor

Choose a reason for hiding this comment

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

This bit may use an explanation... maybe

Manually add 3 append entries to each node's WAL, except for one node who is one behind

I actually am not sure. Your inner loop goes to 3, but then you have a break at 1.

Copy link
Member Author

Choose a reason for hiding this comment

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

That description is correct. Two servers will have 3 uncommitted entries, and one server will have 2 uncommitted entries so it needs to catchup for that third one.

Have moved that condition for that one server up, so it's a bit clearer it gets 2 iterations of that loop.

}

// Check that the first two published messages came from our WAL, and
// the last came from a catchup by another leader.
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me you are doing the same check for all 3 entries you look at, this comment is maybe outdated?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are 3 checks, 2x require_Equal and 1x require_NotEqual. Have changed it to use require_True with == and != instead, that seems a bit more clear.
(And it doesn't matter what the values being compared are, just that they either match or not)

if len(expected) > 0 && int(state.LastSeq-state.FirstSeq+1) != len(expected) {
return fmt.Errorf("WAL is different: too many entries")
}
for index := state.FirstSeq; index <= state.LastSeq; index++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looped check deserves a comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

n, err := s.initRaftNode(globalAccountName, cfg, pprofLabels{})
require_NoError(t, err)

encode := func(ae *appendEntry) *appendEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment this bit of arcane magic

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen marked this pull request as ready for review October 14, 2024 20:43
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner October 14, 2024 20:43
Copy link
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

@derekcollison derekcollison merged commit ac5ba12 into main Oct 15, 2024
5 checks passed
@derekcollison derekcollison deleted the maurice/truncate-entries-without-quorum branch October 15, 2024 14:02
MauriceVanVeen added a commit that referenced this pull request Oct 22, 2024
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
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.

4 participants