Skip to content

Streaming Compression support for fullsync - #4075

Merged
sarthakaggarwal97 merged 2 commits into
valkey-io:unstablefrom
roshkhatri:repl-streaming-comression-fullsync-pr
Sep 11, 2026
Merged

sarthakaggarwal97 merged 2 commits into
valkey-io:unstablefrom
roshkhatri:repl-streaming-comression-fullsync-pr

Conversation

@roshkhatri

@roshkhatri roshkhatri commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Compresses the full-sync RDB payload with the LZ4 stream codec from #3531, across
disk-based, diskless, and dual-channel sync (on the wire, and on the shared disk file for
disk-based).

No new config. Sync compression is driven by the existing rdbcompression lz4 on both
ends, negotiated per replica so no replica ever receives a payload it cannot load.

Negotiation:

  • A replica whose own rdbcompression is lz4 advertises REPLCONF capa lz4. The
    capability names the codec, so a replica advertises only what its binary can decode and a
    future codec adds its own capability.
  • The primary compresses only when its own rdbcompression is lz4 and every replica
    attaching to that sync advertised the capability. If any replica is not capable, everyone
    gets plaintext and that sync writes a plain snapshot.
  • A replica arriving during an in-flight disk BGSAVE can join a plain save regardless of
    capability; a compressed save requires it.
  • rdbcompression yes and lzf select per-string LZF, which is not a stream codec and
    cannot frame a payload, so only lz4 enables this.

What this changes about rdbcompression

rdbcompression gains a second meaning: it now also selects the full-sync wire format.
Setting lz4 for persistence opts a server into compressed sync, and a replica must be
willing to write lz4 snapshots in order to accept them. This was chosen over a dedicated
knob because both formats are the same codec, and a separate switch would only let them
disagree.

Two consequences follow:

  • With a non-capable replica attached, a disk-based round writes a plain dump.rdb even
    under rdbcompression lz4, so the persisted format depends on which replicas attached to
    that round.
  • When AOF is enabled, a compressed sync snapshot is not reused as an AOF base; the replica
    runs BGREWRITEAOF instead.

Framing and failure handling

The $EOF:<mark> preamble and its 40-byte suffix stay plaintext; only the payload is
compressed. A link dropped mid-frame is recoverable truncation and retries as a full
resync. A corrupt frame is fatal and terminates the load rather than driving a resync loop,
matching how the RDB parser already treats corruption.

Metrics

Replica-side input counts wire (compressed) bytes at the read source, so
total_net_repl_input_bytes reflects what crossed the network rather than the logical RDB
size. Dual-channel output aggregates the bytes actually written across every socket in the
connset and is reported even when the save fails partway, which also corrects a
pre-existing undercount on the plain dual-channel path.

How configs affect full sync

Config Where Effect on full sync
rdbcompression (no / yes / lzf / lz4) primary and replica Drives this feature: a replica with lz4 advertises the capability, and a primary with lz4 compresses only when the whole cohort is capable (otherwise plaintext). Codec-default level, no separate level knob. Runtime changes apply to subsequent syncs.
repl-diskless-sync (yes/no) primary Unchanged path selection; compression is layered onto each path (no = one shared compressed disk file, yes = compressed socket stream with the $EOF:<mark> framing kept plaintext).
repl-diskless-sync-delay / repl-diskless-sync-max-replicas primary Unchanged: defines the cohort window that the capability AND is computed over.
repl-diskless-load (disabled/swapdb/on-empty-db) replica Unchanged: both load paths decompress transparently (inline for swapdb/on-empty-db, via temp-file rdbLoad auto-detect for disabled). A file received to disk is kept in the received format; existing configs govern its retention.
dual-channel-replication-enabled both Rides the diskless path; the dual-channel handshake also advertises the lz4 capability so the RDB-channel payload negotiates the same way.
rdbchecksum (yes/no) primary Unchanged when uncompressed; under lz4 the logical CRC64 trailer is zero and this instead controls the LZ4 block and content checksums that protect the stream.

All other replication and RDB configs are unaffected by this change.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▢️ Resume reviews
  • πŸ” Trigger review
πŸ“ Walkthrough

Walkthrough

Adds vendored LZ4 streaming compression for RDB files and replication full syncs. It introduces compression abstractions, VCS stream envelopes, rio integration, capability negotiation, configuration modes, RDB validation, and unit, integration, and CI coverage.

Changes

Streaming compression feature

