Adding cluster commands support in java language binding #5105
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.
Issue link
This Pull Request is linked to issue (URL): #5106
Description
This PR implements 30 cluster management commands for the Java client, enabling comprehensive control over Valkey cluster operations. These commands allow applications to inspect cluster state, manage node membership, control slot allocation, handle failovers, and perform administrative tasks programmatically.
What This PR Adds
This implementation provides complete cluster management capabilities:
Cluster Information & Topology (7 commands)
clusterInfo()- Get cluster state and statisticsclusterNodes()- List all nodes with their roles and statesclusterShards()- Get detailed shard information with slot rangesclusterSlots()- Get slot-to-node mappingclusterLinks()- View inter-node connectionsclusterMyId()- Get current node's unique identifierclusterMyShardId()- Get current node's shard identifierSlot Management (7 commands)
clusterAddSlots()/clusterAddSlotsRange()- Assign slots to nodesclusterDelSlots()/clusterDelSlotsRange()- Remove slot assignmentsclusterKeySlot()- Calculate which slot a key belongs toclusterCountKeysInSlot()- Count keys in a specific slotclusterGetKeysInSlot()- Retrieve keys from a specific slotNode Management (5 commands)
clusterMeet()- Add a new node to the clusterclusterForget()- Remove a node from the clusterclusterReplicate()- Configure replication between nodesclusterReplicas()- List replicas of a specific nodeclusterCountFailureReports()- Get failure report count for a nodeCluster Operations (6 commands)
clusterFailover()- Trigger manual failoverclusterSetSlot()- Manage slot migration statesclusterBumpEpoch()- Force configuration epoch incrementclusterSetConfigEpoch()- Set node's configuration epochclusterFlushSlots()- Clear slot assignment cacheclusterResetSoft()/clusterResetHard()- Reset cluster stateConnection Control (3 commands)
readOnly()- Enable read commands on replicasreadWrite()- Disable read-only modeasking()- Allow commands during slot migrationAdmin Operations (2 commands)
clusterSaveConfig()- Persist cluster configuration to diskclusterDumpKeysInSlot()- Get serialized key data for migrationUse Cases
Use Case 1: Dynamic Cluster Scaling
Use Case 2: Monitoring Cluster Health
Use Case 3: Slot Migration for Rebalancing
Use Case 4: Controlled Failover
Use Case 5: Read Scaling with Replicas
Use Case 6: Batch Operations for Efficiency
Implementation Details
1. Command Interface
Added
ClusterCommandsinterface defining all 30 cluster commands with:2. Client Implementation
Extended
GlideClusterClientto implement all cluster commands:Routeparameter for multi-node operations3. Batch Support
Extended
ClusterBatchto support all cluster commands:4. Client-Side Validation
Added
ClusterCommandValidationutility with input validation:5. Comprehensive Testing
Created extensive test suite with 92 tests:
Test coverage includes:
GlideString)Files Modified
Created:
java/client/src/main/java/glide/api/commands/ClusterCommands.java- Interface defining 30 cluster commandsjava/client/src/main/java/glide/api/models/ClusterCommandValidation.java- Input validation utilitiesjava/integTest/src/test/java/glide/cluster/ClusterManagementCommandsTests.java- 46 functional testsjava/integTest/src/test/java/glide/cluster/ClusterCommandValidationTests.java- 37 validation testsModified:
java/client/src/main/java/glide/api/GlideClusterClient.java- Implemented all 30 cluster commandsjava/client/src/main/java/glide/api/models/ClusterBatch.java- Added batch support for cluster commandsjava/client/src/main/java/glide/api/BaseClient.java- AddedhandleStringArrayResponsehelperCHANGELOG.md- Documented new featuresTest Results
API Compatibility
Feature Parity: This implementation achieves feature parity with other major Java clients (Jedis, Lettuce) for cluster commands.
Additional Features:
Breaking Changes: None. This is a new feature addition.
Backward Compatibility: Fully compatible with existing code.
Issue Link
This Pull Request is linked to issue (URL): #5106
Checklist
Before submitting the PR make sure the following are checked:
Testing Instructions
To verify this PR:
Expected results: