diff --git a/cluster/cluster_impl/forking_cluster_invoker.go b/cluster/cluster_impl/forking_cluster_invoker.go index 168444881653ca38ef61a9bc8e50f2d4bc3e624c..be3203070d37de296d116a1e6f6831fd7d58365b 100644 --- a/cluster/cluster_impl/forking_cluster_invoker.go +++ b/cluster/cluster_impl/forking_cluster_invoker.go @@ -56,7 +56,7 @@ func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation pro } var selected []protocol.Invoker - forks := int(invoker.GetUrl().GetParamInt(constant.FORKS_KEY, constant.DEFAULT_FORKS)) + forks := invoker.GetUrl().GetParamByInt0(constant.FORKS_KEY, constant.DEFAULT_FORKS) timeouts := invoker.GetUrl().GetParamInt(constant.TIMEOUT_KEY, constant.DEFAULT_TIMEOUT) if forks < 0 || forks > len(invokers) { selected = invokers diff --git a/cluster/loadbalance/consistent_hash.go b/cluster/loadbalance/consistent_hash.go index 27ce2369f9de6dfe76bd35581ea26f0e0c24e480..3cb14d6287e9b7731b147cf5844fc60ec4459ee5 100644 --- a/cluster/loadbalance/consistent_hash.go +++ b/cluster/loadbalance/consistent_hash.go @@ -105,7 +105,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string, selector.virtualInvokers = make(map[uint32]protocol.Invoker) selector.hashCode = hashCode url := invokers[0].GetUrl() - selector.replicaNum = int(url.GetMethodParamInt(methodName, HashNodes, 160)) + selector.replicaNum = url.GetMethodParamInt0(methodName, HashNodes, 160) indices := re.Split(url.GetMethodParam(methodName, HashArguments, "0"), -1) for _, index := range indices { i, err := strconv.Atoi(index) diff --git a/cluster/router/healthcheck/default_health_check.go b/cluster/router/healthcheck/default_health_check.go index 9757f22768fa0d5ea19ae37ce74555e794653cbe..3effd779c989ed8e68c91eb6eab20d10d8b04e8c 100644 --- a/cluster/router/healthcheck/default_health_check.go +++ b/cluster/router/healthcheck/default_health_check.go @@ -115,8 +115,8 @@ func (c *DefaultHealthChecker) GetOutStandingRequestCountLimit() int32 { // NewDefaultHealthChecker constructs a new DefaultHealthChecker based on the url func NewDefaultHealthChecker(url *common.URL) router.HealthChecker { return &DefaultHealthChecker{ - outStandingRequestConutLimit: int32(url.GetParamInt(constant.OUTSTANDING_REQUEST_COUNT_LIMIT_KEY, math.MaxInt32)), - requestSuccessiveFailureThreshold: int32(url.GetParamInt(constant.SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY, constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF)), - circuitTrippedTimeoutFactor: int32(url.GetParamInt(constant.CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY, constant.DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR)), + outStandingRequestConutLimit: url.GetParamInt32(constant.OUTSTANDING_REQUEST_COUNT_LIMIT_KEY, math.MaxInt32), + requestSuccessiveFailureThreshold: url.GetParamInt32(constant.SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY, constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF), + circuitTrippedTimeoutFactor: url.GetParamInt32(constant.CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY, constant.DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR), } } diff --git a/common/url.go b/common/url.go index 8297afdaad235cbd9a70b057e0f43db6c48dbf82..665aeb5ee3fdb1d07f26ff9fa86bdd518f47c539 100644 --- a/common/url.go +++ b/common/url.go @@ -484,22 +484,49 @@ func (c URL) GetParamBool(key string, d bool) bool { return r } -// GetParamInt gets int value by @key +// GetParamInt gets int64 value by @key func (c URL) GetParamInt(key string, d int64) int64 { - r, err := strconv.Atoi(c.GetParam(key, "")) + r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 64) if r == 0 || err != nil { return d } - return int64(r) + return r +} + +// GetParamInt32 gets int32 value by @key +func (c URL) GetParamInt32(key string, d int32) int32 { + r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 32) + if r == 0 || err != nil { + return d + } + return int32(r) +} + +// GetParamByInt0 gets int value by @key +func (c URL) GetParamByInt0(key string, d int) int { + r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 0) + if r == 0 || err != nil { + return d + } + return int(r) } // GetMethodParamInt gets int method param func (c URL) GetMethodParamInt(method string, key string, d int64) int64 { - r, err := strconv.Atoi(c.GetParam("methods."+method+"."+key, "")) + r, err := strconv.ParseInt(c.GetParam("methods."+method+"."+key, ""), 10, 64) + if r == 0 || err != nil { + return d + } + return r +} + +// GetMethodParamInt0 gets int method param +func (c URL) GetMethodParamInt0(method string, key string, d int) int { + r, err := strconv.ParseInt(c.GetParam("methods."+method+"."+key, ""), 10, 0) if r == 0 || err != nil { return d } - return int64(r) + return int(r) } // GetMethodParamInt64 gets int64 method param