A checksum is a value computed from data and stored or transmitted alongside it. Recomputing the value later and comparing the results can reveal interrupted writes, transmission errors, or corrupted data. section 7.7.4
Use a checksum by following this cycle:
- Before writing data, apply a checking function to its bytes and store the result beside the original data. section 7.7.4
- When reading, calculate a fresh checksum from the data and compare it with the saved value. section 7.7.4
- Treat a mismatch as corruption and report an error rather than trusting the data. section 7.7.4
Parity checking
A parity bit counts the 1 bits in a byte stream and records whether their total is even or odd. For the bytes representing “abc”, the counts are 3, 3, and 4, producing 00000001; adding “d” changes the result to 00000000. A Rust implementation loops over a byte slice, uses count_ones(), totals the counts, and returns whether the total is even. section 7.7.4
Figure 7.3 A single record in the Bitcask file format. To parse a record, read the header information, then use that information to read the body. Lastly, verify the body’s contents with the checksum provided in the header.
A Bitcask record places the checksum in a header with key and value lengths: read the header, read the body, then verify the body against the stored checksum. section 7.7.2
Checksum choices trade simplicity, speed, and reliability. Parity bits are fast and easy but prone to errors; CRC32 is more complex and more trustworthy; cryptographic hash functions are slower but provide stronger assurance. section 7.7.4




