Class: Pinot::CircuitBreakerRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/pinot/circuit_breaker.rb

Overview

Thread-safe registry that lazily creates and caches one CircuitBreaker per broker address string. Shared by all Connection instances built from the same ClientConfig so that failures from parallel queries accumulate correctly.

Instance Method Summary collapse

Constructor Details

#initialize(failure_threshold: 5, open_timeout: 30) ⇒ CircuitBreakerRegistry

Returns a new instance of CircuitBreakerRegistry.



119
120
121
122
123
124
# File 'lib/pinot/circuit_breaker.rb', line 119

def initialize(failure_threshold: 5, open_timeout: 30)
  @failure_threshold = failure_threshold
  @open_timeout      = open_timeout
  @breakers          = {}
  @mutex             = Mutex.new
end

Instance Method Details

#for(broker_address) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/pinot/circuit_breaker.rb', line 126

def for(broker_address)
  @mutex.synchronize do
    @breakers[broker_address] ||= CircuitBreaker.new(
      failure_threshold: @failure_threshold,
      open_timeout: @open_timeout
    )
  end
end

#open?(broker_address) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/pinot/circuit_breaker.rb', line 135

def open?(broker_address)
  @mutex.synchronize { @breakers[broker_address]&.open? || false }
end

#reset_allObject

Remove all state (useful for testing).



140
141
142
# File 'lib/pinot/circuit_breaker.rb', line 140

def reset_all
  @mutex.synchronize { @breakers.clear }
end