-
Notifications
You must be signed in to change notification settings - Fork 937
Add multi-database support to cluster mode #1671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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:
|
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add history to SWAPDB
, SELECT
, MOVE
json files to indicate it's supported since 9.0.
3dc03d6
to
af2d46a
Compare
documentation: valkey-io/valkey-doc#242 |
It looks like there are still some test cases failed related to multiply db feature. Please fix them first, Thanks |
538e23e
to
63151ae
Compare
Co-authored-by: Ran Shidlansik <[email protected]> Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
Signed-off-by: xbasel <[email protected]>
I created issues for everything I noticed was a followup, wanted to merge to allow other PRs like atomic slot migration to rebase. |
Almost all tests in Daily failed today. What happened here?
https://github.com/valkey-io/valkey/actions/runs/14826557992 |
Re-adds a statement to restore the `singledb` config that was accidentally removed in PR valkey-io#1671. Signed-off-by: xbasel <[email protected]>
Re-adds a statement to restore the `singledb` config that was accidentally removed in PR valkey-io#1671. Signed-off-by: xbasel <[email protected]>
Re-adds a statement to restore the `singledb` config that was accidentally removed in PR #1671. Fixes #2049 Signed-off-by: xbasel <[email protected]>
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 <[email protected]>
## 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 <[email protected]> Signed-off-by: zhaozhao.zz <[email protected]> Co-authored-by: zhaozhao.zz <[email protected]> Co-authored-by: Viktor Söderqvist <[email protected]> Co-authored-by: Madelyn Olson <[email protected]> Co-authored-by: Ran Shidlansik <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]> Signed-off-by: Simon Baatz <[email protected]> Co-authored-by: Viktor Söderqvist <[email protected]>
…#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 <[email protected]> Signed-off-by: Simon Baatz <[email protected]> Co-authored-by: Viktor Söderqvist <[email protected]>
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