FileCollector

Thread-safe file assembly from asynchronous chunks: overlaps, duplicates, completeness, immutable snapshots and lifecycle. Multithreaded and failure tests.

Systems programming
Figure 1 — Systems programming

Contract

Registration supplies a file identifier and size. A chunk contains the identifier, an offset and bytes. It may arrive out of order or overlap a previously received range. A file is complete when each byte of its declared length has been written.

Write path

The specification tracks committed and reserved bytes separately. A worker reserves a free range, writes it and marks completion. An error releases that reservation. A read waits for tasks on the requested file. A snapshot of an incomplete file or a specific range needs a copy so later writes cannot change data already returned.

Verification

IFileCollector declares CollectFile, OnNewChunk, GetFile and TakeFile. The tests directory contains separate boundary, concurrency, exception and snapshot tests.

Related projects, disciplines and materials

Source code · 57a6c0d613b4b6e343c16c202d7abab26fe452c9