Layer / File(s) Summary
Vendored LZ4 library and build wiring
deps/lz4/*, deps/*, cmake/*, src/Makefile, src/CMakeLists.txt, src/unit/*
Adds LZ4 and xxHash sources, static-library build targets, and server and test linkage.
Generic streaming codec abstraction
src/compression.*, src/compression_lz4.*
Defines compression algorithms, flush modes, stream state, checksum controls, and LZ4 frame operations.
VCS envelope and rio adapters
src/compression_stream.*, src/rio.*
Adds envelope validation, incremental compression and decompression, passthrough handling, partial reads, stream attachment, and transformed byte accounting.
RDB persistence and replication integration
src/rdb.*, src/aof.c, src/replication.c, src/server.h, src/valkey-check-rdb.c
Adds compressed RDB save/load paths, checksum and format tracking, capability negotiation, cohort-wide full-sync selection, replica stream decoding, and AOF fallback handling.
Validation, CI, and configuration documentation
src/unit/test_compression.cpp, tests/integration/*, .github/workflows/ci.yml, valkey.conf, tests/support/*, tests/test_helper.tcl
Adds coverage for compression, replication, corruption, fallback, accounting, and configuration behavior. Adds a dedicated CI job and test tagging.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related issues

Possibly related PRs

  • valkey-io/valkey#3531 β€” Strong code-level overlap across LZ4 sources, compression APIs, RDB, rio, replication integration, and tests.
  • valkey-io/valkey#3772 β€” Modifies the diskless RDB pipe test area used by the new replication-compression coverage.

Suggested reviewers: sarthakaggarwal97

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (4 passed)
Check name Status Explanation
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
Title check βœ… Passed The title clearly identifies the primary change: adding streaming compression support for full synchronization.
Description check βœ… Passed The description is detailed and directly relates to full-sync compression, negotiation, framing, failure handling, metrics, and configuration behavior.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🧹 Nitpick comments (3)
src/compression.h (1)

28-42: 🩺 Stability & Availability | πŸ”΅ Trivial | ⚑ Quick win

streamCompressor lacks an error-latch flag mirroring streamDecompressor.

streamDecompressor has errored/frame_done to prevent further use after a fatal failure, but streamCompressor has no equivalent. Per the rationale documented in compression_lz4.c (compressionLz4CompressFeed), once LZ4F_compressUpdate/LZ4F_flush/LZ4F_compressEnd fails after the frame header was written, the frame is permanently corrupt and not retriable, yet a caller that ignores the -1 return and calls again (e.g. with a bigger buffer, mistaking it for a capacity-retriable error) would continue mutating LZ4F state on an already-broken frame. Adding an errored flag to streamCompressor, checked at the top of streamCompressorFeed/compressionLz4CompressFeed, would make this defensive against misuse symmetric with the decompressor side.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/compression.h` around lines 28 - 42, `streamCompressor` is missing a
fatal-error latch like `streamDecompressor`, so a failed compress operation can
be retried and keep mutating broken LZ4F state. Add an `errored` flag to
`streamCompressor` and set it when `compressionLz4CompressFeed` (and the
underlying `LZ4F_compressUpdate`/`LZ4F_flush`/`LZ4F_compressEnd` paths) returns
a non-recoverable failure after the header is written. Then guard the top of
`streamCompressorFeed`/`compressionLz4CompressFeed` to immediately reject
further use once `errored` is set, mirroring the existing `streamDecompressor`
behavior.
src/compression_lz4.c (2)

49-67: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | πŸ’€ Low value

Allocation-failure handling relies entirely on assert.

compressionLz4CompressorInit/compressionLz4DecompressorInit always return 0; the only failure indication is assert(ctx != NULL), which aborts the process rather than letting the compression.c dispatcher's if (... != 0) { ...; return -1; } path run. This matches the project's general fail-fast-on-OOM convention (since zmalloc/zcalloc already abort on allocation failure by default), so it's consistent rather than a functional bug, but the int return contract documented in compression_lz4.h ("Returns 0 on success") is effectively dead since these specific functions can't return non-zero.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/compression_lz4.c` around lines 49 - 67, The LZ4 init paths in
compressionLz4CompressorInit and compressionLz4DecompressorInit rely only on
assert() and always return 0, so the declared success/failure contract is
effectively unused. Update these initializers to either propagate a real failure
return when LZ4F_createCompressionContext_advanced or
LZ4F_createDecompressionContext_advanced cannot produce a context, or align the
signatures/docs in compression_lz4.h with the intended fail-fast behavior so the
compression.c dispatcher and the API contract match. Ensure
compressor->ctx/decompressor->ctx handling remains consistent with
compressionLz4CompressorFree.

12-13: 🎯 Functional Correctness | πŸ”΅ Trivial

Keep future LZ4 bumps on the checklist: LZ4F_createCompressionContext_advanced and LZ4F_createDecompressionContext_advanced sit behind LZ4F_STATIC_LINKING_ONLY; upstream marks that block as unstable and only safe for statically linked callers. Re-check their signatures and behavior whenever deps/lz4 is updated.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/compression_lz4.c` around lines 12 - 13, The LZ4 frame APIs used in this
file are gated by the static-linking-only block, so make sure the implementation
in compression_lz4.c explicitly treats LZ4F_createCompressionContext_advanced
and LZ4F_createDecompressionContext_advanced as unstable upstream dependencies.
Keep the include of LZ4F_STATIC_LINKING_ONLY paired with <lz4frame.h>, and
update the surrounding code in the compression/decompression setup helpers to
re-validate the function signatures and behavior whenever deps/lz4 is bumped.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deps/lz4/lz4frame.c`:
- Around line 1619-1623: The issue is reachable null-pointer arithmetic in
LZ4F_decompress when LZ4F_getFrameInfo calls it with a null srcBuffer and zero
input size. Update the LZ4F_decompress path in lz4frame.c to match the upstream
fix so it never computes srcStart + *srcSizePtr on a null base; use the same
null-safe handling around srcStart/srcEnd and the related LZ4F_getFrameInfo call
path. Locate the change in LZ4F_decompress and ensure the vendored LZ4 copy is
refreshed from upstream rather than patched locally.

In `@deps/lz4/Makefile`:
- Line 19: The lz4hc.o build rule is missing its dependency on lz4.c, so
incremental builds can leave lz4hc.o stale after lz4.c changes. Update the
Makefile rule for lz4hc.o to include lz4.c alongside lz4hc.c, lz4hc.h, and lz4.h
so the object is rebuilt whenever the included source changes.

In `@src/compression_stream.h`:
- Around line 156-157: Update the contract comment for streamReaderRead to match
its actual read-like behavior: the implementation can return positive partial
reads, so remove or revise the β€œFull or fail” wording in the streamReaderRead
declaration in compression_stream.h and describe that it may return fewer than
len bytes, while still documenting 0 for EOF and -1 for error. If you want to
keep the current wording, then enforce full-read semantics in the
streamReaderRead implementation instead.

In `@src/rdb.c`:
- Around line 515-524: The per-string LZF branch in the RDB save path still
depends on server.rdb_compression, so full-sync replication can incorrectly emit
compressed objects when only repl-compression should govern the behavior. Update
the condition in the RDB string serialization logic around
rdbSaveLzfStringObject so it uses the streaming/full-sync compression capability
gate instead of rdbcompression, and preserve the existing fallback to verbatim
storage when compression is disabled or not supported.

In `@src/replication.c`:
- Around line 1163-1177: The disk full-sync compression decision in
replication.c is currently based only on matched replicas’ capabilities, but it
must also honor the primary’s repl-compression configuration. Update the logic
around the save_flags / matched / all_capable check so
RDBFLAGS_REPL_COMPRESSED_SYNC is set only when all matched replicas support
compression and the primary-side repl-compression setting is enabled. Use the
existing replication negotiation code in this block (including replicaRdbVersion
and the replica capability checks) to keep the condition centralized and
consistent.

In `@src/rio.c`:
- Around line 245-270: The read-limit enforcement in rio.c is vulnerable to
integer overflow because the comparisons in the read path add read_so_far,
min_read, avail, and toread before checking the limit. Update the limit checks
in the rio connection read logic so they compare against the remaining allowed
bytes without performing unchecked addition, and ensure both the initial
strict_limit guard and the loop inside the read helper handle overflow-safe
arithmetic consistently. Locate the fix in the code that updates
r->io.conn.read_so_far, r->io.conn.read_limit, and the buffer-growth/read loop.

In `@tests/integration/dual-channel-replication.tcl`:
- Line 351: The buffer-accounting assertions in the dual-channel replication
tests should not run under the repl-compression tag set because compression
changes replication buffer byte counts and can cause spurious failures. Move the
exact memory/buffer invariant cases out of the tagged repl-compression blocks
into untagged blocks, following the pattern used by the byte-volume case, and
keep the replication-compression-specific coverage separate in the
dual-channel-replication test file.

In `@tests/integration/rdb-compression.tcl`:
- Line 498: The test file has a stray unmatched closing brace at the end, which
leaves the Tcl syntax unbalanced. Remove the extra closing brace at the end of
tests/integration/rdb-compression.tcl and verify the surrounding test block
structure still matches the expected opener/closer pairing in the integration
test content.

In `@tests/integration/repl-compression.tcl`:
- Line 1: The top-level tag declaration in repl-compression.tcl is applying
repl-compression to every test in the file, which forces baseline cases into the
compressed-default setup. Update the tagging so only the compression-specific
test blocks are tagged, or move the non-compressed baseline coverage into an
untagged file; use the existing tags block and nested start_server cases as the
places to adjust.

In `@tests/integration/repl-fullsync-compression.tcl`:
- Around line 649-650: The retry check in the full-sync test is too weak because
sync_full can increment when the aborted sync starts, so it doesn’t prove a
clean retry occurred. Update the assertion in the test around status $primary
sync_full to verify the post-abort full sync actually completed, using a
stronger condition that distinguishes the restarted sync from the interrupted
one and ties it to the second, clean full sync behavior.

---

Nitpick comments:
In `@src/compression_lz4.c`:
- Around line 49-67: The LZ4 init paths in compressionLz4CompressorInit and
compressionLz4DecompressorInit rely only on assert() and always return 0, so the
declared success/failure contract is effectively unused. Update these
initializers to either propagate a real failure return when
LZ4F_createCompressionContext_advanced or
LZ4F_createDecompressionContext_advanced cannot produce a context, or align the
signatures/docs in compression_lz4.h with the intended fail-fast behavior so the
compression.c dispatcher and the API contract match. Ensure
compressor->ctx/decompressor->ctx handling remains consistent with
compressionLz4CompressorFree.
- Around line 12-13: The LZ4 frame APIs used in this file are gated by the
static-linking-only block, so make sure the implementation in compression_lz4.c
explicitly treats LZ4F_createCompressionContext_advanced and
LZ4F_createDecompressionContext_advanced as unstable upstream dependencies. Keep
the include of LZ4F_STATIC_LINKING_ONLY paired with <lz4frame.h>, and update the
surrounding code in the compression/decompression setup helpers to re-validate
the function signatures and behavior whenever deps/lz4 is bumped.

In `@src/compression.h`:
- Around line 28-42: `streamCompressor` is missing a fatal-error latch like
`streamDecompressor`, so a failed compress operation can be retried and keep
mutating broken LZ4F state. Add an `errored` flag to `streamCompressor` and set
it when `compressionLz4CompressFeed` (and the underlying
`LZ4F_compressUpdate`/`LZ4F_flush`/`LZ4F_compressEnd` paths) returns a
non-recoverable failure after the header is written. Then guard the top of
`streamCompressorFeed`/`compressionLz4CompressFeed` to immediately reject
further use once `errored` is set, mirroring the existing `streamDecompressor`
behavior.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a330f77-f27e-4161-8da7-b6249d04994f

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 5b690ce and ef02d03.

πŸ“’ Files selected for processing (59)
  • .github/workflows/ci.yml
  • cmake/Modules/SourceFiles.cmake
  • cmake/Modules/ValkeySetup.cmake
  • deps/CMakeLists.txt
  • deps/Makefile
  • deps/lz4/CMakeLists.txt
  • deps/lz4/LICENSE
  • deps/lz4/Makefile
  • deps/lz4/lz4.c
  • deps/lz4/lz4.h
  • deps/lz4/lz4frame.c
  • deps/lz4/lz4frame.h
  • deps/lz4/lz4hc.c
  • deps/lz4/lz4hc.h
  • deps/lz4/xxhash.c
  • deps/lz4/xxhash.h
  • src/CMakeLists.txt
  • src/Makefile
  • src/aof.c
  • src/compression.c
  • src/compression.h
  • src/compression_lz4.c
  • src/compression_lz4.h
  • src/compression_repl.c
  • src/compression_repl.h
  • src/compression_rio.c
  • src/compression_rio.h
  • src/compression_stream.c
  • src/compression_stream.h
  • src/config.c
  • src/io_threads.c
  • src/networking.c
  • src/rdb.c
  • src/rdb.h
  • src/replication.c
  • src/rio.c
  • src/rio.h
  • src/server.c
  • src/server.h
  • src/unit/CMakeLists.txt
  • src/unit/Makefile
  • src/unit/test_compression.cpp
  • src/unit/test_repl_compression.cpp
  • src/valkey-check-rdb.c
  • tests/integration/block-repl.tcl
  • tests/integration/dual-channel-replication.tcl
  • tests/integration/rdb-compression.tcl
  • tests/integration/repl-compression.tcl
  • tests/integration/repl-fullsync-compression.tcl
  • tests/integration/replication-2.tcl
  • tests/integration/replication-3.tcl
  • tests/integration/replication-4.tcl
  • tests/integration/replication-aof-sync.tcl
  • tests/integration/replication.tcl
  • tests/integration/skip-rdb-checksum.tcl
  • tests/integration/valkey-check-rdb.tcl
  • tests/support/server.tcl
  • tests/test_helper.tcl
  • valkey.conf

Comment thread deps/lz4/lz4frame.c Resolved
Comment thread deps/lz4/Makefile Resolved
Comment thread src/compression_stream.h Resolved
Comment thread src/rdb.c Resolved
Comment thread src/replication.c Resolved
Comment thread src/rio.c Resolved
Comment thread tests/integration/rdb-compression.tcl Resolved
Comment thread tests/integration/repl-compression.tcl Outdated
@@ -0,0 +1,1027 @@
tags {"repl repl-compression external:skip"} {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚑ Quick win

Don't put the whole file under the repl-compression tag.

The new CI job runs --tags "repl-compression -slow" --config repl-compression lz4-stream, so this top-level tag forces every test here into a compressed-default environment. That breaks baseline cases that intentionally rely on the default no pathβ€”for example, Lines 144-159 no longer model an older/non-capable replica unless every nested start_server restates repl-compression no. Tag only the compression-specific blocks or split the baseline coverage into an untagged file.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/repl-compression.tcl` at line 1, The top-level tag
declaration in repl-compression.tcl is applying repl-compression to every test
in the file, which forces baseline cases into the compressed-default setup.
Update the tagging so only the compression-specific test blocks are tagged, or
move the non-compressed baseline coverage into an untagged file; use the
existing tags block and nested start_server cases as the places to adjust.

@codecov

codecov Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.69231% with 24 lines in your changes missing coverage. Please review.
βœ… Project coverage is 80.14%. Comparing base (98f9152) to head (1d68c5f).

Files with missing lines Patch % Lines
src/rdb.c 79.24% 11 Missing ⚠️
src/replication.c 88.23% 8 Missing ⚠️
src/rio.c 86.84% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #4075      +/-   ##
============================================
+ Coverage     80.04%   80.14%   +0.10%     
============================================
  Files           189      189              
  Lines         97253    97391     +138     
============================================
+ Hits          77842    78053     +211     
+ Misses        19411    19338      -73     
Files with missing lines Coverage Ξ”
src/compression_stream.c 95.27% <100.00%> (+0.02%) ⬆️
src/rdb.h 100.00% <ΓΈ> (ΓΈ)
src/rio.h 94.23% <ΓΈ> (ΓΈ)
src/server.h 100.00% <ΓΈ> (ΓΈ)
src/unit/test_compression.cpp 96.82% <100.00%> (+0.04%) ⬆️
src/rio.c 87.25% <86.84%> (+0.77%) ⬆️
src/replication.c 86.39% <88.23%> (+0.36%) ⬆️
src/rdb.c 76.34% <79.24%> (+0.11%) ⬆️

... and 20 files with indirect coverage changes

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@roshkhatri

Copy link
Copy Markdown
Member Author

@coderabbitai review the code for Streaming Compression support for fullsync,
This PR is bases on the branch of #3853, which is also based on #3531

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -e
echo "=== compression_stream.h ==="
cat -n src/compression_stream.h
echo "=== compression_stream.c (first 250 lines) ==="
sed -n '1,250p' src/compression_stream.c

Length of output: 16694


🏁 Script executed:

#!/bin/bash
set -e
echo "=== compression_repl.c ==="
cat -n src/compression_repl.c

Length of output: 9042


🏁 Script executed:

#!/bin/bash
set -e
echo "=== rdb.c relevant excerpts ==="
rg -n "RDBFLAGS_REPL_COMPRESSED_SYNC|compressRio|rdbSaveRioWithOptionalCompression|RIO_FLAG_SKIP_RDB_CHECKSUM|rdbRioHasCorruptCompressedInput" src/rdb.c
echo "=== replication.c capability negotiation ==="
rg -n "REPLICA_CAPA_COMPRESSION|reconcileReplicaCompression|RDBFLAGS_REPL_COMPRESSED_SYNC|repl_provisional_compression" src/replication.c

Length of output: 4023


🏁 Script executed:

#!/bin/bash
set -e
echo "=== io_threads.c write offload checks ==="
rg -n "ioThreadWriteToClient|repl_compressor|JOB_REQ_WRITE_CLIENT|trySendWriteToIOThreads" src/io_threads.c src/networking.c | head -60

Length of output: 2160


🏁 Script executed:

#!/bin/bash
set -e
sed -n '520,600p' src/io_threads.c
echo "=== writeToReplicaCompressed context ==="
sed -n '2440,2520p' src/networking.c

Length of output: 7078


@roshkhatri Thanks for the context β€” I went through the core compression machinery and the replication/RDB integration points rather than just the AI summary. Here's what I found:

Architecture β€” the layering is clean: compression.c dispatches on compressionAlgo, compression_lz4.c wraps LZ4F, compression_stream.c implements the VCS envelope + generic streaming reader/writer, and compression_repl.c / compression_rio.c are thin wire adapters for replication and RDB respectively. This separation makes it easy to reason about each layer independently and should make adding a second codec straightforward later.

Capability negotiation β€” verified in src/replication.c: rdbSaveToReplicasSockets()/the disk-based full-sync BGSAVE-flag path only sets RDBFLAGS_REPL_COMPRESSED_SYNC when every replica in the matched cohort has REPLICA_CAPA_COMPRESSION set (Line ~1175-1177), and reconcileReplicaCompression() correctly diffs actual compressor state against the capa bit before disconnecting mismatched replicas. This matches the PR's stated "all-or-plaintext" cohort behavior.

Checksum handling β€” rdbSaveRawString()'s per-string LZF compression is properly gated off via RIO_FLAG_STREAMING_COMPRESSION to avoid double-compressing, and RDB-level checksum computation is consistently skipped (RIO_FLAG_SKIP_RDB_CHECKSUM) in favor of the LZ4 frame's own checksum across rdb.c and valkey-check-rdb.c. rdbRioHasCorruptCompressedInput() gives a clean way to distinguish codec corruption from ordinary truncation.

Decompression-bomb guard β€” compression_repl.c's replDecodeFeed() bounds output against output_max, detects the "no progress with pending input" impossible state, and disconnects on an unexpected frame_done mid-stream (a replication stream should never legitimately hit a frame end). The VCS magic-prefix probing correctly handles the case where the 3-7 byte header arrives split across multiple socket reads, replaying buffered bytes if the stream turns out to be plaintext passthrough.

IO-threads interaction β€” trySendReadToIOThreads() explicitly excludes primaries with active repl_decompressor/repl_compression from read offload, and writeToReplicaCompressed() is deliberately written to be safe on either the IO thread or main thread (single-owner semantics via io_write_state), so I didn't find a thread-safety gap there.

Config-time behavior β€” updateReplCompression() defers the actual reconnect/reconcile work via repl_compression_reconcile_pending until after CONFIG SET commits, so a rolled-back transaction won't spuriously disconnect replicas. That's a nice touch.

I didn't find functional bugs in the areas I traced end-to-end. Given the size of this PR (compression core + LZ4 vendoring + RDB/replication/AOF/IO-thread integration + ~2,700 lines of new tests), a full line-by-line audit of every path (e.g., dual-channel diskless decode, AOF base-file reuse fallback logging, and the CI job's test-tag exclusions) is out of scope for a single pass at this depth β€” happy to dig into any of those specifically if you'd like.

One process note: since this PR is stacked on #3853 and #3531, I'd suggest getting those merged/stabilized first, since diffs here already assume their APIs (REPLICA_CAPA_*, ClientReplicationData fields, etc.) β€” otherwise rebases could get painful.

βœ… Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@roshkhatri roshkhatri added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Aug 5, 2026
@roshkhatri
roshkhatri force-pushed the repl-streaming-comression-fullsync-pr branch from f96bf89 to 2c22c20 Compare August 5, 2026 08:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
deps/lz4/lz4.c (1)

105-116: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | ⚑ Quick win

Record the upstream LZ4 provenance.

These files target LZ4 v1.10.0, but there is no repository note recording the exact upstream tag. Add that provenance record so future LZ4 fixes are applied as a re-vendor and not an in-place patch.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deps/lz4/lz4.c` around lines 105 - 116, Add a repository provenance note for
the vendored LZ4 sources identifying upstream LZ4 version/tag v1.10.0. Place it
alongside the existing LZ4 vendor files or project metadata, and make clear that
future fixes must be applied by re-vendoring rather than patching these files in
place.

Sources: Coding guidelines, Learnings

πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration/repl-fullsync-compression.tcl`:
- Around line 655-660: Update the verify_no_log_message call in the mixed
diskless full-sync cohort test to use log index -2, targeting the primary server
rather than the capable replica. Keep the existing compression message pattern
and primary log-line collection unchanged.

In `@valkey.conf`:
- Around line 599-601: Update the rdbcompression comment to remove the obsolete
claim that full-sync negotiation is not implemented. State that rdbcompression
applies only to on-disk snapshots, while repl-compression controls full-sync
payload compression.

---

Nitpick comments:
In `@deps/lz4/lz4.c`:
- Around line 105-116: Add a repository provenance note for the vendored LZ4
sources identifying upstream LZ4 version/tag v1.10.0. Place it alongside the
existing LZ4 vendor files or project metadata, and make clear that future fixes
must be applied by re-vendoring rather than patching these files in place.
πŸͺ„ Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b73b661-66d4-44fb-bcbc-4a4b1b2903aa

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d84a2e8 and f96bf89.

πŸ“’ Files selected for processing (45)
  • .github/workflows/ci.yml
  • cmake/Modules/SourceFiles.cmake
  • cmake/Modules/ValkeySetup.cmake
  • deps/CMakeLists.txt
  • deps/Makefile
  • deps/lz4/CMakeLists.txt
  • deps/lz4/LICENSE
  • deps/lz4/Makefile
  • deps/lz4/lz4.c
  • deps/lz4/lz4.h
  • deps/lz4/lz4frame.c
  • deps/lz4/lz4frame.h
  • deps/lz4/lz4hc.c
  • deps/lz4/lz4hc.h
  • deps/lz4/xxhash.c
  • deps/lz4/xxhash.h
  • src/CMakeLists.txt
  • src/Makefile
  • src/aof.c
  • src/compression.c
  • src/compression.h
  • src/compression_lz4.c
  • src/compression_lz4.h
  • src/compression_stream.c
  • src/compression_stream.h
  • src/config.c
  • src/rdb.c
  • src/rdb.h
  • src/replication.c
  • src/rio.c
  • src/rio.h
  • src/server.h
  • src/unit/CMakeLists.txt
  • src/unit/Makefile
  • src/unit/test_compression.cpp
  • src/valkey-check-rdb.c
  • tests/integration/dual-channel-replication.tcl
  • tests/integration/rdb-compression.tcl
  • tests/integration/repl-fullsync-compression.tcl
  • tests/integration/replication-aof-sync.tcl
  • tests/integration/replication.tcl
  • tests/integration/valkey-check-rdb.tcl
  • tests/support/server.tcl
  • tests/test_helper.tcl
  • valkey.conf
🚧 Files skipped from review as they are similar to previous changes (17)
  • tests/test_helper.tcl
  • src/unit/CMakeLists.txt
  • src/CMakeLists.txt
  • cmake/Modules/ValkeySetup.cmake
  • deps/CMakeLists.txt
  • deps/lz4/CMakeLists.txt
  • deps/Makefile
  • cmake/Modules/SourceFiles.cmake
  • tests/support/server.tcl
  • deps/lz4/lz4frame.h
  • deps/lz4/LICENSE
  • deps/lz4/xxhash.c
  • deps/lz4/xxhash.h
  • src/Makefile
  • src/unit/Makefile
  • deps/lz4/lz4hc.h
  • deps/lz4/lz4.h

Comment thread valkey.conf Resolved
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@roshkhatri
roshkhatri force-pushed the repl-streaming-comression-fullsync-pr branch from 2c22c20 to 77af97e Compare August 5, 2026 08:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/unit/test_compression.cpp (1)

278-286: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | πŸ’€ Low value

Consider a compile-time check that ties the envelope literals to VCS_ENVELOPE_SIZE.

Three tests build a VCS_ENVELOPE_SIZE array from exactly seven positional initializers (Lines 214, 278-286, 460-468, 1132-1133). If VCS_ENVELOPE_SIZE grows, the extra bytes are zero-filled and these tests keep compiling while they no longer describe a full envelope. A static assertion makes that change fail loudly.

♻️ Proposed addition near the top of the file
+/* The envelope literals below list one initializer per envelope byte. Keep them
+ * in sync with the on-wire envelope size. */
+static_assert(VCS_ENVELOPE_SIZE == 7, "envelope test literals assume 7 bytes");
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/unit/test_compression.cpp` around lines 278 - 286, Add a compile-time
assertion near the top of test_compression.cpp that verifies the seven envelope
initializer literals match VCS_ENVELOPE_SIZE, covering the envelope arrays used
by the tests including the one shown and the corresponding definitions at the
other referenced locations.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/compression_stream.c`:
- Around line 210-214: Update compressionLz4CompressorInit and
compressionLz4DecompressorInit to return an error status when advanced LZ4
context allocation returns NULL instead of asserting. Propagate these failures
through streamWriterInit and streamReaderInit, setting STREAM_WRITER_STATE_ERROR
or STREAM_READER_ERROR_IO respectively so their existing return-value handling
can report the failure.

