Skip to content

fix(kvrocks2redis): translate FLUSHDB/FLUSHALL via DeleteRange (#2177) - #3564

Open
advisedy wants to merge 4 commits into
apache:unstablefrom
advisedy:#2177
Open

fix(kvrocks2redis): translate FLUSHDB/FLUSHALL via DeleteRange (#2177)#3564
advisedy wants to merge 4 commits into
apache:unstablefrom
advisedy:#2177

Conversation

@advisedy

Copy link
Copy Markdown
Contributor

Fixes #2177.

Problem

FLUSHDB / FLUSHALL is implemented via DeleteRange on the metadata
CF, but the replication path did not propagate it:

  • WriteBatchExtractor::DeleteRangeCF was a no-op, so the delete was
    silently dropped and never translated into a Redis command on replicas
    or kvrocks2redis.
  • Database::FlushAll merged all namespaces into a single DeleteRange,
    which could not be mapped back to any specific namespace.

Fix

  • FlushAll now emits one DeleteRange per namespace in the same batch.
  • DeleteRangeCF translates those ranges into a per-namespace FLUSHDB,
    and rejects unrecognized ranges with a warning.

Tests

  • Go integration test TestReplicationFlushDBAcrossNamespaces:
    reproduces the issue with repl-namespace-enabled=yes.
  • C++ gtests in batch_extractor_test.cc for single-namespace FLUSHDB,
    multi-namespace FLUSHALL, and unrecognized ranges.

AI-assisted contribution

The tests were generated by an LLM. I reviewed all of them to make sure
they are correct and meaningful.

Scope

Only covers plain FLUSHDB / FLUSHALL. The MULTI/EXEC case
mentioned in #2177 is not handled here — I'm not sure what kind of
approach would fit best, and would appreciate reviewer input.

Copilot AI 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.

Pull request overview

This PR fixes a replication/kvrocks2redis gap where FLUSHDB/FLUSHALL implemented as RocksDB DeleteRange on the metadata CF was previously dropped (no-op extraction) and thus never translated into equivalent Redis commands downstream—especially problematic when namespace replication is enabled.

Changes:

  • Update Database::FlushAll to emit one metadata-DeleteRange per namespace (so ranges can be mapped back to namespaces).
  • Implement WriteBatchExtractor::DeleteRangeCF translation of namespace-wide metadata DeleteRange into per-namespace FLUSHDB, with warnings for unrecognized ranges.
  • Add Go integration coverage for cross-namespace replication and C++ unit tests for the extractor behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/gocase/integration/replication/replication_test.go Adds an integration test reproducing #2177 with repl-namespace-enabled=yes and verifying FLUSHALL replicates across namespaces.
tests/cppunit/batch_extractor_test.cc Adds gtests validating DeleteRangeCFFLUSHDB translation and handling of unsupported ranges.
src/storage/redis_db.cc Changes FlushAll to emit per-namespace DeleteRange operations in a single write batch.
src/storage/batch_extractor.cc Implements DeleteRangeCF handling for metadata range deletes, translating whole-namespace ranges into FLUSHDB.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/storage/batch_extractor.cc
Comment thread tests/cppunit/batch_extractor_test.cc
Comment thread src/storage/redis_db.cc
@jihuayu
jihuayu requested review from PragmaTwice and git-hulk July 21, 2026 09:40
advisedy and others added 2 commits July 21, 2026 17:54
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@advisedy

Copy link
Copy Markdown
Contributor Author

Hi, @git-hulk , @PragmaTwice ,just friendly ping on this one, whenever you have some time. Thanks!

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.

kvrocks2redis can't sync flush commands

2 participants