Skip to content

Conversation

atakavci
Copy link
Contributor

Summary

Add dual-threshold failover to Jedis multi-cluster: failover occurs only when both minimum failures and failure-rate thresholds are exceeded. Simplify configuration, adapt thresholds cleanly to resilience4j, and update docs/tests.

Key changes

  • CircuitBreakerCommandExecutor: enforce dual thresholds using CB metrics; raise JedisFailoverThresholdsExceededException on exceed.
  • CircuitBreakerThresholdsAdapter (new): maps MultiClusterClientConfig to resilience4j CB config, handling 0.0% rate and min calls robustly.
  • MultiClusterClientConfig simplified:
    • Defaults: failureRate=10%, windowSize=2, minFailures=1000
    • Removed slow-call and window-type/min-calls knobs
    • Added thresholdMinNumOfFailures and validation (disallow 0 failures + 0.0% rate)
    • Added JedisFailoverThresholdsExceededException to fallback list
  • MultiClusterPooledConnectionProvider: build CB via adapter; cluster exposes getThresholdMinNumOfFailures
  • Docs: updated defaults and examples; clarified simpler CB model
  • Tests: added/updated parameterized and integration tests, including 0.0% rate and large min-failures

Behavior

  • Failover triggers when:
    • failures >= thresholdMinNumOfFailures AND
    • (failed / total) × 100 >= failureRateThreshold
  • For configured 0.0% rate: adapter maps to 100% and sets very large minimumNumberOfCalls to prevent CB from self-opening; executor still applies dual thresholds.

Migration

  • Prefer:
    • thresholdMinNumOfFailures(int)
    • circuitBreakerFailureRateThreshold(float)
    • circuitBreakerSlidingWindowSize(int)
  • Removed: slidingWindowType, slidingWindowMinCalls, slowCallDurationThreshold, slowCallRateThreshold. Adjust configs accordingly.

Validation

  • Unit and parameterized tests cover edge thresholds (0%, 100%), small/large sample sizes.
  • Integration tests updated; docs aligned with new defaults and API.

…t breaker executor

- Map config to resilience4j via CircuitBreakerThresholdsAdapter
- clean up/simplfy config: drop slow-call and window type
- Add thresholdMinNumOfFailures; update some of the defaults
- Update provider to use thresholds adapter
- Update docs; align examples with new defaults
- Add tests for 0% rate, edge thresholds
@atakavci atakavci self-assigned this Sep 26, 2025
Copy link

jit-ci bot commented Sep 26, 2025

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

Copy link
Contributor

@Copilot 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

This PR adds dual-threshold failover capability to Jedis multi-cluster circuit breaker functionality. The circuit breaker now requires both a minimum number of failures AND a failure rate threshold to be exceeded before triggering failover, providing more robust failover control.

Key changes:

  • Introduces dual threshold logic requiring both minimum failures and failure rate criteria to be met
  • Simplifies configuration by removing deprecated circuit breaker settings and updating defaults
  • Adds new adapter class to handle threshold mapping to resilience4j configuration

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
MultiClusterClientConfig.java Updated configuration with new dual threshold properties and simplified circuit breaker settings
CircuitBreakerThresholdsAdapter.java New adapter class for mapping configuration to resilience4j circuit breaker settings
CircuitBreakerCommandExecutor.java Added dual threshold checking logic before triggering failover
CircuitBreakerFailoverBase.java Base class with shared threshold validation logic
JedisFailoverThresholdsExceededException.java New exception type for threshold-based failover
Various test files Updated tests to remove deprecated configuration options and add threshold testing
docs/failover.md Updated documentation with new defaults and simplified configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

private static int calculateMinTotalCalls(int failures, float rate) {
int minCalls = (int) (failures * rate * 100);
Copy link
Preview

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

The calculation appears incorrect. The formula failures * rate * 100 doesn't represent the minimum number of total calls needed. For example, if you need 3 failures at 50% rate, you'd need at least 6 total calls, but this formula gives 150. The correct formula should be (int) Math.ceil(failures / (rate / 100.0)) or (int) Math.ceil(failures * 100.0 / rate).

Suggested change
int minCalls = (int) (failures * rate * 100);
int minCalls = (int) Math.ceil(failures * 100.0 / rate);

Copilot uses AI. Check for mistakes.

atakavci and others added 2 commits September 26, 2025 20:26
…Adapter.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@atakavci atakavci added the breakingchange Pull request that has breaking changes. Must include the breaking behavior in release notes. label Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breakingchange Pull request that has breaking changes. Must include the breaking behavior in release notes. feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant