Repository navigation
Streaming Compression support for fullsync - #4075
sarthakaggarwal97 merged 2 commits into
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
π WalkthroughWalkthroughAdds vendored LZ4 streaming compression for RDB files and replication full syncs. It introduces compression abstractions, VCS stream envelopes, ChangesStreaming compression feature
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: π₯ Pre-merge checks | β 4 | β 1β Failed checks (1 warning)
β Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 10
π§Ή Nitpick comments (3)
src/compression.h (1)
28-42: π©Ί Stability & Availability | π΅ Trivial | β‘ Quick win
streamCompressorlacks an error-latch flag mirroringstreamDecompressor.
streamDecompressorhaserrored/frame_doneto prevent further use after a fatal failure, butstreamCompressorhas no equivalent. Per the rationale documented incompression_lz4.c(compressionLz4CompressFeed), onceLZ4F_compressUpdate/LZ4F_flush/LZ4F_compressEndfails after the frame header was written, the frame is permanently corrupt and not retriable, yet a caller that ignores the-1return 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 anerroredflag tostreamCompressor, checked at the top ofstreamCompressorFeed/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 valueAllocation-failure handling relies entirely on
assert.
compressionLz4CompressorInit/compressionLz4DecompressorInitalways return0; the only failure indication isassert(ctx != NULL), which aborts the process rather than letting thecompression.cdispatcher'sif (... != 0) { ...; return -1; }path run. This matches the project's general fail-fast-on-OOM convention (sincezmalloc/zcallocalready abort on allocation failure by default), so it's consistent rather than a functional bug, but theintreturn contract documented incompression_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 | π΅ TrivialKeep future LZ4 bumps on the checklist:
LZ4F_createCompressionContext_advancedandLZ4F_createDecompressionContext_advancedsit behindLZ4F_STATIC_LINKING_ONLY; upstream marks that block as unstable and only safe for statically linked callers. Re-check their signatures and behavior wheneverdeps/lz4is 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
π Files selected for processing (59)
.github/workflows/ci.ymlcmake/Modules/SourceFiles.cmakecmake/Modules/ValkeySetup.cmakedeps/CMakeLists.txtdeps/Makefiledeps/lz4/CMakeLists.txtdeps/lz4/LICENSEdeps/lz4/Makefiledeps/lz4/lz4.cdeps/lz4/lz4.hdeps/lz4/lz4frame.cdeps/lz4/lz4frame.hdeps/lz4/lz4hc.cdeps/lz4/lz4hc.hdeps/lz4/xxhash.cdeps/lz4/xxhash.hsrc/CMakeLists.txtsrc/Makefilesrc/aof.csrc/compression.csrc/compression.hsrc/compression_lz4.csrc/compression_lz4.hsrc/compression_repl.csrc/compression_repl.hsrc/compression_rio.csrc/compression_rio.hsrc/compression_stream.csrc/compression_stream.hsrc/config.csrc/io_threads.csrc/networking.csrc/rdb.csrc/rdb.hsrc/replication.csrc/rio.csrc/rio.hsrc/server.csrc/server.hsrc/unit/CMakeLists.txtsrc/unit/Makefilesrc/unit/test_compression.cppsrc/unit/test_repl_compression.cppsrc/valkey-check-rdb.ctests/integration/block-repl.tcltests/integration/dual-channel-replication.tcltests/integration/rdb-compression.tcltests/integration/repl-compression.tcltests/integration/repl-fullsync-compression.tcltests/integration/replication-2.tcltests/integration/replication-3.tcltests/integration/replication-4.tcltests/integration/replication-aof-sync.tcltests/integration/replication.tcltests/integration/skip-rdb-checksum.tcltests/integration/valkey-check-rdb.tcltests/support/server.tcltests/test_helper.tclvalkey.conf
| @@ -0,0 +1,1027 @@ | |||
| tags {"repl repl-compression external:skip"} { | |||
There was a problem hiding this comment.
π― 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 Reportβ Patch coverage is
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
π New features to boost your workflow:
|
|
@coderabbitai review the code for Streaming Compression support for fullsync, |
π§© 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.cLength of output: 16694 π Script executed: #!/bin/bash
set -e
echo "=== compression_repl.c ==="
cat -n src/compression_repl.cLength 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.cLength 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 -60Length 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.cLength of output: 7078
Architecture β the layering is clean: Capability negotiation β verified in Checksum handling β Decompression-bomb guard β IO-threads interaction β Config-time behavior β 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 β Action performedReview finished.
|
ef02d03 to
f96bf89
Compare
|
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. |
f96bf89 to
2c22c20
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
π§Ή Nitpick comments (1)
deps/lz4/lz4.c (1)
105-116: π Maintainability & Code Quality | π΅ Trivial | β‘ Quick winRecord 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
π Files selected for processing (45)
.github/workflows/ci.ymlcmake/Modules/SourceFiles.cmakecmake/Modules/ValkeySetup.cmakedeps/CMakeLists.txtdeps/Makefiledeps/lz4/CMakeLists.txtdeps/lz4/LICENSEdeps/lz4/Makefiledeps/lz4/lz4.cdeps/lz4/lz4.hdeps/lz4/lz4frame.cdeps/lz4/lz4frame.hdeps/lz4/lz4hc.cdeps/lz4/lz4hc.hdeps/lz4/xxhash.cdeps/lz4/xxhash.hsrc/CMakeLists.txtsrc/Makefilesrc/aof.csrc/compression.csrc/compression.hsrc/compression_lz4.csrc/compression_lz4.hsrc/compression_stream.csrc/compression_stream.hsrc/config.csrc/rdb.csrc/rdb.hsrc/replication.csrc/rio.csrc/rio.hsrc/server.hsrc/unit/CMakeLists.txtsrc/unit/Makefilesrc/unit/test_compression.cppsrc/valkey-check-rdb.ctests/integration/dual-channel-replication.tcltests/integration/rdb-compression.tcltests/integration/repl-fullsync-compression.tcltests/integration/replication-aof-sync.tcltests/integration/replication.tcltests/integration/valkey-check-rdb.tcltests/support/server.tcltests/test_helper.tclvalkey.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
|
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. |
2c22c20 to
77af97e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
π§Ή Nitpick comments (1)
src/unit/test_compression.cpp (1)
278-286: π Maintainability & Code Quality | π΅ Trivial | π€ Low valueConsider a compile-time check that ties the envelope literals to
VCS_ENVELOPE_SIZE.Three tests build a
VCS_ENVELOPE_SIZEarray from exactly seven positional initializers (Lines 214, 278-286, 460-468, 1132-1133). IfVCS_ENVELOPE_SIZEgrows, 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
π Files selected for processing (45)
.github/workflows/ci.ymlcmake/Modules/SourceFiles.cmakecmake/Modules/ValkeySetup.cmakedeps/CMakeLists.txtdeps/Makefiledeps/lz4/CMakeLists.txtdeps/lz4/LICENSEdeps/lz4/Makefiledeps/lz4/lz4.cdeps/lz4/lz4.hdeps/lz4/lz4frame.cdeps/lz4/lz4frame.hdeps/lz4/lz4hc.cdeps/lz4/lz4hc.hdeps/lz4/xxhash.cdeps/lz4/xxhash.hsrc/CMakeLists.txtsrc/Makefilesrc/aof.csrc/compression.csrc/compression.hsrc/compression_lz4.csrc/compression_lz4.hsrc/compression_stream.csrc/compression_stream.hsrc/config.csrc/rdb.csrc/rdb.hsrc/replication.csrc/rio.csrc/rio.hsrc/server.hsrc/unit/CMakeLists.txtsrc/unit/Makefilesrc/unit/test_compression.cppsrc/valkey-check-rdb.ctests/integration/dual-channel-replication.tcltests/integration/rdb-compression.tcltests/integration/repl-fullsync-compression.tcltests/integration/replication-aof-sync.tcltests/integration/replication.tcltests/integration/valkey-check-rdb.tcltests/support/server.tcltests/test_helper.tclvalkey.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
|
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. |
There was a problem hiding this comment.
β»οΈ Duplicate comments (1)
deps/lz4/Makefile (1)
19-19: π Maintainability & Code Quality | π‘ Minor | β‘ Quick winAdd
lz4.cto thelz4hc.oprerequisites.
deps/lz4/lz4hc.ctextually includeslz4.c. This rule does not listlz4.c, so an incrementalmakecan leavelz4hc.ostale afterlz4.cchanges.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 valueDocument the vendored LZ4 source version.
deps/lz4/is upstream-managed, anddeps/lz4/lz4.hdeclaresLZ4_VERSION_MAJOR.MINOR.RELEASEas1.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 winReject an over-reporting
streamReaderReadresult.If
streamReaderReadreturns more thanremaining, Line 523 underflowsremainingto a huge value and Line 518 keeps writing past the caller buffer. The stream reader is expected to honorremaining, 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
π Files selected for processing (45)
.github/workflows/ci.ymlcmake/Modules/SourceFiles.cmakecmake/Modules/ValkeySetup.cmakedeps/CMakeLists.txtdeps/Makefiledeps/lz4/CMakeLists.txtdeps/lz4/LICENSEdeps/lz4/Makefiledeps/lz4/lz4.cdeps/lz4/lz4.hdeps/lz4/lz4frame.cdeps/lz4/lz4frame.hdeps/lz4/lz4hc.cdeps/lz4/lz4hc.hdeps/lz4/xxhash.cdeps/lz4/xxhash.hsrc/CMakeLists.txtsrc/Makefilesrc/aof.csrc/compression.csrc/compression.hsrc/compression_lz4.csrc/compression_lz4.hsrc/compression_stream.csrc/compression_stream.hsrc/config.csrc/rdb.csrc/rdb.hsrc/replication.csrc/rio.csrc/rio.hsrc/server.hsrc/unit/CMakeLists.txtsrc/unit/Makefilesrc/unit/test_compression.cppsrc/valkey-check-rdb.ctests/integration/dual-channel-replication.tcltests/integration/rdb-compression.tcltests/integration/repl-fullsync-compression.tcltests/integration/replication-aof-sync.tcltests/integration/replication.tcltests/integration/valkey-check-rdb.tcltests/support/server.tcltests/test_helper.tclvalkey.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
77af97e to
574a85c
Compare
|
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. |
There was a problem hiding this comment.
β»οΈ Duplicate comments (4)
tests/integration/repl-fullsync-compression.tcl (1)
655-660: π― Functional Correctness | π Major | β‘ Quick winUse
-2for the primary log in the mixed diskless cohort test.This assertion still targets the wrong server. Inside this triply nested
start_serverscope, srv 0 is$replica_plain,-1is$replica_capable, and-2is 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_loglinesfrom the primary, and lines 231 and 737 already use-2for 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.ostill lacks itslz4.cprerequisite.
deps/lz4/lz4hc.cincludeslz4.ctextually. This rule does not listlz4.c, so an edit tolz4.cleaveslz4hc.ostale on an incrementalmake. 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 tradeoffNull-pointer arithmetic in
LZ4F_decompress()is still present.
LZ4F_getFrameInfo()at line 1496 callsLZ4F_decompress(dctx, NULL, &o, NULL, &i, NULL)withi == 0. Line 1620 then evaluatessrcStart + *srcSizePtron 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 winVerify every reader of
server.rdb_compressionafter the bool-to-enum widening.
rdbcompressionchanges from a boolean to a three-valued enum. Any remaining truthiness test such asif (server.rdb_compression)now also matchesRDB_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 andyes/noremain accepted, so existing config files andCONFIG SETcalls 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 winFill
bufbefore returning an over-read length.Line 58 returns
len + 1without writing tobuf. 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 intobuffirst.β»οΈ 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
π Files selected for processing (45)
.github/workflows/ci.ymlcmake/Modules/SourceFiles.cmakecmake/Modules/ValkeySetup.cmakedeps/CMakeLists.txtdeps/Makefiledeps/lz4/CMakeLists.txtdeps/lz4/LICENSEdeps/lz4/Makefiledeps/lz4/lz4.cdeps/lz4/lz4.hdeps/lz4/lz4frame.cdeps/lz4/lz4frame.hdeps/lz4/lz4hc.cdeps/lz4/lz4hc.hdeps/lz4/xxhash.cdeps/lz4/xxhash.hsrc/CMakeLists.txtsrc/Makefilesrc/aof.csrc/compression.csrc/compression.hsrc/compression_lz4.csrc/compression_lz4.hsrc/compression_stream.csrc/compression_stream.hsrc/config.csrc/rdb.csrc/rdb.hsrc/replication.csrc/rio.csrc/rio.hsrc/server.hsrc/unit/CMakeLists.txtsrc/unit/Makefilesrc/unit/test_compression.cppsrc/valkey-check-rdb.ctests/integration/dual-channel-replication.tcltests/integration/rdb-compression.tcltests/integration/repl-fullsync-compression.tcltests/integration/replication-aof-sync.tcltests/integration/replication.tcltests/integration/valkey-check-rdb.tcltests/support/server.tcltests/test_helper.tclvalkey.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
|
Based on our discussions offline, we will proceed with introducing a new configuration and |
574a85c to
e2c74ed
Compare
186d69c to
95621f7
Compare
zuiderkwast
left a comment
There was a problem hiding this comment.
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.
|
Test failure is unrelated: https://github.com/valkey-io/valkey/actions/runs/34608333804/job/103292222848?pr=4075#step:7:10307 |
|
Merging this now! Thank you @roshkhatri @zuiderkwast @madolson for all your efforts on this! |
4be324e
into
valkey-io:unstable
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>
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
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
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 lz4on bothends, negotiated per replica so no replica ever receives a payload it cannot load.
Negotiation:
rdbcompressionislz4advertisesREPLCONF capa lz4. Thecapability names the codec, so a replica advertises only what its binary can decode and a
future codec adds its own capability.
rdbcompressionislz4and every replicaattaching to that sync advertised the capability. If any replica is not capable, everyone
gets plaintext and that sync writes a plain snapshot.
capability; a compressed save requires it.
rdbcompression yesandlzfselect per-string LZF, which is not a stream codec andcannot frame a payload, so only
lz4enables this.What this changes about
rdbcompressionrdbcompressiongains a second meaning: it now also selects the full-sync wire format.Setting
lz4for persistence opts a server into compressed sync, and a replica must bewilling to write
lz4snapshots in order to accept them. This was chosen over a dedicatedknob because both formats are the same codec, and a separate switch would only let them
disagree.
Two consequences follow:
dump.rdbevenunder
rdbcompression lz4, so the persisted format depends on which replicas attached tothat round.
runs
BGREWRITEAOFinstead.Framing and failure handling
The
$EOF:<mark>preamble and its 40-byte suffix stay plaintext; only the payload iscompressed. 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_bytesreflects what crossed the network rather than the logical RDBsize. 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
rdbcompression(no/yes/lzf/lz4)lz4advertises the capability, and a primary withlz4compresses 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)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-replicasrepl-diskless-load(disabled/swapdb/on-empty-db)swapdb/on-empty-db, via temp-filerdbLoadauto-detect fordisabled). A file received to disk is kept in the received format; existing configs govern its retention.dual-channel-replication-enabledlz4capability so the RDB-channel payload negotiates the same way.rdbchecksum(yes/no)lz4the 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.