Skip to content

Comments

[automatic failover] Add Dynamic Weight Management for Redis Multi-Database Connections#3672

Open
atakavci wants to merge 4 commits intoredis:mainfrom
atakavci:failover/dynamicWeights
Open

[automatic failover] Add Dynamic Weight Management for Redis Multi-Database Connections#3672
atakavci wants to merge 4 commits intoredis:mainfrom
atakavci:failover/dynamicWeights

Conversation

@atakavci
Copy link
Collaborator

Summary

Adds the ability to dynamically update database weights at runtime for multi-database Redis connections, enabling flexible endpoint priority adjustments without reconnection.

Changes

API Enhancements

  • Added setWeight(float) method to RedisDatabase interface
  • Made weight field mutable in RedisDatabaseImpl

Documentation Updates

  • Clarified that weight is used for "endpoint priority" rather than "load balancing" across javadocs
  • Updated terminology in DatabaseConfig, BaseRedisMultiDbConnection, and RedisDatabase

Test Coverage

  • Added 6 integration tests for weight management operations
  • Added 7 unit tests covering edge cases (zero, negative, max values, multiple updates)
  • Tests verify weight retrieval, updates, and multi-database scenarios

Use Case

Allows runtime adjustment of database priorities for failover scenarios without requiring connection recreation.

- add setWeight
- add tests

- format
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds runtime weight updates for multi-database Redis failover connections so endpoint priority can be adjusted without recreating connections.

Changes:

  • Extends RedisDatabase with a runtime setWeight(float) API and makes RedisDatabaseImpl.weight mutable.
  • Updates terminology in Javadocs from “load balancing” to “endpoint priority”.
  • Adds unit/integration tests covering weight retrieval and updates.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/java/io/lettuce/core/failover/api/RedisDatabase.java Adds setWeight(float) to the public database API.
src/main/java/io/lettuce/core/failover/RedisDatabaseImpl.java Makes weight mutable and implements setWeight.
src/main/java/io/lettuce/core/failover/api/DatabaseConfig.java Updates Javadocs to reflect endpoint-priority semantics.
src/main/java/io/lettuce/core/failover/api/BaseRedisMultiDbConnection.java Updates addDatabase parameter documentation for endpoint priority.
src/test/java/io/lettuce/core/failover/StatefulRedisMultiDbConnectionImplUnitTests.java Adds unit tests for weight get/set and edge values.
src/test/java/io/lettuce/core/failover/StatefulMultiDbConnectionIntegrationTests.java Adds integration tests for weight operations via connection APIs.
src/test/java/io/lettuce/core/failover/DatabaseConfigBuilderUnitTests.java Updates example naming/terminology around weights.

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

Copy link
Contributor

@ggivo ggivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding or removing databases, we evaluate and switch to the database with the highest weight.
However, changing the weights does not currently trigger a re-evaluation or switch. I would expect weight updates to behave similarly to add/remove operations and trigger a switch to the highest-weighted database.

Copy link
Contributor

@ggivo ggivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding or removing databases, we evaluate and switch to the database with the highest weight.
However, changing the weights does not currently trigger a re-evaluation or switch. I would expect weight updates to behave similarly to add/remove operations and trigger a switch to the highest-weighted database.

@atakavci
Copy link
Collaborator Author

When adding or removing databases, we evaluate and switch to the database with the highest weight. However, changing the weights does not currently trigger a re-evaluation or switch. I would expect weight updates to behave similarly to add/remove operations and trigger a switch to the highest-weighted database.

@ggivo adding/removing db does not trigger a failback/failover directly. Right now fundamental parts are there to set/switch/failover in case user likes to do so.

- adding unit test for setting a higher weight dynamically causes a failback
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


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

@ggivo
Copy link
Contributor

ggivo commented Feb 23, 2026

adding/removing db does not trigger a failback/failover directly. Right now fundamental parts are there to set/switch/failover in case user likes to do so.

@atakavci
Agree.
But this change made me think, if we update the weights of databases, we are missing an API to trigger reevaluation and select the best match.

Copy link
Contributor

@ggivo ggivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants