Documentation ¶
Index ¶
- func HashFromContext(ctx context.Context) (code uint32, ok bool)
- func InjectSubsetCarrier(ctx context.Context, kvs []string) context.Context
- func NewContextWithHash(ctx context.Context, hash interface{}) context.Context
- func NewContextWithHashCode(ctx context.Context, hash uint32) context.Context
- func SetLogger(l *log.Logger)
- type ActiveHalthFailureType
- type ActiveHealthCheckSession
- type AtomicBool
- type BalanceType
- type Balancer
- type ChangeStateCallback
- type Cluster
- type ClusterManager
- func (cm *ClusterManager) ChooseAllHosts(ctx context.Context, service string) []*Host
- func (cm *ClusterManager) ChooseHost(ctx context.Context, service string) *Host
- func (cm *ClusterManager) Cluster(name string) *Cluster
- func (cm *ClusterManager) InitService(conf config.Cluster) error
- func (cm *ClusterManager) PutResult(service, address string, code int)
- type Detector
- type DetectorHostMonitor
- type Hashable
- type HealthCheckCompleteCallback
- type HealthCheckFailureType
- type HealthChecker
- type HealthCheckerType
- type HealthFlag
- type HealthTransition
- type Host
- func (h *Host) Address() string
- func (h *Host) GetActiveHealthFailureType() (tp ActiveHalthFailureType)
- func (h *Host) GetDetectorMonitor() DetectorHostMonitor
- func (h *Host) HealthFlagClear(flag HealthFlag)
- func (h *Host) HealthFlagGet(flag HealthFlag) (res bool)
- func (h *Host) HealthFlagSet(flag HealthFlag)
- func (h *Host) Healthy() (health bool)
- func (h *Host) Meta() map[string]string
- func (h *Host) SetActiveHealthFailureType(tp ActiveHalthFailureType)
- func (h *Host) SetDetectorMonitor(d DetectorHostMonitor)
- func (h *Host) SetMeta(meta map[string]string)
- func (h *Host) SetUsed(new bool)
- func (h *Host) SetWeight(new uint32)
- func (h *Host) Used() (used bool)
- func (h *Host) Weight() (weight uint32)
- type HostSet
- type RandomBalancer
- type Result
- type RingHashBalancer
- type RoundRobinBalancer
- type SimpleDetector
- func (sd *SimpleDetector) AddChangedStateCallback(cb ChangeStateCallback)
- func (sd *SimpleDetector) CheckHostForUneject(h *Host, m *SimpleDetectorHostMonitor, now time.Time)
- func (sd *SimpleDetector) EjectHost(h *Host, t ejectType)
- func (sd *SimpleDetector) OnConsecutiveConnectionFailure(host *Host)
- func (sd *SimpleDetector) OnConsecutiveFailure(host *Host)
- func (sd *SimpleDetector) ProcessSuccessRateEjections()
- func (sd *SimpleDetector) Start()
- func (sd *SimpleDetector) SuccessRateAverage() float64
- func (sd *SimpleDetector) SuccessRateEjectionThreshold() float64
- type SimpleDetectorHostMonitor
- func (hm *SimpleDetectorHostMonitor) Eject(t time.Time)
- func (hm *SimpleDetectorHostMonitor) LastEjectionTime() time.Time
- func (hm *SimpleDetectorHostMonitor) LastUnejectionTime() time.Time
- func (hm *SimpleDetectorHostMonitor) NumEjections() uint32
- func (hm *SimpleDetectorHostMonitor) PutResponseTime(time.Duration)
- func (hm *SimpleDetectorHostMonitor) PutResult(r Result)
- func (hm *SimpleDetectorHostMonitor) ResetConsecutiveConnectionError()
- func (hm *SimpleDetectorHostMonitor) ResetConsecutiveError()
- func (hm *SimpleDetectorHostMonitor) SetSuccessRate(newSuccessRate float64)
- func (hm *SimpleDetectorHostMonitor) SuccessRate() float64
- func (hm *SimpleDetectorHostMonitor) SuccessRateAccumulator() *successRateAccumulator
- func (hm *SimpleDetectorHostMonitor) Uneject(t time.Time)
- func (hm *SimpleDetectorHostMonitor) UpdateCurrentSuccessRateBucket()
- type SubsetBalancer
- type WeightRoundRobinBalancer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectSubsetCarrier ¶
func NewContextWithHash ¶
func NewContextWithHashCode ¶
Types ¶
type ActiveHalthFailureType ¶
type ActiveHalthFailureType uint32
const ( Unknown ActiveHalthFailureType = iota UnHealthy Timeout )
func (ActiveHalthFailureType) String ¶
func (t ActiveHalthFailureType) String() string
type ActiveHealthCheckSession ¶
type ActiveHealthCheckSession struct {
// contains filtered or unexported fields
}
func (*ActiveHealthCheckSession) Close ¶
func (ahcs *ActiveHealthCheckSession) Close()
func (*ActiveHealthCheckSession) SetUnhealthy ¶
func (ahcs *ActiveHealthCheckSession) SetUnhealthy(tp HealthCheckFailureType) HealthTransition
func (*ActiveHealthCheckSession) Start ¶
func (ahcs *ActiveHealthCheckSession) Start()
type AtomicBool ¶
type AtomicBool *bool
type BalanceType ¶
type BalanceType int32
const ( RoundRobin BalanceType = iota LeastRequest Random RingHash WeightRoundRobin SubsetBalanceType )
func UnmarshalBalanceFromText ¶
func UnmarshalBalanceFromText(t string) BalanceType
func (BalanceType) String ¶
func (t BalanceType) String() string
type ChangeStateCallback ¶
type ChangeStateCallback func(*Host)
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
func (*Cluster) AddHostChangedCallback ¶
func (*Cluster) GetHostByAddress ¶
type ClusterManager ¶
type ClusterManager struct {
// contains filtered or unexported fields
}
func NewClusterManager ¶
func NewClusterManager() *ClusterManager
func (*ClusterManager) ChooseAllHosts ¶
func (cm *ClusterManager) ChooseAllHosts(ctx context.Context, service string) []*Host
func (*ClusterManager) ChooseHost ¶
func (cm *ClusterManager) ChooseHost(ctx context.Context, service string) *Host
func (*ClusterManager) Cluster ¶
func (cm *ClusterManager) Cluster(name string) *Cluster
func (*ClusterManager) InitService ¶
func (cm *ClusterManager) InitService(conf config.Cluster) error
func (*ClusterManager) PutResult ¶
func (cm *ClusterManager) PutResult(service, address string, code int)
type Detector ¶
type Detector interface { AddChangedStateCallback(ChangeStateCallback) SuccessRateAverage() float64 SuccessRateEjectionThreshold() float64 }
type DetectorHostMonitor ¶
type Hashable ¶
type Hashable interface {
HashCode() int32
}
Hashable is a interface for hashable object.
type HealthCheckCompleteCallback ¶
type HealthCheckCompleteCallback func(*Host, HealthTransition)
type HealthCheckFailureType ¶
type HealthCheckFailureType int
const ( ACTIVE HealthCheckFailureType = iota PASSIVE NETWORK )
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
func NewHealthChecker ¶
func NewHealthChecker(tp HealthCheckerType, interval time.Duration, unHealthyThreshold, healthyThreshold uint32, name string) *HealthChecker
func (*HealthChecker) AddHostCheckCompleteCb ¶
func (hc *HealthChecker) AddHostCheckCompleteCb(cb HealthCheckCompleteCallback)
func (*HealthChecker) AddHosts ¶
func (hc *HealthChecker) AddHosts(added []*Host)
func (*HealthChecker) OnHostsChanged ¶
func (hc *HealthChecker) OnHostsChanged(added []*Host, removed []*Host)
type HealthFlag ¶
type HealthFlag uint32
const ( FailedActiveHC HealthFlag = 0x01 FailedDetectorCheck HealthFlag = 0x02 FailedRegistryHealth HealthFlag = 0x04 )
type HealthTransition ¶
type HealthTransition int
const ( Unchanged HealthTransition = iota Changed ChangePending )
func (HealthTransition) String ¶
func (t HealthTransition) String() string
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
func (*Host) GetActiveHealthFailureType ¶
func (h *Host) GetActiveHealthFailureType() (tp ActiveHalthFailureType)
func (*Host) GetDetectorMonitor ¶
func (h *Host) GetDetectorMonitor() DetectorHostMonitor
func (*Host) HealthFlagClear ¶
func (h *Host) HealthFlagClear(flag HealthFlag)
func (*Host) HealthFlagGet ¶
func (h *Host) HealthFlagGet(flag HealthFlag) (res bool)
func (*Host) HealthFlagSet ¶
func (h *Host) HealthFlagSet(flag HealthFlag)
func (*Host) SetActiveHealthFailureType ¶
func (h *Host) SetActiveHealthFailureType(tp ActiveHalthFailureType)
func (*Host) SetDetectorMonitor ¶
func (h *Host) SetDetectorMonitor(d DetectorHostMonitor)
type HostSet ¶
type HostSet struct {
// contains filtered or unexported fields
}
func NewHostSet ¶
func (*HostSet) AddUpdateCallback ¶
func (h *HostSet) AddUpdateCallback(m memberUpdateCallback)
func (*HostSet) HelathHosts ¶
func (*HostSet) UpdateHosts ¶
type RandomBalancer ¶
type RandomBalancer struct {
// contains filtered or unexported fields
}
func NewRandomBalancer ¶
func NewRandomBalancer(set *HostSet, threshhold int) *RandomBalancer
func (*RandomBalancer) ChooseHost ¶
func (rr *RandomBalancer) ChooseHost(ctx context.Context) *Host
type RingHashBalancer ¶
type RingHashBalancer struct {
// contains filtered or unexported fields
}
func NewRingHashBalancer ¶
func NewRingHashBalancer(set *HostSet, threshhold int) *RingHashBalancer
* * Maglev 一致hash算法 * https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/44824.pdf *
func (*RingHashBalancer) ChooseHost ¶
func (rh *RingHashBalancer) ChooseHost(ctx context.Context) *Host
type RoundRobinBalancer ¶
type RoundRobinBalancer struct {
// contains filtered or unexported fields
}
func NewRoundRobinBalancer ¶
func NewRoundRobinBalancer(set *HostSet, threshhold int) *RoundRobinBalancer
func (*RoundRobinBalancer) ChooseHost ¶
func (rr *RoundRobinBalancer) ChooseHost(ctx context.Context) *Host
type SimpleDetector ¶
type SimpleDetector struct {
// contains filtered or unexported fields
}
func NewSimpleDector ¶
func NewSimpleDector(c *Cluster, conf config.Detector) *SimpleDetector
func (*SimpleDetector) AddChangedStateCallback ¶
func (sd *SimpleDetector) AddChangedStateCallback(cb ChangeStateCallback)
func (*SimpleDetector) CheckHostForUneject ¶
func (sd *SimpleDetector) CheckHostForUneject(h *Host, m *SimpleDetectorHostMonitor, now time.Time)
func (*SimpleDetector) EjectHost ¶
func (sd *SimpleDetector) EjectHost(h *Host, t ejectType)
func (*SimpleDetector) OnConsecutiveConnectionFailure ¶
func (sd *SimpleDetector) OnConsecutiveConnectionFailure(host *Host)
func (*SimpleDetector) OnConsecutiveFailure ¶
func (sd *SimpleDetector) OnConsecutiveFailure(host *Host)
func (*SimpleDetector) ProcessSuccessRateEjections ¶
func (sd *SimpleDetector) ProcessSuccessRateEjections()
func (*SimpleDetector) Start ¶
func (sd *SimpleDetector) Start()
func (*SimpleDetector) SuccessRateAverage ¶
func (sd *SimpleDetector) SuccessRateAverage() float64
func (*SimpleDetector) SuccessRateEjectionThreshold ¶
func (sd *SimpleDetector) SuccessRateEjectionThreshold() float64
type SimpleDetectorHostMonitor ¶
type SimpleDetectorHostMonitor struct {
// contains filtered or unexported fields
}
func NewSimpleDetectoHostMonitor ¶
func NewSimpleDetectoHostMonitor(detector *SimpleDetector, host *Host) *SimpleDetectorHostMonitor
func (*SimpleDetectorHostMonitor) Eject ¶
func (hm *SimpleDetectorHostMonitor) Eject(t time.Time)
func (*SimpleDetectorHostMonitor) LastEjectionTime ¶
func (hm *SimpleDetectorHostMonitor) LastEjectionTime() time.Time
func (*SimpleDetectorHostMonitor) LastUnejectionTime ¶
func (hm *SimpleDetectorHostMonitor) LastUnejectionTime() time.Time
func (*SimpleDetectorHostMonitor) NumEjections ¶
func (hm *SimpleDetectorHostMonitor) NumEjections() uint32
func (*SimpleDetectorHostMonitor) PutResponseTime ¶
func (hm *SimpleDetectorHostMonitor) PutResponseTime(time.Duration)
func (*SimpleDetectorHostMonitor) PutResult ¶
func (hm *SimpleDetectorHostMonitor) PutResult(r Result)
func (*SimpleDetectorHostMonitor) ResetConsecutiveConnectionError ¶
func (hm *SimpleDetectorHostMonitor) ResetConsecutiveConnectionError()
func (*SimpleDetectorHostMonitor) ResetConsecutiveError ¶
func (hm *SimpleDetectorHostMonitor) ResetConsecutiveError()
func (*SimpleDetectorHostMonitor) SetSuccessRate ¶
func (hm *SimpleDetectorHostMonitor) SetSuccessRate(newSuccessRate float64)
func (*SimpleDetectorHostMonitor) SuccessRate ¶
func (hm *SimpleDetectorHostMonitor) SuccessRate() float64
func (*SimpleDetectorHostMonitor) SuccessRateAccumulator ¶
func (hm *SimpleDetectorHostMonitor) SuccessRateAccumulator() *successRateAccumulator
func (*SimpleDetectorHostMonitor) Uneject ¶
func (hm *SimpleDetectorHostMonitor) Uneject(t time.Time)
func (*SimpleDetectorHostMonitor) UpdateCurrentSuccessRateBucket ¶
func (hm *SimpleDetectorHostMonitor) UpdateCurrentSuccessRateBucket()
type SubsetBalancer ¶
type SubsetBalancer struct { LBType BalanceType LBPanicThreshold int // contains filtered or unexported fields }
func NewSubsetBalancer ¶
func NewSubsetBalancer(hostSet *HostSet, lbType BalanceType, threshhold int, keys [][]string, defaultKVs []string, name string) *SubsetBalancer
func (*SubsetBalancer) ChooseHost ¶
func (ss *SubsetBalancer) ChooseHost(ctx context.Context) *Host
type WeightRoundRobinBalancer ¶
type WeightRoundRobinBalancer struct {
// contains filtered or unexported fields
}
func NewWeightRoundRobinBalancer ¶
func NewWeightRoundRobinBalancer(set *HostSet, threshhold int) *WeightRoundRobinBalancer
func (*WeightRoundRobinBalancer) ChooseHost ¶
func (wrr *WeightRoundRobinBalancer) ChooseHost(ctx context.Context) *Host
Click to show internal directories.
Click to hide internal directories.