nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
16k stars 1.41k forks source link

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

Closed MauriceVanVeen closed 1 week ago

MauriceVanVeen commented 2 weeks ago

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