Fewer checks, sealed later¶
A tape's checks cost a writer time. A writer that must keep up with a fast source, such as a radio receiver, can leave some of them out. A seal adds them later. When bytes go bad says what each check catches.
Three integrity levels¶
A writer can skip the hashes, or the payload CRCs too. Each piece names its integrity level in its
piece head. WriterOptions::integrity sets the level of the pieces a writer starts.
| Level | The writer skips | A reader still checks |
|---|---|---|
Full |
nothing | every CRC and the content hash |
CrcOnly |
the content hash, the unit hashes in the index and the [[track hash | track hashes]] |
None |
also the CRCs over chunk payloads | block CRCs, chunk head CRCs and every structure block |
Below Full, the fields of the hashes stay in place and hold zero, and the piece head's level says that they are
absent. A chunk of None is marked unchecked in its header. A reader reports it as Checked::Unprotected, and
ChainLink::Unproven marks a link between pieces that no content hash proves. The bench levels writes chunks into
a memory tape at each level:
| Chunk | Level | ns per chunk | ns per byte | GB/s |
|---|---|---|---|---|
| series 1 MiB | Full | 396 865 | 0.378 | 2.64 |
| series 1 MiB | CrcOnly | 133 066 | 0.127 | 7.88 |
| series 1 MiB | None | 99 634 | 0.095 | 10.52 |
| series 4 MiB | Full | 1 709 624 | 0.408 | 2.45 |
| series 4 MiB | CrcOnly | 611 222 | 0.146 | 6.86 |
| series 4 MiB | None | 454 212 | 0.108 | 9.23 |
| events 16 KiB | Full | 8034 | 0.490 | 2.04 |
| events 16 KiB | CrcOnly | 3637 | 0.222 | 4.50 |
| events 16 KiB | None | 3036 | 0.185 | 5.40 |
just bench-levels on build-1, load average 5.94 before, 5.94 after.
A 1 MiB series chunk takes 34 % of the time of Full at CrcOnly and 25 % at None. What is left at None is mostly
the copy into memory.
The seal¶
A seal raises a closed piece to Full later, at save time or whenever there is time. It computes what the writer
skipped and writes every block in its place, so the piece keeps its length and its offsets. The sealed piece holds the
bytes a writer at Full writes from the same calls.
MemPieces::sealswaps a sealed copy in, while a reader holding the old tape reads on.ww_tape_fs::writer::sealseals a file in place and writes each piece head last. A crash before that leaves the piece at its old level, and a seal again finishes it.- A chain is sealed from its first piece on, since each piece's id comes from the content hash of the piece before.
| Chunk | From | ns per chunk | ns per byte | GB/s |
|---|---|---|---|---|
| series 1 MiB | CrcOnly | 442 961 | 0.422 | 2.37 |
| series 1 MiB | None | 416 531 | 0.397 | 2.52 |
| series 4 MiB | CrcOnly | 1 776 376 | 0.424 | 2.36 |
| series 4 MiB | None | 1 588 340 | 0.379 | 2.64 |
| events 16 KiB | CrcOnly | 8939 | 0.546 | 1.83 |
| events 16 KiB | None | 8219 | 0.502 | 1.99 |
just bench-levels on build-1, load average 5.94 before, 5.94 after.
Sealing a 1 MiB series chunk of None takes about as long as writing it at Full: 100 % of that time. The seal reads
the piece, checks it and hashes it, and copies it into memory again.
The bench ran on build-1, a virtual machine with 14 logical CPUs (AMD EPYC-Genoa Processor, x86_64) and 35 GiB of memory. It was a release build at opt-level 3 of commit f39d29d5, built with the default jobs. The load average ran from 5.94 to 5.94 across the tables.
pub integrity: Integrity,
Which CRCs and hashes the pieces this writer starts get (Integrity), named in each piece head.
Unprotected,
A chunk block whose writer computed no CRCs over its payload (FLAG_PAYLOAD_UNCHECKED, Integrity::None): its header and head checked, its payload taken as it is, whatever the reader asked for.
Unproven,
As Self::Linked by id, but the earlier piece is below [Integrity::Full]: it has no content hash, so the link is not proven by hash.
pub fn seal(
&self,
key: &K,
after: Option<&Sealed>,
) -> Result<Option<Vec<Sealed>>, WriteError<MemError<K>>>
where
K: core::fmt::Debug + 'static,
Raise the closed tape under key to Integrity::Full (TapeWriter::seal_on): its
pieces sealed in order, the first after the piece after when it follows a piece sealed before; None when
there is no tape under key.
pub fn seal(path: &Path, after: Option<&Sealed>) -> Result<Vec<Sealed>, WriteError<FsError>>
Raise the closed file at path to Integrity::Full in place.