8000 [automatic failover] Add support for initialization policy for multidb connection by atakavci · Pull Request #4427 · redis/jedis · GitHub
[go: up one dir, main page]

Skip to content

[automatic failover] Add support for initialization policy for multidb connection#4427

Merged
atakavci merged 7 commits intoredis:masterfrom
atakavci:failover/initPolicy
Feb 13, 2026
Merged

[automatic failover] Add support for initialization policy for multidb connection#4427
atakavci merged 7 commits intoredis:masterfrom
atakavci:failover/initPolicy

Conversation

@atakavci
Copy link
Contributor

Add Initialization Policy for Multi-Database Connection Provider

Summary

Introduces a configurable InitializationPolicy that determines when the MultiDbConnectionProvider is ready based on database connection availability during initialization.

Changes

New Classes

  • InitializationPolicy - Interface for defining initialization policies with three built-in implementations:

    • ALL_AVAILABLE - Requires all databases to be healthy before initialization succeeds
    • MAJORITY_AVAILABLE - Requires a majority of databases to be healthy (default)
    • ONE_AVAILABLE - Requires at least one database to be healthy
  • ConnectionInitializationContext - Tracks connection initialization status (available, failed, pending counts) and evaluates policies

Configuration

  • Added initializationPolicy field to MultiDbConfig with builder support
  • Default policy: MAJORITY_AVAILABLE

Provider Updates

  • Refactored waitForInitialHealthyDatabase()waitForInitializationPolicy() to use policy-based evaluation
  • Added selectBestAvailableDatabase() for selecting the highest-weighted healthy database after policy success
  • Supports early success/failure based on policy evaluation (e.g., majority reached before all checks complete)

Usage

MultiDbConfig config = new MultiDbConfig.Builder(databases)
    .initializationPolicy(InitializationPolicy.BuiltIn.ONE_AVAILABLE)
    .build();

Tests

  • InitializationPolicyTest - Unit tests for all built-in policy decision logic
  • ConnectionInitializationContextTest - Unit tests for context construction and policy evaluation
  • Updated DefaultValuesTest and MultiDbConnectionProviderInitializationTest with policy tests

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 a configurable initialization policy to determine when MultiDbConnectionProvider considers itself ready during startup, based on how many DB endpoints are available/failed/pending.

Changes:

  • Introduces InitializationPolicy (with built-in policies) and ConnectionInitializationContext for policy evaluation.
  • Extends MultiDbConfig to configure initializationPolicy (default intended to be MAJORITY_AVAILABLE).
  • Refactors provider initialization to wait for policy satisfaction and select the best available DB by weight; adds/updates unit tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java Refactors startup wait logic to policy-based evaluation and adds best-DB selection by weight.
src/main/java/redis/clients/jedis/mcf/InitializationPolicy.java Adds initialization policy interface + built-in policies (all/majority/one).
src/main/java/redis/clients/jedis/mcf/ConnectionInitializationContext.java Adds context object for counting available/failed/pending endpoints and evaluating policies.
src/main/java/redis/clients/jedis/MultiDbConfig.java Adds initializationPolicy to configuration + builder setter/default.
src/test/java/redis/clients/jedis/mcf/MultiDbConnectionProviderInitializationTest.java Adds initialization-policy-focused provider initialization tests and adjusts endpoints for mocking.
src/test/java/redis/clients/jedis/mcf/MultiDbConnectionProviderHelper.java Exposes provider policy-wait method for tests.
src/test/java/redis/clients/jedis/mcf/InitializationPolicyTest.java Adds unit tests for built-in policy decision logic.
src/test/java/redis/clients/jedis/mcf/ConnectionInitializationContextTest.java Adds unit tests for context construction and policy evaluation.
src/test/java/redis/clients/jedis/mcf/DefaultValuesTest.java Asserts default initialization policy value.
src/test/java/redis/clients/jedis/mcf/MultiDbConnectionProviderFailoverAttemptsConfigTest.java Adjusts a timing constant used in a test.

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

ggivo
ggivo previously approved these changes Feb 12, 2026
Copy link
Collaborator
@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.

Nice!
LGTM!
I suggest reducing the log level (moving info->debug). Mostly those are expected states, and I think we should not clutter the application log's.

ggivo
ggivo previously approved these changes Feb 12, 2026
@atakavci atakavci merged commit 6aabfcf into redis:master Feb 13, 2026
12 checks passed
@atakavci atakavci deleted the failover/initPolicy branch February 27, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0