---

Nitpick comments:
In `@src/unit/test_compression.cpp`:
- Around line 278-286: Add a compile-time assertion near the top of
test_compression.cpp that verifies the seven envelope initializer literals match
VCS_ENVELOPE_SIZE, covering the envelope arrays used by the tests including the
one shown and the corresponding definitions at the other referenced locations.
πŸͺ„ Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 483305a8-4129-4258-8f24-959181f2f968

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d84a2e8 and 2c22c20.

πŸ“’ Files selected for processing (45)
  • .github/workflows/ci.yml
  • cmake/Modules/SourceFiles.cmake
  • cmake/Modules/ValkeySetup.cmake
  • deps/CMakeLists.txt
  • deps/Makefile
  • deps/lz4/CMakeLists.txt
  • deps/lz4/LICENSE
  • deps/lz4/Makefile
  • deps/lz4/lz4.c
  • deps/lz4/lz4.h
  • deps/lz4/lz4frame.c
  • deps/lz4/lz4frame.h
  • deps/lz4/lz4hc.c
  • deps/lz4/lz4hc.h
  • deps/lz4/xxhash.c
  • deps/lz4/xxhash.h
  • src/CMakeLists.txt
  • src/Makefile
  • src/aof.c
  • src/compression.c
  • src/compression.h
  • src/compression_lz4.c
  • src/compression_lz4.h
  • src/compression_stream.c
  • src/compression_stream.h
  • src/config.c
  • src/rdb.c
  • src/rdb.h
  • src/replication.c
  • src/rio.c
  • src/rio.h
  • src/server.h
  • src/unit/CMakeLists.txt
  • src/unit/Makefile
  • src/unit/test_compression.cpp
  • src/valkey-check-rdb.c
  • tests/integration/dual-channel-replication.tcl
  • tests/integration/rdb-compression.tcl
  • tests/integration/repl-fullsync-compression.tcl
  • tests/integration/replication-aof-sync.tcl
  • tests/integration/replication.tcl
  • tests/integration/valkey-check-rdb.tcl
  • tests/support/server.tcl
  • tests/test_helper.tcl
  • valkey.conf
🚧 Files skipped from review as they are similar to previous changes (34)
  • tests/integration/dual-channel-replication.tcl
  • tests/support/server.tcl
  • cmake/Modules/SourceFiles.cmake
  • src/unit/CMakeLists.txt
  • tests/test_helper.tcl
  • deps/lz4/CMakeLists.txt
  • deps/CMakeLists.txt
  • deps/lz4/LICENSE
  • src/CMakeLists.txt
  • tests/integration/replication.tcl
  • src/unit/Makefile
  • cmake/Modules/ValkeySetup.cmake
  • src/Makefile
  • deps/lz4/xxhash.h
  • valkey.conf
  • src/compression.h
  • src/compression_stream.h
  • deps/lz4/xxhash.c
  • tests/integration/replication-aof-sync.tcl
  • src/server.h
  • src/compression_lz4.h
  • deps/lz4/lz4frame.h
  • src/rdb.h
  • deps/Makefile
  • deps/lz4/lz4hc.c
  • tests/integration/repl-fullsync-compression.tcl
  • deps/lz4/lz4hc.h
  • src/compression_lz4.c
  • src/aof.c
  • deps/lz4/lz4.h
  • src/rio.h
  • src/replication.c
  • src/rdb.c
  • src/valkey-check-rdb.c

Comment thread src/compression_stream.c Resolved
Comment thread src/config.c Resolved
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
deps/lz4/Makefile (1)

