Skip to content

Chunker refactor #8883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 3, 2025
Merged

Conversation

ThomasWaldmann
Copy link
Member

@ThomasWaldmann ThomasWaldmann commented May 26, 2025

  • transform buzhash chunker C code to Cython

  • split concerns into FileFMAPReader, FileReader, Chunker:

    • FileFMAPReader reads blocks from the input file, supporting sparse files and fmaps.
    • FileReader uses FileFMAPReader to fill its buffer and offers clients a .read(size) method so they can read arbitrarily sized pieces of the data.
    • both chunkers (fixed and buzhash) now use the FileReader/FileFMAPReader code
  • more tests

Copy link

codecov bot commented May 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.02%. Comparing base (8d3767e) to head (9f73862).
Report is 28 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8883      +/-   ##
==========================================
- Coverage   82.48%   82.02%   -0.47%     
==========================================
  Files          74       74              
  Lines       13367    13367              
  Branches     1977     1977              
==========================================
- Hits        11026    10964      -62     
- Misses       1682     1745      +63     
+ Partials      659      658       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Replaced `ChunkerFixed`'s block-reading functionality with a new `FileReader` class to streamline code and improve separation of concerns. Adjusted `ChunkerFixed` to delegate file reading to `FileReader` while focusing on chunk assembly.

`FileReader` is intended to be useful for other chunkers also, so they can easily implement sparse file reading / fmap support.
`FileFMAPReader` deals with sparse files (data vs holes) or fmap and yields blocks of some specific read_size using a generator.

`FileReader` uses the `FileFMAPReader` to fill an internal buffer and lets users use its `read` method to read arbitrary sized chunks from the buffer.

For both classes, instances now only deal with a single file.
The `header_size` parameter and related logic have been removed from file readers, simplifying their implementation. This change eliminates unnecessary complexity while maintaining all functional capabilities via `read_size` and `fmap`.
Simplified and improved handling of mixed types of chunks during reading. The allocation type of resulting chunks is now determined based on contributing chunks.
Includes cases for simple reads, multiple reads, and mock chunk scenarios to verify behavior with mixed allocation types.

Also: change Chunk type for empty read result for better consistency.
Includes unit tests for basic functionality, handling of custom file maps, allocation types, sparse file support, and `_build_fmap` method.
Replaced inline file reading logic with `FileReader` to standardize handling across chunkers. Improved buffer updates and allocation handling for sparse files and optimized read operations.
Could happen at EOF when remaining data is insufficient and no new data can be added.
@ThomasWaldmann ThomasWaldmann force-pushed the chunker-refactor2 branch 2 times, most recently from 633f09a to 8fb5951 Compare May 28, 2025 10:19
@ThomasWaldmann ThomasWaldmann changed the title Chunker refactor, try 2 Chunker refactor Jun 3, 2025
@ThomasWaldmann ThomasWaldmann merged commit 1c07087 into borgbackup:master Jun 3, 2025
14 of 15 checks passed
@ThomasWaldmann ThomasWaldmann deleted the chunker-refactor2 branch June 3, 2025 10:51
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