[VOL-5486] Upgrade library versions
Change-Id: I8b4e88699e03f44ee13e467867f45ae3f0a63c4b
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/vendor/github.com/eapache/go-resiliency/breaker/breaker.go b/vendor/github.com/eapache/go-resiliency/breaker/breaker.go
index f88ca72..9214386 100644
--- a/vendor/github.com/eapache/go-resiliency/breaker/breaker.go
+++ b/vendor/github.com/eapache/go-resiliency/breaker/breaker.go
@@ -12,10 +12,13 @@
// because the breaker is currently open.
var ErrBreakerOpen = errors.New("circuit breaker is open")
+// State is a type representing the possible states of a circuit breaker.
+type State uint32
+
const (
- closed uint32 = iota
- open
- halfOpen
+ Closed State = iota
+ Open
+ HalfOpen
)
// Breaker implements the circuit-breaker resiliency pattern
@@ -24,7 +27,7 @@
timeout time.Duration
lock sync.Mutex
- state uint32
+ state State
errors, successes int
lastError time.Time
}
@@ -46,9 +49,9 @@
// already open, or it will run the given function and pass along its return
// value. It is safe to call Run concurrently on the same Breaker.
func (b *Breaker) Run(work func() error) error {
- state := atomic.LoadUint32(&b.state)
+ state := b.GetState()
- if state == open {
+ if state == Open {
return ErrBreakerOpen
}
@@ -61,9 +64,9 @@
// the return value of the function. It is safe to call Go concurrently on the
// same Breaker.
func (b *Breaker) Go(work func() error) error {
- state := atomic.LoadUint32(&b.state)
+ state := b.GetState()
- if state == open {
+ if state == Open {
return ErrBreakerOpen
}
@@ -75,7 +78,13 @@
return nil
}
-func (b *Breaker) doWork(state uint32, work func() error) error {
+// GetState returns the current State of the circuit-breaker at the moment
+// that it is called.
+func (b *Breaker) GetState() State {
+ return (State)(atomic.LoadUint32((*uint32)(&b.state)))
+}
+
+func (b *Breaker) doWork(state State, work func() error) error {
var panicValue interface{}
result := func() error {
@@ -85,7 +94,7 @@
return work()
}()
- if result == nil && panicValue == nil && state == closed {
+ if result == nil && panicValue == nil && state == Closed {
// short-circuit the normal, success path without contending
// on the lock
return nil
@@ -108,7 +117,7 @@
defer b.lock.Unlock()
if result == nil && panicValue == nil {
- if b.state == halfOpen {
+ if b.state == HalfOpen {
b.successes++
if b.successes == b.successThreshold {
b.closeBreaker()
@@ -123,26 +132,26 @@
}
switch b.state {
- case closed:
+ case Closed:
b.errors++
if b.errors == b.errorThreshold {
b.openBreaker()
} else {
b.lastError = time.Now()
}
- case halfOpen:
+ case HalfOpen:
b.openBreaker()
}
}
}
func (b *Breaker) openBreaker() {
- b.changeState(open)
+ b.changeState(Open)
go b.timer()
}
func (b *Breaker) closeBreaker() {
- b.changeState(closed)
+ b.changeState(Closed)
}
func (b *Breaker) timer() {
@@ -151,11 +160,11 @@
b.lock.Lock()
defer b.lock.Unlock()
- b.changeState(halfOpen)
+ b.changeState(HalfOpen)
}
-func (b *Breaker) changeState(newState uint32) {
+func (b *Breaker) changeState(newState State) {
b.errors = 0
b.successes = 0
- atomic.StoreUint32(&b.state, newState)
+ atomic.StoreUint32((*uint32)(&b.state), (uint32)(newState))
}