19-19: πŸ“ Maintainability & Code Quality | 🟑 Minor | ⚑ Quick win

Add lz4.c to the lz4hc.o prerequisites.

deps/lz4/lz4hc.c textually includes lz4.c. This rule does not list lz4.c, so an incremental make can leave lz4hc.o stale after lz4.c changes.

Proposed fix
-lz4hc.o: lz4hc.c lz4hc.h lz4.h
+lz4hc.o: lz4hc.c lz4hc.h lz4.h lz4.c
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deps/lz4/Makefile` at line 19, Update the lz4hc.o dependency rule in the
Makefile to include lz4.c alongside its existing prerequisites, ensuring changes
to the textually included implementation trigger rebuilding lz4hc.o.
🧹 Nitpick comments (2)
deps/lz4/lz4.c (1)

1-33: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | πŸ’€ Low value

Document the vendored LZ4 source version.

deps/lz4/ is upstream-managed, and deps/lz4/lz4.h declares LZ4_VERSION_MAJOR.MINOR.RELEASE as 1.10.0. Add a small provenance/vendor tracking note or metadata file so future LZ4 updates can re-vendor a tagged release instead of patching vendored files in place.

The current compression wrapper uses LZ4 frame APIs only, which is appropriate for this import.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deps/lz4/lz4.c` around lines 1 - 33, Add a small provenance or vendor
metadata note within deps/lz4 identifying the vendored source as upstream LZ4
release 1.10.0, using LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, and
LZ4_VERSION_RELEASE from lz4.h as the reference. Document that future updates
should re-vendor a tagged upstream release rather than patching vendored files
in place; leave the existing LZ4 frame API wrapper unchanged.

