Class CircuitBreakerDriver

All Implemented Interfaces:
Driver

@DriverCapability(prefix="circuitbreaker", description="Implements circuit breaker pattern for fault tolerance with CLOSED/OPEN/HALF_OPEN states", capabilities="resilience") @DriverParameter(name="name",type=STRING,description="Circuit breaker name for monitoring",defaultValue="default") @DriverParameter(name="failureThreshold",type=INTEGER,description="Failures before opening circuit",defaultValue="5",min=1L) @DriverParameter(name="successThreshold",type=INTEGER,description="Successes in half-open to close circuit",defaultValue="1",min=1L) @DriverParameter(name="resetTimeout",type=INTEGER,description="Time in ms before open -> half-open",defaultValue="30000",min=1L) @DriverSideEffects(stateful=true) public class CircuitBreakerDriver extends AbstractProxyDriver
CircuitBreakerDriver implements the circuit breaker pattern for fault tolerance.

The circuit breaker has three states:

  • CLOSED - Normal operation, requests pass through to the database
  • OPEN - Circuit is tripped, all requests fail fast without attempting the operation
  • HALF_OPEN - Testing state, allows limited requests to check if backend has recovered

State transitions:

  • CLOSED to OPEN: After failureThreshold consecutive failures
  • OPEN to HALF_OPEN: After resetTimeout milliseconds have elapsed
  • HALF_OPEN to CLOSED: After successThreshold consecutive successes
  • HALF_OPEN to OPEN: On any failure

URL format: jdbc:circuitbreaker[param=value,...]:jdbc:target:...

Example URLs:

 jdbc:circuitbreaker:jdbc:postgresql://localhost/mydb
 jdbc:circuitbreaker[failureThreshold=3,resetTimeout=60000]:jdbc:postgresql://localhost/mydb
 jdbc:circuitbreaker[name=primary-db,failureThreshold=10]:jdbc:mysql://localhost/db
 

JMX Monitoring

Circuit breakers can be monitored via JMX. Enable with:

  • System property: -Dpjdbc.jmx.enabled=true
  • Programmatic: CircuitBreakerRegistry.enableJmx()

When enabled, MBeans are registered under: org.pjdbc:type=CircuitBreaker,name=<name>

Exposed attributes: state, failureCount, successCount, totalRequests, totalFailures, totalRejections, failureRatePercent. Operations: reset(), forceOpen(), forceClosed().