Repository navigation
refactor: use one snapshot entry codec - #414
Merged
Merged
Conversation
Snapshot values were encoded in three places and decoded in four. The plaintext file reader re-encoded every field it read to feed the footer CRC, and the replication path had its own reader doing the same. Now write_snap_value and encode_entry write every entry, decode_entry reads it, and readers feed the CRC through CrcReader.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
snapshot.rshad the value encoding written out three times:SnapshotWriter::write_entry,serialize_entryfor replication snapshots, andserialize_snap_valuefor DUMP and MIGRATE. It had the decoding four times:parse_snap_value,read_plaintext_entry,read_entry_with_bytes, and the encrypted reader's inline copy. The two plaintext readers also re-encoded every field into a buffer as they read it, only to feed the footer CRC.Now:
write_snap_valuewrites[type_tag][payload].encode_entryadds the key and expiry around it, and all three writers use it.decode_entryreads an entry, including version-1 entries without a type tag. The file reader, the encrypted reader andread_snapshot_from_bytesall use it.format::CrcReaderand combining its hasher into the running one (crc32fast::Hasher::combine).CrcReadergainsinto_hasherfor this.The file format and the public functions are unchanged.
snapshot.rsloses about 400 lines. The existing round-trip tests cover every value type, with and without theencryption,protobufandvectorfeatures.