Source: Learnings

src/rio.c (1)

512-527: 🩺 Stability & Availability | πŸ”΅ Trivial | ⚑ Quick win

Reject an over-reporting streamReaderRead result.

If streamReaderRead returns more than remaining, Line 523 underflows remaining to a huge value and Line 518 keeps writing past the caller buffer. The stream reader is expected to honor remaining, so this is defensive only. A cheap guard turns a contract violation into a latched read error.

♻️ Proposed guard
         ssize_t nread = streamReaderRead(r->stream_reader, dst, remaining);
-        if (nread <= 0) {
+        if (nread <= 0 || (size_t)nread > remaining) {
             r->flags |= RIO_FLAG_READ_ERROR;
             return 0;
         }
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/rio.c` around lines 512 - 527, Add a defensive check in rioReadStream
after streamReaderRead returns to reject any positive nread greater than
remaining; set RIO_FLAG_READ_ERROR and return 0 before updating remaining or
advancing dst, while preserving the existing handling for nonpositive results
and valid reads.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@deps/lz4/Makefile`:
- Line 19: Update the lz4hc.o dependency rule in the Makefile to include lz4.c
alongside its existing prerequisites, ensuring changes to the textually included
implementation trigger rebuilding lz4hc.o.

---

Nitpick comments:
In `@deps/lz4/lz4.c`:
- Around line 1-33: Add a small provenance or vendor metadata note within
deps/lz4 identifying the vendored source as upstream LZ4 release 1.10.0, using
LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, and LZ4_VERSION_RELEASE from lz4.h as the
reference. Document that future updates should re-vendor a tagged upstream
release rather than patching vendored files in place; leave the existing LZ4
frame API wrapper unchanged.

In `@src/rio.c`:
- Around line 512-527: Add a defensive check in rioReadStream after
streamReaderRead returns to reject any positive nread greater than remaining;
set RIO_FLAG_READ_ERROR and return 0 before updating remaining or advancing dst,
while preserving the existing handling for nonpositive results and valid reads.

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c6e97c48-c738-43fa-b582-e521b821cc4c

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d84a2e8 and 77af97e.

πŸ“’ Files selected for processing (45)
  • .github/workflows/ci.yml
  • cmake/Modules/SourceFiles.cmake
  • cmake/Modules/ValkeySetup.cmake
  • deps/CMakeLists.txt
  • deps/Makefile
  • deps/lz4/CMakeLists.txt
  • deps/lz4/LICENSE
  • deps/lz4/Makefile
  • deps/lz4/lz4.c
  • deps/lz4/lz4.h
  • deps/lz4/lz4frame.c
  • deps/lz4/lz4frame.h
  • deps/lz4/lz4hc.c
  • deps/lz4/lz4hc.h
  • deps/lz4/xxhash.c
  • deps/lz4/xxhash.h
  • src/CMakeLists.txt
  • src/Makefile
  • src/aof.c
  • src/compression.c
  • src/compression.h
  • src/compression_lz4.c
  • src/compression_lz4.h
  • src/compression_stream.c
  • src/compression_stream.h
  • src/config.c
  • src/rdb.c
  • src/rdb.h
  • src/replication.c
  • src/rio.c
  • src/rio.h
  • src/server.h
  • src/unit/CMakeLists.txt
  • src/unit/Makefile
  • src/unit/test_compression.cpp
  • src/valkey-check-rdb.c
  • tests/integration/dual-channel-replication.tcl
  • tests/integration/rdb-compression.tcl
  • tests/integration/repl-fullsync-compression.tcl
  • tests/integration/replication-aof-sync.tcl
  • tests/integration/replication.tcl
  • tests/integration/valkey-check-rdb.tcl
  • tests/support/server.tcl
  • tests/test_helper.tcl
  • valkey.conf
🚧 Files skipped from review as they are similar to previous changes (38)
  • cmake/Modules/SourceFiles.cmake
  • tests/test_helper.tcl
  • cmake/Modules/ValkeySetup.cmake
  • tests/integration/dual-channel-replication.tcl
  • src/unit/Makefile
  • src/Makefile
  • tests/support/server.tcl
  • deps/lz4/LICENSE
  • src/CMakeLists.txt
  • deps/CMakeLists.txt
  • deps/lz4/CMakeLists.txt
  • deps/Makefile
  • tests/integration/replication.tcl
  • src/aof.c
  • src/compression.c
  • src/compression_stream.h
  • src/rdb.h
  • deps/lz4/xxhash.h
  • valkey.conf
  • src/compression_lz4.h
  • src/server.h
  • tests/integration/rdb-compression.tcl
  • src/compression.h
  • deps/lz4/lz4frame.h
  • tests/integration/repl-fullsync-compression.tcl
  • src/unit/CMakeLists.txt
  • deps/lz4/xxhash.c
  • tests/integration/valkey-check-rdb.tcl
  • src/compression_lz4.c
  • src/compression_stream.c
  • deps/lz4/lz4.h
  • deps/lz4/lz4hc.h
  • src/valkey-check-rdb.c
  • src/rdb.c
  • src/rio.h
  • tests/integration/replication-aof-sync.tcl
  • deps/lz4/lz4hc.c
  • src/replication.c

@roshkhatri
roshkhatri force-pushed the repl-streaming-comression-fullsync-pr branch from 77af97e to 574a85c Compare August 5, 2026 21:53
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (4)
tests/integration/repl-fullsync-compression.tcl (1)

655-660: 🎯 Functional Correctness | 🟠 Major | ⚑ Quick win

Use -2 for the primary log in the mixed diskless cohort test.

This assertion still targets the wrong server. Inside this triply nested start_server scope, srv 0 is $replica_plain, -1 is $replica_capable, and -2 is the primary. Line 660 checks the capable replica's log, which never contains "with compression: lz4", so the assertion always passes and the plaintext-fallback property is not verified. Line 643 takes $primary_loglines from the primary, and lines 231 and 737 already use -2 for the primary in equivalent scopes.

πŸ› Proposed fix
-                verify_no_log_message -1 "*with compression: lz4*" $primary_loglines
+                verify_no_log_message -2 "*with compression: lz4*" $primary_loglines
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/repl-fullsync-compression.tcl` around lines 655 - 660,
Update the verify_no_log_message assertion in the mixed diskless full-sync test
to target the primary server log using -2 instead of -1. Keep the existing
compression message and $primary_loglines arguments unchanged so the
plaintext-fallback check validates the primary’s log.
deps/lz4/Makefile (1)

19-19: πŸ“ Maintainability & Code Quality | 🟑 Minor | ⚑ Quick win

lz4hc.o still lacks its lz4.c prerequisite.

deps/lz4/lz4hc.c includes lz4.c textually. This rule does not list lz4.c, so an edit to lz4.c leaves lz4hc.o stale on an incremental make. The earlier review marked this as addressed, but the current file still omits the prerequisite.

πŸ”§ Proposed fix
-lz4hc.o: lz4hc.c lz4hc.h lz4.h
+lz4hc.o: lz4hc.c lz4hc.h lz4.h lz4.c
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deps/lz4/Makefile` at line 19, Update the lz4hc.o dependency rule to include
lz4.c alongside its existing prerequisites, ensuring changes to the textually
included source trigger recompilation of lz4hc.o.
deps/lz4/lz4frame.c (1)

1619-1620: 🩺 Stability & Availability | 🟠 Major | βš–οΈ Poor tradeoff

Null-pointer arithmetic in LZ4F_decompress() is still present.

LZ4F_getFrameInfo() at line 1496 calls LZ4F_decompress(dctx, NULL, &o, NULL, &i, NULL) with i == 0. Line 1620 then evaluates srcStart + *srcSizePtr on a null base, which is undefined behavior in C and can trip UBSan builds. Do not patch this copy. Re-vendor a newer upstream LZ4 release that contains the null-safe handling.

Based on learnings: treat the vendored LZ4 code under deps/lz4/ as upstream-managed and fix issues by re-vendoring a newer upstream release, not by editing files in place.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deps/lz4/lz4frame.c` around lines 1619 - 1620, Re-vendor the upstream LZ4
release containing null-safe handling for LZ4F_decompress, replacing the managed
contents under deps/lz4/ rather than editing lz4frame.c in place. Verify that
LZ4F_getFrameInfo’s zero-length call with a NULL source no longer performs
null-pointer arithmetic.

Sources: Learnings, Linters/SAST tools

src/config.c (1)

179-186: πŸ—„οΈ Data Integrity & Integration | 🟠 Major | ⚑ Quick win

Verify every reader of server.rdb_compression after the bool-to-enum widening.

rdbcompression changes from a boolean to a three-valued enum. Any remaining truthiness test such as if (server.rdb_compression) now also matches RDB_COMPRESSION_LZ4, which selects per-string LZF for a mode that should use the streaming codec. Compare against explicit enum constants at every read site. The enum tables themselves look correct: both are NULL-terminated and yes/no remain accepted, so existing config files and CONFIG SET calls keep working.

#!/bin/bash
# Find every read of the two widened config fields and check for truthiness tests.
rg -n -C4 'server\.rdb_compression|server\.repl_compression' src -g '*.c' -g '*.h'

# Confirm the enum constants and the field types.
rg -n -C3 'RDB_COMPRESSION_|REPL_COMPRESSION_' src/server.h
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/config.c` around lines 179 - 186, Audit every read of
server.rdb_compression identified by the repository search, especially
truthiness checks, and replace implicit boolean evaluation with explicit
comparisons against the appropriate RDB_COMPRESSION_* constants so
RDB_COMPRESSION_LZ4 uses the streaming codec rather than per-string LZF. Also
verify server.repl_compression readers use explicit REPL_COMPRESSION_*
comparisons where needed, while leaving the NULL-terminated enum tables
unchanged.
🧹 Nitpick comments (1)
src/unit/test_compression.cpp (1)

55-75: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | ⚑ Quick win

Fill buf before returning an over-read length.

Line 58 returns len + 1 without writing to buf. The reader under test may then inspect bytes that were never written. The reader correctly rejects the over-read, so the assertions still hold, but a sanitizer build can report a use of uninitialized memory and hide the real signal. Write a deterministic pattern into buf first.

♻️ Proposed change
     MemReader *r = (MemReader *)ctx;
     r->calls++;
-    if (r->overread_on_call > 0 && r->calls == r->overread_on_call) return (ssize_t)(len + 1);
+    if (r->overread_on_call > 0 && r->calls == r->overread_on_call) {
+        /* Report more bytes than were written, to assert the reader rejects a
+         * source callback that violates the length contract. Fill the buffer so
+         * the rejection path never reads uninitialized memory. */
+        memset(buf, 0, len);
+        return (ssize_t)(len + 1);
+    }
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/unit/test_compression.cpp` around lines 55 - 75, Update memReaderRead so
the overread_on_call branch fills buf with a deterministic pattern for the
requested len bytes before returning len + 1. Keep the existing over-read return
value and all other reader behavior unchanged.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@deps/lz4/lz4frame.c`:
- Around line 1619-1620: Re-vendor the upstream LZ4 release containing null-safe
handling for LZ4F_decompress, replacing the managed contents under deps/lz4/
rather than editing lz4frame.c in place. Verify that LZ4F_getFrameInfo’s
zero-length call with a NULL source no longer performs null-pointer arithmetic.

In `@deps/lz4/Makefile`:
- Line 19: Update the lz4hc.o dependency rule to include lz4.c alongside its
existing prerequisites, ensuring changes to the textually included source
trigger recompilation of lz4hc.o.

In `@src/config.c`:
- Around line 179-186: Audit every read of server.rdb_compression identified by
the repository search, especially truthiness checks, and replace implicit
boolean evaluation with explicit comparisons against the appropriate
RDB_COMPRESSION_* constants so RDB_COMPRESSION_LZ4 uses the streaming codec
rather than per-string LZF. Also verify server.repl_compression readers use
explicit REPL_COMPRESSION_* comparisons where needed, while leaving the
NULL-terminated enum tables unchanged.

In `@tests/integration/repl-fullsync-compression.tcl`:
- Around line 655-660: Update the verify_no_log_message assertion in the mixed
diskless full-sync test to target the primary server log using -2 instead of -1.
Keep the existing compression message and $primary_loglines arguments unchanged
so the plaintext-fallback check validates the primary’s log.

---

Nitpick comments:
In `@src/unit/test_compression.cpp`:
- Around line 55-75: Update memReaderRead so the overread_on_call branch fills
buf with a deterministic pattern for the requested len bytes before returning
len + 1. Keep the existing over-read return value and all other reader behavior
unchanged.

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bd43b5d3-2506-4001-a12a-a33c649c01f8

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 0adff5c and 574a85c.

πŸ“’ Files selected for processing (45)
  • .github/workflows/ci.yml
  • cmake/Modules/SourceFiles.cmake
  • cmake/Modules/ValkeySetup.cmake
  • deps/CMakeLists.txt
  • deps/Makefile
  • deps/lz4/CMakeLists.txt
  • deps/lz4/LICENSE
  • deps/lz4/Makefile
  • deps/lz4/lz4.c
  • deps/lz4/lz4.h
  • deps/lz4/lz4frame.c
  • deps/lz4/lz4frame.h
  • deps/lz4/lz4hc.c
  • deps/lz4/lz4hc.h
  • deps/lz4/xxhash.c
  • deps/lz4/xxhash.h
  • src/CMakeLists.txt
  • src/Makefile
  • src/aof.c
  • src/compression.c
  • src/compression.h
  • src/compression_lz4.c
  • src/compression_lz4.h
  • src/compression_stream.c
  • src/compression_stream.h
  • src/config.c
  • src/rdb.c
  • src/rdb.h
  • src/replication.c
  • src/rio.c
  • src/rio.h
  • src/server.h
  • src/unit/CMakeLists.txt
  • src/unit/Makefile
  • src/unit/test_compression.cpp
  • src/valkey-check-rdb.c
  • tests/integration/dual-channel-replication.tcl
  • tests/integration/rdb-compression.tcl
  • tests/integration/repl-fullsync-compression.tcl
  • tests/integration/replication-aof-sync.tcl
  • tests/integration/replication.tcl
  • tests/integration/valkey-check-rdb.tcl
  • tests/support/server.tcl
  • tests/test_helper.tcl
  • valkey.conf
🚧 Files skipped from review as they are similar to previous changes (37)
  • src/unit/CMakeLists.txt
  • tests/support/server.tcl
  • src/Makefile
  • tests/test_helper.tcl
  • cmake/Modules/SourceFiles.cmake
  • tests/integration/dual-channel-replication.tcl
  • tests/integration/replication-aof-sync.tcl
  • deps/lz4/LICENSE
  • src/CMakeLists.txt
  • tests/integration/replication.tcl
  • deps/Makefile
  • cmake/Modules/ValkeySetup.cmake
  • tests/integration/valkey-check-rdb.tcl
  • valkey.conf
  • src/valkey-check-rdb.c
  • deps/lz4/CMakeLists.txt
  • src/compression.h
  • src/unit/Makefile
  • src/rdb.h
  • src/compression_lz4.c
  • deps/CMakeLists.txt
  • src/rio.h
  • deps/lz4/xxhash.c
  • src/server.h
  • deps/lz4/lz4frame.h
  • src/replication.c
  • deps/lz4/lz4.h
  • src/compression_stream.c
  • src/compression_lz4.h
  • deps/lz4/lz4hc.c
  • src/compression_stream.h
  • deps/lz4/lz4hc.h
  • src/compression.c
  • tests/integration/rdb-compression.tcl
  • src/rdb.c
  • src/aof.c
  • deps/lz4/xxhash.h

@sarthakaggarwal97

Copy link
Copy Markdown
Contributor

Based on our discussions offline, we will proceed with introducing a new configuration and CAPA for full sync to decouple the incremental replication with full sync replication. This will allow users options to disable either one of them on demand.

@roshkhatri
roshkhatri force-pushed the repl-streaming-comression-fullsync-pr branch from 574a85c to e2c74ed Compare August 6, 2026 20:03
@roshkhatri
roshkhatri force-pushed the repl-streaming-comression-fullsync-pr branch 4 times, most recently from 186d69c to 95621f7 Compare August 10, 2026 18:18
@zuiderkwast zuiderkwast mentioned this pull request Sep 11, 2026
5 of 9 tasks

@zuiderkwast zuiderkwast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. (Didn't review all code manually though.)

Posted some comments that we can fix in other PRs. Let's merge so the other PRs can be completed also.

@zuiderkwast zuiderkwast added major-decision-pending-auto-approve major-decision-approved Major decision approved by TSC team release-notes This issue should get a line item in the release notes and removed major-decision-pending-auto-approve labels Sep 11, 2026
@sarthakaggarwal97 sarthakaggarwal97 added run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) and removed run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) labels Sep 11, 2026
@sarthakaggarwal97

