Repository navigation
Conversation
Signed-off-by: Willis Wu <willis060510@gmail.com>
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| #pragma once |
There was a problem hiding this comment.
merge this file into zfile.cpp
| } | ||
|
|
||
| // Shared by the whole-file writer and both streaming builders. | ||
| static int write_index(IFile *file, const std::vector<uint32_t> &lengths, |
There was a problem hiding this comment.
why static? why not let it be a member of ZFileBuilderBase?
| pht->opt.use_dict); | ||
|
|
||
| if (index_bytes > trailer_offset - pht->index_offset) | ||
| LOG_ERROR_RETURN(0, false, "invalid index bytes or size. "); |
There was a problem hiding this comment.
is it necessary to change so much here?
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
An unresolved out-of-bounds read needs correction, and historical format compatibility still requires human review.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds opt-in ZFile index compression while preserving raw indexes by default.
Changes:
- Adds LZ4/ZSTD index compression shared by all writers.
- Exposes API and CLI options.
- Strengthens validation and adds round-trip and malformed-input tests.
| File | Description |
|---|---|
| src/tools/overlaybd-zfile.cpp | Adds --compress-index. |
| src/overlaybd/zfile/zfile.cpp | Integrates index compression and validation. |
| src/overlaybd/zfile/test/test.cpp | Tests writers, codecs, and invalid inputs. |
| src/overlaybd/zfile/index_compression.h | Implements index codec helpers. |
| src/overlaybd/zfile/format_spec.md | Documents compressed-index storage and compatibility. |
| src/overlaybd/zfile/compressor.h | Adds the opt-in API setting. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Willis Wu <willis060510@gmail.com>
|
|
||
| // Whole-index codecs use CPU routines: data-block/QAT buffer limits do not apply. | ||
| // Return 1 for compressed output, 0 to keep the original, or -1 on codec error. | ||
| static int compress_index_buffer(const void *src, size_t size, uint8_t algo, |
There was a problem hiding this comment.
make it a member of ZFileBuilderBase.
| } | ||
|
|
||
| // A successful decode must restore exactly the expected index byte count. | ||
| static int decompress_index_buffer(const void *src, size_t size, void *dst, |
There was a problem hiding this comment.
make it a member of ZFileBuilderBase.
Signed-off-by: Willis Wu <willis060510@gmail.com>
| } | ||
|
|
||
| // Check before buffering or queueing data, not after the index has already grown. | ||
| static int check_input_size(uint64_t current_size, size_t count, uint32_t block_size) { |
There was a problem hiding this comment.
put it into ZFileBuilderBase, not necessarily static.
| virtual int fini() = 0; | ||
| // Whole-index codecs use CPU routines: data-block/QAT buffer limits do not apply. | ||
| // Return 1 for compressed output, 0 to keep the original, or -1 on codec error. | ||
| static int compress_index_buffer(const void *src, size_t size, uint8_t algo, |
| } | ||
|
|
||
| // A successful decode must restore exactly the expected index byte count. | ||
| static int decompress_index_buffer(const void *src, size_t size, void *dst, |

ZFile already compresses data blocks, but stores the block-length index uncompressed. This PR adds optional index compression using the existing format’s flag bit 5.
Changes:
CompressArgs::compress_indexand the--compress-indexCLI flag, disabled by default.Format choices:
index_sizeremains the entry count.Existing raw indexes remain supported. Older readers cannot read compressed indexes, so compression remains opt-in. I have not compared these format choices with the historical ease implementation.
Validation:
zfile_testsuite: all 12 tests passed.git diff --checkpassed.