Skip to content
Snippets Groups Projects
Unverified Commit 359bdab8 authored by Xin.Zh's avatar Xin.Zh Committed by GitHub
Browse files

Merge pull request #195 from hxmhlt/fix_failoverbug_and_reties_0

Fix:failoverbug and retries change to string type
parents bb1216a7 ead43d6a
No related branches found
No related tags found
No related merge requests found
Showing
with 73 additions and 51 deletions
......@@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
*.jar
# Test binary, build with `go test -c`
*.test
......@@ -24,3 +25,8 @@ coverage.txt
logs/
.vscode/
coverage.txt
# unit test
remoting/zookeeper/zookeeper-4unittest/
config_center/zookeeper/zookeeper-4unittest/
registry/zookeeper/zookeeper-4unittest/
\ No newline at end of file
......@@ -18,6 +18,7 @@
package cluster_impl
import (
"strconv"
"sync"
"time"
)
......@@ -54,15 +55,18 @@ func newFailbackClusterInvoker(directory cluster.Directory) protocol.Invoker {
invoker := &failbackClusterInvoker{
baseClusterInvoker: newBaseClusterInvoker(directory),
}
retriesConfig := invoker.GetUrl().GetParamInt(constant.RETRIES_KEY, constant.DEFAULT_FAILBACK_TIMES)
if retriesConfig <= 0 {
retriesConfig = constant.DEFAULT_FAILBACK_TIMES
retriesConfig := invoker.GetUrl().GetParam(constant.RETRIES_KEY, constant.DEFAULT_FAILBACK_TIMES)
retries, err := strconv.Atoi(retriesConfig)
if err != nil || retries < 0 {
logger.Error("Your retries config is invalid,pls do a check. And will use the default fail back times configuration instead.")
retries = constant.DEFAULT_FAILBACK_TIMES_INT
}
failbackTasksConfig := invoker.GetUrl().GetParamInt(constant.FAIL_BACK_TASKS_KEY, constant.DEFAULT_FAILBACK_TASKS)
if failbackTasksConfig <= 0 {
failbackTasksConfig = constant.DEFAULT_FAILBACK_TASKS
}
invoker.maxRetries = retriesConfig
invoker.maxRetries = int64(retries)
invoker.failbackTasks = failbackTasksConfig
return invoker
}
......
......@@ -17,6 +17,10 @@
package cluster_impl
import (
"strconv"
)
import (
perrors "github.com/pkg/errors"
)
......@@ -24,6 +28,7 @@ import (
import (
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/protocol"
)
......@@ -53,16 +58,21 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr
url := invokers[0].GetUrl()
//get reties
retries := url.GetParamInt(constant.RETRIES_KEY, constant.DEFAULT_RETRIES)
retriesConfig := url.GetParam(constant.RETRIES_KEY, constant.DEFAULT_RETRIES)
//Get the service method loadbalance config if have
if v := url.GetMethodParamInt(methodName, constant.RETRIES_KEY, 0); v != 0 {
retries = v
if v := url.GetMethodParam(methodName, constant.RETRIES_KEY, ""); len(v) != 0 {
retriesConfig = v
}
retries, err := strconv.Atoi(retriesConfig)
if err != nil || retries < 0 {
logger.Error("Your retries config is invalid,pls do a check. And will use the default retries configuration instead.")
retries = constant.DEFAULT_RETRIES_INT
}
invoked := []protocol.Invoker{}
providers := []string{}
var result protocol.Result
for i := int64(0); i < retries; i++ {
for i := 0; i <= retries; i++ {
//Reselect before retry to avoid a change of candidate `invokers`.
//NOTE: if `invokers` changed, then `invoked` also lose accuracy.
if i > 0 {
......
......@@ -118,14 +118,14 @@ func normalInvoke(t *testing.T, successCount int, urlParam url.Values, invocatio
}
func Test_FailoverInvokeSuccess(t *testing.T) {
urlParams := url.Values{}
result := normalInvoke(t, 2, urlParams)
result := normalInvoke(t, 3, urlParams)
assert.NoError(t, result.Error())
count = 0
}
func Test_FailoverInvokeFail(t *testing.T) {
urlParams := url.Values{}
result := normalInvoke(t, 3, urlParams)
result := normalInvoke(t, 4, urlParams)
assert.Errorf(t, result.Error(), "error")
count = 0
}
......@@ -133,7 +133,7 @@ func Test_FailoverInvokeFail(t *testing.T) {
func Test_FailoverInvoke1(t *testing.T) {
urlParams := url.Values{}
urlParams.Set(constant.RETRIES_KEY, "3")
result := normalInvoke(t, 3, urlParams)
result := normalInvoke(t, 4, urlParams)
assert.NoError(t, result.Error())
count = 0
}
......@@ -144,7 +144,7 @@ func Test_FailoverInvoke2(t *testing.T) {
urlParams.Set("methods.test."+constant.RETRIES_KEY, "3")
ivc := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("test"))
result := normalInvoke(t, 3, urlParams, ivc)
result := normalInvoke(t, 4, urlParams, ivc)
assert.NoError(t, result.Error())
count = 0
}
......
......@@ -26,13 +26,15 @@ const (
)
const (
DEFAULT_LOADBALANCE = "random"
DEFAULT_RETRIES = 2
DEFAULT_PROTOCOL = "dubbo"
DEFAULT_REG_TIMEOUT = "10s"
DEFAULT_CLUSTER = "failover"
DEFAULT_FAILBACK_TIMES = 3
DEFAULT_FAILBACK_TASKS = 100
DEFAULT_LOADBALANCE = "random"
DEFAULT_RETRIES = "2"
DEFAULT_RETRIES_INT = 2
DEFAULT_PROTOCOL = "dubbo"
DEFAULT_REG_TIMEOUT = "10s"
DEFAULT_CLUSTER = "failover"
DEFAULT_FAILBACK_TIMES = "3"
DEFAULT_FAILBACK_TIMES_INT = 3
DEFAULT_FAILBACK_TASKS = 100
)
const (
......
......@@ -92,7 +92,7 @@ func Test_refresh(t *testing.T) {
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: 3,
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
......@@ -100,14 +100,14 @@ func Test_refresh(t *testing.T) {
InterfaceId: "MockService",
InterfaceName: "com.MockService",
Name: "GetUser",
Retries: 2,
Retries: "2",
Loadbalance: "random",
},
{
InterfaceId: "MockService",
InterfaceName: "com.MockService",
Name: "GetUser1",
Retries: 2,
Retries: "2",
Loadbalance: "random",
},
},
......@@ -118,9 +118,9 @@ func Test_refresh(t *testing.T) {
c.SetFatherConfig(father)
c.fresh()
assert.Equal(t, "mock100", father.Registries["shanghai_reg1"].Protocol)
assert.Equal(t, int64(10), father.References["MockService"].Retries)
assert.Equal(t, "10", father.References["MockService"].Retries)
assert.Equal(t, int64(10), father.References["MockService"].Methods[0].Retries)
assert.Equal(t, "10", father.References["MockService"].Methods[0].Retries)
assert.Equal(t, &[]bool{false}[0], father.Check)
assert.Equal(t, "dubbo", father.ApplicationConfig.Name)
}
......@@ -188,7 +188,7 @@ func Test_refreshProvider(t *testing.T) {
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: 3,
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
......@@ -196,13 +196,13 @@ func Test_refreshProvider(t *testing.T) {
InterfaceId: "MockService",
InterfaceName: "com.MockService",
Name: "GetUser",
Retries: 2,
Retries: "2",
Loadbalance: "random",
},
{InterfaceId: "MockService",
InterfaceName: "com.MockService",
Name: "GetUser1",
Retries: 2,
Retries: "2",
Loadbalance: "random",
},
},
......@@ -213,9 +213,9 @@ func Test_refreshProvider(t *testing.T) {
c.SetFatherConfig(father)
c.fresh()
assert.Equal(t, "mock100", father.Registries["shanghai_reg1"].Protocol)
assert.Equal(t, int64(10), father.Services["MockService"].Retries)
assert.Equal(t, "10", father.Services["MockService"].Retries)
assert.Equal(t, int64(10), father.Services["MockService"].Methods[0].Retries)
assert.Equal(t, "10", father.Services["MockService"].Methods[0].Retries)
assert.Equal(t, "dubbo", father.ApplicationConfig.Name)
assert.Equal(t, "20001", father.Protocols["jsonrpc1"].Port)
}
......
......@@ -24,7 +24,7 @@ type MethodConfig struct {
InterfaceId string
InterfaceName string
Name string `yaml:"name" json:"name,omitempty" property:"name"`
Retries int64 `yaml:"retries" json:"retries,omitempty" property:"retries"`
Retries string `yaml:"retries" json:"retries,omitempty" property:"retries"`
Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"`
Weight int64 `yaml:"weight" json:"weight,omitempty" property:"weight"`
}
......
......@@ -47,7 +47,7 @@ type ReferenceConfig struct {
Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"`
Cluster string `yaml:"cluster" json:"cluster,omitempty" property:"cluster"`
Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"`
Retries int64 `yaml:"retries" json:"retries,omitempty" property:"retries"`
Retries string `yaml:"retries" json:"retries,omitempty" property:"retries"`
Group string `yaml:"group" json:"group,omitempty" property:"group"`
Version string `yaml:"version" json:"version,omitempty" property:"version"`
Methods []*MethodConfig `yaml:"methods" json:"methods,omitempty" property:"methods"`
......@@ -154,7 +154,7 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values {
urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10))
urlMap.Set(constant.CLUSTER_KEY, refconfig.Cluster)
urlMap.Set(constant.LOADBALANCE_KEY, refconfig.Loadbalance)
urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(refconfig.Retries, 10))
urlMap.Set(constant.RETRIES_KEY, refconfig.Retries)
urlMap.Set(constant.GROUP_KEY, refconfig.Group)
urlMap.Set(constant.VERSION_KEY, refconfig.Version)
urlMap.Set(constant.GENERIC_KEY, strconv.FormatBool(refconfig.Generic))
......@@ -180,7 +180,7 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values {
for _, v := range refconfig.Methods {
urlMap.Set("methods."+v.Name+"."+constant.LOADBALANCE_KEY, v.Loadbalance)
urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.Retries, 10))
urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, v.Retries)
}
return urlMap
......
......@@ -90,18 +90,18 @@ func doInit() {
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: 3,
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
{
Name: "GetUser",
Retries: 2,
Retries: "2",
Loadbalance: "random",
},
{
Name: "GetUser1",
Retries: 2,
Retries: "2",
Loadbalance: "random",
},
},
......
......@@ -54,7 +54,7 @@ type ServiceConfig struct {
Version string `yaml:"version" json:"version,omitempty" property:"version" `
Methods []*MethodConfig `yaml:"methods" json:"methods,omitempty" property:"methods"`
Warmup string `yaml:"warmup" json:"warmup,omitempty" property:"warmup"`
Retries int64 `yaml:"retries" json:"retries,omitempty" property:"retries"`
Retries string `yaml:"retries" json:"retries,omitempty" property:"retries"`
Params map[string]string `yaml:"params" json:"params,omitempty" property:"params"`
unexported *atomic.Bool
exported *atomic.Bool
......@@ -160,7 +160,7 @@ func (srvconfig *ServiceConfig) getUrlMap() url.Values {
urlMap.Set(constant.CLUSTER_KEY, srvconfig.Cluster)
urlMap.Set(constant.LOADBALANCE_KEY, srvconfig.Loadbalance)
urlMap.Set(constant.WARMUP_KEY, srvconfig.Warmup)
urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(srvconfig.Retries, 10))
urlMap.Set(constant.RETRIES_KEY, srvconfig.Retries)
urlMap.Set(constant.GROUP_KEY, srvconfig.Group)
urlMap.Set(constant.VERSION_KEY, srvconfig.Version)
urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
......@@ -178,7 +178,7 @@ func (srvconfig *ServiceConfig) getUrlMap() url.Values {
for _, v := range srvconfig.Methods {
urlMap.Set("methods."+v.Name+"."+constant.LOADBALANCE_KEY, v.Loadbalance)
urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.Retries, 10))
urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, v.Retries)
urlMap.Set("methods."+v.Name+"."+constant.WEIGHT_KEY, strconv.FormatInt(v.Weight, 10))
}
......
......@@ -79,19 +79,19 @@ func doinit() {
Registry: "shanghai_reg1,shanghai_reg2,hangzhou_reg1,hangzhou_reg2",
Cluster: "failover",
Loadbalance: "random",
Retries: 3,
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
{
Name: "GetUser",
Retries: 2,
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
{
Name: "GetUser1",
Retries: 2,
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
......
......@@ -43,7 +43,7 @@ references:
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
retries: "3"
params:
"serviceid":
"soa.com.ikurento.user.UserProvider"
......
......@@ -13,7 +13,7 @@ references:
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
retries: "3"
protocol_conf:
dubbo:
......
......@@ -13,7 +13,7 @@ references:
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
retries: "3"
protocol_conf:
dubbo:
......
......@@ -13,7 +13,7 @@ references:
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
retries: "3"
protocol_conf:
dubbo:
......
......@@ -13,7 +13,7 @@ references:
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
retries: "3"
protocol_conf:
dubbo:
......
......@@ -17,7 +17,7 @@ services:
cluster: "failover"
methods:
- name: "GetUser"
retries: 1
retries: "1"
loadbalance: "random"
protocol_conf:
......
......@@ -17,7 +17,7 @@ services:
cluster: "failover"
methods:
- name: "GetUser"
retries: 1
retries: "1"
loadbalance: "random"
protocol_conf:
......
......@@ -17,7 +17,7 @@ services:
cluster: "failover"
methods:
- name: "GetUser"
retries: 1
retries: "1"
loadbalance: "random"
protocol_conf:
......
......@@ -21,7 +21,7 @@ references:
cluster: "failover"
methods :
- name: "SayHello"
retries: 3
retries: "3"
protocol_conf:
dubbo:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment