PSYNC based on AOF
This is the feature as described in #2677. An earlier PR #2366 implemented it but it was reverted later because the AOF bytes don't always match the replication offset.
To make it possible to do partial sync based on AOF, we need to store the replication offsets in the AOF file.
The parent issue mentions how to store it in the AOF file:
2.1 Backwards-Compatible AOF Log Headers To resolve data integrity and psync limitations, we will annotate every AOF log entry > with a metadata header.
Header Fields:
len: The length of the log entry. lsn: A monotonically increasing Log Sequence Number, incrementing by exactly 1 for > every log entry. replid: Replication id to allow psync on server restart. reploff: Replication offset to allow psync on server restart. cksum: A checksum for the log entry to detect torn writes and bit rot. Format and Compatibility:
The log headers will be added as Valkey protocol annotations to ensure backwards compatibility. Older AOF parsers will simply ignore them. The format will be:
#HDR:len:{$len};lsn:{$lsn};replid:{$replid};reploff:{$reploff};cksum:{$cksum}\r\n
To support partial sync, we only need the reploff field.
Source: valkey-io/valkey