Skip to content

Fixed a Valkey version issue related to diskless replication. - #116

Merged
leonchen83 merged 4 commits into
leonchen83:masterfrom
otheng03:fix/diskless-rdb-eof-consume
Apr 7, 2026
Merged

leonchen83 merged 4 commits into
leonchen83:masterfrom
otheng03:fix/diskless-rdb-eof-consume

Conversation

@otheng03

@otheng03 otheng03 commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

skip(long, boolean) does not advance head before calling fill() when the internal buffer is exhausted. If fill() throws — e.g. because a PostRdbSyncEvent listener closed the socket — stale EOF marker bytes remain in buf. A subsequent ReplyParser.parse() call reads those bytes as RESP and hits the default branch:

Additionally, the dev setup in CONTRIBUTING.md required --repl-diskless-sync no to work around this issue; that workaround is no longer needed.

Changes

Change 1 — EOF marker fix

  • Add RedisInputStream.drain(int len) to consume bytes via read(), advancing head each time. If an exception occurs, the buffer is partially drained.
  • Replace magic number with Constants.RDB_EOF_MARK_SIZE = 40.

Change 2 — Flavor / CONTRIBUTING cleanup

  • Remove --repl-diskless-sync no from CONTRIBUTING.md.
  • Add FlavorSupport.serverVersionKey() to abstract the INFO SERVER field name per flavor (redis_version vs valkey_version).
  • Implement serverVersionKey() in Flavor.REDIS and Flavor.VALKEY.

How it was tested

# Valkey
docker run -d --rm -p 6380:6380 valkey/valkey:9 --port 6380 --requirepass test
docker run -d --rm -p 6379:6379 valkey/valkey:9
mvn test -Dtest.flavor=valkey

# Redis
redis-server --port 6380 --requirepass test 
redis-server --port 6379 
mvn test

Feedback welcome! 🙏

otheng03 added 4 commits April 2, 2026 01:28
skip(long, boolean) does not advance head before calling fill() when the
buffer is exhausted. If fill() throws (e.g. peer closed connection), stale
EOF marker bytes remain in the buffer and are later misread as RESP by
ReplyParser, producing an AssertionError the retrier cannot catch.

Introduce RedisInputStream.consume(int) which reads one byte at a time so
head is always advanced on each successful read. Add RDB_EOF_MARK_SIZE = 40
constant and wrap the consume call in a try/catch so a listener-triggered
socket close does not prevent trySync from saving replId/replOffset.
- Remove --repl-diskless-sync no from CONTRIBUTING dev setup; diskless
  replication is now supported via the EOF marker fix
- Add FlavorSupport.serverVersionKey() to abstract the INFO SERVER field
  name per flavor (redis_version vs valkey_version)
- Implement serverVersionKey() in Flavor.REDIS and Flavor.VALKEY enum entries
@otheng03
otheng03 marked this pull request as ready for review April 5, 2026 06:20
@otheng03 otheng03 mentioned this pull request Apr 5, 2026
6 of 12 tasks
@otheng03 otheng03 changed the title Fix diskless RDB EOF marker consumption using RedisInputStream.consume() Fixed a Valkey version issue related to diskless replication. Apr 5, 2026
@leonchen83
leonchen83 merged commit 511bd20 into leonchen83:master Apr 7, 2026
7 checks passed
@leonchen83

leonchen83 commented Apr 7, 2026 •

Copy link
Copy Markdown
Owner

Hey! I tweaked the serverVersionKey part a bit on my side (simplified it using magic()), but merged the rest of your changes — really nice work, thanks for the fixes

One small thing for diskless replication (redis-diskless-repl): the stream looks like

$EOF:<40 bytes delimiter>\r\n
RDB
<40 bytes delimiter>
AOF
...

That 40-byte delimiter after the RDB isn’t really useful, and passing it to RawByteListener would force users to skip it manually — a bit awkward.

So I added a drain(int len, boolean notify) method internally, which safely consumes bytes without notifying the listener. You might want to sync your branch with this change.

@otheng03

otheng03 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I’ll sync my branch with these changes for the next PR.

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