This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git
The following commit(s) were added to refs/heads/develop by this push:
new 484f4518 style:change hash calculate (#530)
484f4518 is described below
commit 484f4518384109699afe3e897a650ef1b6f4a858
Author: baerwang <[email protected]>
AuthorDate: Fri Jan 6 18:54:31 2023 +0800
style:change hash calculate (#530)
---
go.mod | 16 ++++++------
go.sum | 29 ++++++++++++++--------
.../cluster/loadbalancer/hash/consistent_hash.go | 21 +++++++++++-----
.../loadbalancer/hash/consistent_hash_test.go | 13 +++++++---
pixiu/pkg/cluster/loadbalancer/load_balancer.go | 2 +-
.../loadbalancer/rand/load_balancer_rand.go | 4 +--
.../cluster/loadbalancer/roundrobin/round_robin.go | 2 +-
pixiu/pkg/common/grpc/manager.go | 3 ++-
pixiu/pkg/context/dubbo/context.go | 5 ++++
pixiu/pkg/context/http/context.go | 5 ++++
pixiu/pkg/filter/accesslog/access_log.go | 1 +
pixiu/pkg/filter/http/dubboproxy/dubbo.go | 2 +-
pixiu/pkg/filter/http/grpcproxy/grpc.go | 2 +-
pixiu/pkg/filter/http/httpproxy/routerfilter.go | 2 +-
.../network/dubboproxy/filter/http/httpfilter.go | 2 +-
.../network/dubboproxy/filter/proxy/proxyfilter.go | 4 +--
pixiu/pkg/filter/seata/transaction.go | 2 +-
pixiu/pkg/model/cluster.go | 26 ++++++++++++++++---
pixiu/pkg/model/lb.go | 4 +++
pixiu/pkg/server/cluster_manager.go | 10 ++++----
pixiu/pkg/server/cluster_manager_test.go | 2 +-
21 files changed, 108 insertions(+), 49 deletions(-)
diff --git a/go.mod b/go.mod
index f0457180..a17eafb6 100644
--- a/go.mod
+++ b/go.mod
@@ -31,7 +31,7 @@ require (
github.com/docker/cli v20.10.17+incompatible
github.com/dubbo-go-pixiu/pixiu-api v0.1.6-0.20220612115254-d9a176b25b99
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5
- github.com/dubbogo/gost v1.11.25
+ github.com/dubbogo/gost v1.13.3-0.20221216065235-4c45e166b5a0
github.com/dubbogo/grpc-go v1.42.9
github.com/dubbogo/triple v1.1.8
github.com/envoyproxy/go-control-plane
v0.10.2-0.20220428052930-ec95b9f870a8
@@ -75,7 +75,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/moby/buildkit v0.10.1
- github.com/nacos-group/nacos-sdk-go v1.1.1
+ github.com/nacos-group/nacos-sdk-go v1.1.3
github.com/onsi/gomega v1.20.1
github.com/openshift/api v0.0.0-20200713203337-b2494ecb17dd
github.com/opentrx/seata-golang/v2 v2.0.5
@@ -116,7 +116,7 @@ require (
gomodules.xyz/jsonpatch/v3 v3.0.1
google.golang.org/api v0.74.0
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21
- google.golang.org/grpc v1.47.0
+ google.golang.org/grpc v1.49.0
google.golang.org/protobuf v1.28.1
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v2 v2.4.0
@@ -159,7 +159,6 @@ require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 //
indirect
github.com/RoaringBitmap/roaring v0.7.1 // indirect
- github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/Workiva/go-datastructures v1.0.52 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 // indirect
@@ -267,6 +266,7 @@ require (
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
+ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c //
indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/prom2json v1.3.1 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
@@ -276,8 +276,7 @@ require (
github.com/russross/blackfriday v1.6.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b //
indirect
- github.com/shirou/gopsutil v3.21.3+incompatible // indirect
- github.com/shirou/gopsutil/v3 v3.21.10 // indirect
+ github.com/shirou/gopsutil/v3 v3.22.2 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
@@ -285,8 +284,8 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
- github.com/tklauser/go-sysconf v0.3.9 // indirect
- github.com/tklauser/numcpus v0.3.0 // indirect
+ github.com/tklauser/go-sysconf v0.3.10 // indirect
+ github.com/tklauser/numcpus v0.4.0 // indirect
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
@@ -297,6 +296,7 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
// indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
+ github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/v3 v3.5.5 // indirect
go.etcd.io/etcd/server/v3 v3.5.5 // indirect
diff --git a/go.sum b/go.sum
index 35c86b86..74e00689 100644
--- a/go.sum
+++ b/go.sum
@@ -187,7 +187,6 @@ github.com/Shopify/sarama v1.19.0/go.mod
h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX
github.com/Shopify/toxiproxy v2.1.4+incompatible
h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod
h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod
h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
-github.com/StackExchange/wmi v1.2.1
h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod
h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/VividCortex/ewma v1.1.1
h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod
h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
@@ -538,8 +537,9 @@ github.com/dubbogo/gost v1.9.0/go.mod
h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fAD
github.com/dubbogo/gost v1.11.11/go.mod
h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.18/go.mod
h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.23/go.mod
h1:PhJ8+qZJx+Txjx1KthNPuVkCvUca0jRLgKWj/noGgeI=
-github.com/dubbogo/gost v1.11.25
h1:jFxE+YPh+ajrkHz7AxaaqYNMdKMDf/yfI1D+ZFoxfW0=
github.com/dubbogo/gost v1.11.25/go.mod
h1:iovrPhv0hyakhQGVr4jwiECBL9HXNuBY4VV3HWK5pM0=
+github.com/dubbogo/gost v1.13.3-0.20221216065235-4c45e166b5a0
h1:3CUA3xhqnPPIgr2ngpcFBVxQ4tMwOEzcI9ZnHl8CBdY=
+github.com/dubbogo/gost v1.13.3-0.20221216065235-4c45e166b5a0/go.mod
h1:2vbZ7bo4PgR7stX1He5XBvQgP6wx4A7q7IFHZU3hVmE=
github.com/dubbogo/grpc-go v1.42.9
h1:nTuglkH9rTJzQfardU4b0OJ0Imd2169dMNLBTNhTdlc=
github.com/dubbogo/grpc-go v1.42.9/go.mod
h1:F1T9hnUvYGW4JLK1QNriavpOkhusU677ovPzLkk6zHM=
github.com/dubbogo/jsonparser v1.0.1/go.mod
h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
@@ -1389,8 +1389,9 @@ github.com/mwitkow/go-proto-validators
v0.0.0-20180403085117-0950a7990007/go.mod
github.com/mwitkow/go-proto-validators v0.2.0/go.mod
h1:ZfA1hW+UH/2ZHOWvQ3HnQaU0DtnpXu850MZiy+YUgcc=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod
h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nacos-group/nacos-sdk-go v1.0.8/go.mod
h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA=
-github.com/nacos-group/nacos-sdk-go v1.1.1
h1:beczWcOoTaVBMgCgikqvZflrN5Xbw7pWAWpxl+VJGIA=
github.com/nacos-group/nacos-sdk-go v1.1.1/go.mod
h1:UHOtQNQY/qpk2dhg6gDq8u5+/CEIc3+lWmrmxEzX0/g=
+github.com/nacos-group/nacos-sdk-go v1.1.3
h1:xNlSC9li2A11ifTA8HCqgM6NRImGUJA4X+gGK5muJuQ=
+github.com/nacos-group/nacos-sdk-go v1.1.3/go.mod
h1:cBv9wy5iObs7khOqov1ERFQrCuTR4ILpgaiaVMxEmGI=
github.com/nakabonne/nestif v0.3.1/go.mod
h1:9EtoZochLn5iUprVDmDjqGKPofoUEBL8U4Ngq6aY7OE=
github.com/natefinch/lumberjack v2.0.0+incompatible
h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod
h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
@@ -1536,6 +1537,8 @@ github.com/polarismesh/polaris-go v1.1.0/go.mod
h1:tquawfjEKp1W3ffNJQSzhfditjjoZ
github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod
h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
github.com/posener/complete v1.1.1/go.mod
h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/posener/complete v1.2.3/go.mod
h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
+github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c
h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
+github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod
h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod
h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod
h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.8.0/go.mod
h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
@@ -1658,11 +1661,10 @@ github.com/sergi/go-diff v1.1.0
h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod
h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod
h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs=
github.com/shirou/gopsutil v3.20.11+incompatible/go.mod
h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
-github.com/shirou/gopsutil v3.21.3+incompatible
h1:uenXGGa8ESCQq+dbgtl916dmg6PSAz2cXov0uORQ9v8=
-github.com/shirou/gopsutil v3.21.3+incompatible/go.mod
h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v3 v3.21.6/go.mod
h1:JfVbDpIBLVzT8oKbvMg9P3wEIMDDpVn+LwHTKj0ST88=
-github.com/shirou/gopsutil/v3 v3.21.10
h1:flTg1DrnV/UVrBqjLgVgDJzx6lf+91rC64/dBHmO2IA=
github.com/shirou/gopsutil/v3 v3.21.10/go.mod
h1:t75NhzCZ/dYyPQjyQmrAYP6c8+LCdFANeBMdLPCNnew=
+github.com/shirou/gopsutil/v3 v3.22.2
h1:wCrArWFkHYIdDxx/FSfF5RB4dpJYW6t7rcp3+zL8uks=
+github.com/shirou/gopsutil/v3 v3.22.2/go.mod
h1:WapW1AOOPlHyXr+yOyw3uYx36enocrtSoSBy0L5vUHY=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod
h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shopspring/decimal v1.2.0
h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod
h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
@@ -1799,11 +1801,13 @@ github.com/tevid/gohamcrest v1.1.1/go.mod
h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZ
github.com/tidwall/pretty v1.0.0/go.mod
h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/timakin/bodyclose v0.0.0-20200424151742-cb6215831a94/go.mod
h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
github.com/tklauser/go-sysconf v0.3.6/go.mod
h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI=
-github.com/tklauser/go-sysconf v0.3.9
h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
github.com/tklauser/go-sysconf v0.3.9/go.mod
h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
+github.com/tklauser/go-sysconf v0.3.10
h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
+github.com/tklauser/go-sysconf v0.3.10/go.mod
h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
github.com/tklauser/numcpus v0.2.2/go.mod
h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
-github.com/tklauser/numcpus v0.3.0
h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ=
github.com/tklauser/numcpus v0.3.0/go.mod
h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
+github.com/tklauser/numcpus v0.4.0
h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
+github.com/tklauser/numcpus v0.4.0/go.mod
h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod
h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod
h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod
h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -1884,6 +1888,8 @@ github.com/yuin/goldmark v1.2.1/go.mod
h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.3.5/go.mod
h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.0/go.mod
h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod
h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
+github.com/yusufpapurcu/wmi v1.2.2
h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
+github.com/yusufpapurcu/wmi v1.2.2/go.mod
h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod
h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs=
github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod
h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA=
github.com/yvasiyarov/newrelic_platform_go
v0.0.0-20140908184405-b21fdbd4370f/go.mod
h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg=
@@ -2317,6 +2323,7 @@ golang.org/x/sys
v0.0.0-20201118182958-a01c418693c7/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -2368,6 +2375,7 @@ golang.org/x/sys
v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -2745,8 +2753,9 @@ google.golang.org/grpc v1.43.0/go.mod
h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ5
google.golang.org/grpc v1.44.0/go.mod
h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc v1.45.0/go.mod
h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
google.golang.org/grpc v1.46.0/go.mod
h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
-google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=
-google.golang.org/grpc v1.47.0/go.mod
h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
+google.golang.org/grpc v1.48.0/go.mod
h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
+google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw=
+google.golang.org/grpc v1.49.0/go.mod
h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod
h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod
h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod
h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
diff --git a/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash.go
b/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash.go
index 8b80be22..f56d6275 100644
--- a/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash.go
+++ b/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash.go
@@ -18,7 +18,7 @@
package consistent
import (
- "math/rand"
+ "fmt"
)
import (
@@ -32,17 +32,26 @@ func init() {
type ConsistentHashing struct{}
-func (ConsistentHashing) Handler(c *model.ClusterConfig) *model.Endpoint {
- hash, err :=
c.Hash.ConsistentHash.GetHash(uint32(rand.Int31n(c.Hash.MaxVnodeNum)))
+func (ConsistentHashing) Handler(c *model.ClusterConfig, policy
model.LbPolicy) *model.Endpoint {
+ u := c.Hash.ConsistentHash.Hash(policy.GenerateHash())
+
+ hash, err := c.Hash.ConsistentHash.GetHash(u)
if err != nil {
return nil
}
- for _, endpoint := range c.Endpoints {
- if endpoint.Address.Address == hash {
+ endpoints := c.GetEndpoint(true)
+
+ for _, endpoint := range endpoints {
+ address := endpoint.Address
+ if fmt.Sprintf("%s:%d", address.Address, address.Port) == hash {
return endpoint
}
}
- return nil
+ if len(endpoints) == 0 {
+ return nil
+ }
+
+ return endpoints[0]
}
diff --git a/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash_test.go
b/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash_test.go
index 085e351c..158a895f 100644
--- a/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash_test.go
+++ b/pixiu/pkg/cluster/loadbalancer/hash/consistent_hash_test.go
@@ -18,11 +18,14 @@
package consistent
import (
+ "fmt"
+ stdHttp "net/http"
"strconv"
"testing"
)
import (
+ "github.com/apache/dubbo-go-pixiu/pixiu/pkg/context/http"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/model"
)
@@ -42,10 +45,14 @@ func TestHashRing(t *testing.T) {
LbStr: model.LoadBalanceConsistentHashing, Hash:
model.Hash{ReplicaNum: 10, MaxVnodeNum: 1023}}
cluster.CreateConsistentHash()
- hashing := ConsistentHashing{}
+ var (
+ hashing = ConsistentHashing{}
+ path string
+ )
- for i := 0; i < 10; i++ {
- t.Log(hashing.Handler(cluster))
+ for i := 1; i <= 20; i++ {
+ path = fmt.Sprintf("/pixiu?total=%d", i)
+ t.Log(hashing.Handler(cluster, &http.HttpContext{Request:
&stdHttp.Request{Method: stdHttp.MethodGet, RequestURI: path}}))
}
}
diff --git a/pixiu/pkg/cluster/loadbalancer/load_balancer.go
b/pixiu/pkg/cluster/loadbalancer/load_balancer.go
index 47b6b3aa..969a1175 100644
--- a/pixiu/pkg/cluster/loadbalancer/load_balancer.go
+++ b/pixiu/pkg/cluster/loadbalancer/load_balancer.go
@@ -22,7 +22,7 @@ import (
)
type LoadBalancer interface {
- Handler(c *model.ClusterConfig) *model.Endpoint
+ Handler(c *model.ClusterConfig, policy model.LbPolicy) *model.Endpoint
}
// LoadBalancerStrategy load balancer strategy mode
diff --git a/pixiu/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
b/pixiu/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
index e6404d21..d9cb4551 100644
--- a/pixiu/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
+++ b/pixiu/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
@@ -32,6 +32,6 @@ func init() {
type Rand struct{}
-func (Rand) Handler(c *model.ClusterConfig) *model.Endpoint {
- return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints))]
+func (Rand) Handler(c *model.ClusterConfig, _ model.LbPolicy) *model.Endpoint {
+ return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints)-1)]
}
diff --git a/pixiu/pkg/cluster/loadbalancer/roundrobin/round_robin.go
b/pixiu/pkg/cluster/loadbalancer/roundrobin/round_robin.go
index 01c17f09..64451f04 100644
--- a/pixiu/pkg/cluster/loadbalancer/roundrobin/round_robin.go
+++ b/pixiu/pkg/cluster/loadbalancer/roundrobin/round_robin.go
@@ -28,7 +28,7 @@ func init() {
type RoundRobin struct{}
-func (RoundRobin) Handler(c *model.ClusterConfig) *model.Endpoint {
+func (RoundRobin) Handler(c *model.ClusterConfig, _ model.LbPolicy)
*model.Endpoint {
endpoints := c.GetEndpoint(true)
lens := len(endpoints)
if c.PrePickEndpointIndex >= lens {
diff --git a/pixiu/pkg/common/grpc/manager.go b/pixiu/pkg/common/grpc/manager.go
index cb8d572d..fec3c891 100644
--- a/pixiu/pkg/common/grpc/manager.go
+++ b/pixiu/pkg/common/grpc/manager.go
@@ -37,6 +37,7 @@ import (
import (
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/extension/filter"
router2 "github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/router"
+ "github.com/apache/dubbo-go-pixiu/pixiu/pkg/context/http"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/logger"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/model"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/server"
@@ -70,7 +71,7 @@ func (gcm *GrpcConnectionManager) ServeHTTP(w
stdHttp.ResponseWriter, r *stdHttp
clusterName := ra.Cluster
clusterManager := server.GetClusterManager()
- endpoint := clusterManager.PickEndpoint(clusterName)
+ endpoint := clusterManager.PickEndpoint(clusterName,
&http.HttpContext{Request: r})
if endpoint == nil {
logger.Infof("GrpcConnectionManager can't find endpoint in
cluster")
gcm.writeStatus(w, status.New(codes.Unknown, "can't find
endpoint in cluster"))
diff --git a/pixiu/pkg/context/dubbo/context.go
b/pixiu/pkg/context/dubbo/context.go
index 2949ba91..fd6c264c 100644
--- a/pixiu/pkg/context/dubbo/context.go
+++ b/pixiu/pkg/context/dubbo/context.go
@@ -60,3 +60,8 @@ func (c *RpcContext) SetInvocation(invocation
*invocation.RPCInvocation) {
func (c *RpcContext) SetRoute(route *model.RouteAction) {
c.Route = route
}
+
+func (c *RpcContext) GenerateHash() string {
+ req := c.RpcInvocation
+ return req.MethodName() + "." + req.Invoker().GetURL().String()
+}
diff --git a/pixiu/pkg/context/http/context.go
b/pixiu/pkg/context/http/context.go
index 3990091e..734113dc 100644
--- a/pixiu/pkg/context/http/context.go
+++ b/pixiu/pkg/context/http/context.go
@@ -231,3 +231,8 @@ func (hc *HttpContext) AppendFilterFunc(ff ...FilterFunc) {
hc.Filters = append(hc.Filters, v)
}
}
+
+func (hc *HttpContext) GenerateHash() string {
+ req := hc.Request
+ return req.Method + "." + req.RequestURI
+}
diff --git a/pixiu/pkg/filter/accesslog/access_log.go
b/pixiu/pkg/filter/accesslog/access_log.go
index a000e656..059e03cd 100644
--- a/pixiu/pkg/filter/accesslog/access_log.go
+++ b/pixiu/pkg/filter/accesslog/access_log.go
@@ -117,6 +117,7 @@ func buildAccessLogMsg(c *http.HttpContext, cost
time.Duration) string {
}
builder := strings.Builder{}
+ builder.Grow(16)
builder.WriteString("[")
builder.WriteString(time.Now().Format(constant.MessageDateLayout))
builder.WriteString("] ")
diff --git a/pixiu/pkg/filter/http/dubboproxy/dubbo.go
b/pixiu/pkg/filter/http/dubboproxy/dubbo.go
index e963570c..b49eeefe 100644
--- a/pixiu/pkg/filter/http/dubboproxy/dubbo.go
+++ b/pixiu/pkg/filter/http/dubboproxy/dubbo.go
@@ -109,7 +109,7 @@ func (f *Filter) Decode(hc *pixiuHttp.HttpContext)
filter.FilterStatus {
clusterName := rEntry.Cluster
clusterManager := server.GetClusterManager()
- endpoint := clusterManager.PickEndpoint(clusterName)
+ endpoint := clusterManager.PickEndpoint(clusterName, hc)
if endpoint == nil {
logger.Info("[dubbo-go-pixiu] cluster not found endpoint")
bt, _ := json.Marshal(pixiuHttp.ErrResponse{Message: "cluster
not found endpoint"})
diff --git a/pixiu/pkg/filter/http/grpcproxy/grpc.go
b/pixiu/pkg/filter/http/grpcproxy/grpc.go
index 89816160..56bc264a 100644
--- a/pixiu/pkg/filter/http/grpcproxy/grpc.go
+++ b/pixiu/pkg/filter/http/grpcproxy/grpc.go
@@ -183,7 +183,7 @@ func (f *Filter) Decode(c *http.HttpContext)
filter.FilterStatus {
re := c.GetRouteEntry()
logger.Debugf("%s client choose endpoint from cluster :%v",
loggerHeader, re.Cluster)
- e := server.GetClusterManager().PickEndpoint(re.Cluster)
+ e := server.GetClusterManager().PickEndpoint(re.Cluster, c)
if e == nil {
logger.Errorf("%s err {cluster not exists}", loggerHeader)
c.SendLocalReply(stdHttp.StatusServiceUnavailable,
[]byte("cluster not exists"))
diff --git a/pixiu/pkg/filter/http/httpproxy/routerfilter.go
b/pixiu/pkg/filter/http/httpproxy/routerfilter.go
index 4dcdccc3..0bbee9d7 100644
--- a/pixiu/pkg/filter/http/httpproxy/routerfilter.go
+++ b/pixiu/pkg/filter/http/httpproxy/routerfilter.go
@@ -88,7 +88,7 @@ func (f *Filter) Decode(hc *http.HttpContext)
filter.FilterStatus {
clusterName := rEntry.Cluster
clusterManager := server.GetClusterManager()
- endpoint := clusterManager.PickEndpoint(clusterName)
+ endpoint := clusterManager.PickEndpoint(clusterName, hc)
if endpoint == nil {
logger.Debugf("[dubbo-go-pixiu] cluster not found endpoint")
bt, _ := json.Marshal(http.ErrResponse{Message: "cluster not
found endpoint"})
diff --git a/pixiu/pkg/filter/network/dubboproxy/filter/http/httpfilter.go
b/pixiu/pkg/filter/network/dubboproxy/filter/http/httpfilter.go
index 805a2838..04a7f233 100644
--- a/pixiu/pkg/filter/network/dubboproxy/filter/http/httpfilter.go
+++ b/pixiu/pkg/filter/network/dubboproxy/filter/http/httpfilter.go
@@ -85,7 +85,7 @@ func (f Filter) Handle(ctx *dubbo2.RpcContext)
filter.FilterStatus {
ra := ctx.Route
clusterName := ra.Cluster
clusterManager := server.GetClusterManager()
- endpoint := clusterManager.PickEndpoint(clusterName)
+ endpoint := clusterManager.PickEndpoint(clusterName, ctx)
if endpoint == nil {
ctx.SetError(errors.Errorf("Requested dubbo rpc invocation
endpoint not found"))
return filter.Stop
diff --git a/pixiu/pkg/filter/network/dubboproxy/filter/proxy/proxyfilter.go
b/pixiu/pkg/filter/network/dubboproxy/filter/proxy/proxyfilter.go
index 98d3843b..c22a916f 100644
--- a/pixiu/pkg/filter/network/dubboproxy/filter/proxy/proxyfilter.go
+++ b/pixiu/pkg/filter/network/dubboproxy/filter/proxy/proxyfilter.go
@@ -96,7 +96,7 @@ func (f Filter) sendDubboRequest(ctx *dubbo2.RpcContext)
filter.FilterStatus {
ra := ctx.Route
clusterName := ra.Cluster
clusterManager := server.GetClusterManager()
- endpoint := clusterManager.PickEndpoint(clusterName)
+ endpoint := clusterManager.PickEndpoint(clusterName, ctx)
if endpoint == nil {
ctx.SetError(errors.Errorf("Requested dubbo rpc invocation
endpoint not found"))
return filter.Stop
@@ -151,7 +151,7 @@ func (f Filter) sendTripleRequest(ctx *dubbo2.RpcContext)
filter.FilterStatus {
ra := ctx.Route
clusterName := ra.Cluster
clusterManager := server.GetClusterManager()
- endpoint := clusterManager.PickEndpoint(clusterName)
+ endpoint := clusterManager.PickEndpoint(clusterName, ctx)
if endpoint == nil {
ctx.SetError(errors.Errorf("Requested dubbo rpc invocation
endpoint not found"))
return filter.Stop
diff --git a/pixiu/pkg/filter/seata/transaction.go
b/pixiu/pkg/filter/seata/transaction.go
index 841ddeec..a224f6e2 100644
--- a/pixiu/pkg/filter/seata/transaction.go
+++ b/pixiu/pkg/filter/seata/transaction.go
@@ -109,7 +109,7 @@ func (f *Filter) handleHttp1BranchRegister(hctx
*http.HttpContext, tccResource *
clusterName := rEntry.Cluster
clusterManager := server.GetClusterManager()
- endpoint := clusterManager.PickEndpoint(clusterName)
+ endpoint := clusterManager.PickEndpoint(clusterName, hctx)
if endpoint == nil {
hctx.SendLocalReply(netHttp.StatusServiceUnavailable,
[]byte("cluster not found endpoint"))
return false
diff --git a/pixiu/pkg/model/cluster.go b/pixiu/pkg/model/cluster.go
index 8f9eccc1..6239c1c6 100644
--- a/pixiu/pkg/model/cluster.go
+++ b/pixiu/pkg/model/cluster.go
@@ -17,6 +17,11 @@
package model
+import (
+ "fmt"
+ "math"
+)
+
import (
"github.com/dubbogo/gost/hash/consistent"
)
@@ -103,7 +108,7 @@ type (
)
func (c *ClusterConfig) GetEndpoint(mustHealth bool) []*Endpoint {
- var endpoints []*Endpoint
+ var endpoints = make([]*Endpoint, 0, len(c.Endpoints))
for _, e := range c.Endpoints {
// select all endpoint or endpoint is health
if !mustHealth || !e.UnHealthy {
@@ -115,10 +120,23 @@ func (c *ClusterConfig) GetEndpoint(mustHealth bool)
[]*Endpoint {
func (c *ClusterConfig) CreateConsistentHash() {
if c.LbStr == LoadBalanceConsistentHashing {
- h :=
consistent.NewConsistentHash(consistent.WithReplicaNum(c.Hash.ReplicaNum),
- consistent.WithMaxVnodeNum(int(c.Hash.MaxVnodeNum)))
+ var ops []consistent.Option
+
+ if c.Hash.ReplicaNum != 0 {
+ ops = append(ops,
consistent.WithReplicaNum(c.Hash.ReplicaNum))
+ }
+
+ if c.Hash.MaxVnodeNum != 0 {
+ ops = append(ops,
consistent.WithMaxVnodeNum(int(c.Hash.MaxVnodeNum)))
+ } else {
+ c.Hash.MaxVnodeNum = math.MinInt32
+ }
+
+ h := consistent.NewConsistentHash(ops...)
+
for _, endpoint := range c.Endpoints {
- h.Add(endpoint.Address.Address)
+ address := endpoint.Address
+ h.Add(fmt.Sprintf("%s:%d", address.Address,
address.Port))
}
c.Hash.ConsistentHash = h
}
diff --git a/pixiu/pkg/model/lb.go b/pixiu/pkg/model/lb.go
index 32a4f9dd..f41b03f2 100644
--- a/pixiu/pkg/model/lb.go
+++ b/pixiu/pkg/model/lb.go
@@ -31,3 +31,7 @@ var LbPolicyTypeValue = map[string]LbPolicyType{
"RoundRobin": LoadBalancerRoundRobin,
"ConsistentHashing": LoadBalanceConsistentHashing,
}
+
+type LbPolicy interface {
+ GenerateHash() string
+}
diff --git a/pixiu/pkg/server/cluster_manager.go
b/pixiu/pkg/server/cluster_manager.go
index b3296872..49f5694b 100644
--- a/pixiu/pkg/server/cluster_manager.go
+++ b/pixiu/pkg/server/cluster_manager.go
@@ -149,19 +149,19 @@ func (cm *ClusterManager) CompareAndSetStore(store
*ClusterStore) bool {
return true
}
-func (cm *ClusterManager) PickEndpoint(clusterName string) *model.Endpoint {
+func (cm *ClusterManager) PickEndpoint(clusterName string, policy
model.LbPolicy) *model.Endpoint {
cm.rw.RLock()
defer cm.rw.RUnlock()
for _, c := range cm.store.Config {
if c.Name == clusterName {
- return cm.pickOneEndpoint(c)
+ return cm.pickOneEndpoint(c, policy)
}
}
return nil
}
-func (cm *ClusterManager) pickOneEndpoint(c *model.ClusterConfig)
*model.Endpoint {
+func (cm *ClusterManager) pickOneEndpoint(c *model.ClusterConfig, policy
model.LbPolicy) *model.Endpoint {
if c.Endpoints == nil || len(c.Endpoints) == 0 {
return nil
}
@@ -175,9 +175,9 @@ func (cm *ClusterManager) pickOneEndpoint(c
*model.ClusterConfig) *model.Endpoin
loadBalancer, ok := loadbalancer.LoadBalancerStrategy[c.LbStr]
if ok {
- return loadBalancer.Handler(c)
+ return loadBalancer.Handler(c, policy)
}
- return
loadbalancer.LoadBalancerStrategy[model.LoadBalancerRand].Handler(c)
+ return
loadbalancer.LoadBalancerStrategy[model.LoadBalancerRand].Handler(c, policy)
}
func (cm *ClusterManager) RemoveCluster(namesToDel []string) {
diff --git a/pixiu/pkg/server/cluster_manager_test.go
b/pixiu/pkg/server/cluster_manager_test.go
index 222ffb0d..e014719b 100644
--- a/pixiu/pkg/server/cluster_manager_test.go
+++ b/pixiu/pkg/server/cluster_manager_test.go
@@ -65,6 +65,6 @@ func TestClusterManager(t *testing.T) {
Address: model.SocketAddress{},
ID: "2",
})
- assert.Equal(t, cm.PickEndpoint("test").ID, "1")
+ assert.Equal(t, cm.PickEndpoint("test", nil).ID, "1")
cm.DeleteEndpoint("test2", "1")
}