Skip to content

Keep 'chop --ignore' reading the file in order - #428

Merged
folbricht merged 2 commits into
masterfrom
fix-chop-ignore-read-order
Sep 3, 2026
Merged

folbricht merged 2 commits into
masterfrom
fix-chop-ignore-read-order

Conversation

@folbricht

Copy link
Copy Markdown
Owner

ChopFile starts a worker per --concurrency, each with its own file handle, and every worker seeks to c.Start before reading. The order the chunks are handed over in is therefore the order the file gets read in, and nothing downstream reorders or buffers.

Without --ignore that list comes straight from the index, in ascending offset order, so the workers read a sliding window that advances through the file. With --ignore the list was rebuilt by ranging over the filter map, and Go randomizes map iteration deliberately — a different random start bucket per loop — so the file was read in a different random order on every run, with no readahead value and no reproducibility.

The survivors are sorted by offset again, which restores the index order exactly since filtering only ever deletes. Keying the filter map by chunk ID also collapses repeated chunks; ChunkStorage already skips storing a chunk twice, but readChunkFromFile runs first, so the dedup still saves a seek and a read per repeat and is kept.

The filtering moved into chunksToStore so the ordering can be asserted. The test runs it ten times, since one pass of a randomized map proves little, and also checks that no chunk ID is handed over twice and that an unfiltered index is passed through untouched.

ChopFile's workers seek to each chunk's offset, so the order the chunks
are handed over in is the order the file is read in. Filtering rebuilt
that list by ranging over a map, and Go randomizes map iteration, so
--ignore turned a front-to-back read into a different random walk over
the whole file on every run.

Sort the survivors by offset again. Keying the filter by chunk ID also
collapses repeated chunks, which saves re-reading them, so that stays.

The filtering moved into its own function to make the order assertable.
ChopFile's workers seek to each chunk's offset, so the order the chunks
are handed over in is the order the file is read in. Filtering rebuilt
that list by ranging over a map, and Go randomizes map iteration, so
--ignore turned a front-to-back read into a different random walk over
the whole file on every run.

Sort the survivors by offset again. Keying the filter by chunk ID also
collapses repeated chunks, which saves re-reading them, so that stays.
@folbricht
folbricht merged commit b9d6117 into master Sep 3, 2026
9 checks passed
@folbricht
folbricht deleted the fix-chop-ignore-read-order branch September 3, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址