storage: Add CompareAndAppendLogEntry to log manager
A part of #6303 and follow-up of !7523 (merged). This MR depends on storage: Move log entry pruning to a concurrent... (!7521 - merged).
This MR adds CompareAndAppendLogEntry method to the log manager. This method is a variant of the existing AppendLogEntry. If the input LSN doesn't match the expected LSN, an error is returned.
This commit adds the CompareAndAppendLogEntry method to the log manager. This method is a variant of the existing AppendLogEntry. If the input LSN doesn't match the expected LSN; an error is returned.
Although the caller can achieve a similar result by checking AppendedLSN() or the returned LSN of AppendLogEntry, this method offers better protection:
- Asserting is performed before modification.
- The lock is acquired before asserting. This prevents another concurrent writer from adding logs after the LSN is asserted.
This new method will be used for components that need to insert log entries at certain LSNs such as backup recovery, Raft manager, etc.
This MR also exposes some methods of log.Manager
via storage.LogReader
and storage.LogManager
interfaces. This change is the prerequisite of #6303.