Add multi-database support to cluster mode#1671
Merged
Merged
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #1671 +/- ##
============================================
- Coverage 71.02% 70.84% -0.18%
============================================
Files 123 123
Lines 66116 66173 +57
============================================
- Hits 46956 46879 -77
- Misses 19160 19294 +134
🚀 New features to boost your workflow:
|
dvkashapov
reviewed
Feb 11, 2025
soloestoy
reviewed
Feb 13, 2025
Member
|
I'm happy that we did "Unified db rehash method for both standalone and cluster #12848" when developing kvstore , which made the implementation of multi-database simpler. |
hpatro
reviewed
Feb 17, 2025
hpatro
left a comment
Contributor
There was a problem hiding this comment.
We need to add history to SWAPDB, SELECT, MOVE json files to indicate it's supported since 9.0.
madolson
reviewed
Feb 17, 2025
hwware
reviewed
Feb 26, 2025
hwware
reviewed
Feb 26, 2025
3dc03d6 to
af2d46a
Compare
Member
Author
|
documentation: valkey-io/valkey-doc#242 |
Contributor
|
It looks like there are still some test cases failed related to multiply db feature. Please fix them first, Thanks |
538e23e to
63151ae
Compare
This was referenced May 5, 2025
xbasel
added a commit
to xbasel/valkey
that referenced
this pull request
May 6, 2025
Re-adds a statement to restore the `singledb` config that was accidentally removed in PR valkey-io#1671. Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
xbasel
added a commit
to xbasel/valkey
that referenced
this pull request
May 6, 2025
Re-adds a statement to restore the `singledb` config that was accidentally removed in PR valkey-io#1671. Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
zuiderkwast
pushed a commit
that referenced
this pull request
May 6, 2025
madolson
added a commit
that referenced
this pull request
May 6, 2025
One of the new tests that was added uses `CONFIG GET PORT`, which isn't right one for TLS. Also removed some other use of the helper which aren't actually used. Introduced as part of #1671. --------- Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
rainsupreme
pushed a commit
to rainsupreme/valkey
that referenced
this pull request
May 14, 2025
## cluster: add multi-database support in cluster mode
Add multi-database support in cluster mode to align with standalone mode
and facilitate migration. Previously, cluster mode was restricted to a
single database (DB0). This change allows multiple databases while
preserving the existing slot-based key distribution.
### Key Features:
- Database-Agnostic Hashing. The hashing algorithm is unchanged.
Identical keys always map to the same slot across all databases,
ensuring consistent key distribution and compatibility with
existing single-database setups.
- Multi-DB commands support. SELECT, MOVE, and COPY are now supported in
cluster mode.
- Fully backward compatible with no API changes.
- SWAPDB is not supported in cluster mode. It is unsafe due to
inconsistency risks.
### Command-Level Changes:
- SELECT / MOVE / COPY are now supported in cluster mode.
- MOVE / COPY (with db) are rejected (TRYAGAIN error) during slot
migration to prevent multi-DB inconsistencies.
- SWAPDB will return an error if used when cluster mode is enabled.
- GETKEYSINSLOT, COUNTKEYSINSLOT and MIGRATE will operate in the context
of the selected database.
This means, for example, that migrating keys in a slot will require
iterating and repeating across all databases.
### Slot Migration Process:
- Multi-DB support in cluster mode affects slot migration. Operators
should now iterate over all the configured databases.
### Transaction Handling (MULTI/EXEC):
- getNodeByQuery key lookup behavior changed:
- No key lookups when queuing commands in MULTI, only cross-slot
validation.
- Key lookups happen at EXEC time.
- SELECT inside MULTI/EXEC is now checked, ensuring key validation
uses the selected DB at lookup.
### Valkey-cli:
- valkey-cli has been updated to support resharding across all
databases.
### Configuration:
- Introduce new configuration `cluster-databases`.
The new configuration controls the maximal number of databases in
cluster mode.
Implements valkey-io#1319
---------
Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
Signed-off-by: zhaozhao.zz <zhaozhao.zz@alibaba-inc.com>
Co-authored-by: zhaozhao.zz <zhaozhao.zz@alibaba-inc.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
Co-authored-by: Ran Shidlansik <ranshid@amazon.com>
rainsupreme
pushed a commit
to rainsupreme/valkey
that referenced
this pull request
May 14, 2025
Re-adds a statement to restore the `singledb` config that was accidentally removed in PR valkey-io#1671. Fixes valkey-io#2049 Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
rainsupreme
pushed a commit
to rainsupreme/valkey
that referenced
this pull request
May 14, 2025
One of the new tests that was added uses `CONFIG GET PORT`, which isn't right one for TLS. Also removed some other use of the helper which aren't actually used. Introduced as part of valkey-io#1671. --------- Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
gmbnomis
added a commit
to gmbnomis/valkey
that referenced
this pull request
Jun 11, 2025
To support multiple databases in cluster mode (see valkey-io#1671), `getNodeByQuery` temporarily switches databases when tracking `SELECT` statements during slot migration/import. The intended logic is to revert any database change after the operation. However, this approach is flawed: in some transactions the database change is not properly reverted, causing the client to remain on the wrong database. For example, if a transaction includes `SELECT` statements, the current database may be changed even if the transaction is never executed (see added test). Fix the issue by saving the original database once and restoring to it after a switch. Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
zuiderkwast
added a commit
that referenced
this pull request
Jun 16, 2025
To support multiple databases in cluster mode (see #1671), `getNodeByQuery` temporarily switches databases when tracking `SELECT` statements during slot migration/import. The intended logic is to revert any database change after the operation. However, this approach is flawed: in some transactions the database change is not properly reverted, causing the client to remain on the wrong database. For example, if a transaction includes `SELECT` statements, the current database may be changed even if the transaction is never executed (see added test). Fix the issue by saving the original database once and restoring to it after a switch. --------- Signed-off-by: Simon Baatz <gmbnomis@gmail.com> Signed-off-by: Simon Baatz <gmbnomis@users.noreply.github.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
ranshid
pushed a commit
to ranshid/valkey
that referenced
this pull request
Jun 18, 2025
…#2206) To support multiple databases in cluster mode (see valkey-io#1671), `getNodeByQuery` temporarily switches databases when tracking `SELECT` statements during slot migration/import. The intended logic is to revert any database change after the operation. However, this approach is flawed: in some transactions the database change is not properly reverted, causing the client to remain on the wrong database. For example, if a transaction includes `SELECT` statements, the current database may be changed even if the transaction is never executed (see added test). Fix the issue by saving the original database once and restoring to it after a switch. --------- Signed-off-by: Simon Baatz <gmbnomis@gmail.com> Signed-off-by: Simon Baatz <gmbnomis@users.noreply.github.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
enjoy-binbin
added a commit
to enjoy-binbin/valkey
that referenced
this pull request
Jul 29, 2025
The comment has been outdated since valkey-io#1671, update it. Signed-off-by: Binbin <binloveplay1314@qq.com>
allenss-amazon
pushed a commit
to allenss-amazon/valkey-core
that referenced
this pull request
Aug 19, 2025
…wed (valkey-io#2391) The comment has been outdated since valkey-io#1671, update it. Signed-off-by: Binbin <binloveplay1314@qq.com>
6 tasks
enjoy-binbin
added a commit
to enjoy-binbin/valkey
that referenced
this pull request
Oct 11, 2025
The test was accidentally removed in PR valkey-io#1671. Signed-off-by: Binbin <binloveplay1314@qq.com>
enjoy-binbin
added a commit
that referenced
this pull request
Oct 14, 2025
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cluster: add multi-database support in cluster mode
Add multi-database support in cluster mode to align with standalone mode
and facilitate migration. Previously, cluster mode was restricted to a
single database (DB0). This change allows multiple databases while
preserving the existing slot-based key distribution.
Key Features:
Identical keys always map to the same slot across all databases,
ensuring consistent key distribution and compatibility with
existing single-database setups.
cluster mode.
Command-Level Changes:
This means, for example, that migrating keys in a slot will require iterating and repeating across all databases.
Slot Migration Process:
Transaction Handling (MULTI/EXEC):
validation.
uses the selected DB at lookup.
Valkey-cli:
Configuration:
cluster-databases.The new configuration controls the maximal number of databases in cluster mode.
Implements #1319