Skip to content
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

Add multi-database support to cluster mode #1671

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from

Conversation

xbasel
Copy link
Member

@xbasel xbasel commented Feb 5, 2025

This commit introduces multi-database support in cluster mode while maintaining backward compatibility and requiring no API changes. Key features include:

  • Database-agnostic hashing: The hashing algorithm is unchanged. Identical keys map to the same slot across all databases. No changes to slot calculation. This ensures consistency in key distribution and maintains compatibility with existing single-database setups.

  • Implementation is fully backward compatible with no API changes.

  • The core structure remains an array of databases, each containing a list of hashtables (one per slot).

Cluster management commands are global commands, except for GETKEYSINSLOT and COUNTKEYSINSLOT, which run in selected-DB context.

MIGRATE command operates a selected-db context. Please note that MIGRATE command parameter destination-db is used, when migrating keys they can be migrated to a different database in the target, like in non-cluster mode.

Slot migration process changes when multiple databases are used:

	Iterate through all databases
 		SELECT database
 		keys = GETKEYSINSLOT
 		MIGRATE source target keys

Valkey-cli has been updated to support resharding across all databases.

#1319

This commit introduces multi-database support in cluster mode while
maintaining backward compatibility and requiring no API changes. Key
features include:

- Database-agnostic hashing: The hashing algorithm is unchanged.
  Identical keys map to the same slot across all databases. No changes
  to slot calculation. This ensures consistency in key distribution
  and maintains compatibility with existing single-database setups.

- Implementation is fully backward compatible with no API changes.

- The core structure remains an array of databases, each containing a
  list of hashtables (one per slot).

Cluster management commands are global commands, except for
GETKEYSINSLOT and COUNTKEYSINSLOT, which run in selected-DB context.

MIGRATE command operates a selected-db context. Please note that
MIGRATE command parameter destination-db is used, when migrating keys
they can be migrated to a different database in the target, like in
non-cluster mode.

Slot migration process changes when multiple databases are used:
	Iterate through all databases
 		SELECT database
 		keys = GETKEYSINSLOT
 		MIGRATE source target keys

Valkey-cli has been updated to support resharding across all
databases.

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 89.23077% with 7 lines in your changes missing coverage. Please review.

Project coverage is 71.12%. Comparing base (2eac2cc) to head (0cf9b2d).
Report is 24 commits behind head on unstable.

Files with missing lines Patch % Lines
src/valkey-cli.c 80.64% 6 Missing ⚠️
src/cluster.c 88.88% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1671      +/-   ##
============================================
+ Coverage     70.97%   71.12%   +0.14%     
============================================
  Files           121      123       +2     
  Lines         65238    65543     +305     
============================================
+ Hits          46305    46619     +314     
+ Misses        18933    18924       -9     
Files with missing lines Coverage Δ
src/cluster_legacy.c 86.24% <100.00%> (+0.34%) ⬆️
src/config.c 78.35% <ø> (-0.06%) ⬇️
src/db.c 89.94% <ø> (+0.37%) ⬆️
src/valkey-benchmark.c 61.83% <ø> (+1.69%) ⬆️
src/cluster.c 89.17% <88.88%> (-0.07%) ⬇️
src/valkey-cli.c 56.10% <80.64%> (+0.22%) ⬆️

... and 33 files with indirect coverage changes

@xbasel xbasel marked this pull request as ready for review February 10, 2025 21:37
@xbasel xbasel requested a review from zuiderkwast February 10, 2025 22:13
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.

1 participant