Copy link
Copy Markdown
Contributor

@sarthakaggarwal97

Copy link
Copy Markdown
Contributor

Merging this now! Thank you @roshkhatri @zuiderkwast @madolson for all your efforts on this!

@sarthakaggarwal97
sarthakaggarwal97 merged commit 4be324e into valkey-io:unstable Sep 11, 2026
234 of 237 checks passed
sarthakaggarwal97 added a commit that referenced this pull request Sep 22, 2026
Built on top #3531, #4075, #3853

Zstd is great for compression ratio and would be useful for both
replication compression and rdb compression. The save time worse as
compared to LZ4 because it tries to compress much harder. The load time
is faster because since it compressed harder, it has much lesser data to
load from the disk.

Zstd is specially useful for replication compression across regions
where network costs are quite significant as compared to compute. We
want to save as much data as possible while transferring data over the
regions.

<img width="3134" height="1034" alt="zstd157_v4_on"
src="https://github.com/user-attachments/assets/1ebb21f7-dc98-4c22-9d71-120a14f30391"
/>

<img width="3134" height="1034" alt="zstd157_v4_off"
src="https://github.com/user-attachments/assets/6aa6e20d-1c8b-45ff-b7f4-657ed3e55d5f"
/>

<img width="2235" height="741" alt="zstd157_blockmesh_bars"
src="https://github.com/user-attachments/assets/f96458be-b5e2-4ecd-baea-7aae506a6971"
/>

---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
valkeyrie-ops Bot pushed a commit that referenced this pull request Sep 23, 2026
Built on top #3531, #4075, #3853

Zstd is great for compression ratio and would be useful for both
replication compression and rdb compression. The save time worse as
compared to LZ4 because it tries to compress much harder. The load time
is faster because since it compressed harder, it has much lesser data to
load from the disk.

Zstd is specially useful for replication compression across regions
where network costs are quite significant as compared to compute. We
want to save as much data as possible while transferring data over the
regions.

<img width="3134" height="1034" alt="zstd157_v4_on"
src="https://github.com/user-attachments/assets/1ebb21f7-dc98-4c22-9d71-120a14f30391"
/>

<img width="3134" height="1034" alt="zstd157_v4_off"
src="https://github.com/user-attachments/assets/6aa6e20d-1c8b-45ff-b7f4-657ed3e55d5f"
/>

<img width="2235" height="741" alt="zstd157_blockmesh_bars"
src="https://github.com/user-attachments/assets/f96458be-b5e2-4ecd-baea-7aae506a6971"
/>

---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Backport-Source-PR: 3798
JimB123 pushed a commit that referenced this pull request Sep 28, 2026
Built on top #3531, #4075, #3853

Zstd is great for compression ratio and would be useful for both
replication compression and rdb compression. The save time worse as
compared to LZ4 because it tries to compress much harder. The load time
is faster because since it compressed harder, it has much lesser data to
load from the disk.

Zstd is specially useful for replication compression across regions
where network costs are quite significant as compared to compute. We
want to save as much data as possible while transferring data over the
regions.

<img width="3134" height="1034" alt="zstd157_v4_on"
src="https://github.com/user-attachments/assets/1ebb21f7-dc98-4c22-9d71-120a14f30391"
/>

<img width="3134" height="1034" alt="zstd157_v4_off"
src="https://github.com/user-attachments/assets/6aa6e20d-1c8b-45ff-b7f4-657ed3e55d5f"
/>

<img width="2235" height="741" alt="zstd157_blockmesh_bars"
src="https://github.com/user-attachments/assets/f96458be-b5e2-4ecd-baea-7aae506a6971"
/>

---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Backport-Source-PR: 3798
@roshkhatri
roshkhatri deleted the repl-streaming-comression-fullsync-pr branch November 3, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major-decision-approved Major decision approved by TSC team release-notes This issue should get a line item in the release notes run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants