فهرست منبع

breaker: remover useless code (#114)

刘青 4 سال پیش
والد
کامیت
e66cca3710
3فایلهای تغییر یافته به همراه0 افزوده شده و 16 حذف شده
  1. 0 6
      core/breaker/breaker.go
  2. 0 9
      core/breaker/googlebreaker.go
  3. 0 1
      core/breaker/googlebreaker_test.go

+ 0 - 6
core/breaker/breaker.go

@@ -13,11 +13,6 @@ import (
 	"github.com/tal-tech/go-zero/core/timex"
 	"github.com/tal-tech/go-zero/core/timex"
 )
 )
 
 
-const (
-	StateClosed State = iota
-	StateOpen
-)
-
 const (
 const (
 	numHistoryReasons = 5
 	numHistoryReasons = 5
 	timeFormat        = "15:04:05"
 	timeFormat        = "15:04:05"
@@ -27,7 +22,6 @@ const (
 var ErrServiceUnavailable = errors.New("circuit breaker is open")
 var ErrServiceUnavailable = errors.New("circuit breaker is open")
 
 
 type (
 type (
-	State      = int32
 	Acceptable func(err error) bool
 	Acceptable func(err error) bool
 
 
 	Breaker interface {
 	Breaker interface {

+ 0 - 9
core/breaker/googlebreaker.go

@@ -2,7 +2,6 @@ package breaker
 
 
 import (
 import (
 	"math"
 	"math"
-	"sync/atomic"
 	"time"
 	"time"
 
 
 	"github.com/tal-tech/go-zero/core/collection"
 	"github.com/tal-tech/go-zero/core/collection"
@@ -21,7 +20,6 @@ const (
 // see Client-Side Throttling section in https://landing.google.com/sre/sre-book/chapters/handling-overload/
 // see Client-Side Throttling section in https://landing.google.com/sre/sre-book/chapters/handling-overload/
 type googleBreaker struct {
 type googleBreaker struct {
 	k     float64
 	k     float64
-	state int32
 	stat  *collection.RollingWindow
 	stat  *collection.RollingWindow
 	proba *mathx.Proba
 	proba *mathx.Proba
 }
 }
@@ -32,7 +30,6 @@ func newGoogleBreaker() *googleBreaker {
 	return &googleBreaker{
 	return &googleBreaker{
 		stat:  st,
 		stat:  st,
 		k:     k,
 		k:     k,
-		state: StateClosed,
 		proba: mathx.NewProba(),
 		proba: mathx.NewProba(),
 	}
 	}
 }
 }
@@ -43,15 +40,9 @@ func (b *googleBreaker) accept() error {
 	// https://landing.google.com/sre/sre-book/chapters/handling-overload/#eq2101
 	// https://landing.google.com/sre/sre-book/chapters/handling-overload/#eq2101
 	dropRatio := math.Max(0, (float64(total-protection)-weightedAccepts)/float64(total+1))
 	dropRatio := math.Max(0, (float64(total-protection)-weightedAccepts)/float64(total+1))
 	if dropRatio <= 0 {
 	if dropRatio <= 0 {
-		if atomic.LoadInt32(&b.state) == StateOpen {
-			atomic.CompareAndSwapInt32(&b.state, StateOpen, StateClosed)
-		}
 		return nil
 		return nil
 	}
 	}
 
 
-	if atomic.LoadInt32(&b.state) == StateClosed {
-		atomic.CompareAndSwapInt32(&b.state, StateClosed, StateOpen)
-	}
 	if b.proba.TrueOnProba(dropRatio) {
 	if b.proba.TrueOnProba(dropRatio) {
 		return ErrServiceUnavailable
 		return ErrServiceUnavailable
 	}
 	}

+ 0 - 1
core/breaker/googlebreaker_test.go

@@ -27,7 +27,6 @@ func getGoogleBreaker() *googleBreaker {
 	return &googleBreaker{
 	return &googleBreaker{
 		stat:  st,
 		stat:  st,
 		k:     5,
 		k:     5,
-		state: StateClosed,
 		proba: mathx.NewProba(),
 		proba: mathx.NewProba(),
 	}
 	}
 }
 }