This is an automated email from the ASF dual-hosted git repository.
laurence pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/1.5 by this push:
new d2ddb7a fix (#1376)
d2ddb7a is described below
commit d2ddb7a8b06cb32971d6f282d28f8056232abb65
Author: Laurence <[email protected]>
AuthorDate: Fri Aug 13 14:07:02 2021 +0800
fix (#1376)
---
cluster/loadbalance/consistent_hash.go | 23 +++++++++++-----------
cluster/loadbalance/consistent_hash_test.go | 8 ++++----
go.mod | 1 -
go.sum | 5 +++--
.../event/protocol_ports_metadata_customizer.go | 4 ++--
remoting/etcdv3/client.go | 1 +
6 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/cluster/loadbalance/consistent_hash.go
b/cluster/loadbalance/consistent_hash.go
index 47d4add..fcda4ae 100644
--- a/cluster/loadbalance/consistent_hash.go
+++ b/cluster/loadbalance/consistent_hash.go
@@ -47,7 +47,7 @@ const (
)
var (
- selectors = make(map[string]*ConsistentHashSelector)
+ selectors = make(map[string]*consistentHashSelector)
re = regexp.MustCompile(constant.COMMA_SPLIT_PATTERN)
)
@@ -89,8 +89,8 @@ func (lb *ConsistentHashLoadBalance) Select(invokers
[]protocol.Invoker, invocat
return selector.Select(invocation)
}
-// ConsistentHashSelector implementation of Selector:get invoker based on load
balancing strategy
-type ConsistentHashSelector struct {
+// consistentHashSelector implementation of Selector:get invoker based on load
balancing strategy
+type consistentHashSelector struct {
hashCode uint32
replicaNum int
virtualInvokers map[uint32]protocol.Invoker
@@ -99,9 +99,9 @@ type ConsistentHashSelector struct {
}
func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
- hashCode uint32) *ConsistentHashSelector {
+ hashCode uint32) *consistentHashSelector {
- selector := &ConsistentHashSelector{}
+ selector := &consistentHashSelector{}
selector.virtualInvokers = make(map[uint32]protocol.Invoker)
selector.hashCode = hashCode
url := invokers[0].GetURL()
@@ -131,13 +131,13 @@ func newConsistentHashSelector(invokers
[]protocol.Invoker, methodName string,
}
// Select gets invoker based on load balancing strategy
-func (c *ConsistentHashSelector) Select(invocation protocol.Invocation)
protocol.Invoker {
+func (c *consistentHashSelector) Select(invocation protocol.Invocation)
protocol.Invoker {
key := c.toKey(invocation.Arguments())
digest := md5.Sum([]byte(key))
return c.selectForKey(c.hash(digest, 0))
}
-func (c *ConsistentHashSelector) toKey(args []interface{}) string {
+func (c *consistentHashSelector) toKey(args []interface{}) string {
var sb strings.Builder
for i := range c.argumentIndex {
if i >= 0 && i < len(args) {
@@ -147,7 +147,7 @@ func (c *ConsistentHashSelector) toKey(args []interface{})
string {
return sb.String()
}
-func (c *ConsistentHashSelector) selectForKey(hash uint32) protocol.Invoker {
+func (c *consistentHashSelector) selectForKey(hash uint32) protocol.Invoker {
idx := sort.Search(len(c.keys), func(i int) bool {
return c.keys[i] >= hash
})
@@ -157,8 +157,7 @@ func (c *ConsistentHashSelector) selectForKey(hash uint32)
protocol.Invoker {
return c.virtualInvokers[c.keys[idx]]
}
-// nolint
-func (c *ConsistentHashSelector) hash(digest [16]byte, i int) uint32 {
- return uint32((digest[3+i*4]&0xFF)<<24) |
uint32((digest[2+i*4]&0xFF)<<16) |
- uint32((digest[1+i*4]&0xFF)<<8) |
uint32(digest[i*4]&0xFF)&0xFFFFFFF
+func (c *consistentHashSelector) hash(digest [16]byte, i int) uint32 {
+ return (uint32(digest[3+i*4]&0xFF) << 24) | (uint32(digest[2+i*4]&0xFF)
<< 16) |
+ (uint32(digest[1+i*4]&0xFF) << 8) |
uint32(digest[i*4]&0xFF)&0xFFFFFFF
}
diff --git a/cluster/loadbalance/consistent_hash_test.go
b/cluster/loadbalance/consistent_hash_test.go
index b6ff69e..8106a50 100644
--- a/cluster/loadbalance/consistent_hash_test.go
+++ b/cluster/loadbalance/consistent_hash_test.go
@@ -36,7 +36,7 @@ import (
const (
ip = "192.168.1.0"
port8080 = 8080
- port8082 = 8082
+ port8081 = 8081
url8080Short = "dubbo://192.168.1.0:8080"
url8081Short = "dubbo://192.168.1.0:8081"
@@ -52,7 +52,7 @@ func TestConsistentHashSelectorSuite(t *testing.T) {
type consistentHashSelectorSuite struct {
suite.Suite
- selector *ConsistentHashSelector
+ selector *consistentHashSelector
}
func (s *consistentHashSelectorSuite) SetupTest() {
@@ -114,9 +114,9 @@ func (s *consistentHashLoadBalanceSuite) SetupTest() {
func (s *consistentHashLoadBalanceSuite) TestSelect() {
args := []interface{}{"name", "password", "age"}
invoker := s.lb.Select(s.invokers, invocation.NewRPCInvocation("echo",
args, nil))
- s.Equal(invoker.GetURL().Location, fmt.Sprintf("%s:%d", ip, port8080))
+ s.Equal(fmt.Sprintf("%s:%d", ip, port8081), invoker.GetURL().Location)
args = []interface{}{"ok", "abc"}
invoker = s.lb.Select(s.invokers, invocation.NewRPCInvocation("echo",
args, nil))
- s.Equal(invoker.GetURL().Location, fmt.Sprintf("%s:%d", ip, port8082))
+ s.Equal(fmt.Sprintf("%s:%d", ip, port8080), invoker.GetURL().Location)
}
diff --git a/go.mod b/go.mod
index a95f0aa..3ca198b 100644
--- a/go.mod
+++ b/go.mod
@@ -46,6 +46,5 @@ require (
replace (
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4
github.com/envoyproxy/go-control-plane =>
github.com/envoyproxy/go-control-plane v0.8.0
- github.com/shirou/gopsutil => github.com/shirou/gopsutil
v0.0.0-20181107111621-48177ef5f880
google.golang.org/grpc => google.golang.org/grpc v1.26.0
)
diff --git a/go.sum b/go.sum
index e55ad32..a2aee3e 100644
--- a/go.sum
+++ b/go.sum
@@ -706,9 +706,10 @@ github.com/sean-/conswriter
v0.0.0-20180208195008-f5ae3917a627/go.mod h1:7zjs06q
github.com/sean-/pager v0.0.0-20180208200047-666be9bf53b5/go.mod
h1:BeybITEsBEg6qbIiqJ6/Bqeq25bCLbL7YFmpaFfJDuM=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529
h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod
h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
-github.com/shirou/gopsutil v0.0.0-20181107111621-48177ef5f880
h1:1Ge4j/3uB2rxzPWD3TC+daeCw+w91z8UCUL/7WH5gn8=
github.com/shirou/gopsutil v0.0.0-20181107111621-48177ef5f880/go.mod
h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
-github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4
h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
+github.com/shirou/gopsutil
v3.20.11-0.20201116082039-2fb5da2f2449+incompatible/go.mod
h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
+github.com/shirou/gopsutil v3.20.11+incompatible
h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto=
+github.com/shirou/gopsutil v3.20.11+incompatible/go.mod
h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod
h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod
h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod
h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
diff --git a/registry/event/protocol_ports_metadata_customizer.go
b/registry/event/protocol_ports_metadata_customizer.go
index a58471c..7dec1fd 100644
--- a/registry/event/protocol_ports_metadata_customizer.go
+++ b/registry/event/protocol_ports_metadata_customizer.go
@@ -101,6 +101,6 @@ func endpointsStr(protocolMap map[string]int) string {
// nolint
type endpoint struct {
- Port int `json:"port, omitempty"`
- Protocol string `json:"protocol, omitempty"`
+ Port int `json:"port,omitempty"`
+ Protocol string `json:"protocol,omitempty"`
}
diff --git a/remoting/etcdv3/client.go b/remoting/etcdv3/client.go
index 34ee31b..3027d02 100644
--- a/remoting/etcdv3/client.go
+++ b/remoting/etcdv3/client.go
@@ -174,6 +174,7 @@ func NewClient(name string, endpoints []string, timeout
time.Duration, heartbeat
DialOptions: []grpc.DialOption{grpc.WithBlock()},
})
if err != nil {
+ cancel()
return nil, perrors.WithMessage(err, "new raw client block
connect to server")
}