Skip to content

Replication compression configs and handshake negotiation - #16

Open
roshkhatri wants to merge 15 commits into
streaming-compression-rio-prfrom
repl-compression-handshake-v2
Open

Replication compression configs and handshake negotiation#16
roshkhatri wants to merge 15 commits into
streaming-compression-rio-prfrom
repl-compression-handshake-v2

Conversation

@roshkhatri

Copy link
Copy Markdown
Owner

… config

Introduces REPLICA_CAPA_COMPRESSION handshake negotiation and a replcompression boolean config. A replica with replcompression=yes advertises capa compression during the PSYNC handshake when using diskless load. The primary records REPLICA_CAPA_COMPRESSION on the replica's capa bitmask but takes no action on it yet — compressed replication transport lands in a follow-up.

Compression parameters (algorithm, level) are fixed internally via REPL_COMPRESSION_ALGO (ALGO_LZ4) and REPL_COMPRESSION_LEVEL (5, HC mode) and will become configurable in a later release.

  • src/server.h: new REPLICA_CAPA_COMPRESSION (1<<4) flag, matching STR, repl_compression field, and REPL_COMPRESSION{ALGO,LEVEL} constants
  • src/config.c: new replcompression bool config
  • src/replication.c: primary records capa in replconfCommand; replica advertises capa compression when server.repl_compression and useDisklessLoad(); argv/lens arrays grown from 9 to 11 entries; useDisklessLoad() extracted into a local reused by skip-rdb-checksum and compression checks
  • valkey.conf: new replcompression config documentation block
  • src/unit/test_repl_compression.cpp: 3 GTest cases covering capa bit uniqueness, capa string, and ALGO_LZ4 non-zero
  • tests/integration/repl-compression.tcl: 9 TCL integration tests covering config CRUD, CONFIG REWRITE persistence, and handshake behavior

sarthakaggarwal97 and others added 15 commits May 12, 2026 12:42
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>
… config

Introduces REPLICA_CAPA_COMPRESSION handshake negotiation and a
replcompression boolean config. A replica with replcompression=yes
advertises capa compression during the PSYNC handshake when using
diskless load. The primary records REPLICA_CAPA_COMPRESSION on the
replica's capa bitmask but takes no action on it yet — compressed
replication transport lands in a follow-up.

Compression parameters (algorithm, level) are fixed internally via
REPL_COMPRESSION_ALGO (ALGO_LZ4) and REPL_COMPRESSION_LEVEL (5, HC
mode) and will become configurable in a later release.

- src/server.h: new REPLICA_CAPA_COMPRESSION (1<<4) flag, matching
  _STR, repl_compression field, and REPL_COMPRESSION_{ALGO,LEVEL}
  constants
- src/config.c: new replcompression bool config
- src/replication.c: primary records capa in replconfCommand; replica
  advertises capa compression when server.repl_compression and
  useDisklessLoad(); argv/lens arrays grown from 9 to 11 entries;
  useDisklessLoad() extracted into a local reused by skip-rdb-checksum
  and compression checks
- valkey.conf: new replcompression config documentation block
- src/unit/test_repl_compression.cpp: 3 GTest cases covering capa bit
  uniqueness, capa string, and ALGO_LZ4 non-zero
- tests/integration/repl-compression.tcl: 9 TCL integration tests
  covering config CRUD, CONFIG REWRITE persistence, and handshake
  behavior

Signed-off-by: Roshan Khatri <rvkhatri@amazon.com>
@roshkhatri
roshkhatri force-pushed the repl-compression-handshake-v2 branch from c5ecfeb to 92db9be Compare May 22, 2026 19:38
@roshkhatri
roshkhatri force-pushed the streaming-compression-rio-pr branch from 750a667 to 68b9d75 Compare May 22, 2026 19:41
@roshkhatri
roshkhatri force-pushed the streaming-compression-rio-pr branch from 3975e1a to dfcc37a Compare August 3, 2026 16:06
@roshkhatri
roshkhatri force-pushed the streaming-compression-rio-pr branch 3 times, most recently from 26d48a4 to e45f2d6 Compare August 14, 2026 19:43
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