Review feedback
This commit is contained in:
parent
a5a4a5108d
commit
bd7bd24e66
@ -691,10 +691,10 @@ func sortBatchRPCResponse(req []*RPCReq, res []*RPCRes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BackendGroup struct {
|
type BackendGroup struct {
|
||||||
Name string
|
Name string
|
||||||
Backends []*Backend
|
Backends []*Backend
|
||||||
UseWeightedRouting bool
|
WeightedRouting bool
|
||||||
Consensus *ConsensusPoller
|
Consensus *ConsensusPoller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bg *BackendGroup) Forward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool) ([]*RPCRes, string, error) {
|
func (bg *BackendGroup) Forward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool) ([]*RPCRes, string, error) {
|
||||||
@ -750,7 +750,7 @@ func (bg *BackendGroup) Forward(ctx context.Context, rpcReqs []*RPCReq, isBatch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rpcReqs = rewrittenReqs
|
rpcReqs = rewrittenReqs
|
||||||
} else if bg.UseWeightedRouting {
|
} else if bg.WeightedRouting {
|
||||||
backends = randomizeFirstBackendByWeight(backends)
|
backends = randomizeFirstBackendByWeight(backends)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +820,7 @@ func (bg *BackendGroup) Forward(ctx context.Context, rpcReqs []*RPCReq, isBatch
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randomizeFirstBackendByWeight(backends []*Backend) []*Backend {
|
func randomizeFirstBackendByWeight(backends []*Backend) []*Backend {
|
||||||
if len(backends) == 0 {
|
if len(backends) <= 1 {
|
||||||
return backends
|
return backends
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -916,7 +916,7 @@ func (bg *BackendGroup) loadBalancedConsensusGroup() []*Backend {
|
|||||||
backendsDegraded[i], backendsDegraded[j] = backendsDegraded[j], backendsDegraded[i]
|
backendsDegraded[i], backendsDegraded[j] = backendsDegraded[j], backendsDegraded[i]
|
||||||
})
|
})
|
||||||
|
|
||||||
if bg.UseWeightedRouting {
|
if bg.WeightedRouting {
|
||||||
backendsHealthy = randomizeFirstBackendByWeight(backendsHealthy)
|
backendsHealthy = randomizeFirstBackendByWeight(backendsHealthy)
|
||||||
backendsDegraded = randomizeFirstBackendByWeight(backendsDegraded)
|
backendsDegraded = randomizeFirstBackendByWeight(backendsDegraded)
|
||||||
}
|
}
|
||||||
|
@ -95,11 +95,11 @@ type BackendConfig struct {
|
|||||||
ClientKeyFile string `toml:"client_key_file"`
|
ClientKeyFile string `toml:"client_key_file"`
|
||||||
StripTrailingXFF bool `toml:"strip_trailing_xff"`
|
StripTrailingXFF bool `toml:"strip_trailing_xff"`
|
||||||
|
|
||||||
|
Weight int `toml:"weight"`
|
||||||
|
|
||||||
ConsensusSkipPeerCountCheck bool `toml:"consensus_skip_peer_count"`
|
ConsensusSkipPeerCountCheck bool `toml:"consensus_skip_peer_count"`
|
||||||
ConsensusForcedCandidate bool `toml:"consensus_forced_candidate"`
|
ConsensusForcedCandidate bool `toml:"consensus_forced_candidate"`
|
||||||
ConsensusReceiptsTarget string `toml:"consensus_receipts_target"`
|
ConsensusReceiptsTarget string `toml:"consensus_receipts_target"`
|
||||||
|
|
||||||
Weight int `toml:"weight"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type BackendsConfig map[string]*BackendConfig
|
type BackendsConfig map[string]*BackendConfig
|
||||||
@ -107,7 +107,7 @@ type BackendsConfig map[string]*BackendConfig
|
|||||||
type BackendGroupConfig struct {
|
type BackendGroupConfig struct {
|
||||||
Backends []string `toml:"backends"`
|
Backends []string `toml:"backends"`
|
||||||
|
|
||||||
UseWeightedRouting bool `toml:"weighted_routing"`
|
WeightedRouting bool `toml:"weighted_routing"`
|
||||||
|
|
||||||
ConsensusAware bool `toml:"consensus_aware"`
|
ConsensusAware bool `toml:"consensus_aware"`
|
||||||
ConsensusAsyncHandler string `toml:"consensus_handler"`
|
ConsensusAsyncHandler string `toml:"consensus_handler"`
|
||||||
|
@ -176,9 +176,9 @@ func Start(config *Config) (*Server, func(), error) {
|
|||||||
backends = append(backends, backendsByName[bName])
|
backends = append(backends, backendsByName[bName])
|
||||||
}
|
}
|
||||||
group := &BackendGroup{
|
group := &BackendGroup{
|
||||||
Name: bgName,
|
Name: bgName,
|
||||||
UseWeightedRouting: bg.UseWeightedRouting,
|
WeightedRouting: bg.WeightedRouting,
|
||||||
Backends: backends,
|
Backends: backends,
|
||||||
}
|
}
|
||||||
backendGroups[bgName] = group
|
backendGroups[bgName] = group
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user