mirror of
https://github.com/redis/go-redis.git
synced 2025-12-03 18:31:14 +03:00
Merge branch 'ndyakov/state-machine-conn' into ndyakov/pool-performance
This commit is contained in:
@@ -234,7 +234,7 @@ func (cn *Conn) SetUsable(usable bool) {
|
|||||||
// This is a backward-compatible wrapper around the state machine.
|
// This is a backward-compatible wrapper around the state machine.
|
||||||
func (cn *Conn) IsInited() bool {
|
func (cn *Conn) IsInited() bool {
|
||||||
state := cn.stateMachine.GetState()
|
state := cn.stateMachine.GetState()
|
||||||
// Connection is initialized if it's in READY or any post-initialization state
|
// Connection is initialized if it's in IDLE or any post-initialization state
|
||||||
return state != StateCreated && state != StateInitializing && state != StateClosed
|
return state != StateCreated && state != StateInitializing && state != StateClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ func NewConnStateMachine() *ConnStateMachine {
|
|||||||
|
|
||||||
// GetState returns the current state (lock-free read).
|
// GetState returns the current state (lock-free read).
|
||||||
// This is the hot path - optimized for zero allocations and minimal overhead.
|
// This is the hot path - optimized for zero allocations and minimal overhead.
|
||||||
|
// Note: Zero allocations applies to state reads; converting the returned state to a string
|
||||||
|
// (via String()) may allocate if the state is unknown.
|
||||||
func (sm *ConnStateMachine) GetState() ConnState {
|
func (sm *ConnStateMachine) GetState() ConnState {
|
||||||
return ConnState(sm.state.Load())
|
return ConnState(sm.state.Load())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func TestConnStateMachine_AwaitAndTransition_FastPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if state := sm.GetState(); state != StateUnusable {
|
if state := sm.GetState(); state != StateUnusable {
|
||||||
t.Errorf("expected state REAUTH_IN_PROGRESS, got %s", state)
|
t.Errorf("expected state UNUSABLE, got %s", state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,9 +384,9 @@ func TestConnStateMachine_AwaitAndTransitionWaitsForInitialization(t *testing.T)
|
|||||||
t.Errorf("expected %d completions, got %d", numGoroutines, completedCount.Load())
|
t.Errorf("expected %d completions, got %d", numGoroutines, completedCount.Load())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Final state should be READY
|
// Final state should be IDLE
|
||||||
if sm.GetState() != StateIdle {
|
if sm.GetState() != StateIdle {
|
||||||
t.Errorf("expected final state READY, got %s", sm.GetState())
|
t.Errorf("expected final state IDLE, got %s", sm.GetState())
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Execution order: %v", executionOrder)
|
t.Logf("Execution order: %v", executionOrder)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ var (
|
|||||||
// circuit breaker errors
|
// circuit breaker errors
|
||||||
var (
|
var (
|
||||||
// ErrCircuitBreakerOpen is returned when the circuit breaker is open
|
// ErrCircuitBreakerOpen is returned when the circuit breaker is open
|
||||||
ErrCircuitBreakerOpen = errors.New("" + logs.CircuitBreakerOpenErrorMessage)
|
ErrCircuitBreakerOpen = errors.New(logs.CircuitBreakerOpenErrorMessage)
|
||||||
)
|
)
|
||||||
|
|
||||||
// circuit breaker configuration errors
|
// circuit breaker configuration errors
|
||||||
|
|||||||
Reference in New Issue
Block a user