Skip to content

Full-sync streaming compression - review vs replication base - #22

Open
roshkhatri wants to merge 56 commits into
replication-streaming-compression-prfrom
repl-streaming-compression-fullsync-v2
Open

Full-sync streaming compression - review vs replication base#22
roshkhatri wants to merge 56 commits into
replication-streaming-compression-prfrom
repl-streaming-compression-fullsync-v2

Conversation

@roshkhatri

Copy link
Copy Markdown
Owner

Full-sync RDB payload compression (disk-based, diskless, dual-channel) as one commit over the squashed replication branch (dbe758135), for a clean review diff. Ported to the new inline streamWriter/streamReader API (compression_rio is gone on this base).

Compression is capability-negotiated: a replica advertises REPLCONF capa compression when its repl-compression is lz4-stream; the primary compresses a full sync only when every replica in the attaching cohort advertised it (cohort-AND). If any attaching replica is not capable, the payload is sent plaintext to all of them. $EOF framing stays plaintext; the frame checksum replaces the RDB CRC64. A link dropped mid-frame is recoverable truncation (resync), not corruption.

Verified: build clean, unit tests green (truncation + in-frame corruption), repl-fullsync-compression 14/14, repl-compression green, compressed CI matrix green.

Counterpart of PR #20 / upstream valkey-io#4075; sibling of PR #21.

Add streaming LZ4-backed RDB compression with rio decorators, stream envelope handling, integration changes, and the follow-up fixes and config cleanup needed on top of unstable.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
- Remove dead code: rdbIsValidMagic() and unused #include <string.h> in rdb.h
- Remove redundant first RIO_FLAG_SKIP_RDB_CHECKSUM set in rdbSaveInternal
- Remove unrelated changes: config_parse_depth, USE_FAST_FLOAT, write-make-settings
- Validate full 8-byte VKCS envelope in aof.c rdbFileUsesStreamingCompression
- Add SAFETY comment for rdbRioHasCorruptCompressedInput cast invariant
- Rename all snake_case identifiers to camelCase per Valkey conventions:
  types (compression_algo_t -> compressionAlgo, stream_compressor_t ->
  streamCompressor, compress_rio_t -> compressRio, etc.), functions
  (stream_writer_create -> streamWriterCreate, compress_rio_finish ->
  compressRioFinish, write_vkcs_envelope -> writeVkcsEnvelope, etc.),
  and static variables (compression_lz4_codec_impl -> compressionLz4CodecImpl)
- Drop _t suffix from all types to match Valkey convention
- Fix typo: streamWriterIsErrord -> streamWriterIsErrored
- Replace silent dummy buffer allocation with assert(needed > 0) in
  streamWriterEnsureOutBuf

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
* Address streaming RDB compression review

* Skip RDB CRC for streaming compression

* Remove brittle 32-bit compression unit test

---------

Co-authored-by: Sarthak Aggarwal <sarthagg@amazon.com>

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
- rdbSaveInternal: the old comment claimed per-string LZF was disabled
  'when algo != LZF', but the actual gate is RIO_FLAG_STREAMING_COMPRESSION
  on the wrapper rio. Standalone rios (DUMP, AOF rewrite, diskless) keep
  using LZF regardless of algo.
- rdbInputStreamPrepare: flag the synchronous probe IO so a future
  non-blocking caller (replication) doesn't accidentally block the loop.
- rdbRioHasCorruptCompressedInput: the cast is sound today only because
  one producer sets RIO_FLAG_STREAMING_DECOMPRESSION. Replace the
  'SAFETY' assertion with a note telling the next person to add a type
  discriminator before adding a second producer.
- rdbSaveRawString: minor wording cleanup on the per-string LZF gate.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Match the surrounding Valkey style: drop comments that restate the
code, drop the Ownership/Threading/Returns boilerplate from headers,
collapse repeated 'capacity-shortage is retriable' notes into one
explanation per function. Behavior is unchanged.

