Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

multidb

v9.24.1
github.com/redis/go-redis/v9/internal/multidb

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

25 matches

Top ↑

Package multidb provides internal components for multi-database support.

Constants

CircuitClosed (3 declarations)

const (
	// CircuitClosed indicates the circuit is closed and requests are allowed.
	CircuitClosed = circuitbreaker.StateClosed
	// CircuitOpen indicates the circuit is open and requests are blocked.
	CircuitOpen = circuitbreaker.StateOpen
	// CircuitHalfOpen indicates the circuit is testing if the service has recovered.
	CircuitHalfOpen = circuitbreaker.StateHalfOpen
)

DefaultProbes (3 declarations)

const (
	DefaultProbes       = 3
	DefaultProbeDelay   = 500 * time.Millisecond
	DefaultProbeTimeout = 3 * time.Second
)

Default probe settings, shared by the root default policy and the multidb package.

Functions

ProbesAllMustPass

func ProbesAllMustPass(ctx context.Context, cfg ProbeConfig, probe ProbeFunc) bool

ProbesAllMustPass runs cfg.Probes probes; all must pass.

ProbesAny

func ProbesAny(ctx context.Context, cfg ProbeConfig, probe ProbeFunc) bool

ProbesAny runs probes until one passes.

ProbesMajority

func ProbesMajority(ctx context.Context, cfg ProbeConfig, probe ProbeFunc) bool

ProbesMajority runs probes until a strict majority passed or failed.

RunChecks

func RunChecks(ctx context.Context, n int, check func(ctx context.Context, i int) bool) bool

RunChecks runs n checks concurrently and returns true only if all pass (AND across checks). check(ctx, i) evaluates check i. A panicking check counts as failed. The first failure cancels the others.

Types

CircuitBreaker

type CircuitBreaker struct {
	*circuitbreaker.CircuitBreaker
	// contains filtered or unexported fields
}

CircuitBreaker wraps the internal circuitbreaker.CircuitBreaker.

MultiDB feeds it two kinds of outcome: admitted commands (the reservation API) and health probes (the ForReset API). The base breaker keeps them as two consecutive-failure streaks, and Stats() reports both: Failures is the command streak, ExternalFailures the probe streak. Either reaching FailureThreshold opens the circuit; a successful command ends only the first, a passing probe only the second.

NewCircuitBreaker

func NewCircuitBreaker(config CircuitBreakerConfig) *CircuitBreaker

NewCircuitBreaker creates a new circuit breaker with the given configuration. Zero-valued fields are replaced with their defaults before the config is stored, so Config() always reports the values the breaker actually runs with.

CircuitBreaker.Config

func (cb *CircuitBreaker) Config() CircuitBreakerConfig

Config returns the circuit breaker configuration.

CircuitBreaker.OnStateChange

func (cb *CircuitBreaker) OnStateChange(callback CircuitBreakerCallback)

OnStateChange registers a callback to be called when the state changes.

CircuitBreakerCallback

type CircuitBreakerCallback func(oldState, newState CircuitState)

CircuitBreakerCallback is called when the circuit breaker state changes.

CircuitBreakerConfig

type CircuitBreakerConfig struct {
	// FailureThreshold is the number of failures before opening the circuit.
	FailureThreshold int
	// SuccessThreshold is the number of successes in half-open state before closing.
	SuccessThreshold int
	// GracePeriod is how long to wait before transitioning from open to half-open.
	// This grace period gives a failed database time to self-heal before it is
	// probed again. Default: 60 seconds.
	GracePeriod time.Duration
}

CircuitBreakerConfig holds configuration for a circuit breaker.

DefaultCircuitBreakerConfig

func DefaultCircuitBreakerConfig() CircuitBreakerConfig

DefaultCircuitBreakerConfig returns the default circuit breaker configuration.

CircuitState

type CircuitState = circuitbreaker.State

CircuitState represents the state of a circuit breaker. This is an alias to the internal circuitbreaker package.

ProbeConfig

type ProbeConfig struct {
	Probes  int
	Delay   time.Duration
	Timeout time.Duration
}

ProbeConfig is how one health check is probed. Its fields match redis.MultiDBHealthCheckConfig so the two convert directly.

ProbeFunc

type ProbeFunc func(ctx context.Context) (bool, error)

ProbeFunc runs one probe of a health check.

ProbeRunner

type ProbeRunner func(ctx context.Context, cfg ProbeConfig, probe ProbeFunc) bool

ProbeRunner interprets the probes of one health check (all / majority / any) and reports whether the check passed.

Reservation

type Reservation = circuitbreaker.Reservation

Reservation is a circuit-breaker admission handle returned by AllowReserve. This is an alias to the internal circuitbreaker package.

Dependency graph