Net -285 lines; integration tests (21/21) and build are clean.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Drop the clamp detail (an internal streamReaderCreate concern) and keep
only the caller-facing contract that buffer_size must be nonzero.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
The loaderr path exits the process, so resetting reading_config_file
there is dead code. It was a leftover from the reverted config_parse_depth
change and is not present upstream.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Collapse the save-notice if/else into one serverLog that always names the
active algorithm (none/lzf/lz4), instead of branching the message.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Replace em dashes in the compression comments with ASCII punctuation and
add a short note above streamWriterCreate describing the writer/reader
push/pull model and the finish-before-free requirement.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
- Simplify the streaming APIs: caller-owned structs with Init/Free and
  descriptive self-parameter names; codec used only for the algorithm
  vtable.
- Store the compression algorithm id directly in the VKCS envelope and
  drop the separate codec enum plus its translation functions.
- Make the rio decorator opaque: track connection-backed streams with a
  flag instead of a transport-type enum.
- Route LZ4 contexts through zmalloc and assert on caller errors; keep
  runtime errors for corrupt or external input.
- Document the feed functions' streaming contract, mark the retriable
  capacity-shortage returns, and drop a redundant probe re-zero.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
valkey-check-rdb reported offsets via rioTell() on every read, and
rdbLoadProgressCallback computed the transport offset via rioTell() on
every read even when no progress event was due. Read processed_bytes
directly for the offset, and only compute the transport position when a
progress event is actually reported.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Replace the separate rdb-compression-algo config with a single
rdbcompression no|yes|lz4-stream. 'yes' keeps the legacy per-string LZF
path; 'lz4-stream' selects whole-file streaming LZ4 RDB saves.

Update valkey.conf and the RDB compression, check-rdb, and replication
AOF sync tests to use the new config value.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
sarthakaggarwal97 and others added 16 commits June 23, 2026 18:52
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
- use explicit VCS wire IDs (VCS_CODEC_LZ4, VCS_STREAM_RDB) instead of
  serializing implementation enum values into the envelope
- drop the redundant envelope checksum flag; the LZ4 frame header is the
  single source of truth for checksum presence, byte 5 is now reserved
- make rdbchecksum and DEBUG SET-SKIP-CHECKSUM-VALIDATION control only
  codec checksum verification for VCS input via LZ4F skipChecksums;
  framing, decompression, parsing, and exact-end validation stay active
- carry the physical format classified by rdbLoad() in rdbSaveInfo and
  use it for the AOF base reuse decision, removing the reopen/read
  classifier and failing closed for VCS or unknown formats
- route the VCS rejection through restartAOFWithSyncRdb() cleanup so
  rdb-del-sync-files removes the downloaded RDB

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
---------
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
streaming compression rio pr api simplification

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
…ession-rio-pr

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>

# Conflicts:
#	src/valkey-check-rdb.c
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Roshan Khatri <rvkhatri@amazon.com>
@roshkhatri
roshkhatri force-pushed the repl-streaming-compression-fullsync-v2 branch from eb23371 to d8abd39 Compare July 30, 2026 17:07
Signed-off-by: Roshan Khatri <rvkhatri@amazon.com>
@roshkhatri
roshkhatri force-pushed the repl-streaming-compression-fullsync-v2 branch from d8abd39 to 11a2fc6 Compare July 30, 2026 17:42
@roshkhatri
roshkhatri force-pushed the replication-streaming-compression-pr branch 5 times, most recently from bd80272 to fc58806 Compare August 4, 2026 02:13
@roshkhatri
roshkhatri force-pushed the replication-streaming-compression-pr branch from fc58806 to 1e7389a Compare August 5, 2026 07:58
@roshkhatri
roshkhatri force-pushed the replication-streaming-compression-pr branch 3 times, most recently from 9814a6d to a7a8cba Compare August 13, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants