From 8f8cf966e2751b01a5a9216b6122dbc28ab5253b Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Fri, 29 Oct 2021 22:18:17 +0800
Subject: [PATCH 01/35] feat(adasvc): add infrastructure for adaptive service
---
cluster/cluster/adasvc/cluster.go | 41 +++++++++++++++++
cluster/cluster/adasvc/cluster_invoker.go | 40 ++++++++++++++++
cluster/loadbalance/p2c/loadbalance.go | 45 ++++++++++++++++++
cluster/metrics/local_metrics.go | 56 +++++++++++++++++++++++
cluster/metrics/metrics.go | 29 ++++++++++++
cluster/metrics/utils.go | 14 ++++++
common/constant/cluster.go | 17 +++----
common/constant/loadbalance.go | 1 +
config/consumer_config.go | 2 +
config/reference_config.go | 21 ++++++---
10 files changed, 251 insertions(+), 15 deletions(-)
create mode 100644 cluster/cluster/adasvc/cluster.go
create mode 100644 cluster/cluster/adasvc/cluster_invoker.go
create mode 100644 cluster/loadbalance/p2c/loadbalance.go
create mode 100644 cluster/metrics/local_metrics.go
create mode 100644 cluster/metrics/metrics.go
create mode 100644 cluster/metrics/utils.go
diff --git a/cluster/cluster/adasvc/cluster.go b/cluster/cluster/adasvc/cluster.go
new file mode 100644
index 0000000000..9cc024ef5e
--- /dev/null
+++ b/cluster/cluster/adasvc/cluster.go
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package adasvc
+
+import (
+ clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
+ "dubbo.apache.org/dubbo-go/v3/cluster/directory"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+)
+
+func init() {
+ extension.SetCluster(constant.ClusterKeyAdaptiveService, newCluster)
+}
+
+// cluster is a cluster for adaptive service.
+type cluster struct {}
+
+func newCluster() clusterpkg.Cluster {
+ return &cluster{}
+}
+
+func (c *cluster) Join(directory directory.Directory) protocol.Invoker {
+ return clusterpkg.BuildInterceptorChain(NewClusterInvoker(directory))
+}
\ No newline at end of file
diff --git a/cluster/cluster/adasvc/cluster_invoker.go b/cluster/cluster/adasvc/cluster_invoker.go
new file mode 100644
index 0000000000..4c02bbaab3
--- /dev/null
+++ b/cluster/cluster/adasvc/cluster_invoker.go
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package adasvc
+
+import (
+ "context"
+ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/base"
+ "dubbo.apache.org/dubbo-go/v3/cluster/directory"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+)
+
+type clusterInvoker struct {
+ base.ClusterInvoker
+}
+
+func NewClusterInvoker(directory directory.Directory) protocol.Invoker {
+ return &clusterInvoker{
+ ClusterInvoker: base.NewClusterInvoker(directory),
+ }
+}
+
+func (ivk *clusterInvoker) Invoke(_ context.Context, invocation protocol.Invocation) protocol.Result {
+ // invokers for the invocation
+ ivks := ivk.Directory.List(invocation)
+}
\ No newline at end of file
diff --git a/cluster/loadbalance/p2c/loadbalance.go b/cluster/loadbalance/p2c/loadbalance.go
new file mode 100644
index 0000000000..6e20575f2b
--- /dev/null
+++ b/cluster/loadbalance/p2c/loadbalance.go
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package p2c
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
+ "dubbo.apache.org/dubbo-go/v3/cluster/metrics"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+)
+
+func init() {
+ extension.SetLoadbalance(constant.LoadBalanceKeyP2C, newLoadBalance)
+}
+
+type loadBalance struct {
+
+}
+
+func newLoadBalance() loadbalance.LoadBalance {
+ return &loadBalance{}
+}
+
+func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {
+ // m is the Metrics, which saves the metrics of instance, invokers and methods
+ // The local metrics is available only for the earlier version.
+ m := metrics.LocalMetrics
+ panic("implement me")
+}
\ No newline at end of file
diff --git a/cluster/metrics/local_metrics.go b/cluster/metrics/local_metrics.go
new file mode 100644
index 0000000000..828c9dc8ae
--- /dev/null
+++ b/cluster/metrics/local_metrics.go
@@ -0,0 +1,56 @@
+package metrics
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "fmt"
+ "sync"
+)
+
+var LocalMetrics Metrics
+
+func init() {
+ LocalMetrics = newLocalMetrics()
+}
+
+type localMetrics struct {
+ // protect metrics
+ lock *sync.Mutex
+ metrics map[string]interface{}
+}
+
+func newLocalMetrics() *localMetrics {
+ return &localMetrics{
+ lock: &sync.Mutex{},
+ metrics: make(map[string]interface{}),
+ }
+}
+
+func (m *localMetrics) GetMethodMetrics(url *common.URL, methodName, key string) (interface{}, error) {
+ metricsKey := fmt.Sprintf("%s.%s.%s.%s", getInstanceKey(url), getInvokerKey(url), methodName, key)
+ if metrics, ok := m.metrics[metricsKey]; ok {
+ return metrics, nil
+ }
+ return nil, ErrMetricsNotFound
+}
+
+func (m *localMetrics) SetMethodMetrics(url *common.URL, methodName, key string, value interface{}) error {
+ metricsKey := fmt.Sprintf("%s.%s.%s.%s", getInstanceKey(url), getInvokerKey(url), methodName, key)
+ m.metrics[metricsKey] = value
+ return nil
+}
+
+func (m *localMetrics) GetInvokerMetrics(url *common.URL, key string) (interface{}, error) {
+ panic("implement me")
+}
+
+func (m *localMetrics) SetInvokerMetrics(url *common.URL, key string, value interface{}) error {
+ panic("implement me")
+}
+
+func (m *localMetrics) GetInstanceMetrics(url *common.URL, key string) (interface{}, error) {
+ panic("implement me")
+}
+
+func (m *localMetrics) SetInstanceMetrics(url *common.URL, key string, value interface{}) error {
+ panic("implement me")
+}
\ No newline at end of file
diff --git a/cluster/metrics/metrics.go b/cluster/metrics/metrics.go
new file mode 100644
index 0000000000..389e0ea18b
--- /dev/null
+++ b/cluster/metrics/metrics.go
@@ -0,0 +1,29 @@
+package metrics
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "github.com/pkg/errors"
+)
+
+var (
+ ErrMetricsNotFound = errors.New("metrics not found")
+)
+
+type Metrics interface {
+ // GetMethodMetrics returns method-level metrics, the format of key is "{instance key}.{invoker key}.{method key}.{key}"
+ // url is invoker's url, which contains information about instance and invoker.
+ // methodName is the method name.
+ // key is the key of the metrics.
+ GetMethodMetrics(url *common.URL, methodName, key string) (interface{}, error)
+ SetMethodMetrics(url *common.URL, methodName, key string, value interface{}) error
+
+ // GetInvokerMetrics returns invoker-level metrics, the format of key is "{instance key}.{invoker key}.{key}"
+ // DO NOT IMPLEMENT FOR EARLIER VERSION
+ GetInvokerMetrics(url *common.URL, key string) (interface{}, error)
+ SetInvokerMetrics(url *common.URL, key string, value interface{}) error
+
+ // GetInstanceMetrics returns instance-level metrics, the format of key is "{instance key}.{key}"
+ // DO NOT IMPLEMENT FOR EARLIER VERSION
+ GetInstanceMetrics(url *common.URL, key string) (interface{}, error)
+ SetInstanceMetrics(url *common.URL, key string, value interface{}) error
+}
\ No newline at end of file
diff --git a/cluster/metrics/utils.go b/cluster/metrics/utils.go
new file mode 100644
index 0000000000..456fa0f57e
--- /dev/null
+++ b/cluster/metrics/utils.go
@@ -0,0 +1,14 @@
+package metrics
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "fmt"
+)
+
+func getInvokerKey(url *common.URL) string {
+ return url.Path
+}
+
+func getInstanceKey(url *common.URL) string {
+ return fmt.Sprintf("%s:%s", url.Ip, url.Port)
+}
\ No newline at end of file
diff --git a/common/constant/cluster.go b/common/constant/cluster.go
index 14f3375317..81af3ec882 100644
--- a/common/constant/cluster.go
+++ b/common/constant/cluster.go
@@ -18,12 +18,13 @@
package constant
const (
- ClusterKeyAvailable = "available"
- ClusterKeyBroadcast = "broadcast"
- ClusterKeyFailback = "failback"
- ClusterKeyFailfast = "failfast"
- ClusterKeyFailover = "failover"
- ClusterKeyFailsafe = "failsafe"
- ClusterKeyForking = "forking"
- ClusterKeyZoneAware = "zoneAware"
+ ClusterKeyAvailable = "available"
+ ClusterKeyBroadcast = "broadcast"
+ ClusterKeyFailback = "failback"
+ ClusterKeyFailfast = "failfast"
+ ClusterKeyFailover = "failover"
+ ClusterKeyFailsafe = "failsafe"
+ ClusterKeyForking = "forking"
+ ClusterKeyZoneAware = "zoneAware"
+ ClusterKeyAdaptiveService = "adaptiveService"
)
diff --git a/common/constant/loadbalance.go b/common/constant/loadbalance.go
index 7b1d8ea195..82c5771f9a 100644
--- a/common/constant/loadbalance.go
+++ b/common/constant/loadbalance.go
@@ -22,4 +22,5 @@ const (
LoadBalanceKeyLeastActive = "leastactive"
LoadBalanceKeyRandom = "random"
LoadBalanceKeyRoundRobin = "roundrobin"
+ LoadBalanceKeyP2C = "p2c"
)
diff --git a/config/consumer_config.go b/config/consumer_config.go
index a0359dd068..cbf2a8decf 100644
--- a/config/consumer_config.go
+++ b/config/consumer_config.go
@@ -45,6 +45,8 @@ type ConsumerConfig struct {
RequestTimeout string `default:"3s" yaml:"request-timeout" json:"request-timeout,omitempty" property:"request-timeout"`
ProxyFactory string `default:"default" yaml:"proxy" json:"proxy,omitempty" property:"proxy"`
Check bool `yaml:"check" json:"check,omitempty" property:"check"`
+ // adaptive service
+ AdaptiveService bool `default:"false" yaml:"adaptive-service" json:"adaptive-service" property:"adaptive-service"`
References map[string]*ReferenceConfig `yaml:"references" json:"references,omitempty" property:"references"`
diff --git a/config/reference_config.go b/config/reference_config.go
index dea00fc75c..c338e44e2f 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -102,6 +102,7 @@ func (rc *ReferenceConfig) Init(root *RootConfig) error {
// Refer ...
func (rc *ReferenceConfig) Refer(srv interface{}) {
+ // cfgURL is an interface-level invoker url, in the other words, it represents an interface.
cfgURL := common.NewURLWithOptions(
common.WithPath(rc.InterfaceName),
common.WithProtocol(rc.Protocol),
@@ -118,10 +119,15 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
// retrieving urls from config, and appending the urls to rc.urls
if rc.URL != "" { // use user-specific urls
/*
- Two types of URL are allowed for rc.URL: direct url and registry url, they will be handled in different ways.
- For example, "tri://localhost:10000" is a direct url, and "registry://localhost:2181" is a registry url.
- rc.URL: "tri://localhost:10000;tri://localhost:10001;registry://localhost:2181",
- urlStrings = []string{"tri://localhost:10000", "tri://localhost:10001", "registry://localhost:2181"}.
+ Two types of URL are allowed for rc.URL:
+ 1. direct url: server IP, that is, no need for a registry anymore
+ 2. registry url
+ They will be handled in different ways:
+ For example, we have a direct url and a registry url:
+ 1. "tri://localhost:10000" is a direct url
+ 2. "registry://localhost:2181" is a registry url.
+ Then, rc.URL looks like a string seperated by semicolon: "tri://localhost:10000;registry://localhost:2181".
+ The result of urlStrings is a string array: []string{"tri://localhost:10000", "registry://localhost:2181"}.
*/
urlStrings := gxstrings.RegSplit(rc.URL, "\\s*[;]+\\s*")
for _, urlStr := range urlStrings {
@@ -129,14 +135,15 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
if err != nil {
panic(fmt.Sprintf("url configuration error, please check your configuration, user specified URL %v refer error, error message is %v ", urlStr, err.Error()))
}
- if serviceURL.Protocol == constant.REGISTRY_PROTOCOL { // URL stands for a registry protocol
+ if serviceURL.Protocol == constant.REGISTRY_PROTOCOL { // serviceURL in this branch is a registry protocol
serviceURL.SubURL = cfgURL
rc.urls = append(rc.urls, serviceURL)
- } else { // URL stands for a direct address
+ } else { // serviceURL in this branch is the target endpoint IP address
if serviceURL.Path == "" {
serviceURL.Path = "/" + rc.InterfaceName
}
- // merge URL param with cfgURL, others are same as serviceURL
+ // replace params of serviceURL with params of cfgUrl
+ // other stuff, e.g. IP, port, etc., are same as serviceURL
newURL := common.MergeURL(serviceURL, cfgURL)
rc.urls = append(rc.urls, newURL)
}
From 4dfc01e8b40e390a81d39e8a87feaa75236ca9f5 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Fri, 29 Oct 2021 22:54:33 +0800
Subject: [PATCH 02/35] feat(adasvc): reference config support adaptive service
---
cluster/cluster/base/cluster_invoker.go | 8 +-
cluster/cluster/failback/cluster_invoker.go | 6 +-
cluster/cluster/failover/cluster_invoker.go | 4 +-
cluster/cluster/failover/cluster_test.go | 6 +-
cluster/cluster/failsafe/cluster_invoker.go | 4 +-
cluster/cluster/forking/cluster_invoker.go | 2 +-
cluster/cluster/forking/cluster_test.go | 2 +-
cluster/directory/base/directory.go | 6 +-
cluster/directory/base/directory_test.go | 28 +++---
common/constant/default.go | 6 +-
common/constant/key.go | 86 +++++++++---------
common/metadata_info.go | 18 ++--
common/proxy/proxy_factory/default.go | 2 +-
common/proxy/proxy_factory/pass_through.go | 2 +-
common/proxy/proxy_test.go | 4 +-
common/url.go | 38 ++++----
common/url_test.go | 46 +++++-----
config/metadata_report_config.go | 4 +-
config/reference_config.go | 91 ++++++++++---------
config/registry_config.go | 12 +--
config/registry_config_test.go | 4 +-
config/service_config.go | 46 +++++-----
config_center/configurator/mock.go | 6 +-
config_center/configurator/override.go | 22 ++---
config_center/configurator/override_test.go | 8 +-
filter/accesslog/filter.go | 28 +++---
filter/accesslog/filter_test.go | 4 +-
filter/auth/default_authenticator.go | 2 +-
filter/execlmt/filter_test.go | 6 +-
filter/generic/filter.go | 6 +-
filter/generic/filter_test.go | 8 +-
filter/generic/service_filter.go | 4 +-
filter/generic/service_filter_test.go | 16 ++--
filter/generic/util.go | 4 +-
...ejected_execution_handler_only_log_test.go | 2 +-
filter/sentinel/filter.go | 4 +-
filter/tps/limiter/method_service_test.go | 8 +-
.../identifier/service_metadata_identifier.go | 6 +-
.../mapping/metadata/service_name_mapping.go | 4 +-
metadata/report/delegate/delegate_report.go | 8 +-
metadata/report/etcd/report.go | 2 +-
metadata/report/etcd/report_test.go | 8 +-
metadata/report/nacos/report_test.go | 4 +-
metadata/report/zookeeper/report.go | 2 +-
.../local/metadata_service_proxy_factory.go | 4 +-
metadata/service/local/service.go | 10 +-
metadata/service/local/service_proxy.go | 4 +-
metadata/service/remote/service.go | 18 ++--
metrics/prometheus/reporter.go | 12 +--
protocol/dubbo/dubbo_codec.go | 12 +--
protocol/dubbo/dubbo_exporter.go | 2 +-
protocol/dubbo/dubbo_invoker.go | 22 ++---
protocol/dubbo/impl/hessian.go | 10 +-
protocol/dubbo3/dubbo3_exporter.go | 4 +-
protocol/dubbo3/dubbo3_invoker.go | 18 ++--
protocol/dubbo3/dubbo3_protocol.go | 6 +-
protocol/grpc/client.go | 2 +-
protocol/grpc/grpc_exporter.go | 2 +-
protocol/invocation/rpcinvocation.go | 4 +-
protocol/invocation/rpcinvocation_test.go | 16 ++--
protocol/jsonrpc/http.go | 4 +-
protocol/jsonrpc/jsonrpc_exporter.go | 2 +-
protocol/jsonrpc/server.go | 4 +-
.../protocol_filter_wrapper.go | 2 +-
.../protocol_filter_wrapper_test.go | 2 +-
protocol/rest/rest_exporter.go | 2 +-
protocol/rest/rest_protocol.go | 6 +-
registry/base_registry.go | 14 +--
registry/directory/directory.go | 4 +-
registry/directory/directory_test.go | 40 ++++----
registry/etcdv3/registry_test.go | 14 +--
.../metadata_service_url_params_customizer.go | 12 +--
registry/event/service_revision_customizer.go | 2 +-
registry/kubernetes/registry_test.go | 12 +--
registry/nacos/listener.go | 6 +-
registry/nacos/registry.go | 20 ++--
registry/nacos/registry_test.go | 52 +++++------
registry/protocol/protocol.go | 20 ++--
registry/protocol/protocol_test.go | 26 +++---
.../service_discovery_registry.go | 10 +-
.../rest/rest_subscribed_urls_synthesizer.go | 6 +-
.../rest_subscribed_urls_synthesizer_test.go | 8 +-
remoting/getty/dubbo_codec_for_test.go | 12 +--
remoting/getty/getty_client_test.go | 24 ++---
remoting/getty/listener_test.go | 4 +-
remoting/getty/readwriter_test.go | 6 +-
remoting/kubernetes/client.go | 6 +-
remoting/kubernetes/facade_test.go | 2 +-
remoting/kubernetes/registry_controller.go | 2 +-
89 files changed, 532 insertions(+), 525 deletions(-)
diff --git a/cluster/cluster/base/cluster_invoker.go b/cluster/cluster/base/cluster_invoker.go
index 5b4958d753..059d0d9733 100644
--- a/cluster/cluster/base/cluster_invoker.go
+++ b/cluster/cluster/base/cluster_invoker.go
@@ -94,9 +94,9 @@ func (invoker *ClusterInvoker) DoSelect(lb loadbalance.LoadBalance, invocation p
}
url := invokers[0].GetURL()
- sticky := url.GetParamBool(constant.STICKY_KEY, false)
+ sticky := url.GetParamBool(constant.StickyKey, false)
// Get the service method sticky config if have
- sticky = url.GetMethodParamBool(invocation.MethodName(), constant.STICKY_KEY, sticky)
+ sticky = url.GetMethodParamBool(invocation.MethodName(), constant.StickyKey, sticky)
if invoker.StickyInvoker != nil && !isInvoked(invoker.StickyInvoker, invokers) {
invoker.StickyInvoker = nil
@@ -176,10 +176,10 @@ func GetLoadBalance(invoker protocol.Invoker, invocation protocol.Invocation) lo
methodName := invocation.MethodName()
// Get the service loadbalance config
- lb := url.GetParam(constant.LOADBALANCE_KEY, constant.DEFAULT_LOADBALANCE)
+ lb := url.GetParam(constant.LoadbalanceKey, constant.DEFAULT_LOADBALANCE)
// Get the service method loadbalance config if have
- if v := url.GetMethodParam(methodName, constant.LOADBALANCE_KEY, ""); len(v) > 0 {
+ if v := url.GetMethodParam(methodName, constant.LoadbalanceKey, ""); len(v) > 0 {
lb = v
}
return extension.GetLoadbalance(lb)
diff --git a/cluster/cluster/failback/cluster_invoker.go b/cluster/cluster/failback/cluster_invoker.go
index 4e677fa303..d9382ecf0b 100644
--- a/cluster/cluster/failback/cluster_invoker.go
+++ b/cluster/cluster/failback/cluster_invoker.go
@@ -58,7 +58,7 @@ func newClusterInvoker(directory directory.Directory) protocol.Invoker {
invoker := &clusterInvoker{
ClusterInvoker: base.NewClusterInvoker(directory),
}
- retriesConfig := invoker.GetURL().GetParam(constant.RETRIES_KEY, constant.DEFAULT_FAILBACK_TIMES)
+ retriesConfig := invoker.GetURL().GetParam(constant.RetriesKey, 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.")
@@ -141,10 +141,10 @@ func (invoker *clusterInvoker) Invoke(ctx context.Context, invocation protocol.I
// Get the service loadbalance config
url := invokers[0].GetURL()
- lb := url.GetParam(constant.LOADBALANCE_KEY, constant.DEFAULT_LOADBALANCE)
+ lb := url.GetParam(constant.LoadbalanceKey, constant.DEFAULT_LOADBALANCE)
// Get the service method loadbalance config if have
methodName := invocation.MethodName()
- if v := url.GetMethodParam(methodName, constant.LOADBALANCE_KEY, ""); v != "" {
+ if v := url.GetMethodParam(methodName, constant.LoadbalanceKey, ""); v != "" {
lb = v
}
diff --git a/cluster/cluster/failover/cluster_invoker.go b/cluster/cluster/failover/cluster_invoker.go
index 6440627cd6..4c33000129 100644
--- a/cluster/cluster/failover/cluster_invoker.go
+++ b/cluster/cluster/failover/cluster_invoker.go
@@ -116,9 +116,9 @@ func getRetries(invokers []protocol.Invoker, methodName string) int {
url := invokers[0].GetURL()
// get reties
- retriesConfig := url.GetParam(constant.RETRIES_KEY, constant.DEFAULT_RETRIES)
+ retriesConfig := url.GetParam(constant.RetriesKey, constant.DEFAULT_RETRIES)
// Get the service method loadbalance config if have
- if v := url.GetMethodParam(methodName, constant.RETRIES_KEY, ""); len(v) != 0 {
+ if v := url.GetMethodParam(methodName, constant.RetriesKey, ""); len(v) != 0 {
retriesConfig = v
}
diff --git a/cluster/cluster/failover/cluster_test.go b/cluster/cluster/failover/cluster_test.go
index ad0aae36d8..53ef3247f2 100644
--- a/cluster/cluster/failover/cluster_test.go
+++ b/cluster/cluster/failover/cluster_test.go
@@ -77,7 +77,7 @@ func TestFailoverInvokeFail(t *testing.T) {
// nolint
func TestFailoverInvoke1(t *testing.T) {
urlParams := url.Values{}
- urlParams.Set(constant.RETRIES_KEY, "3")
+ urlParams.Set(constant.RetriesKey, "3")
result := normalInvoke(4, urlParams)
assert.NoError(t, result.Error())
clusterpkg.Count = 0
@@ -86,8 +86,8 @@ func TestFailoverInvoke1(t *testing.T) {
// nolint
func TestFailoverInvoke2(t *testing.T) {
urlParams := url.Values{}
- urlParams.Set(constant.RETRIES_KEY, "2")
- urlParams.Set("methods.test."+constant.RETRIES_KEY, "3")
+ urlParams.Set(constant.RetriesKey, "2")
+ urlParams.Set("methods.test."+constant.RetriesKey, "3")
ivc := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("test"))
result := normalInvoke(4, urlParams, ivc)
diff --git a/cluster/cluster/failsafe/cluster_invoker.go b/cluster/cluster/failsafe/cluster_invoker.go
index b9ba62f8b5..c714443e90 100644
--- a/cluster/cluster/failsafe/cluster_invoker.go
+++ b/cluster/cluster/failsafe/cluster_invoker.go
@@ -58,9 +58,9 @@ func (invoker *clusterInvoker) Invoke(ctx context.Context, invocation protocol.I
url := invokers[0].GetURL()
methodName := invocation.MethodName()
// Get the service loadbalance config
- lb := url.GetParam(constant.LOADBALANCE_KEY, constant.DEFAULT_LOADBALANCE)
+ lb := url.GetParam(constant.LoadbalanceKey, constant.DEFAULT_LOADBALANCE)
// Get the service method loadbalance config if have
- if v := url.GetMethodParam(methodName, constant.LOADBALANCE_KEY, ""); v != "" {
+ if v := url.GetMethodParam(methodName, constant.LoadbalanceKey, ""); v != "" {
lb = v
}
loadbalance := extension.GetLoadbalance(lb)
diff --git a/cluster/cluster/forking/cluster_invoker.go b/cluster/cluster/forking/cluster_invoker.go
index 0b76ffb93c..8cda8b5e65 100644
--- a/cluster/cluster/forking/cluster_invoker.go
+++ b/cluster/cluster/forking/cluster_invoker.go
@@ -57,7 +57,7 @@ func (invoker *clusterInvoker) Invoke(ctx context.Context, invocation protocol.I
var selected []protocol.Invoker
forks := invoker.GetURL().GetParamByIntValue(constant.FORKS_KEY, constant.DEFAULT_FORKS)
- timeouts := invoker.GetURL().GetParamInt(constant.TIMEOUT_KEY, constant.DEFAULT_TIMEOUT)
+ timeouts := invoker.GetURL().GetParamInt(constant.TimeoutKey, constant.DEFAULT_TIMEOUT)
if forks < 0 || forks > len(invokers) {
selected = invokers
} else {
diff --git a/cluster/cluster/forking/cluster_test.go b/cluster/cluster/forking/cluster_test.go
index c92bade090..78412bb6cd 100644
--- a/cluster/cluster/forking/cluster_test.go
+++ b/cluster/cluster/forking/cluster_test.go
@@ -72,7 +72,7 @@ func TestForkingInvokeSuccess(t *testing.T) {
mockResult := &protocol.RPCResult{Rest: clusterpkg.Rest{Tried: 0, Success: true}}
forkingUrl.AddParam(constant.FORKS_KEY, strconv.Itoa(3))
- // forkingUrl.AddParam(constant.TIMEOUT_KEY, strconv.Itoa(constant.DEFAULT_TIMEOUT))
+ // forkingUrl.AddParam(constant.TimeoutKey, strconv.Itoa(constant.DEFAULT_TIMEOUT))
var wg sync.WaitGroup
wg.Add(2)
diff --git a/cluster/directory/base/directory.go b/cluster/directory/base/directory.go
index 52445fcb03..93dfcb6382 100644
--- a/cluster/directory/base/directory.go
+++ b/cluster/directory/base/directory.go
@@ -73,10 +73,10 @@ func (dir *Directory) GetDirectoryUrl() *common.URL {
}
func (dir *Directory) isProperRouter(url *common.URL) bool {
- app := url.GetParam(constant.APPLICATION_KEY, "")
- dirApp := dir.GetURL().GetParam(constant.APPLICATION_KEY, "")
+ app := url.GetParam(constant.ApplicationKey, "")
+ dirApp := dir.GetURL().GetParam(constant.ApplicationKey, "")
if len(dirApp) == 0 && dir.GetURL().SubURL != nil {
- dirApp = dir.GetURL().SubURL.GetParam(constant.APPLICATION_KEY, "")
+ dirApp = dir.GetURL().SubURL.GetParam(constant.ApplicationKey, "")
}
serviceKey := dir.GetURL().ServiceKey()
if len(serviceKey) == 0 {
diff --git a/cluster/directory/base/directory_test.go b/cluster/directory/base/directory_test.go
index 3e8c5c946e..731f042e75 100644
--- a/cluster/directory/base/directory_test.go
+++ b/cluster/directory/base/directory_test.go
@@ -47,7 +47,7 @@ func TestNewBaseDirectory(t *testing.T) {
func TestBuildRouterChain(t *testing.T) {
regURL := url
- regURL.AddParam(constant.INTERFACE_KEY, "mock-app")
+ regURL.AddParam(constant.InterfaceKey, "mock-app")
directory := NewDirectory(regURL)
var err error
directory.routerChain, err = chain.NewRouterChain()
@@ -64,43 +64,43 @@ func getRouteURL(rule string, u *common.URL) *common.URL {
func TestIsProperRouter(t *testing.T) {
regURL := url
- regURL.AddParam(constant.APPLICATION_KEY, "mock-app")
+ regURL.AddParam(constant.ApplicationKey, "mock-app")
d := NewDirectory(regURL)
localIP := common.GetLocalIp()
rule := base64.URLEncoding.EncodeToString([]byte("true => " + " host = " + localIP))
routeURL := getRouteURL(rule, anyURL)
- routeURL.AddParam(constant.APPLICATION_KEY, "mock-app")
+ routeURL.AddParam(constant.ApplicationKey, "mock-app")
rst := d.isProperRouter(routeURL)
assert.True(t, rst)
- regURL.AddParam(constant.APPLICATION_KEY, "")
- regURL.AddParam(constant.INTERFACE_KEY, "com.foo.BarService")
+ regURL.AddParam(constant.ApplicationKey, "")
+ regURL.AddParam(constant.InterfaceKey, "com.foo.BarService")
d = NewDirectory(regURL)
routeURL = getRouteURL(rule, anyURL)
- routeURL.AddParam(constant.INTERFACE_KEY, "com.foo.BarService")
+ routeURL.AddParam(constant.InterfaceKey, "com.foo.BarService")
rst = d.isProperRouter(routeURL)
assert.True(t, rst)
- regURL.AddParam(constant.APPLICATION_KEY, "")
- regURL.AddParam(constant.INTERFACE_KEY, "")
+ regURL.AddParam(constant.ApplicationKey, "")
+ regURL.AddParam(constant.InterfaceKey, "")
d = NewDirectory(regURL)
routeURL = getRouteURL(rule, anyURL)
rst = d.isProperRouter(routeURL)
assert.True(t, rst)
- regURL.SetParam(constant.APPLICATION_KEY, "")
- regURL.SetParam(constant.INTERFACE_KEY, "")
+ regURL.SetParam(constant.ApplicationKey, "")
+ regURL.SetParam(constant.InterfaceKey, "")
d = NewDirectory(regURL)
routeURL = getRouteURL(rule, anyURL)
- routeURL.AddParam(constant.APPLICATION_KEY, "mock-service")
+ routeURL.AddParam(constant.ApplicationKey, "mock-service")
rst = d.isProperRouter(routeURL)
assert.False(t, rst)
- regURL.SetParam(constant.APPLICATION_KEY, "")
- regURL.SetParam(constant.INTERFACE_KEY, "")
+ regURL.SetParam(constant.ApplicationKey, "")
+ regURL.SetParam(constant.InterfaceKey, "")
d = NewDirectory(regURL)
routeURL = getRouteURL(rule, anyURL)
- routeURL.AddParam(constant.INTERFACE_KEY, "mock-service")
+ routeURL.AddParam(constant.InterfaceKey, "mock-service")
rst = d.isProperRouter(routeURL)
assert.False(t, rst)
}
diff --git a/common/constant/default.go b/common/constant/default.go
index 91c6742e65..0081462304 100644
--- a/common/constant/default.go
+++ b/common/constant/default.go
@@ -53,9 +53,9 @@ const (
DEFAULT_KEY = "default"
PREFIX_DEFAULT_KEY = "default."
DEFAULT_SERVICE_FILTERS = EchoFilterKey + "," + MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," + GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey
- DEFAULT_REFERENCE_FILTERS = GracefulShutdownConsumerFilterKey
- GENERIC_REFERENCE_FILTERS = GenericFilterKey
- GENERIC = "$invoke"
+ DefaultReferenceFilters = GracefulShutdownConsumerFilterKey
+ GenericReferenceFilters = GenericFilterKey
+ GENERIC = "$invoke"
ECHO = "$echo"
)
diff --git a/common/constant/key.go b/common/constant/key.go
index d44542d94b..ffde1218c1 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -20,31 +20,31 @@ package constant
type DubboCtxKey string
const (
- ASYNC_KEY = "async" // it's value should be "true" or "false" of string type
+ AsyncKey = "async" // it's value should be "true" or "false" of string type
)
const (
- GROUP_KEY = "group"
- VERSION_KEY = "version"
- INTERFACE_KEY = "interface"
- MESSAGE_SIZE_KEY = "message_size"
+ GroupKey = "group"
+ VersionKey = "version"
+ InterfaceKey = "interface"
+ MESSAGE_SIZE_KEY = "message_size"
PATH_KEY = "path"
SERVICE_KEY = "service"
- METHODS_KEY = "methods"
- TIMEOUT_KEY = "timeout"
- CATEGORY_KEY = "category"
+ METHODS_KEY = "methods"
+ TimeoutKey = "timeout"
+ CATEGORY_KEY = "category"
CHECK_KEY = "check"
- ENABLED_KEY = "enabled"
- SIDE_KEY = "side"
- OVERRIDE_PROVIDERS_KEY = "providerAddresses"
- BEAN_NAME_KEY = "bean.name"
- GENERIC_KEY = "generic"
- CLASSIFIER_KEY = "classifier"
+ ENABLED_KEY = "enabled"
+ SideKey = "side"
+ OVERRIDE_PROVIDERS_KEY = "providerAddresses"
+ BeanNameKey = "bean.name"
+ GenericKey = "generic"
+ CLASSIFIER_KEY = "classifier"
TOKEN_KEY = "token"
LOCAL_ADDR = "local-addr"
REMOTE_ADDR = "remote-addr"
DEFAULT_REMOTING_TIMEOUT = 3000
- RELEASE_KEY = "release"
+ ReleaseKey = "release"
ANYHOST_KEY = "anyhost"
PORT_KEY = "port"
PROTOCOL_KEY = "protocol"
@@ -54,13 +54,13 @@ const (
SSL_ENABLED_KEY = "ssl-enabled"
// PARAMS_TYPE_Key key used in pass through invoker factory, to define param type
PARAMS_TYPE_Key = "parameter-type-names"
- DEFAULT_Key = "default"
- METADATATYPE_KEY = "metadata-type"
+ DEFAULT_Key = "default"
+ MetadatatypeKey = "metadata-type"
)
const (
- SERVICE_FILTER_KEY = "service.filter"
- REFERENCE_FILTER_KEY = "reference.filter"
+ SERVICE_FILTER_KEY = "service.filter"
+ ReferenceFilterKey = "reference.filter"
)
// Filter Keys
@@ -88,15 +88,15 @@ const (
)
const (
- TIMESTAMP_KEY = "timestamp"
- REMOTE_TIMESTAMP_KEY = "remote.timestamp"
- CLUSTER_KEY = "cluster"
- LOADBALANCE_KEY = "loadbalance"
- WEIGHT_KEY = "weight"
- WARMUP_KEY = "warmup"
- RETRIES_KEY = "retries"
- STICKY_KEY = "sticky"
- BEAN_NAME = "bean.name"
+ TimestampKey = "timestamp"
+ REMOTE_TIMESTAMP_KEY = "remote.timestamp"
+ ClusterKey = "cluster"
+ LoadbalanceKey = "loadbalance"
+ WEIGHT_KEY = "weight"
+ WARMUP_KEY = "warmup"
+ RetriesKey = "retries"
+ StickyKey = "sticky"
+ BEAN_NAME = "bean.name"
FAIL_BACK_TASKS_KEY = "failbacktasks"
FORKS_KEY = "forks"
DEFAULT_FORKS = 2
@@ -111,7 +111,7 @@ const (
EXECUTE_LIMIT_KEY = "execute.limit"
DEFAULT_EXECUTE_LIMIT = "-1"
EXECUTE_REJECTED_EXECUTION_HANDLER_KEY = "execute.limit.rejected.handler"
- SERIALIZATION_KEY = "serialization"
+ SerializationKey = "serialization"
PID_KEY = "pid"
SYNC_REPORT_KEY = "sync.report"
RETRY_PERIOD_KEY = "retry.period"
@@ -126,9 +126,9 @@ const (
const (
REGISTRY_KEY = "registry"
- REGISTRY_PROTOCOL = "registry"
- SERVICE_REGISTRY_PROTOCOL = "service-discovery-registry"
- ROLE_KEY = "registry.role"
+ RegistryProtocol = "registry"
+ ServiceRegistryProtocol = "service-discovery-registry"
+ RoleKey = "registry.role"
REGISTRY_DEFAULT_KEY = "registry.default"
REGISTRY_TIMEOUT_KEY = "registry.timeout"
REGISTRY_LABEL_KEY = "label"
@@ -142,14 +142,14 @@ const (
)
const (
- APPLICATION_KEY = "application"
- ORGANIZATION_KEY = "organization"
- NAME_KEY = "name"
- MODULE_KEY = "module"
- APP_VERSION_KEY = "app.version"
- OWNER_KEY = "owner"
- ENVIRONMENT_KEY = "environment"
- METHOD_KEY = "method"
+ ApplicationKey = "application"
+ OrganizationKey = "organization"
+ NameKey = "name"
+ ModuleKey = "module"
+ AppVersionKey = "app.version"
+ OwnerKey = "owner"
+ EnvironmentKey = "environment"
+ METHOD_KEY = "method"
METHOD_KEYS = "methods"
RULE_KEY = "rule"
RUNTIME_KEY = "runtime"
@@ -307,9 +307,9 @@ const (
// service discovery
const (
- SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services"
- PROVIDED_BY = "provided-by"
- EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.metadata.revision"
+ SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services"
+ ProvidedBy = "provided-by"
+ EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.metadata.revision"
SUBSCRIBED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.subscribed-services.revision"
SERVICE_INSTANCE_SELECTOR = "service-instance-selector"
METADATA_STORAGE_TYPE_PROPERTY_NAME = "dubbo.metadata.storage-type"
diff --git a/common/metadata_info.go b/common/metadata_info.go
index 9c43f69bef..123598ac2c 100644
--- a/common/metadata_info.go
+++ b/common/metadata_info.go
@@ -34,19 +34,19 @@ import (
)
var IncludeKeys = gxset.NewSet(
- constant.APPLICATION_KEY,
- constant.GROUP_KEY,
- constant.TIMESTAMP_KEY,
- constant.SERIALIZATION_KEY,
- constant.CLUSTER_KEY,
- constant.LOADBALANCE_KEY,
+ constant.ApplicationKey,
+ constant.GroupKey,
+ constant.TimestampKey,
+ constant.SerializationKey,
+ constant.ClusterKey,
+ constant.LoadbalanceKey,
constant.PATH_KEY,
- constant.TIMEOUT_KEY,
+ constant.TimeoutKey,
constant.TOKEN_KEY,
- constant.VERSION_KEY,
+ constant.VersionKey,
constant.WARMUP_KEY,
constant.WEIGHT_KEY,
- constant.RELEASE_KEY)
+ constant.ReleaseKey)
// MetadataInfo the metadata information of instance
type MetadataInfo struct {
diff --git a/common/proxy/proxy_factory/default.go b/common/proxy/proxy_factory/default.go
index f76bc38dd3..2e1816bb50 100644
--- a/common/proxy/proxy_factory/default.go
+++ b/common/proxy/proxy_factory/default.go
@@ -66,7 +66,7 @@ func (factory *DefaultProxyFactory) GetProxy(invoker protocol.Invoker, url *comm
func (factory *DefaultProxyFactory) GetAsyncProxy(invoker protocol.Invoker, callBack interface{}, url *common.URL) *proxy.Proxy {
// create proxy
attachments := map[string]string{}
- attachments[constant.ASYNC_KEY] = url.GetParam(constant.ASYNC_KEY, "false")
+ attachments[constant.AsyncKey] = url.GetParam(constant.AsyncKey, "false")
return proxy.NewProxy(invoker, callBack, attachments)
}
diff --git a/common/proxy/proxy_factory/pass_through.go b/common/proxy/proxy_factory/pass_through.go
index d237d9937a..cc854cf18f 100644
--- a/common/proxy/proxy_factory/pass_through.go
+++ b/common/proxy/proxy_factory/pass_through.go
@@ -56,7 +56,7 @@ func (factory *PassThroughProxyFactory) GetProxy(invoker protocol.Invoker, url *
func (factory *PassThroughProxyFactory) GetAsyncProxy(invoker protocol.Invoker, callBack interface{}, url *common.URL) *proxy.Proxy {
//create proxy
attachments := map[string]string{}
- attachments[constant.ASYNC_KEY] = url.GetParam(constant.ASYNC_KEY, "false")
+ attachments[constant.AsyncKey] = url.GetParam(constant.AsyncKey, "false")
return proxy.NewProxy(invoker, callBack, attachments)
}
diff --git a/common/proxy/proxy_test.go b/common/proxy/proxy_test.go
index e9bacd664e..835e42121f 100644
--- a/common/proxy/proxy_test.go
+++ b/common/proxy/proxy_test.go
@@ -60,7 +60,7 @@ func (s *TestServiceInt) Reference() string {
func TestProxyImplement(t *testing.T) {
invoker := protocol.NewBaseInvoker(&common.URL{})
- p := NewProxy(invoker, nil, map[string]string{constant.ASYNC_KEY: "false"})
+ p := NewProxy(invoker, nil, map[string]string{constant.AsyncKey: "false"})
s := &TestService{}
p.Implement(s)
@@ -128,7 +128,7 @@ func TestProxyImplementForContext(t *testing.T) {
invoker := &TestProxyInvoker{
BaseInvoker: *protocol.NewBaseInvoker(&common.URL{}),
}
- p := NewProxy(invoker, nil, map[string]string{constant.ASYNC_KEY: "false"})
+ p := NewProxy(invoker, nil, map[string]string{constant.AsyncKey: "false"})
s := &TestService{}
p.Implement(s)
attachments1 := make(map[string]interface{}, 4)
diff --git a/common/url.go b/common/url.go
index fc618ea7cf..1eda3c80fb 100644
--- a/common/url.go
+++ b/common/url.go
@@ -48,8 +48,8 @@ import (
// dubbo role type constant
const (
- // CONSUMER is consumer role
- CONSUMER = iota
+ // Consumer is consumer role
+ Consumer = iota
// CONFIGURATOR is configurator role
CONFIGURATOR
// ROUTER is router role
@@ -287,12 +287,12 @@ func MatchKey(serviceKey string, protocol string) string {
// Group get group
func (c *URL) Group() string {
- return c.GetParam(constant.GROUP_KEY, "")
+ return c.GetParam(constant.GroupKey, "")
}
// Version get group
func (c *URL) Version() string {
- return c.GetParam(constant.VERSION_KEY, "")
+ return c.GetParam(constant.VersionKey, "")
}
// URLEqual judge @URL and @c is equal or not.
@@ -305,8 +305,8 @@ func (c *URL) URLEqual(url *URL) bool {
tmpURL.Ip = ""
tmpURL.Port = ""
- cGroup := tmpC.GetParam(constant.GROUP_KEY, "")
- urlGroup := tmpURL.GetParam(constant.GROUP_KEY, "")
+ cGroup := tmpC.GetParam(constant.GroupKey, "")
+ urlGroup := tmpURL.GetParam(constant.GroupKey, "")
cKey := tmpC.Key()
urlKey := tmpURL.Key()
@@ -358,7 +358,7 @@ func (c *URL) String() string {
// Key gets key
func (c *URL) Key() string {
buildString := fmt.Sprintf("%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s",
- c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, ""))
+ c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GroupKey, ""), c.GetParam(constant.VersionKey, ""))
return buildString
}
@@ -367,15 +367,15 @@ func (c *URL) GetCacheInvokerMapKey() string {
urlNew, _ := NewURL(c.PrimitiveURL)
buildString := fmt.Sprintf("%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s×tamp=%s",
- c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GROUP_KEY, ""),
- c.GetParam(constant.VERSION_KEY, ""), urlNew.GetParam(constant.TIMESTAMP_KEY, ""))
+ c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GroupKey, ""),
+ c.GetParam(constant.VersionKey, ""), urlNew.GetParam(constant.TimestampKey, ""))
return buildString
}
// ServiceKey gets a unique key of a service.
func (c *URL) ServiceKey() string {
- return ServiceKey(c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/")),
- c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, ""))
+ return ServiceKey(c.GetParam(constant.InterfaceKey, strings.TrimPrefix(c.Path, "/")),
+ c.GetParam(constant.GroupKey, ""), c.GetParam(constant.VersionKey, ""))
}
func ServiceKey(intf string, group string, version string) string {
@@ -401,18 +401,18 @@ func ServiceKey(intf string, group string, version string) string {
// ColonSeparatedKey
// The format is "{interface}:[version]:[group]"
func (c *URL) ColonSeparatedKey() string {
- intf := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
+ intf := c.GetParam(constant.InterfaceKey, strings.TrimPrefix(c.Path, "/"))
if intf == "" {
return ""
}
var buf strings.Builder
buf.WriteString(intf)
buf.WriteString(":")
- version := c.GetParam(constant.VERSION_KEY, "")
+ version := c.GetParam(constant.VersionKey, "")
if version != "" && version != "0.0.0" {
buf.WriteString(version)
}
- group := c.GetParam(constant.GROUP_KEY, "")
+ group := c.GetParam(constant.GroupKey, "")
buf.WriteString(":")
if group != "" {
buf.WriteString(group)
@@ -428,11 +428,11 @@ func (c *URL) EncodedServiceKey() string {
// Service gets service
func (c *URL) Service() string {
- service := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
+ service := c.GetParam(constant.InterfaceKey, strings.TrimPrefix(c.Path, "/"))
if service != "" {
return service
} else if c.SubURL != nil {
- service = c.SubURL.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
+ service = c.SubURL.GetParam(constant.InterfaceKey, strings.TrimPrefix(c.Path, "/"))
if service != "" { // if URL.path is "" then return suburl's path, special for registry URL
return service
}
@@ -701,12 +701,12 @@ func MergeURL(serviceURL *URL, referenceURL *URL) *URL {
}
// loadBalance,cluster,retries strategy config
- methodConfigMergeFcn := mergeNormalParam(params, referenceURL, []string{constant.LOADBALANCE_KEY, constant.CLUSTER_KEY, constant.RETRIES_KEY, constant.TIMEOUT_KEY})
+ methodConfigMergeFcn := mergeNormalParam(params, referenceURL, []string{constant.LoadbalanceKey, constant.ClusterKey, constant.RetriesKey, constant.TimeoutKey})
// remote timestamp
- if v := serviceURL.GetParam(constant.TIMESTAMP_KEY, ""); len(v) > 0 {
+ if v := serviceURL.GetParam(constant.TimestampKey, ""); len(v) > 0 {
params[constant.REMOTE_TIMESTAMP_KEY] = []string{v}
- params[constant.TIMESTAMP_KEY] = []string{referenceURL.GetParam(constant.TIMESTAMP_KEY, "")}
+ params[constant.TimestampKey] = []string{referenceURL.GetParam(constant.TimestampKey, "")}
}
// finally execute methodConfigMergeFcn
diff --git a/common/url_test.go b/common/url_test.go
index ba5092a3c8..38254bac0f 100644
--- a/common/url_test.go
+++ b/common/url_test.go
@@ -306,24 +306,24 @@ func TestURLGetMethodParamBool(t *testing.T) {
func TestMergeUrl(t *testing.T) {
referenceUrlParams := url.Values{}
- referenceUrlParams.Set(constant.CLUSTER_KEY, "random")
- referenceUrlParams.Set(constant.RETRIES_KEY, "1")
+ referenceUrlParams.Set(constant.ClusterKey, "random")
+ referenceUrlParams.Set(constant.RetriesKey, "1")
referenceUrlParams.Set("test3", "1")
- referenceUrlParams.Set("methods.testMethod."+constant.RETRIES_KEY, "1")
+ referenceUrlParams.Set("methods.testMethod."+constant.RetriesKey, "1")
serviceUrlParams := url.Values{}
serviceUrlParams.Set("test2", "1")
- serviceUrlParams.Set(constant.CLUSTER_KEY, "roundrobin")
- serviceUrlParams.Set(constant.RETRIES_KEY, "2")
- serviceUrlParams.Set(constant.METHOD_KEYS+".testMethod."+constant.RETRIES_KEY, "2")
+ serviceUrlParams.Set(constant.ClusterKey, "roundrobin")
+ serviceUrlParams.Set(constant.RetriesKey, "2")
+ serviceUrlParams.Set(constant.METHOD_KEYS+".testMethod."+constant.RetriesKey, "2")
referenceUrl, _ := NewURL("mock1://127.0.0.1:1111", WithParams(referenceUrlParams), WithMethods([]string{"testMethod"}))
serviceUrl, _ := NewURL("mock2://127.0.0.1:20000", WithParams(serviceUrlParams))
mergedUrl := MergeURL(serviceUrl, referenceUrl)
- assert.Equal(t, "random", mergedUrl.GetParam(constant.CLUSTER_KEY, ""))
+ assert.Equal(t, "random", mergedUrl.GetParam(constant.ClusterKey, ""))
assert.Equal(t, "1", mergedUrl.GetParam("test2", ""))
assert.Equal(t, "1", mergedUrl.GetParam("test3", ""))
- assert.Equal(t, "1", mergedUrl.GetParam(constant.RETRIES_KEY, ""))
- assert.Equal(t, "2", mergedUrl.GetParam(constant.METHOD_KEYS+".testMethod."+constant.RETRIES_KEY, ""))
+ assert.Equal(t, "1", mergedUrl.GetParam(constant.RetriesKey, ""))
+ assert.Equal(t, "2", mergedUrl.GetParam(constant.METHOD_KEYS+".testMethod."+constant.RetriesKey, ""))
}
func TestURLSetParams(t *testing.T) {
@@ -359,15 +359,15 @@ func TestClone(t *testing.T) {
func TestColonSeparatedKey(t *testing.T) {
u1, _ := NewURL("dubbo://127.0.0.1:20000")
- u1.AddParam(constant.INTERFACE_KEY, "com.ikurento.user.UserProvider")
-
- assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.INTERFACE_KEY, "")+"::")
- u1.AddParam(constant.VERSION_KEY, "version1")
- assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.INTERFACE_KEY, "")+":version1:")
- u1.AddParam(constant.GROUP_KEY, "group1")
- assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.INTERFACE_KEY, "")+":version1:group1")
- u1.SetParam(constant.VERSION_KEY, "")
- assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.INTERFACE_KEY, "")+"::group1")
+ u1.AddParam(constant.InterfaceKey, "com.ikurento.user.UserProvider")
+
+ assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.InterfaceKey, "")+"::")
+ u1.AddParam(constant.VersionKey, "version1")
+ assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.InterfaceKey, "")+":version1:")
+ u1.AddParam(constant.GroupKey, "group1")
+ assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.InterfaceKey, "")+":version1:group1")
+ u1.SetParam(constant.VersionKey, "")
+ assert.Equal(t, u1.ColonSeparatedKey(), u1.GetParam(constant.InterfaceKey, "")+"::group1")
}
func TestCompareURLEqualFunc(t *testing.T) {
@@ -383,7 +383,7 @@ func TestCompareURLEqualFunc(t *testing.T) {
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000×tamp=155650979798")
assert.False(t, GetCompareURLEqualFunc()(url1, url2))
- assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
+ assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TimestampKey, constant.REMOTE_TIMESTAMP_KEY))
// test custom
url1, _ = NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
@@ -396,10 +396,10 @@ func TestCompareURLEqualFunc(t *testing.T) {
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000×tamp=155650979798")
- assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
+ assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TimestampKey, constant.REMOTE_TIMESTAMP_KEY))
SetCompareURLEqualFunc(CustomCompareURLEqual)
assert.False(t, GetCompareURLEqualFunc()(url1, url2))
- assert.False(t, GetCompareURLEqualFunc()(url1, url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
+ assert.False(t, GetCompareURLEqualFunc()(url1, url2, constant.TimestampKey, constant.REMOTE_TIMESTAMP_KEY))
url1, _ = NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
@@ -412,10 +412,10 @@ func TestCompareURLEqualFunc(t *testing.T) {
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000")
assert.True(t, GetCompareURLEqualFunc()(url1, url2))
- assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
+ assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TimestampKey, constant.REMOTE_TIMESTAMP_KEY))
SetCompareURLEqualFunc(CustomCompareURLEqual)
assert.True(t, GetCompareURLEqualFunc()(url1, url2))
- assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
+ assert.True(t, GetCompareURLEqualFunc()(url1, url2, constant.TimestampKey, constant.REMOTE_TIMESTAMP_KEY))
}
func CustomCompareURLEqual(l *URL, r *URL, execludeParam ...string) bool {
diff --git a/config/metadata_report_config.go b/config/metadata_report_config.go
index f5740d19ae..4d4e03c370 100644
--- a/config/metadata_report_config.go
+++ b/config/metadata_report_config.go
@@ -59,7 +59,7 @@ func (mc *MetadataReportConfig) ToUrl() (*common.URL, error) {
common.WithPassword(mc.Password),
common.WithLocation(mc.Address),
common.WithProtocol(mc.Protocol),
- common.WithParamsValue(constant.METADATATYPE_KEY, mc.MetadataType),
+ common.WithParamsValue(constant.MetadatatypeKey, mc.MetadataType),
)
if err != nil || len(res.Protocol) == 0 {
return nil, perrors.New("Invalid MetadataReport Config.")
@@ -92,7 +92,7 @@ func publishServiceDefinition(url *common.URL) {
return
}
localService.PublishServiceDefinition(url)
- if url.GetParam(constant.METADATATYPE_KEY, "") != constant.REMOTE_METADATA_STORAGE_TYPE {
+ if url.GetParam(constant.MetadatatypeKey, "") != constant.REMOTE_METADATA_STORAGE_TYPE {
return
}
if remoteMetadataService, err := extension.GetRemoteMetadataService(); err == nil && remoteMetadataService != nil {
diff --git a/config/reference_config.go b/config/reference_config.go
index c338e44e2f..a762818d4c 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -72,7 +72,6 @@ type ReferenceConfig struct {
metaDataType string
}
-// nolint
func (rc *ReferenceConfig) Prefix() string {
return constant.ReferenceConfigPrefix + rc.InterfaceName + "."
}
@@ -100,16 +99,24 @@ func (rc *ReferenceConfig) Init(root *RootConfig) error {
return verify(rc)
}
-// Refer ...
+// Refer retrieves invokers from urls.
func (rc *ReferenceConfig) Refer(srv interface{}) {
+ // If adaptive service is enabled,
+ // the cluster and load balance should be overridden to "adasvc" and "p2c" respectively.
+ if rc.rootConfig.Consumer.AdaptiveService {
+ rc.Cluster = constant.ClusterKeyAdaptiveService
+ rc.Loadbalance = constant.LoadBalanceKeyP2C
+ }
+
// cfgURL is an interface-level invoker url, in the other words, it represents an interface.
cfgURL := common.NewURLWithOptions(
common.WithPath(rc.InterfaceName),
common.WithProtocol(rc.Protocol),
common.WithParams(rc.getURLMap()),
- common.WithParamsValue(constant.BEAN_NAME_KEY, rc.id),
- common.WithParamsValue(constant.METADATATYPE_KEY, rc.metaDataType),
+ common.WithParamsValue(constant.BeanNameKey, rc.id),
+ common.WithParamsValue(constant.MetadatatypeKey, rc.metaDataType),
)
+
SetConsumerServiceByInterfaceName(rc.InterfaceName, srv)
if rc.ForceTag {
cfgURL.AddParam(constant.ForceUseTag, "true")
@@ -135,7 +142,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
if err != nil {
panic(fmt.Sprintf("url configuration error, please check your configuration, user specified URL %v refer error, error message is %v ", urlStr, err.Error()))
}
- if serviceURL.Protocol == constant.REGISTRY_PROTOCOL { // serviceURL in this branch is a registry protocol
+ if serviceURL.Protocol == constant.RegistryProtocol { // serviceURL in this branch is a registry protocol
serviceURL.SubURL = cfgURL
rc.urls = append(rc.urls, serviceURL)
} else { // serviceURL in this branch is the target endpoint IP address
@@ -149,7 +156,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
}
}
} else { // use registry configs
- rc.urls = loadRegistries(rc.RegistryIDs, rc.rootConfig.Registries, common.CONSUMER)
+ rc.urls = loadRegistries(rc.RegistryIDs, rc.rootConfig.Registries, common.Consumer)
// set url to regURLs
for _, regURL := range rc.urls {
regURL.SubURL = cfgURL
@@ -163,18 +170,18 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
)
invokers := make([]protocol.Invoker, len(rc.urls))
for i, u := range rc.urls {
- if u.Protocol == constant.SERVICE_REGISTRY_PROTOCOL {
+ if u.Protocol == constant.ServiceRegistryProtocol {
invoker = extension.GetProtocol("registry").Refer(u)
} else {
invoker = extension.GetProtocol(u.Protocol).Refer(u)
}
if rc.URL != "" {
- invoker = protocolwrapper.BuildInvokerChain(invoker, constant.REFERENCE_FILTER_KEY)
+ invoker = protocolwrapper.BuildInvokerChain(invoker, constant.ReferenceFilterKey)
}
invokers[i] = invoker
- if u.Protocol == constant.REGISTRY_PROTOCOL {
+ if u.Protocol == constant.RegistryProtocol {
regURL = u
}
}
@@ -185,7 +192,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
if rc.URL != "" {
hitClu := constant.ClusterKeyFailover
if u := rc.invoker.GetURL(); u != nil {
- hitClu = u.GetParam(constant.CLUSTER_KEY, constant.ClusterKeyZoneAware)
+ hitClu = u.GetParam(constant.ClusterKey, constant.ClusterKeyZoneAware)
}
rc.invoker = extension.GetCluster(hitClu).Join(static.NewDirectory(invokers))
}
@@ -198,7 +205,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
// not a registry url, must be direct invoke.
hitClu = constant.ClusterKeyFailover
if u := invokers[0].GetURL(); u != nil {
- hitClu = u.GetParam(constant.CLUSTER_KEY, constant.ClusterKeyZoneAware)
+ hitClu = u.GetParam(constant.ClusterKey, constant.ClusterKeyZoneAware)
}
}
rc.invoker = extension.GetCluster(hitClu).Join(static.NewDirectory(invokers))
@@ -237,50 +244,50 @@ func (rc *ReferenceConfig) getURLMap() url.Values {
for k, v := range rc.Params {
urlMap.Set(k, v)
}
- urlMap.Set(constant.INTERFACE_KEY, rc.InterfaceName)
- urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10))
- urlMap.Set(constant.CLUSTER_KEY, rc.Cluster)
- urlMap.Set(constant.LOADBALANCE_KEY, rc.Loadbalance)
- urlMap.Set(constant.RETRIES_KEY, rc.Retries)
- urlMap.Set(constant.GROUP_KEY, rc.Group)
- urlMap.Set(constant.VERSION_KEY, rc.Version)
- urlMap.Set(constant.GENERIC_KEY, rc.Generic)
- urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
- urlMap.Set(constant.PROVIDED_BY, rc.ProvidedBy)
- urlMap.Set(constant.SERIALIZATION_KEY, rc.Serialization)
-
- urlMap.Set(constant.RELEASE_KEY, "dubbo-golang-"+constant.Version)
- urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.CONSUMER)).Role())
+ urlMap.Set(constant.InterfaceKey, rc.InterfaceName)
+ urlMap.Set(constant.TimestampKey, strconv.FormatInt(time.Now().Unix(), 10))
+ urlMap.Set(constant.ClusterKey, rc.Cluster)
+ urlMap.Set(constant.LoadbalanceKey, rc.Loadbalance)
+ urlMap.Set(constant.RetriesKey, rc.Retries)
+ urlMap.Set(constant.GroupKey, rc.Group)
+ urlMap.Set(constant.VersionKey, rc.Version)
+ urlMap.Set(constant.GenericKey, rc.Generic)
+ urlMap.Set(constant.RoleKey, strconv.Itoa(common.Consumer))
+ urlMap.Set(constant.ProvidedBy, rc.ProvidedBy)
+ urlMap.Set(constant.SerializationKey, rc.Serialization)
+
+ urlMap.Set(constant.ReleaseKey, "dubbo-golang-"+constant.Version)
+ urlMap.Set(constant.SideKey, (common.RoleType(common.Consumer)).Role())
if len(rc.RequestTimeout) != 0 {
- urlMap.Set(constant.TIMEOUT_KEY, rc.RequestTimeout)
+ urlMap.Set(constant.TimeoutKey, rc.RequestTimeout)
}
// getty invoke async or sync
- urlMap.Set(constant.ASYNC_KEY, strconv.FormatBool(rc.Async))
- urlMap.Set(constant.STICKY_KEY, strconv.FormatBool(rc.Sticky))
+ urlMap.Set(constant.AsyncKey, strconv.FormatBool(rc.Async))
+ urlMap.Set(constant.StickyKey, strconv.FormatBool(rc.Sticky))
// applicationConfig info
- urlMap.Set(constant.APPLICATION_KEY, rc.rootConfig.Application.Name)
- urlMap.Set(constant.ORGANIZATION_KEY, rc.rootConfig.Application.Organization)
- urlMap.Set(constant.NAME_KEY, rc.rootConfig.Application.Name)
- urlMap.Set(constant.MODULE_KEY, rc.rootConfig.Application.Module)
- urlMap.Set(constant.APP_VERSION_KEY, rc.rootConfig.Application.Version)
- urlMap.Set(constant.OWNER_KEY, rc.rootConfig.Application.Owner)
- urlMap.Set(constant.ENVIRONMENT_KEY, rc.rootConfig.Application.Environment)
+ urlMap.Set(constant.ApplicationKey, rc.rootConfig.Application.Name)
+ urlMap.Set(constant.OrganizationKey, rc.rootConfig.Application.Organization)
+ urlMap.Set(constant.NameKey, rc.rootConfig.Application.Name)
+ urlMap.Set(constant.ModuleKey, rc.rootConfig.Application.Module)
+ urlMap.Set(constant.AppVersionKey, rc.rootConfig.Application.Version)
+ urlMap.Set(constant.OwnerKey, rc.rootConfig.Application.Owner)
+ urlMap.Set(constant.EnvironmentKey, rc.rootConfig.Application.Environment)
// filter
- defaultReferenceFilter := constant.DEFAULT_REFERENCE_FILTERS
+ defaultReferenceFilter := constant.DefaultReferenceFilters
if rc.Generic != "" {
- defaultReferenceFilter = constant.GENERIC_REFERENCE_FILTERS + "," + defaultReferenceFilter
+ defaultReferenceFilter = constant.GenericReferenceFilters + "," + defaultReferenceFilter
}
- urlMap.Set(constant.REFERENCE_FILTER_KEY, mergeValue(rc.rootConfig.Consumer.Filter, "", defaultReferenceFilter))
+ urlMap.Set(constant.ReferenceFilterKey, mergeValue(rc.rootConfig.Consumer.Filter, "", defaultReferenceFilter))
for _, v := range rc.Methods {
- urlMap.Set("methods."+v.Name+"."+constant.LOADBALANCE_KEY, v.LoadBalance)
- urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, v.Retries)
- urlMap.Set("methods."+v.Name+"."+constant.STICKY_KEY, strconv.FormatBool(v.Sticky))
+ urlMap.Set("methods."+v.Name+"."+constant.LoadbalanceKey, v.LoadBalance)
+ urlMap.Set("methods."+v.Name+"."+constant.RetriesKey, v.Retries)
+ urlMap.Set("methods."+v.Name+"."+constant.StickyKey, strconv.FormatBool(v.Sticky))
if len(v.RequestTimeout) != 0 {
- urlMap.Set("methods."+v.Name+"."+constant.TIMEOUT_KEY, v.RequestTimeout)
+ urlMap.Set("methods."+v.Name+"."+constant.TimeoutKey, v.RequestTimeout)
}
}
diff --git a/config/registry_config.go b/config/registry_config.go
index 51e3539076..203bd3520d 100644
--- a/config/registry_config.go
+++ b/config/registry_config.go
@@ -73,8 +73,8 @@ func (c *RegistryConfig) Init() error {
func (c *RegistryConfig) getUrlMap(roleType common.RoleType) url.Values {
urlMap := url.Values{}
- urlMap.Set(constant.GROUP_KEY, c.Group)
- urlMap.Set(constant.ROLE_KEY, strconv.Itoa(int(roleType)))
+ urlMap.Set(constant.GroupKey, c.Group)
+ urlMap.Set(constant.RoleKey, strconv.Itoa(int(roleType)))
urlMap.Set(constant.REGISTRY_KEY, c.Protocol)
urlMap.Set(constant.REGISTRY_TIMEOUT_KEY, c.Timeout)
// multi registry invoker weight label for load balance
@@ -110,7 +110,7 @@ func (c *RegistryConfig) GetInstance(roleType common.RoleType) (registry.Registr
return nil, err
}
// if the protocol == registry, set protocol the registry value in url.params
- if u.Protocol == constant.REGISTRY_PROTOCOL {
+ if u.Protocol == constant.RegistryProtocol {
u.Protocol = u.GetParam(constant.REGISTRY_KEY, "")
}
return extension.GetRegistry(u.Protocol, u)
@@ -121,15 +121,15 @@ func (c *RegistryConfig) toURL(roleType common.RoleType) (*common.URL, error) {
var registryURLProtocol string
if c.RegistryType == "service" {
// service discovery protocol
- registryURLProtocol = constant.SERVICE_REGISTRY_PROTOCOL
+ registryURLProtocol = constant.ServiceRegistryProtocol
} else {
- registryURLProtocol = constant.REGISTRY_PROTOCOL
+ registryURLProtocol = constant.RegistryProtocol
}
return common.NewURL(registryURLProtocol+"://"+address,
common.WithParams(c.getUrlMap(roleType)),
common.WithParamsValue(constant.SIMPLIFIED_KEY, strconv.FormatBool(c.Simplified)),
common.WithParamsValue(constant.REGISTRY_KEY, c.Protocol),
- common.WithParamsValue(constant.GROUP_KEY, c.Group),
+ common.WithParamsValue(constant.GroupKey, c.Group),
common.WithParamsValue(constant.NAMESPACE_KEY, c.Namespace),
common.WithUsername(c.Username),
common.WithPassword(c.Password),
diff --git a/config/registry_config_test.go b/config/registry_config_test.go
index d9c5521d02..7e94e7171e 100644
--- a/config/registry_config_test.go
+++ b/config/registry_config_test.go
@@ -41,7 +41,7 @@ func TestLoadRegistries(t *testing.T) {
Password: "pwd1",
},
}
- urls := loadRegistries(target, regs, common.CONSUMER)
+ urls := loadRegistries(target, regs, common.Consumer)
t.Logf("loadRegistries() = urls:%v", urls)
assert.Equal(t, "127.0.0.2:2181,128.0.0.1:2181", urls[0].Location)
}
@@ -59,7 +59,7 @@ func TestLoadRegistries1(t *testing.T) {
Password: "pwd1",
},
}
- urls := loadRegistries(target, regs, common.CONSUMER)
+ urls := loadRegistries(target, regs, common.Consumer)
t.Logf("loadRegistries() = urls:%v", urls)
assert.Equal(t, "127.0.0.2:2181", urls[0].Location)
}
diff --git a/config/service_config.go b/config/service_config.go
index da08a2ab7a..9d51f16f77 100644
--- a/config/service_config.go
+++ b/config/service_config.go
@@ -192,11 +192,11 @@ func (svc *ServiceConfig) Export() error {
common.WithIp(proto.Ip),
common.WithPort(port),
common.WithParams(urlMap),
- common.WithParamsValue(constant.BEAN_NAME_KEY, svc.id),
+ common.WithParamsValue(constant.BeanNameKey, svc.id),
//common.WithParamsValue(constant.SSL_ENABLED_KEY, strconv.FormatBool(config.GetSslEnabled())),
common.WithMethods(strings.Split(methods, ",")),
common.WithToken(svc.Token),
- common.WithParamsValue(constant.METADATATYPE_KEY, svc.metadataType),
+ common.WithParamsValue(constant.MetadatatypeKey, svc.metadataType),
)
if len(svc.Tag) > 0 {
ivkURL.AddParam(constant.Tagkey, svc.Tag)
@@ -227,7 +227,7 @@ func (svc *ServiceConfig) Export() error {
svc.exporters = append(svc.exporters, exporter)
}
} else {
- if ivkURL.GetParam(constant.INTERFACE_KEY, "") == constant.METADATA_SERVICE_NAME {
+ if ivkURL.GetParam(constant.InterfaceKey, "") == constant.METADATA_SERVICE_NAME {
ms, err := extension.GetLocalMetadataService("")
if err != nil {
logger.Warnf("export org.apache.dubbo.metadata.MetadataService failed beacause of %s ! pls check if you import _ \"dubbo.apache.org/dubbo-go/v3/metadata/service/local\"", err)
@@ -331,29 +331,29 @@ func (svc *ServiceConfig) getUrlMap() url.Values {
for k, v := range svc.Params {
urlMap.Set(k, v)
}
- urlMap.Set(constant.INTERFACE_KEY, svc.Interface)
- urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10))
- urlMap.Set(constant.CLUSTER_KEY, svc.Cluster)
- urlMap.Set(constant.LOADBALANCE_KEY, svc.Loadbalance)
+ urlMap.Set(constant.InterfaceKey, svc.Interface)
+ urlMap.Set(constant.TimestampKey, strconv.FormatInt(time.Now().Unix(), 10))
+ urlMap.Set(constant.ClusterKey, svc.Cluster)
+ urlMap.Set(constant.LoadbalanceKey, svc.Loadbalance)
urlMap.Set(constant.WARMUP_KEY, svc.Warmup)
- urlMap.Set(constant.RETRIES_KEY, svc.Retries)
- urlMap.Set(constant.GROUP_KEY, svc.Group)
- urlMap.Set(constant.VERSION_KEY, svc.Version)
- urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
- urlMap.Set(constant.RELEASE_KEY, "dubbo-golang-"+constant.Version)
- urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.PROVIDER)).Role())
+ urlMap.Set(constant.RetriesKey, svc.Retries)
+ urlMap.Set(constant.GroupKey, svc.Group)
+ urlMap.Set(constant.VersionKey, svc.Version)
+ urlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
+ urlMap.Set(constant.ReleaseKey, "dubbo-golang-"+constant.Version)
+ urlMap.Set(constant.SideKey, (common.RoleType(common.PROVIDER)).Role())
urlMap.Set(constant.MESSAGE_SIZE_KEY, strconv.Itoa(svc.GrpcMaxMessageSize))
// todo: move
- urlMap.Set(constant.SERIALIZATION_KEY, svc.Serialization)
+ urlMap.Set(constant.SerializationKey, svc.Serialization)
// application config info
ac := GetApplicationConfig()
- urlMap.Set(constant.APPLICATION_KEY, ac.Name)
- urlMap.Set(constant.ORGANIZATION_KEY, ac.Organization)
- urlMap.Set(constant.NAME_KEY, ac.Name)
- urlMap.Set(constant.MODULE_KEY, ac.Module)
- urlMap.Set(constant.APP_VERSION_KEY, ac.Version)
- urlMap.Set(constant.OWNER_KEY, ac.Owner)
- urlMap.Set(constant.ENVIRONMENT_KEY, ac.Environment)
+ urlMap.Set(constant.ApplicationKey, ac.Name)
+ urlMap.Set(constant.OrganizationKey, ac.Organization)
+ urlMap.Set(constant.NameKey, ac.Name)
+ urlMap.Set(constant.ModuleKey, ac.Module)
+ urlMap.Set(constant.AppVersionKey, ac.Version)
+ urlMap.Set(constant.OwnerKey, ac.Owner)
+ urlMap.Set(constant.EnvironmentKey, ac.Environment)
// filter
if svc.Filter == "" {
@@ -384,8 +384,8 @@ func (svc *ServiceConfig) getUrlMap() url.Values {
for _, v := range svc.Methods {
prefix := "methods." + v.Name + "."
- urlMap.Set(prefix+constant.LOADBALANCE_KEY, v.LoadBalance)
- urlMap.Set(prefix+constant.RETRIES_KEY, v.Retries)
+ urlMap.Set(prefix+constant.LoadbalanceKey, v.LoadBalance)
+ urlMap.Set(prefix+constant.RetriesKey, v.Retries)
urlMap.Set(prefix+constant.WEIGHT_KEY, strconv.FormatInt(v.Weight, 10))
urlMap.Set(prefix+constant.TPS_LIMIT_STRATEGY_KEY, v.TpsLimitStrategy)
diff --git a/config_center/configurator/mock.go b/config_center/configurator/mock.go
index 711ec4ced1..b5e0629f2c 100644
--- a/config_center/configurator/mock.go
+++ b/config_center/configurator/mock.go
@@ -37,9 +37,9 @@ func (c *mockConfigurator) GetUrl() *common.URL {
return c.configuratorUrl
}
-// Configure sets up param CLUSTER_KEY and cluster for url
+// Configure sets up param ClusterKey and cluster for url
func (c *mockConfigurator) Configure(url *common.URL) {
- if cluster := c.GetUrl().GetParam(constant.CLUSTER_KEY, ""); cluster != "" {
- url.SetParam(constant.CLUSTER_KEY, cluster)
+ if cluster := c.GetUrl().GetParam(constant.ClusterKey, ""); cluster != "" {
+ url.SetParam(constant.ClusterKey, cluster)
}
}
diff --git a/config_center/configurator/override.go b/config_center/configurator/override.go
index d8e97c89bd..4c4ec37eb3 100644
--- a/config_center/configurator/override.go
+++ b/config_center/configurator/override.go
@@ -57,9 +57,9 @@ func (c *overrideConfigurator) Configure(url *common.URL) {
// branch for version 2.7.x
apiVersion := c.configuratorUrl.GetParam(constant.CONFIG_VERSION_KEY, "")
if len(apiVersion) != 0 {
- currentSide := url.GetParam(constant.SIDE_KEY, "")
- configuratorSide := c.configuratorUrl.GetParam(constant.SIDE_KEY, "")
- if currentSide == configuratorSide && common.DubboRole[common.CONSUMER] == currentSide && c.configuratorUrl.Port == "0" {
+ currentSide := url.GetParam(constant.SideKey, "")
+ configuratorSide := c.configuratorUrl.GetParam(constant.SideKey, "")
+ if currentSide == configuratorSide && common.DubboRole[common.Consumer] == currentSide && c.configuratorUrl.Port == "0" {
localIP := common.GetLocalIp()
c.configureIfMatch(localIP, url)
} else if currentSide == configuratorSide && common.DubboRole[common.PROVIDER] == currentSide && c.configuratorUrl.Port == url.Port {
@@ -72,23 +72,23 @@ func (c *overrideConfigurator) Configure(url *common.URL) {
}
func (c *overrideConfigurator) configureIfMatchInternal(url *common.URL) {
- configApp := c.configuratorUrl.GetParam(constant.APPLICATION_KEY, c.configuratorUrl.Username)
- currentApp := url.GetParam(constant.APPLICATION_KEY, url.Username)
+ configApp := c.configuratorUrl.GetParam(constant.ApplicationKey, c.configuratorUrl.Username)
+ currentApp := url.GetParam(constant.ApplicationKey, url.Username)
if len(configApp) == 0 || constant.ANY_VALUE == configApp || configApp == currentApp {
conditionKeys := gxset.NewSet()
conditionKeys.Add(constant.CATEGORY_KEY)
conditionKeys.Add(constant.CHECK_KEY)
conditionKeys.Add(constant.ENABLED_KEY)
- conditionKeys.Add(constant.GROUP_KEY)
- conditionKeys.Add(constant.VERSION_KEY)
- conditionKeys.Add(constant.APPLICATION_KEY)
- conditionKeys.Add(constant.SIDE_KEY)
+ conditionKeys.Add(constant.GroupKey)
+ conditionKeys.Add(constant.VersionKey)
+ conditionKeys.Add(constant.ApplicationKey)
+ conditionKeys.Add(constant.SideKey)
conditionKeys.Add(constant.CONFIG_VERSION_KEY)
conditionKeys.Add(constant.COMPATIBLE_CONFIG_KEY)
returnUrl := false
c.configuratorUrl.RangeParams(func(k, _ string) bool {
value := c.configuratorUrl.GetParam(k, "")
- if strings.HasPrefix(k, "~") || k == constant.APPLICATION_KEY || k == constant.SIDE_KEY {
+ if strings.HasPrefix(k, "~") || k == constant.ApplicationKey || k == constant.SideKey {
conditionKeys.Add(k)
if len(value) != 0 && value != constant.ANY_VALUE && value != url.GetParam(strings.TrimPrefix(k, "~"), "") {
returnUrl = true
@@ -125,7 +125,7 @@ func (c *overrideConfigurator) configureDeprecated(url *common.URL) {
// override url don't have a port, means the ip override url specify is a consumer address or 0.0.0.0
// 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore;
// 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider
- if url.GetParam(constant.SIDE_KEY, "") == common.DubboRole[common.CONSUMER] {
+ if url.GetParam(constant.SideKey, "") == common.DubboRole[common.Consumer] {
localIP := common.GetLocalIp()
c.configureIfMatch(localIP, url)
} else {
diff --git a/config_center/configurator/override_test.go b/config_center/configurator/override_test.go
index 117598535e..0537752a07 100644
--- a/config_center/configurator/override_test.go
+++ b/config_center/configurator/override_test.go
@@ -46,7 +46,7 @@ func TestConfigureVersion2p6(t *testing.T) {
providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100")
assert.NoError(t, err)
configurator.Configure(providerUrl)
- assert.Equal(t, failfast, providerUrl.GetParam(constant.CLUSTER_KEY, ""))
+ assert.Equal(t, failfast, providerUrl.GetParam(constant.ClusterKey, ""))
}
func TestConfigureVersionOverrideAddr(t *testing.T) {
@@ -58,7 +58,7 @@ func TestConfigureVersionOverrideAddr(t *testing.T) {
providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100")
assert.NoError(t, err)
configurator.Configure(providerUrl)
- assert.Equal(t, failover, providerUrl.GetParam(constant.CLUSTER_KEY, ""))
+ assert.Equal(t, failover, providerUrl.GetParam(constant.ClusterKey, ""))
}
func TestConfigureVersion2p6WithIp(t *testing.T) {
@@ -70,7 +70,7 @@ func TestConfigureVersion2p6WithIp(t *testing.T) {
providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100")
assert.NoError(t, err)
configurator.Configure(providerUrl)
- assert.Equal(t, failfast, providerUrl.GetParam(constant.CLUSTER_KEY, ""))
+ assert.Equal(t, failfast, providerUrl.GetParam(constant.ClusterKey, ""))
}
func TestConfigureVersion2p7(t *testing.T) {
@@ -81,5 +81,5 @@ func TestConfigureVersion2p7(t *testing.T) {
providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100")
assert.NoError(t, err)
configurator.Configure(providerUrl)
- assert.Equal(t, failfast, providerUrl.GetParam(constant.CLUSTER_KEY, ""))
+ assert.Equal(t, failfast, providerUrl.GetParam(constant.ClusterKey, ""))
}
diff --git a/filter/accesslog/filter.go b/filter/accesslog/filter.go
index 981f24c4a0..102df9ef81 100644
--- a/filter/accesslog/filter.go
+++ b/filter/accesslog/filter.go
@@ -104,24 +104,24 @@ func (f *Filter) logIntoChannel(accessLogData Data) {
func (f *Filter) buildAccessLogData(_ protocol.Invoker, invocation protocol.Invocation) map[string]string {
dataMap := make(map[string]string, 16)
attachments := invocation.Attachments()
- itf := attachments[constant.INTERFACE_KEY]
+ itf := attachments[constant.InterfaceKey]
if itf == nil || len(itf.(string)) == 0 {
itf = attachments[constant.PATH_KEY]
}
if itf != nil {
- dataMap[constant.INTERFACE_KEY] = itf.(string)
+ dataMap[constant.InterfaceKey] = itf.(string)
}
if v, ok := attachments[constant.METHOD_KEY]; ok && v != nil {
dataMap[constant.METHOD_KEY] = v.(string)
}
- if v, ok := attachments[constant.VERSION_KEY]; ok && v != nil {
- dataMap[constant.VERSION_KEY] = v.(string)
+ if v, ok := attachments[constant.VersionKey]; ok && v != nil {
+ dataMap[constant.VersionKey] = v.(string)
}
- if v, ok := attachments[constant.GROUP_KEY]; ok && v != nil {
- dataMap[constant.GROUP_KEY] = v.(string)
+ if v, ok := attachments[constant.GroupKey]; ok && v != nil {
+ dataMap[constant.GroupKey] = v.(string)
}
- if v, ok := attachments[constant.TIMESTAMP_KEY]; ok && v != nil {
- dataMap[constant.TIMESTAMP_KEY] = v.(string)
+ if v, ok := attachments[constant.TimestampKey]; ok && v != nil {
+ dataMap[constant.TimestampKey] = v.(string)
}
if v, ok := attachments[constant.LOCAL_ADDR]; ok && v != nil {
dataMap[constant.LOCAL_ADDR] = v.(string)
@@ -240,22 +240,22 @@ type Data struct {
func (d *Data) toLogMessage() string {
builder := strings.Builder{}
builder.WriteString("[")
- builder.WriteString(d.data[constant.TIMESTAMP_KEY])
+ builder.WriteString(d.data[constant.TimestampKey])
builder.WriteString("] ")
builder.WriteString(d.data[constant.REMOTE_ADDR])
builder.WriteString(" -> ")
builder.WriteString(d.data[constant.LOCAL_ADDR])
builder.WriteString(" - ")
- if len(d.data[constant.GROUP_KEY]) > 0 {
- builder.WriteString(d.data[constant.GROUP_KEY])
+ if len(d.data[constant.GroupKey]) > 0 {
+ builder.WriteString(d.data[constant.GroupKey])
builder.WriteString("/")
}
- builder.WriteString(d.data[constant.INTERFACE_KEY])
+ builder.WriteString(d.data[constant.InterfaceKey])
- if len(d.data[constant.VERSION_KEY]) > 0 {
+ if len(d.data[constant.VersionKey]) > 0 {
builder.WriteString(":")
- builder.WriteString(d.data[constant.VERSION_KEY])
+ builder.WriteString(d.data[constant.VersionKey])
}
builder.WriteString(" ")
diff --git a/filter/accesslog/filter_test.go b/filter/accesslog/filter_test.go
index 4bd6f2e40e..4fa5f7e817 100644
--- a/filter/accesslog/filter_test.go
+++ b/filter/accesslog/filter_test.go
@@ -66,8 +66,8 @@ func TestFilterInvokeDefaultConfig(t *testing.T) {
invoker := protocol.NewBaseInvoker(url)
attach := make(map[string]interface{}, 10)
- attach[constant.VERSION_KEY] = "1.0"
- attach[constant.GROUP_KEY] = "MyGroup"
+ attach[constant.VersionKey] = "1.0"
+ attach[constant.GroupKey] = "MyGroup"
inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach)
accessLogFilter := &Filter{}
diff --git a/filter/auth/default_authenticator.go b/filter/auth/default_authenticator.go
index a36f1e1268..fd12db0965 100644
--- a/filter/auth/default_authenticator.go
+++ b/filter/auth/default_authenticator.go
@@ -46,7 +46,7 @@ type DefaultAuthenticator struct{}
func (authenticator *DefaultAuthenticator) Sign(invocation protocol.Invocation, url *common.URL) error {
currentTimeMillis := strconv.Itoa(int(time.Now().Unix() * 1000))
- consumer := url.GetParam(constant.APPLICATION_KEY, "")
+ consumer := url.GetParam(constant.ApplicationKey, "")
accessKeyPair, err := getAccessKeyPair(invocation, url)
if err != nil {
return errors.New("get accesskey pair failed, cause: " + err.Error())
diff --git a/filter/execlmt/filter_test.go b/filter/execlmt/filter_test.go
index d5ff23725c..43c56c3f6f 100644
--- a/filter/execlmt/filter_test.go
+++ b/filter/execlmt/filter_test.go
@@ -40,7 +40,7 @@ func TestFilterInvokeIgnored(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, methodName))
+ common.WithParamsValue(constant.InterfaceKey, methodName))
limitFilter := newFilter()
@@ -55,7 +55,7 @@ func TestFilterInvokeConfigureError(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, methodName),
+ common.WithParamsValue(constant.InterfaceKey, methodName),
common.WithParamsValue(constant.EXECUTE_LIMIT_KEY, "13a"),
)
@@ -72,7 +72,7 @@ func TestFilterInvoke(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, methodName),
+ common.WithParamsValue(constant.InterfaceKey, methodName),
common.WithParamsValue(constant.EXECUTE_LIMIT_KEY, "20"),
)
diff --git a/filter/generic/filter.go b/filter/generic/filter.go
index 4aa2d6ef5c..4da67d7b67 100644
--- a/filter/generic/filter.go
+++ b/filter/generic/filter.go
@@ -54,7 +54,7 @@ func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocatio
args := make([]hessian.Object, 0, len(oldargs))
// get generic info from attachments of invocation, the default value is "true"
- generic := invocation.AttachmentsByKey(constant.GENERIC_KEY, constant.GenericSerializationDefault)
+ generic := invocation.AttachmentsByKey(constant.GenericKey, constant.GenericSerializationDefault)
// get generalizer according to value in the `generic`
g := getGeneralizer(generic)
@@ -81,11 +81,11 @@ func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocatio
}
newivc := invocation2.NewRPCInvocation(constant.GENERIC, newargs, invocation.Attachments())
newivc.SetReply(invocation.Reply())
- newivc.Attachments()[constant.GENERIC_KEY] = invoker.GetURL().GetParam(constant.GENERIC_KEY, "")
+ newivc.Attachments()[constant.GenericKey] = invoker.GetURL().GetParam(constant.GenericKey, "")
return invoker.Invoke(ctx, newivc)
} else if isMakingAGenericCall(invoker, invocation) {
- invocation.Attachments()[constant.GENERIC_KEY] = invoker.GetURL().GetParam(constant.GENERIC_KEY, "")
+ invocation.Attachments()[constant.GenericKey] = invoker.GetURL().GetParam(constant.GenericKey, "")
}
return invoker.Invoke(ctx, invocation)
}
diff --git a/filter/generic/filter_test.go b/filter/generic/filter_test.go
index c8bf45a710..23bdf64098 100644
--- a/filter/generic/filter_test.go
+++ b/filter/generic/filter_test.go
@@ -43,7 +43,7 @@ import (
func TestFilter_Invoke(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.GENERIC_KEY, constant.GenericSerializationDefault))
+ common.WithParamsValue(constant.GenericKey, constant.GenericSerializationDefault))
filter := &Filter{}
ctrl := gomock.NewController(t)
@@ -60,7 +60,7 @@ func TestFilter_Invoke(t *testing.T) {
assert.Equal(t, "Hello", args[0])
assert.Equal(t, "java.lang.String", args[1].([]string)[0])
assert.Equal(t, "arg1", args[2].([]hessian.Object)[0].(string))
- assert.Equal(t, constant.GenericSerializationDefault, invocation.AttachmentsByKey(constant.GENERIC_KEY, ""))
+ assert.Equal(t, constant.GenericSerializationDefault, invocation.AttachmentsByKey(constant.GenericKey, ""))
return &protocol.RPCResult{}
})
@@ -72,7 +72,7 @@ func TestFilter_Invoke(t *testing.T) {
func TestFilter_InvokeWithGenericCall(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.GENERIC_KEY, constant.GenericSerializationDefault))
+ common.WithParamsValue(constant.GenericKey, constant.GenericSerializationDefault))
filter := &Filter{}
ctrl := gomock.NewController(t)
@@ -93,7 +93,7 @@ func TestFilter_InvokeWithGenericCall(t *testing.T) {
assert.Equal(t, "hello", args[0])
assert.Equal(t, "java.lang.String", args[1].([]string)[0])
assert.Equal(t, "arg1", args[2].([]string)[0])
- assert.Equal(t, constant.GenericSerializationDefault, invocation.AttachmentsByKey(constant.GENERIC_KEY, ""))
+ assert.Equal(t, constant.GenericSerializationDefault, invocation.AttachmentsByKey(constant.GenericKey, ""))
return &protocol.RPCResult{}
})
diff --git a/filter/generic/service_filter.go b/filter/generic/service_filter.go
index 2b6f7e4685..3693825a2b 100644
--- a/filter/generic/service_filter.go
+++ b/filter/generic/service_filter.go
@@ -75,7 +75,7 @@ func (f *ServiceFilter) Invoke(ctx context.Context, invoker protocol.Invoker, in
argsType := method.ArgsType()
// get generic info from attachments of invocation, the default value is "true"
- generic := invocation.AttachmentsByKey(constant.GENERIC_KEY, constant.GenericSerializationDefault)
+ generic := invocation.AttachmentsByKey(constant.GenericKey, constant.GenericSerializationDefault)
// get generalizer according to value in the `generic`
g := getGeneralizer(generic)
@@ -114,7 +114,7 @@ func (f *ServiceFilter) Invoke(ctx context.Context, invoker protocol.Invoker, in
func (f *ServiceFilter) OnResponse(_ context.Context, result protocol.Result, _ protocol.Invoker, invocation protocol.Invocation) protocol.Result {
if isGenericInvocation(invocation) && result.Result() != nil {
// get generic info from attachments of invocation, the default value is "true"
- generic := invocation.AttachmentsByKey(constant.GENERIC_KEY, constant.GenericSerializationDefault)
+ generic := invocation.AttachmentsByKey(constant.GenericKey, constant.GenericSerializationDefault)
// get generalizer according to value in the `generic`
g := getGeneralizer(generic)
diff --git a/filter/generic/service_filter_test.go b/filter/generic/service_filter_test.go
index c6eb49904a..5cd5f1b5ba 100644
--- a/filter/generic/service_filter_test.go
+++ b/filter/generic/service_filter_test.go
@@ -96,10 +96,10 @@ func TestServiceFilter_Invoke(t *testing.T) {
ivkUrl := common.NewURLWithOptions(
common.WithProtocol("test"),
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, service.Reference()),
- common.WithParamsValue(constant.GENERIC_KEY, constant.GenericSerializationDefault))
+ common.WithParamsValue(constant.InterfaceKey, service.Reference()),
+ common.WithParamsValue(constant.GenericKey, constant.GenericSerializationDefault))
// registry RPC service
- _, err := common.ServiceMap.Register(ivkUrl.GetParam(constant.INTERFACE_KEY, ""),
+ _, err := common.ServiceMap.Register(ivkUrl.GetParam(constant.InterfaceKey, ""),
ivkUrl.Protocol,
"",
"",
@@ -116,7 +116,7 @@ func TestServiceFilter_Invoke(t *testing.T) {
[]string{"java.lang.String"},
[]hessian.Object{"world"},
}, map[string]interface{}{
- constant.GENERIC_KEY: "true",
+ constant.GenericKey: "true",
})
// invoke a non-existed method
invocation5 := invocation.NewRPCInvocation(constant.GENERIC,
@@ -125,7 +125,7 @@ func TestServiceFilter_Invoke(t *testing.T) {
[]string{"java.lang.String"},
[]hessian.Object{"world"},
}, map[string]interface{}{
- constant.GENERIC_KEY: "true",
+ constant.GenericKey: "true",
})
// invoke a method with incorrect arguments
invocation6 := invocation.NewRPCInvocation(constant.GENERIC,
@@ -134,7 +134,7 @@ func TestServiceFilter_Invoke(t *testing.T) {
[]string{"java.lang.String", "java.lang.String"},
[]hessian.Object{"world", "haha"},
}, map[string]interface{}{
- constant.GENERIC_KEY: "true",
+ constant.GenericKey: "true",
})
// invoke a method without errors using protobuf-json generalization
//invocation7 := invocation.NewRPCInvocation(constant.GENERIC,
@@ -143,7 +143,7 @@ func TestServiceFilter_Invoke(t *testing.T) {
// []string{},
// []hessian.Object{"{\"id\":1}"},
// }, map[string]interface{}{
- // constant.GENERIC_KEY: constant.GenericSerializationProtobuf,
+ // constant.GenericKey: constant.GenericSerializationProtobuf,
// })
mockInvoker.EXPECT().Invoke(gomock.All(
@@ -202,7 +202,7 @@ func TestServiceFilter_OnResponse(t *testing.T) {
[]interface{}{"java.lang.String"},
[]interface{}{"world"},
}, map[string]interface{}{
- constant.GENERIC_KEY: "true",
+ constant.GenericKey: "true",
})
rpcResult := &protocol.RPCResult{
diff --git a/filter/generic/util.go b/filter/generic/util.go
index a7fe467bb5..b586bb45ca 100644
--- a/filter/generic/util.go
+++ b/filter/generic/util.go
@@ -30,13 +30,13 @@ import (
// isCallingToGenericService check if it calls to a generic service
func isCallingToGenericService(invoker protocol.Invoker, invocation protocol.Invocation) bool {
- return isGeneric(invoker.GetURL().GetParam(constant.GENERIC_KEY, "")) &&
+ return isGeneric(invoker.GetURL().GetParam(constant.GenericKey, "")) &&
invocation.MethodName() != constant.GENERIC
}
// isMakingAGenericCall check if it is making a generic call to a generic service
func isMakingAGenericCall(invoker protocol.Invoker, invocation protocol.Invocation) bool {
- return isGeneric(invoker.GetURL().GetParam(constant.GENERIC_KEY, "")) &&
+ return isGeneric(invoker.GetURL().GetParam(constant.GenericKey, "")) &&
invocation.MethodName() == constant.GENERIC &&
invocation.Arguments() != nil &&
len(invocation.Arguments()) == 3
diff --git a/filter/handler/rejected_execution_handler_only_log_test.go b/filter/handler/rejected_execution_handler_only_log_test.go
index 9dd47c940b..27e2fb7e96 100644
--- a/filter/handler/rejected_execution_handler_only_log_test.go
+++ b/filter/handler/rejected_execution_handler_only_log_test.go
@@ -31,6 +31,6 @@ func TestOnlyLogRejectedExecutionHandler_RejectedExecution(t *testing.T) {
handler := GetOnlyLogRejectedExecutionHandler()
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, "methodName"))
+ common.WithParamsValue(constant.InterfaceKey, "methodName"))
handler.RejectedExecution(invokeUrl, nil)
}
diff --git a/filter/sentinel/filter.go b/filter/sentinel/filter.go
index ceadb3259a..2bbb46cb3d 100644
--- a/filter/sentinel/filter.go
+++ b/filter/sentinel/filter.go
@@ -243,6 +243,6 @@ func getInterfaceGroupAndVersionEnabled() bool {
func getColonSeparatedKey(url *common.URL) string {
return fmt.Sprintf("%s:%s:%s",
url.Service(),
- url.GetParam(constant.GROUP_KEY, ""),
- url.GetParam(constant.VERSION_KEY, ""))
+ url.GetParam(constant.GroupKey, ""),
+ url.GetParam(constant.VersionKey, ""))
}
diff --git a/filter/tps/limiter/method_service_test.go b/filter/tps/limiter/method_service_test.go
index df79def826..b72954ce0b 100644
--- a/filter/tps/limiter/method_service_test.go
+++ b/filter/tps/limiter/method_service_test.go
@@ -46,7 +46,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableOnlyServiceLevel(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, methodName),
+ common.WithParamsValue(constant.InterfaceKey, methodName),
common.WithParamsValue(constant.TPS_LIMIT_RATE_KEY, "20"))
mockStrategyImpl := strategy.NewMockTpsLimitStrategy(ctrl)
@@ -72,7 +72,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableNoConfig(t *testing.T) {
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, methodName),
+ common.WithParamsValue(constant.InterfaceKey, methodName),
common.WithParamsValue(constant.TPS_LIMIT_RATE_KEY, ""))
limiter := GetMethodServiceTpsLimiter()
@@ -89,7 +89,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableMethodLevelOverride(t *testing.T)
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, methodName),
+ common.WithParamsValue(constant.InterfaceKey, methodName),
common.WithParamsValue(constant.TPS_LIMIT_RATE_KEY, "20"),
common.WithParamsValue(constant.TPS_LIMIT_INTERVAL_KEY, "3000"),
common.WithParamsValue(constant.TPS_LIMIT_STRATEGY_KEY, "invalid"),
@@ -122,7 +122,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableBothMethodAndService(t *testing.T
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.INTERFACE_KEY, methodName),
+ common.WithParamsValue(constant.InterfaceKey, methodName),
common.WithParamsValue(constant.TPS_LIMIT_RATE_KEY, "20"),
common.WithParamsValue(constant.TPS_LIMIT_INTERVAL_KEY, "3000"),
common.WithParamsValue(methodConfigPrefix+constant.TPS_LIMIT_RATE_KEY, "40"),
diff --git a/metadata/identifier/service_metadata_identifier.go b/metadata/identifier/service_metadata_identifier.go
index b8e56adff4..c80bcd7d58 100644
--- a/metadata/identifier/service_metadata_identifier.go
+++ b/metadata/identifier/service_metadata_identifier.go
@@ -36,9 +36,9 @@ func NewServiceMetadataIdentifier(url *common.URL) *ServiceMetadataIdentifier {
return &ServiceMetadataIdentifier{
BaseMetadataIdentifier: BaseMetadataIdentifier{
ServiceInterface: url.Service(),
- Version: url.GetParam(constant.VERSION_KEY, ""),
- Group: url.GetParam(constant.GROUP_KEY, ""),
- Side: url.GetParam(constant.SIDE_KEY, ""),
+ Version: url.GetParam(constant.VersionKey, ""),
+ Group: url.GetParam(constant.GroupKey, ""),
+ Side: url.GetParam(constant.SideKey, ""),
},
Protocol: url.Protocol,
}
diff --git a/metadata/mapping/metadata/service_name_mapping.go b/metadata/mapping/metadata/service_name_mapping.go
index f155aa9ddc..e392540299 100644
--- a/metadata/mapping/metadata/service_name_mapping.go
+++ b/metadata/mapping/metadata/service_name_mapping.go
@@ -53,7 +53,7 @@ type MetadataServiceNameMapping struct {
// Map will map the service to this application-level service
func (d *MetadataServiceNameMapping) Map(url *common.URL) error {
- serviceInterface := url.GetParam(constant.INTERFACE_KEY, "")
+ serviceInterface := url.GetParam(constant.InterfaceKey, "")
// metadata service is admin service, should not be mapped
if constant.METADATA_SERVICE_NAME == serviceInterface {
logger.Info("try to map the metadata service, will be ignored")
@@ -71,7 +71,7 @@ func (d *MetadataServiceNameMapping) Map(url *common.URL) error {
// Get will return the application-level services. If not found, the empty set will be returned.
func (d *MetadataServiceNameMapping) Get(url *common.URL) (*gxset.HashSet, error) {
- serviceInterface := url.GetParam(constant.INTERFACE_KEY, "")
+ serviceInterface := url.GetParam(constant.InterfaceKey, "")
metadataReport := instance.GetMetadataReportInstance()
return metadataReport.GetServiceAppMapping(serviceInterface, defaultGroup)
}
diff --git a/metadata/report/delegate/delegate_report.go b/metadata/report/delegate/delegate_report.go
index 536da6b357..7eec8e7c5d 100644
--- a/metadata/report/delegate/delegate_report.go
+++ b/metadata/report/delegate/delegate_report.go
@@ -212,7 +212,7 @@ func (mr *MetadataReport) storeMetadataTask(role int, identifier *identifier.Met
report := instance.GetMetadataReportInstance()
if role == common.PROVIDER {
err = report.StoreProviderMetadata(identifier, string(data))
- } else if role == common.CONSUMER {
+ } else if role == common.Consumer {
err = report.StoreConsumerMetadata(identifier, string(data))
}
@@ -224,9 +224,9 @@ func (mr *MetadataReport) storeMetadataTask(role int, identifier *identifier.Met
// StoreConsumerMetadata will delegate to call remote metadata's sdk to store consumer side service definition
func (mr *MetadataReport) StoreConsumerMetadata(identifier *identifier.MetadataIdentifier, definer map[string]string) {
if mr.syncReport {
- mr.storeMetadataTask(common.CONSUMER, identifier, definer)
+ mr.storeMetadataTask(common.Consumer, identifier, definer)
}
- go mr.storeMetadataTask(common.CONSUMER, identifier, definer)
+ go mr.storeMetadataTask(common.Consumer, identifier, definer)
}
// SaveServiceMetadata will delegate to call remote metadata's sdk to save service metadata
@@ -307,7 +307,7 @@ func (mr *MetadataReport) doHandlerMetadataCollection(metadataMap map[*identifie
for e := range metadataMap {
if common.RoleType(common.PROVIDER).Role() == e.Side {
mr.StoreProviderMetadata(e, metadataMap[e].(*definition.ServiceDefinition))
- } else if common.RoleType(common.CONSUMER).Role() == e.Side {
+ } else if common.RoleType(common.Consumer).Role() == e.Side {
mr.StoreConsumerMetadata(e, metadataMap[e].(map[string]string))
}
}
diff --git a/metadata/report/etcd/report.go b/metadata/report/etcd/report.go
index a677b7621a..195ffe18f9 100644
--- a/metadata/report/etcd/report.go
+++ b/metadata/report/etcd/report.go
@@ -186,7 +186,7 @@ func (e *etcdMetadataReportFactory) CreateMetadataReport(url *common.URL) report
logger.Errorf("Could not create etcd metadata report. URL: %s,error:{%v}", url.String(), err)
return nil
}
- group := url.GetParam(constant.GROUP_KEY, DEFAULT_ROOT)
+ group := url.GetParam(constant.GroupKey, DEFAULT_ROOT)
group = constant.PATH_SEPARATOR + strings.TrimPrefix(group, constant.PATH_SEPARATOR)
return &etcdMetadataReport{client: client, root: group}
}
diff --git a/metadata/report/etcd/report_test.go b/metadata/report/etcd/report_test.go
index aed380bf90..8453db0ad0 100644
--- a/metadata/report/etcd/report_test.go
+++ b/metadata/report/etcd/report_test.go
@@ -56,7 +56,7 @@ func initEtcd(t *testing.T) *embed.Etcd {
func TestEtcdMetadataReportFactory_CreateMetadataReport(t *testing.T) {
e := initEtcd(t)
- url, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ url, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
if err != nil {
t.Fatal(err)
}
@@ -68,7 +68,7 @@ func TestEtcdMetadataReportFactory_CreateMetadataReport(t *testing.T) {
func TestEtcdMetadataReport_CRUD(t *testing.T) {
e := initEtcd(t)
- url, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ url, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
if err != nil {
t.Fatal(err)
}
@@ -83,7 +83,7 @@ func TestEtcdMetadataReport_CRUD(t *testing.T) {
assert.Nil(t, err)
serviceMi := newServiceMetadataIdentifier()
- serviceUrl, err := common.NewURL("registry://localhost:8848", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ serviceUrl, err := common.NewURL("registry://localhost:8848", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
assert.Nil(t, err)
err = metadataReport.SaveServiceMetadata(serviceMi, serviceUrl)
assert.Nil(t, err)
@@ -116,7 +116,7 @@ func TestEtcdMetadataReport_CRUD(t *testing.T) {
func TestEtcdMetadataReport_ServiceAppMapping(t *testing.T) {
e := initEtcd(t)
- url, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ url, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
if err != nil {
t.Fatal(err)
}
diff --git a/metadata/report/nacos/report_test.go b/metadata/report/nacos/report_test.go
index 2f5e37536f..a261e158f6 100644
--- a/metadata/report/nacos/report_test.go
+++ b/metadata/report/nacos/report_test.go
@@ -54,7 +54,7 @@ func TestNacosMetadataReport_CRUD(t *testing.T) {
assert.Nil(t, err)
serviceMi := newServiceMetadataIdentifier()
- serviceUrl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ serviceUrl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
err = rpt.SaveServiceMetadata(serviceMi, serviceUrl)
assert.Nil(t, err)
@@ -97,7 +97,7 @@ func TestNacosMetadataReportFactory_CreateMetadataReport(t *testing.T) {
}
func newTestReport() report.MetadataReport {
- regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
res := extension.GetMetadataReportFactory("nacos").CreateMetadataReport(regurl)
return res
}
diff --git a/metadata/report/zookeeper/report.go b/metadata/report/zookeeper/report.go
index 4402d61a8b..14c99381d5 100644
--- a/metadata/report/zookeeper/report.go
+++ b/metadata/report/zookeeper/report.go
@@ -190,7 +190,7 @@ func (mf *zookeeperMetadataReportFactory) CreateMetadataReport(url *common.URL)
panic(err)
}
- rootDir := url.GetParam(constant.GROUP_KEY, "dubbo")
+ rootDir := url.GetParam(constant.GroupKey, "dubbo")
if !strings.HasPrefix(rootDir, constant.PATH_SEPARATOR) {
rootDir = constant.PATH_SEPARATOR + rootDir
}
diff --git a/metadata/service/local/metadata_service_proxy_factory.go b/metadata/service/local/metadata_service_proxy_factory.go
index e6e2f40bfa..5c38e145c0 100644
--- a/metadata/service/local/metadata_service_proxy_factory.go
+++ b/metadata/service/local/metadata_service_proxy_factory.go
@@ -87,8 +87,8 @@ func buildStandardMetadataServiceURL(ins registry.ServiceInstance) []*common.URL
common.WithProtocol(ps[constant.PROTOCOL_KEY]),
common.WithPort(ps[constant.PORT_KEY]),
common.WithParams(convertedParams),
- common.WithParamsValue(constant.GROUP_KEY, sn),
- common.WithParamsValue(constant.INTERFACE_KEY, constant.METADATA_SERVICE_NAME))
+ common.WithParamsValue(constant.GroupKey, sn),
+ common.WithParamsValue(constant.InterfaceKey, constant.METADATA_SERVICE_NAME))
res = append(res, u)
return res
diff --git a/metadata/service/local/service.go b/metadata/service/local/service.go
index c5c1418ded..5abeb0f7c5 100644
--- a/metadata/service/local/service.go
+++ b/metadata/service/local/service.go
@@ -157,7 +157,7 @@ func (mts *MetadataService) getSpecifiedService(services *sync.Map, serviceKey s
// ExportURL can store the in memory
func (mts *MetadataService) ExportURL(url *common.URL) (bool, error) {
- if constant.METADATA_SERVICE_NAME == url.GetParam(constant.INTERFACE_KEY, "") {
+ if constant.METADATA_SERVICE_NAME == url.GetParam(constant.InterfaceKey, "") {
mts.metadataServiceURL = url
return true, nil
}
@@ -170,7 +170,7 @@ func (mts *MetadataService) ExportURL(url *common.URL) (bool, error) {
// UnexportURL can remove the url store in memory
func (mts *MetadataService) UnexportURL(url *common.URL) error {
- if constant.METADATA_SERVICE_NAME == url.GetParam(constant.INTERFACE_KEY, "") {
+ if constant.METADATA_SERVICE_NAME == url.GetParam(constant.InterfaceKey, "") {
mts.metadataServiceURL = nil
return nil
}
@@ -194,11 +194,11 @@ func (mts *MetadataService) UnsubscribeURL(url *common.URL) error {
// PublishServiceDefinition: publish url's service metadata info, and write into memory
func (mts *MetadataService) PublishServiceDefinition(url *common.URL) error {
- if common.RoleType(common.CONSUMER).Role() == url.GetParam(constant.SIDE_KEY, "") {
+ if common.RoleType(common.Consumer).Role() == url.GetParam(constant.SideKey, "") {
return nil
}
- interfaceName := url.GetParam(constant.INTERFACE_KEY, "")
- isGeneric := url.GetParamBool(constant.GENERIC_KEY, false)
+ interfaceName := url.GetParam(constant.InterfaceKey, "")
+ isGeneric := url.GetParamBool(constant.GenericKey, false)
if len(interfaceName) > 0 && !isGeneric {
tmpService := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey())
sd := definition.BuildServiceDefinition(*tmpService, url)
diff --git a/metadata/service/local/service_proxy.go b/metadata/service/local/service_proxy.go
index 03c71aab4c..8418bea15a 100644
--- a/metadata/service/local/service_proxy.go
+++ b/metadata/service/local/service_proxy.go
@@ -55,7 +55,7 @@ func (m *MetadataServiceProxy) GetExportedURLs(serviceInterface string, group st
inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName(methodName),
invocation.WithArguments([]interface{}{siV.Interface(), gV.Interface(), vV.Interface(), pV.Interface()}),
invocation.WithReply(reflect.ValueOf(&[]interface{}{}).Interface()),
- invocation.WithAttachments(map[string]interface{}{constant.ASYNC_KEY: "false"}),
+ invocation.WithAttachments(map[string]interface{}{constant.AsyncKey: "false"}),
invocation.WithParameterValues([]reflect.Value{siV, gV, vV, pV}))
res := m.invkr.Invoke(context.Background(), inv)
@@ -177,7 +177,7 @@ func (m *MetadataServiceProxy) GetMetadataInfo(revision string) (*common.Metadat
inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName(methodName),
invocation.WithArguments([]interface{}{rV.Interface()}),
invocation.WithReply(reflect.ValueOf(&common.MetadataInfo{}).Interface()),
- invocation.WithAttachments(map[string]interface{}{constant.ASYNC_KEY: "false"}),
+ invocation.WithAttachments(map[string]interface{}{constant.AsyncKey: "false"}),
invocation.WithParameterValues([]reflect.Value{rV}))
res := m.invkr.Invoke(context.Background(), inv)
if res.Error() != nil {
diff --git a/metadata/service/remote/service.go b/metadata/service/remote/service.go
index dfe9ec5b21..14bd9d9a10 100644
--- a/metadata/service/remote/service.go
+++ b/metadata/service/remote/service.go
@@ -103,18 +103,18 @@ func (s *MetadataService) GetMetadata(instance registry.ServiceInstance) (*commo
// PublishServiceDefinition will call remote metadata's StoreProviderMetadata to store url info and service definition
func (s *MetadataService) PublishServiceDefinition(url *common.URL) error {
- interfaceName := url.GetParam(constant.INTERFACE_KEY, "")
- isGeneric := url.GetParamBool(constant.GENERIC_KEY, false)
- if common.RoleType(common.PROVIDER).Role() == url.GetParam(constant.SIDE_KEY, "") {
+ interfaceName := url.GetParam(constant.InterfaceKey, "")
+ isGeneric := url.GetParamBool(constant.GenericKey, false)
+ if common.RoleType(common.PROVIDER).Role() == url.GetParam(constant.SideKey, "") {
if len(interfaceName) > 0 && !isGeneric {
sv := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey())
sd := definition.BuildServiceDefinition(*sv, url)
id := &identifier.MetadataIdentifier{
BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{
ServiceInterface: interfaceName,
- Version: url.GetParam(constant.VERSION_KEY, ""),
- Group: url.GetParam(constant.GROUP_KEY, constant.DUBBO),
- Side: url.GetParam(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
+ Version: url.GetParam(constant.VersionKey, ""),
+ Group: url.GetParam(constant.GroupKey, constant.DUBBO),
+ Side: url.GetParam(constant.SideKey, constant.PROVIDER_PROTOCOL),
},
}
s.delegateReport.StoreProviderMetadata(id, sd)
@@ -130,9 +130,9 @@ func (s *MetadataService) PublishServiceDefinition(url *common.URL) error {
id := &identifier.MetadataIdentifier{
BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{
ServiceInterface: interfaceName,
- Version: url.GetParam(constant.VERSION_KEY, ""),
- Group: url.GetParam(constant.GROUP_KEY, constant.DUBBO),
- Side: url.GetParam(constant.SIDE_KEY, "consumer"),
+ Version: url.GetParam(constant.VersionKey, ""),
+ Group: url.GetParam(constant.GroupKey, constant.DUBBO),
+ Side: url.GetParam(constant.SideKey, "consumer"),
},
}
s.delegateReport.StoreConsumerMetadata(id, params)
diff --git a/metrics/prometheus/reporter.go b/metrics/prometheus/reporter.go
index 55d1bd6a45..6f11c9171d 100644
--- a/metrics/prometheus/reporter.go
+++ b/metrics/prometheus/reporter.go
@@ -45,10 +45,10 @@ import (
const (
reporterName = "prometheus"
serviceKey = constant.SERVICE_KEY
- groupKey = constant.GROUP_KEY
- versionKey = constant.VERSION_KEY
+ groupKey = constant.GroupKey
+ versionKey = constant.VersionKey
methodKey = constant.METHOD_KEY
- timeoutKey = constant.TIMEOUT_KEY
+ timeoutKey = constant.TimeoutKey
// to identify side
providerPrefix = "provider_"
@@ -199,14 +199,14 @@ func newSummaryVec(name, namespace string, labels []string) *prometheus.SummaryV
// isProvider shows whether this url represents the application received the request as server
func isProvider(url *common.URL) bool {
- role := url.GetParam(constant.ROLE_KEY, "")
+ role := url.GetParam(constant.RoleKey, "")
return strings.EqualFold(role, strconv.Itoa(common.PROVIDER))
}
// isConsumer shows whether this url represents the application sent then request as client
func isConsumer(url *common.URL) bool {
- role := url.GetParam(constant.ROLE_KEY, "")
- return strings.EqualFold(role, strconv.Itoa(common.CONSUMER))
+ role := url.GetParam(constant.RoleKey, "")
+ return strings.EqualFold(role, strconv.Itoa(common.Consumer))
}
// newPrometheusReporter create new prometheusReporter
diff --git a/protocol/dubbo/dubbo_codec.go b/protocol/dubbo/dubbo_codec.go
index 1ad4c37d17..e568ba07b5 100644
--- a/protocol/dubbo/dubbo_codec.go
+++ b/protocol/dubbo/dubbo_codec.go
@@ -65,11 +65,11 @@ func (c *DubboCodec) EncodeRequest(request *remoting.Request) (*bytes.Buffer, er
svc := impl.Service{}
svc.Path = invocation.AttachmentsByKey(constant.PATH_KEY, "")
- svc.Interface = invocation.AttachmentsByKey(constant.INTERFACE_KEY, "")
- svc.Version = invocation.AttachmentsByKey(constant.VERSION_KEY, "")
- svc.Group = invocation.AttachmentsByKey(constant.GROUP_KEY, "")
+ svc.Interface = invocation.AttachmentsByKey(constant.InterfaceKey, "")
+ svc.Version = invocation.AttachmentsByKey(constant.VersionKey, "")
+ svc.Group = invocation.AttachmentsByKey(constant.GroupKey, "")
svc.Method = invocation.MethodName()
- timeout, err := strconv.Atoi(invocation.AttachmentsByKey(constant.TIMEOUT_KEY, strconv.Itoa(constant.DEFAULT_REMOTING_TIMEOUT)))
+ timeout, err := strconv.Atoi(invocation.AttachmentsByKey(constant.TimeoutKey, strconv.Itoa(constant.DEFAULT_REMOTING_TIMEOUT)))
if err != nil {
// it will be wrapped in readwrite.Write .
return nil, perrors.WithStack(err)
@@ -77,7 +77,7 @@ func (c *DubboCodec) EncodeRequest(request *remoting.Request) (*bytes.Buffer, er
svc.Timeout = time.Duration(timeout)
header := impl.DubboHeader{}
- serialization := invocation.AttachmentsByKey(constant.SERIALIZATION_KEY, constant.HESSIAN2_SERIALIZATION)
+ serialization := invocation.AttachmentsByKey(constant.SerializationKey, constant.HESSIAN2_SERIALIZATION)
if serialization == constant.PROTOBUF_SERIALIZATION {
header.SerialID = constant.S_Proto
} else {
@@ -218,7 +218,7 @@ func (c *DubboCodec) decodeRequest(data []byte) (*remoting.Request, int, error)
// path
attachments[constant.PATH_KEY] = pkg.Service.Path
// version
- attachments[constant.VERSION_KEY] = pkg.Service.Version
+ attachments[constant.VersionKey] = pkg.Service.Version
// method
methodName = pkg.Service.Method
args = req[impl.ArgsKey].([]interface{})
diff --git a/protocol/dubbo/dubbo_exporter.go b/protocol/dubbo/dubbo_exporter.go
index 534365871f..655c28e4d4 100644
--- a/protocol/dubbo/dubbo_exporter.go
+++ b/protocol/dubbo/dubbo_exporter.go
@@ -42,7 +42,7 @@ func NewDubboExporter(key string, invoker protocol.Invoker, exporterMap *sync.Ma
// Unexport unexport dubbo service exporter.
func (de *DubboExporter) Unexport() {
- interfaceName := de.GetInvoker().GetURL().GetParam(constant.INTERFACE_KEY, "")
+ interfaceName := de.GetInvoker().GetURL().GetParam(constant.InterfaceKey, "")
de.BaseExporter.Unexport()
err := common.ServiceMap.UnRegister(interfaceName, DUBBO, de.GetInvoker().GetURL().ServiceKey())
if err != nil {
diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go
index 7ae67232b7..bea12168f2 100644
--- a/protocol/dubbo/dubbo_invoker.go
+++ b/protocol/dubbo/dubbo_invoker.go
@@ -40,8 +40,8 @@ import (
)
var attachmentKey = []string{
- constant.INTERFACE_KEY, constant.GROUP_KEY, constant.TOKEN_KEY, constant.TIMEOUT_KEY,
- constant.VERSION_KEY,
+ constant.InterfaceKey, constant.GroupKey, constant.TOKEN_KEY, constant.TimeoutKey,
+ constant.VersionKey,
}
// DubboInvoker is implement of protocol.Invoker. A dubboInvoker refers to one service and ip.
@@ -59,7 +59,7 @@ type DubboInvoker struct {
func NewDubboInvoker(url *common.URL, client *remoting.ExchangeClient) *DubboInvoker {
rt := config.GetConsumerConfig().RequestTimeout
- timeout := url.GetParamDuration(constant.TIMEOUT_KEY, rt)
+ timeout := url.GetParamDuration(constant.TimeoutKey, rt)
di := &DubboInvoker{
BaseInvoker: *protocol.NewBaseInvoker(url),
clientGuard: &sync.RWMutex{},
@@ -117,7 +117,7 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
inv := invocation.(*invocation_impl.RPCInvocation)
// init param
- inv.SetAttachments(constant.PATH_KEY, di.GetURL().GetParam(constant.INTERFACE_KEY, ""))
+ inv.SetAttachments(constant.PATH_KEY, di.GetURL().GetParam(constant.InterfaceKey, ""))
for _, k := range attachmentKey {
if v := di.GetURL().GetParam(k, ""); len(v) > 0 {
inv.SetAttachments(k, v)
@@ -129,11 +129,11 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
url := di.GetURL()
// default hessian2 serialization, compatible
- if url.GetParam(constant.SERIALIZATION_KEY, "") == "" {
- url.SetParam(constant.SERIALIZATION_KEY, constant.HESSIAN2_SERIALIZATION)
+ if url.GetParam(constant.SerializationKey, "") == "" {
+ url.SetParam(constant.SerializationKey, constant.HESSIAN2_SERIALIZATION)
}
// async
- async, err := strconv.ParseBool(inv.AttachmentsByKey(constant.ASYNC_KEY, "false"))
+ async, err := strconv.ParseBool(inv.AttachmentsByKey(constant.AsyncKey, "false"))
if err != nil {
logger.Errorf("ParseBool - error: %v", err)
async = false
@@ -166,19 +166,19 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
// get timeout including methodConfig
func (di *DubboInvoker) getTimeout(invocation *invocation_impl.RPCInvocation) time.Duration {
methodName := invocation.MethodName()
- if di.GetURL().GetParamBool(constant.GENERIC_KEY, false) {
+ if di.GetURL().GetParamBool(constant.GenericKey, false) {
methodName = invocation.Arguments()[0].(string)
}
- timeout := di.GetURL().GetParam(strings.Join([]string{constant.METHOD_KEYS, methodName, constant.TIMEOUT_KEY}, "."), "")
+ timeout := di.GetURL().GetParam(strings.Join([]string{constant.METHOD_KEYS, methodName, constant.TimeoutKey}, "."), "")
if len(timeout) != 0 {
if t, err := time.ParseDuration(timeout); err == nil {
// config timeout into attachment
- invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(t.Milliseconds())))
+ invocation.SetAttachments(constant.TimeoutKey, strconv.Itoa(int(t.Milliseconds())))
return t
}
}
// set timeout into invocation at method level
- invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(di.timeout.Milliseconds())))
+ invocation.SetAttachments(constant.TimeoutKey, strconv.Itoa(int(di.timeout.Milliseconds())))
return di.timeout
}
diff --git a/protocol/dubbo/impl/hessian.go b/protocol/dubbo/impl/hessian.go
index 756650f770..2d966755c4 100644
--- a/protocol/dubbo/impl/hessian.go
+++ b/protocol/dubbo/impl/hessian.go
@@ -255,7 +255,7 @@ func unmarshalRequestBody(body []byte, p *DubboPackage) error {
}
if attachments == nil {
- attachments = map[interface{}]interface{}{constant.INTERFACE_KEY: target}
+ attachments = map[interface{}]interface{}{constant.InterfaceKey: target}
}
if v, ok := attachments.(map[interface{}]interface{}); ok {
@@ -373,13 +373,13 @@ func buildServerSidePackageBody(pkg *DubboPackage) {
if svc.Path == "" && attachments[constant.PATH_KEY] != nil && len(attachments[constant.PATH_KEY].(string)) > 0 {
svc.Path = attachments[constant.PATH_KEY].(string)
}
- if _, ok := attachments[constant.INTERFACE_KEY]; ok {
- svc.Interface = attachments[constant.INTERFACE_KEY].(string)
+ if _, ok := attachments[constant.InterfaceKey]; ok {
+ svc.Interface = attachments[constant.InterfaceKey].(string)
} else {
svc.Interface = svc.Path
}
- if _, ok := attachments[constant.GROUP_KEY]; ok {
- svc.Group = attachments[constant.GROUP_KEY].(string)
+ if _, ok := attachments[constant.GroupKey]; ok {
+ svc.Group = attachments[constant.GroupKey].(string)
}
pkg.SetService(svc)
pkg.SetBody(map[string]interface{}{
diff --git a/protocol/dubbo3/dubbo3_exporter.go b/protocol/dubbo3/dubbo3_exporter.go
index 8bea0fa0cd..e82423833a 100644
--- a/protocol/dubbo3/dubbo3_exporter.go
+++ b/protocol/dubbo3/dubbo3_exporter.go
@@ -50,8 +50,8 @@ func NewDubboExporter(key string, invoker protocol.Invoker, exporterMap *sync.Ma
// Unexport unexport dubbo3 service exporter.
func (de *DubboExporter) Unexport() {
url := de.GetInvoker().GetURL()
- serviceId := url.GetParam(constant.BEAN_NAME_KEY, "")
- interfaceName := url.GetParam(constant.INTERFACE_KEY, "")
+ serviceId := url.GetParam(constant.BeanNameKey, "")
+ interfaceName := url.GetParam(constant.InterfaceKey, "")
de.BaseExporter.Unexport()
err := common.ServiceMap.UnRegister(interfaceName, tripleConstant.TRIPLE, serviceId)
if err != nil {
diff --git a/protocol/dubbo3/dubbo3_invoker.go b/protocol/dubbo3/dubbo3_invoker.go
index a55ee54c9a..0539790c23 100644
--- a/protocol/dubbo3/dubbo3_invoker.go
+++ b/protocol/dubbo3/dubbo3_invoker.go
@@ -58,21 +58,21 @@ type DubboInvoker struct {
func NewDubboInvoker(url *common.URL) (*DubboInvoker, error) {
rt := config.GetConsumerConfig().RequestTimeout
- timeout := url.GetParamDuration(constant.TIMEOUT_KEY, rt)
+ timeout := url.GetParamDuration(constant.TimeoutKey, rt)
// for triple pb serialization. The bean name from provider is the provider reference key,
// which can't locate the target consumer stub, so we use interface key..
- interfaceKey := url.GetParam(constant.INTERFACE_KEY, "")
+ interfaceKey := url.GetParam(constant.InterfaceKey, "")
consumerService := config.GetConsumerServiceByInterfaceName(interfaceKey)
- dubboSerializaerType := url.GetParam(constant.SERIALIZATION_KEY, constant.PROTOBUF_SERIALIZATION)
+ dubboSerializaerType := url.GetParam(constant.SerializationKey, constant.PROTOBUF_SERIALIZATION)
triCodecType := tripleConstant.CodecType(dubboSerializaerType)
// new triple client
triOption := triConfig.NewTripleOption(
triConfig.WithClientTimeout(uint32(timeout.Seconds())),
triConfig.WithCodecType(triCodecType),
triConfig.WithLocation(url.Location),
- triConfig.WithHeaderAppVersion(url.GetParam(constant.APP_VERSION_KEY, "")),
- triConfig.WithHeaderGroup(url.GetParam(constant.GROUP_KEY, "")),
+ triConfig.WithHeaderAppVersion(url.GetParam(constant.AppVersionKey, "")),
+ triConfig.WithHeaderGroup(url.GetParam(constant.GroupKey, "")),
triConfig.WithLogger(logger.GetLogger()),
)
client, err := triple.NewTripleClient(consumerService, triOption)
@@ -135,7 +135,7 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
// append interface id to ctx
ctx = context.WithValue(ctx, tripleConstant.CtxAttachmentKey, invocation.Attachments())
- ctx = context.WithValue(ctx, tripleConstant.InterfaceKey, di.BaseInvoker.GetURL().GetParam(constant.INTERFACE_KEY, ""))
+ ctx = context.WithValue(ctx, tripleConstant.InterfaceKey, di.BaseInvoker.GetURL().GetParam(constant.InterfaceKey, ""))
in := make([]reflect.Value, 0, 16)
in = append(in, reflect.ValueOf(ctx))
@@ -155,16 +155,16 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
// get timeout including methodConfig
func (di *DubboInvoker) getTimeout(invocation *invocation_impl.RPCInvocation) time.Duration {
- timeout := di.GetURL().GetParam(strings.Join([]string{constant.METHOD_KEYS, invocation.MethodName(), constant.TIMEOUT_KEY}, "."), "")
+ timeout := di.GetURL().GetParam(strings.Join([]string{constant.METHOD_KEYS, invocation.MethodName(), constant.TimeoutKey}, "."), "")
if len(timeout) != 0 {
if t, err := time.ParseDuration(timeout); err == nil {
// config timeout into attachment
- invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(t.Milliseconds())))
+ invocation.SetAttachments(constant.TimeoutKey, strconv.Itoa(int(t.Milliseconds())))
return t
}
}
// set timeout into invocation at method level
- invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(di.timeout.Milliseconds())))
+ invocation.SetAttachments(constant.TimeoutKey, strconv.Itoa(int(di.timeout.Milliseconds())))
return di.timeout
}
diff --git a/protocol/dubbo3/dubbo3_protocol.go b/protocol/dubbo3/dubbo3_protocol.go
index e53b6a4ec8..a836e0d37f 100644
--- a/protocol/dubbo3/dubbo3_protocol.go
+++ b/protocol/dubbo3/dubbo3_protocol.go
@@ -79,11 +79,11 @@ func (dp *DubboProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
dp.SetExporterMap(serviceKey, exporter)
logger.Infof("Export service: %s", url.String())
- key := url.GetParam(constant.BEAN_NAME_KEY, "")
+ key := url.GetParam(constant.BeanNameKey, "")
var service interface{}
service = config.GetProviderService(key)
- serializationType := url.GetParam(constant.SERIALIZATION_KEY, constant.PROTOBUF_SERIALIZATION)
+ serializationType := url.GetParam(constant.SerializationKey, constant.PROTOBUF_SERIALIZATION)
var triSerializationType tripleConstant.CodecType
if serializationType == constant.PROTOBUF_SERIALIZATION {
@@ -119,7 +119,7 @@ func (dp *DubboProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
triSerializationType = tripleConstant.CodecType(serializationType)
}
- dp.serviceMap.Store(url.GetParam(constant.INTERFACE_KEY, ""), service)
+ dp.serviceMap.Store(url.GetParam(constant.InterfaceKey, ""), service)
// try start server
dp.openServer(url, triSerializationType)
diff --git a/protocol/grpc/client.go b/protocol/grpc/client.go
index ab8c0dba8b..8a05abcc69 100644
--- a/protocol/grpc/client.go
+++ b/protocol/grpc/client.go
@@ -83,7 +83,7 @@ func NewClient(url *common.URL) (*Client, error) {
return nil, err
}
- key := url.GetParam(constant.INTERFACE_KEY, "")
+ key := url.GetParam(constant.InterfaceKey, "")
impl := config.GetConsumerServiceByInterfaceName(key)
invoker := getInvoker(impl, conn)
diff --git a/protocol/grpc/grpc_exporter.go b/protocol/grpc/grpc_exporter.go
index 46740f7f78..a5f00450d0 100644
--- a/protocol/grpc/grpc_exporter.go
+++ b/protocol/grpc/grpc_exporter.go
@@ -42,7 +42,7 @@ func NewGrpcExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map
// Unexport and unregister gRPC service from registry and memory.
func (gg *GrpcExporter) Unexport() {
- interfaceName := gg.GetInvoker().GetURL().GetParam(constant.INTERFACE_KEY, "")
+ interfaceName := gg.GetInvoker().GetURL().GetParam(constant.InterfaceKey, "")
gg.BaseExporter.Unexport()
err := common.ServiceMap.UnRegister(interfaceName, GRPC, gg.GetInvoker().GetURL().ServiceKey())
if err != nil {
diff --git a/protocol/invocation/rpcinvocation.go b/protocol/invocation/rpcinvocation.go
index 6aa49407a3..c729c09be7 100644
--- a/protocol/invocation/rpcinvocation.go
+++ b/protocol/invocation/rpcinvocation.go
@@ -194,8 +194,8 @@ func (r *RPCInvocation) SetCallBack(c interface{}) {
}
func (r *RPCInvocation) ServiceKey() string {
- return common.ServiceKey(strings.TrimPrefix(r.AttachmentsByKey(constant.PATH_KEY, r.AttachmentsByKey(constant.INTERFACE_KEY, "")), "/"),
- r.AttachmentsByKey(constant.GROUP_KEY, ""), r.AttachmentsByKey(constant.VERSION_KEY, ""))
+ return common.ServiceKey(strings.TrimPrefix(r.AttachmentsByKey(constant.PATH_KEY, r.AttachmentsByKey(constant.InterfaceKey, "")), "/"),
+ r.AttachmentsByKey(constant.GroupKey, ""), r.AttachmentsByKey(constant.VersionKey, ""))
}
// /////////////////////////
diff --git a/protocol/invocation/rpcinvocation_test.go b/protocol/invocation/rpcinvocation_test.go
index 320f8aee92..b29f23c634 100644
--- a/protocol/invocation/rpcinvocation_test.go
+++ b/protocol/invocation/rpcinvocation_test.go
@@ -54,10 +54,10 @@ func TestRPCInvocation_ServiceKey(t *testing.T) {
sameInfPathConsumerUrl, err := common.NewURL(sameInfPathConsumerURL)
assert.NoError(t, err)
invocation := NewRPCInvocationWithOptions(WithAttachments(map[string]interface{}{
- constant.INTERFACE_KEY: sameInfPathConsumerUrl.GetParam(constant.INTERFACE_KEY, ""),
- constant.PATH_KEY: sameInfPathConsumerUrl.Path,
- constant.GROUP_KEY: sameInfPathConsumerUrl.GetParam(constant.GROUP_KEY, ""),
- constant.VERSION_KEY: sameInfPathConsumerUrl.GetParam(constant.VERSION_KEY, ""),
+ constant.InterfaceKey: sameInfPathConsumerUrl.GetParam(constant.InterfaceKey, ""),
+ constant.PATH_KEY: sameInfPathConsumerUrl.Path,
+ constant.GroupKey: sameInfPathConsumerUrl.GetParam(constant.GroupKey, ""),
+ constant.VersionKey: sameInfPathConsumerUrl.GetParam(constant.VersionKey, ""),
}))
assert.Equal(t, providerUrl.ServiceKey(), invocation.ServiceKey())
@@ -65,10 +65,10 @@ func TestRPCInvocation_ServiceKey(t *testing.T) {
diffInfPathConsumerUrl, err := common.NewURL(diffInfPathConsumerURL)
assert.NoError(t, err)
invocation = NewRPCInvocationWithOptions(WithAttachments(map[string]interface{}{
- constant.INTERFACE_KEY: diffInfPathConsumerUrl.GetParam(constant.INTERFACE_KEY, ""),
- constant.PATH_KEY: diffInfPathConsumerUrl.Path,
- constant.GROUP_KEY: diffInfPathConsumerUrl.GetParam(constant.GROUP_KEY, ""),
- constant.VERSION_KEY: diffInfPathConsumerUrl.GetParam(constant.VERSION_KEY, ""),
+ constant.InterfaceKey: diffInfPathConsumerUrl.GetParam(constant.InterfaceKey, ""),
+ constant.PATH_KEY: diffInfPathConsumerUrl.Path,
+ constant.GroupKey: diffInfPathConsumerUrl.GetParam(constant.GroupKey, ""),
+ constant.VersionKey: diffInfPathConsumerUrl.GetParam(constant.VersionKey, ""),
}))
assert.Equal(t, providerUrl.ServiceKey(), invocation.ServiceKey())
}
diff --git a/protocol/jsonrpc/http.go b/protocol/jsonrpc/http.go
index 92c748ac8d..95d4ddbd9a 100644
--- a/protocol/jsonrpc/http.go
+++ b/protocol/jsonrpc/http.go
@@ -101,9 +101,9 @@ func NewHTTPClient(opt *HTTPOptions) *HTTPClient {
func (c *HTTPClient) NewRequest(service *common.URL, method string, args interface{}) *Request {
return &Request{
ID: atomic.AddInt64(&c.ID, 1),
- group: service.GetParam(constant.GROUP_KEY, ""),
+ group: service.GetParam(constant.GroupKey, ""),
protocol: service.Protocol,
- version: service.GetParam(constant.VERSION_KEY, ""),
+ version: service.GetParam(constant.VersionKey, ""),
service: service.Path,
method: method,
args: args,
diff --git a/protocol/jsonrpc/jsonrpc_exporter.go b/protocol/jsonrpc/jsonrpc_exporter.go
index dc9848c844..a1b85a0147 100644
--- a/protocol/jsonrpc/jsonrpc_exporter.go
+++ b/protocol/jsonrpc/jsonrpc_exporter.go
@@ -42,7 +42,7 @@ func NewJsonrpcExporter(key string, invoker protocol.Invoker, exporterMap *sync.
// Unexport exported JSON RPC service.
func (je *JsonrpcExporter) Unexport() {
- interfaceName := je.GetInvoker().GetURL().GetParam(constant.INTERFACE_KEY, "")
+ interfaceName := je.GetInvoker().GetURL().GetParam(constant.InterfaceKey, "")
je.BaseExporter.Unexport()
err := common.ServiceMap.UnRegister(interfaceName, JSONRPC, je.GetInvoker().GetURL().ServiceKey())
if err != nil {
diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go
index 771615f40d..400b69072f 100644
--- a/protocol/jsonrpc/server.go
+++ b/protocol/jsonrpc/server.go
@@ -347,8 +347,8 @@ func serveRequest(ctx context.Context, header map[string]string, body []byte, co
invoker := exporter.(*JsonrpcExporter).GetInvoker()
if invoker != nil {
result := invoker.Invoke(ctx, invocation.NewRPCInvocation(methodName, args, map[string]interface{}{
- constant.PATH_KEY: path,
- constant.VERSION_KEY: codec.req.Version,
+ constant.PATH_KEY: path,
+ constant.VersionKey: codec.req.Version,
}))
if err := result.Error(); err != nil {
rspStream, codecErr := codec.Write(err.Error(), invalidRequest)
diff --git a/protocol/protocolwrapper/protocol_filter_wrapper.go b/protocol/protocolwrapper/protocol_filter_wrapper.go
index 42b6905f35..f04e15a3a8 100644
--- a/protocol/protocolwrapper/protocol_filter_wrapper.go
+++ b/protocol/protocolwrapper/protocol_filter_wrapper.go
@@ -63,7 +63,7 @@ func (pfw *ProtocolFilterWrapper) Refer(url *common.URL) protocol.Invoker {
if invoker == nil {
return nil
}
- return BuildInvokerChain(invoker, constant.REFERENCE_FILTER_KEY)
+ return BuildInvokerChain(invoker, constant.ReferenceFilterKey)
}
// Destroy will destroy all invoker and exporter.
diff --git a/protocol/protocolwrapper/protocol_filter_wrapper_test.go b/protocol/protocolwrapper/protocol_filter_wrapper_test.go
index 2400058e56..42bd0a0512 100644
--- a/protocol/protocolwrapper/protocol_filter_wrapper_test.go
+++ b/protocol/protocolwrapper/protocol_filter_wrapper_test.go
@@ -56,7 +56,7 @@ func TestProtocolFilterWrapperRefer(t *testing.T) {
u := common.NewURLWithOptions(
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.REFERENCE_FILTER_KEY, mockFilterKey))
+ common.WithParamsValue(constant.ReferenceFilterKey, mockFilterKey))
invoker := filtProto.Refer(u)
_, ok := invoker.(*FilterInvoker)
assert.True(t, ok)
diff --git a/protocol/rest/rest_exporter.go b/protocol/rest/rest_exporter.go
index 68f56670f0..b3e3a4814c 100644
--- a/protocol/rest/rest_exporter.go
+++ b/protocol/rest/rest_exporter.go
@@ -42,7 +42,7 @@ func NewRestExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map
// Unexport unexport the RestExporter
func (re *RestExporter) Unexport() {
- interfaceName := re.GetInvoker().GetURL().GetParam(constant.INTERFACE_KEY, "")
+ interfaceName := re.GetInvoker().GetURL().GetParam(constant.InterfaceKey, "")
re.BaseExporter.Unexport()
err := common.ServiceMap.UnRegister(interfaceName, REST, re.GetInvoker().GetURL().ServiceKey())
if err != nil {
diff --git a/protocol/rest/rest_protocol.go b/protocol/rest/rest_protocol.go
index 476a9fe6f1..32d007aa7c 100644
--- a/protocol/rest/rest_protocol.go
+++ b/protocol/rest/rest_protocol.go
@@ -68,7 +68,7 @@ func (rp *RestProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
url := invoker.GetURL()
serviceKey := url.ServiceKey()
exporter := NewRestExporter(serviceKey, invoker, rp.ExporterMap())
- id := url.GetParam(constant.BEAN_NAME_KEY, "")
+ id := url.GetParam(constant.BeanNameKey, "")
restServiceConfig := rest_config.GetRestProviderServiceConfig(id)
if restServiceConfig == nil {
logger.Errorf("%s service doesn't has provider config", url.Path)
@@ -88,13 +88,13 @@ func (rp *RestProtocol) Refer(url *common.URL) protocol.Invoker {
// todo fix timeout config
// start
requestTimeout := time.Duration(3 * time.Second)
- requestTimeoutStr := url.GetParam(constant.TIMEOUT_KEY, "3s")
+ requestTimeoutStr := url.GetParam(constant.TimeoutKey, "3s")
connectTimeout := requestTimeout // config.GetConsumerConfig().ConnectTimeout
// end
if t, err := time.ParseDuration(requestTimeoutStr); err == nil {
requestTimeout = t
}
- id := url.GetParam(constant.BEAN_NAME_KEY, "")
+ id := url.GetParam(constant.BeanNameKey, "")
restServiceConfig := rest_config.GetRestConsumerServiceConfig(id)
if restServiceConfig == nil {
logger.Errorf("%s service doesn't has consumer config", url.Path)
diff --git a/registry/base_registry.go b/registry/base_registry.go
index bdc991509e..6acbfbdc55 100644
--- a/registry/base_registry.go
+++ b/registry/base_registry.go
@@ -144,8 +144,8 @@ func (r *BaseRegistry) Register(conf *common.URL) error {
conf.Port = portToRegistry
}
// todo bug when provider、consumer simultaneous initialization
- //role, _ := strconv.Atoi(r.URL.GetParam(constant.ROLE_KEY, ""))
- role, _ := strconv.Atoi(conf.GetParam(constant.ROLE_KEY, ""))
+ //role, _ := strconv.Atoi(r.URL.GetParam(constant.RoleKey, ""))
+ role, _ := strconv.Atoi(conf.GetParam(constant.RoleKey, ""))
// Check if the service has been registered
r.cltLock.Lock()
_, ok = r.services[conf.Key()]
@@ -270,13 +270,13 @@ func (r *BaseRegistry) processURL(c *common.URL, f func(string, string) error, c
params.Add("ip", localIP)
// params.Add("timeout", fmt.Sprintf("%d", int64(r.Timeout)/1e6))
- role, _ := strconv.Atoi(c.GetParam(constant.ROLE_KEY, ""))
- //role, _ := strconv.Atoi(r.URL.GetParam(constant.ROLE_KEY, ""))
+ role, _ := strconv.Atoi(c.GetParam(constant.RoleKey, ""))
+ //role, _ := strconv.Atoi(r.URL.GetParam(constant.RoleKey, ""))
switch role {
case common.PROVIDER:
dubboPath, rawURL, err = r.providerRegistry(c, params, cpf)
- case common.CONSUMER:
+ case common.Consumer:
dubboPath, rawURL, err = r.consumerRegistry(c, params, cpf)
default:
return perrors.Errorf("@c{%v} type is not referencer or provider", c)
@@ -360,7 +360,7 @@ func (r *BaseRegistry) consumerRegistry(c *common.URL, params url.Values, f crea
rawURL string
err error
)
- dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.CONSUMER])
+ dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.Consumer])
if f != nil {
err = f(dubboPath)
@@ -383,7 +383,7 @@ func (r *BaseRegistry) consumerRegistry(c *common.URL, params url.Values, f crea
params.Add("protocol", c.Protocol)
s, _ := url.QueryUnescape(params.Encode())
rawURL = fmt.Sprintf("consumer://%s%s?%s", localIP, c.Path, s)
- dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), (common.RoleType(common.CONSUMER)).String())
+ dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), (common.RoleType(common.Consumer)).String())
logger.Debugf("consumer path:%s, url:%s", dubboPath, rawURL)
return dubboPath, rawURL, nil
diff --git a/registry/directory/directory.go b/registry/directory/directory.go
index bec03343bb..eb67b77a67 100644
--- a/registry/directory/directory.go
+++ b/registry/directory/directory.go
@@ -291,7 +291,7 @@ func (dir *RegistryDirectory) toGroupInvokers() []protocol.Invoker {
})
for _, invoker := range newInvokersList {
- group := invoker.GetURL().GetParam(constant.GROUP_KEY, "")
+ group := invoker.GetURL().GetParam(constant.GroupKey, "")
groupInvokersMap[group] = append(groupInvokersMap[group], invoker)
}
@@ -304,7 +304,7 @@ func (dir *RegistryDirectory) toGroupInvokers() []protocol.Invoker {
} else {
for _, invokers := range groupInvokersMap {
staticDir := static.NewDirectory(invokers)
- cst := extension.GetCluster(dir.GetURL().SubURL.GetParam(constant.CLUSTER_KEY, constant.DEFAULT_CLUSTER))
+ cst := extension.GetCluster(dir.GetURL().SubURL.GetParam(constant.ClusterKey, constant.DEFAULT_CLUSTER))
err = staticDir.BuildRouterChain(invokers)
if err != nil {
logger.Error(err)
diff --git a/registry/directory/directory_test.go b/registry/directory/directory_test.go
index 49f305e119..ce760ccc55 100644
--- a/registry/directory/directory_test.go
+++ b/registry/directory/directory_test.go
@@ -82,36 +82,36 @@ func Test_List(t *testing.T) {
func Test_MergeProviderUrl(t *testing.T) {
registryDirectory, mockRegistry := normalRegistryDir(true)
providerUrl, _ := common.NewURL("dubbo://0.0.0.0:20000/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock1"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"))
+ common.WithParamsValue(constant.ClusterKey, "mock1"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"))
mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: providerUrl})
time.Sleep(1e9)
assert.Len(t, registryDirectory.cacheInvokers, 1)
if len(registryDirectory.cacheInvokers) > 0 {
- assert.Equal(t, "mock", registryDirectory.cacheInvokers[0].GetURL().GetParam(constant.CLUSTER_KEY, ""))
+ assert.Equal(t, "mock", registryDirectory.cacheInvokers[0].GetURL().GetParam(constant.ClusterKey, ""))
}
}
func Test_MergeOverrideUrl(t *testing.T) {
registryDirectory, mockRegistry := normalRegistryDir(true)
providerUrl, _ := common.NewURL("dubbo://0.0.0.0:20000/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"))
+ common.WithParamsValue(constant.ClusterKey, "mock"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"))
mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: providerUrl})
Loop1:
for {
if len(registryDirectory.cacheInvokers) > 0 {
overrideUrl, _ := common.NewURL("override://0.0.0.0:20000/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock1"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"))
+ common.WithParamsValue(constant.ClusterKey, "mock1"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"))
mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: overrideUrl})
Loop2:
for {
if len(registryDirectory.cacheInvokers) > 0 {
- if "mock1" == registryDirectory.cacheInvokers[0].GetURL().GetParam(constant.CLUSTER_KEY, "") {
+ if "mock1" == registryDirectory.cacheInvokers[0].GetURL().GetParam(constant.ClusterKey, "") {
assert.Len(t, registryDirectory.cacheInvokers, 1)
assert.True(t, true)
break Loop2
@@ -128,13 +128,13 @@ Loop1:
func Test_RefreshUrl(t *testing.T) {
registryDirectory, mockRegistry := normalRegistryDir()
providerUrl, _ := common.NewURL("dubbo://0.0.0.0:20011/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock1"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"))
+ common.WithParamsValue(constant.ClusterKey, "mock1"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"))
providerUrl2, _ := common.NewURL("dubbo://0.0.0.0:20012/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock1"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"))
+ common.WithParamsValue(constant.ClusterKey, "mock1"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"))
time.Sleep(1e9)
assert.Len(t, registryDirectory.cacheInvokers, 3)
mockRegistry.MockEvent(®istry.ServiceEvent{Action: remoting.EventTypeAdd, Service: providerUrl})
@@ -161,9 +161,9 @@ func normalRegistryDir(noMockEvent ...bool) (*RegistryDirectory, *registry.MockR
url, _ := common.NewURL("mock://127.0.0.1:1111")
suburl, _ := common.NewURL(
"dubbo://127.0.0.1:20000/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"),
)
url.SubURL = suburl
mockRegistry, _ := registry.NewMockRegistry(&common.URL{})
diff --git a/registry/etcdv3/registry_test.go b/registry/etcdv3/registry_test.go
index 1cd300bbf9..beca799ffe 100644
--- a/registry/etcdv3/registry_test.go
+++ b/registry/etcdv3/registry_test.go
@@ -33,7 +33,7 @@ import (
)
func initRegistry(t *testing.T) *etcdV3Registry {
- regurl, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ regurl, err := common.NewURL("registry://127.0.0.1:2379", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
if err != nil {
t.Fatal(err)
}
@@ -53,7 +53,7 @@ func initRegistry(t *testing.T) *etcdV3Registry {
//func (suite *RegistryTestSuite) TestRegister() {
// t := suite.T()
//
-// url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
+// url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.ClusterKey, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
//
// reg := initRegistry(t)
// err := reg.Register(url)
@@ -68,8 +68,8 @@ func initRegistry(t *testing.T) *etcdV3Registry {
//
//func (suite *RegistryTestSuite) TestSubscribe() {
// t := suite.T()
-// regurl, _ := common.NewURL("registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
-// url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
+// regurl, _ := common.NewURL("registry://127.0.0.1:1111", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
+// url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.ClusterKey, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
//
// reg := initRegistry(t)
// // provider register
@@ -79,7 +79,7 @@ func initRegistry(t *testing.T) *etcdV3Registry {
// }
//
// // consumer register
-// regurl.SetParam(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
+// regurl.SetParam(constant.RoleKey, strconv.Itoa(common.Consumer))
// reg2 := initRegistry(t)
//
// err = reg2.Register(url)
@@ -98,7 +98,7 @@ func initRegistry(t *testing.T) *etcdV3Registry {
func (suite *RegistryTestSuite) TestConsumerDestroy() {
t := suite.T()
- url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
+ url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.ClusterKey, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
reg := initRegistry(t)
_, err := reg.DoSubscribe(url)
@@ -116,7 +116,7 @@ func (suite *RegistryTestSuite) TestConsumerDestroy() {
func (suite *RegistryTestSuite) TestProviderDestroy() {
t := suite.T()
reg := initRegistry(t)
- url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
+ url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.ClusterKey, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
err := reg.Register(url)
assert.NoError(t, err)
diff --git a/registry/event/metadata_service_url_params_customizer.go b/registry/event/metadata_service_url_params_customizer.go
index 53e79b44e2..085480d2f9 100644
--- a/registry/event/metadata_service_url_params_customizer.go
+++ b/registry/event/metadata_service_url_params_customizer.go
@@ -36,12 +36,12 @@ import (
func init() {
exceptKeys := gxset.NewSet(
- // remove APPLICATION_KEY because service name must be present
- constant.APPLICATION_KEY,
- // remove GROUP_KEY, always uses service name.
- constant.GROUP_KEY,
- // remove TIMESTAMP_KEY because it's nonsense
- constant.TIMESTAMP_KEY)
+ // remove ApplicationKey because service name must be present
+ constant.ApplicationKey,
+ // remove GroupKey, always uses service name.
+ constant.GroupKey,
+ // remove TimestampKey because it's nonsense
+ constant.TimestampKey)
extension.AddCustomizers(&metadataServiceURLParamsMetadataCustomizer{exceptKeys: exceptKeys})
}
diff --git a/registry/event/service_revision_customizer.go b/registry/event/service_revision_customizer.go
index 77e022cc17..ccf848588e 100644
--- a/registry/event/service_revision_customizer.go
+++ b/registry/event/service_revision_customizer.go
@@ -104,7 +104,7 @@ func resolveRevision(urls []*common.URL) string {
candidates := make([]string, 0, len(urls))
for _, u := range urls {
- sk := u.GetParam(constant.INTERFACE_KEY, "")
+ sk := u.GetParam(constant.InterfaceKey, "")
if len(u.Methods) == 0 {
candidates = append(candidates, sk)
diff --git a/registry/kubernetes/registry_test.go b/registry/kubernetes/registry_test.go
index 1125a9ebf4..d3ab0de51d 100644
--- a/registry/kubernetes/registry_test.go
+++ b/registry/kubernetes/registry_test.go
@@ -226,7 +226,7 @@ func getTestRegistry(t *testing.T) *kubernetesRegistry {
}
}
- regurl, err := common.NewURL("registry://127.0.0.1:443", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ regurl, err := common.NewURL("registry://127.0.0.1:443", common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
if err != nil {
t.Fatal(err)
}
@@ -244,7 +244,7 @@ func TestRegister(t *testing.T) {
url, _ := common.NewURL(
"dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
common.WithMethods([]string{"GetUser", "AddUser"}),
)
@@ -261,7 +261,7 @@ func TestRegister(t *testing.T) {
// r := getTestRegistry(t)
// defer r.Destroy()
//
-// url, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
+// url, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.ClusterKey, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
// if err != nil {
// t.Fatal(err)
// }
@@ -294,7 +294,7 @@ func TestConsumerDestroy(t *testing.T) {
r := getTestRegistry(t)
url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
_, err := r.DoSubscribe(url)
@@ -313,7 +313,7 @@ func TestProviderDestroy(t *testing.T) {
r := getTestRegistry(t)
url, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
err := r.Register(url)
assert.NoError(t, err)
@@ -325,7 +325,7 @@ func TestProviderDestroy(t *testing.T) {
func TestNewRegistry(t *testing.T) {
regUrl, err := common.NewURL("registry://127.0.0.1:443",
- common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
+ common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.PROVIDER)))
if err != nil {
t.Fatal(err)
}
diff --git a/registry/nacos/listener.go b/registry/nacos/listener.go
index 8dad195c19..a186182a5d 100644
--- a/registry/nacos/listener.go
+++ b/registry/nacos/listener.go
@@ -179,9 +179,9 @@ func getSubscribeName(url *common.URL) string {
var buffer bytes.Buffer
buffer.Write([]byte(common.DubboNodes[common.PROVIDER]))
- appendParam(&buffer, url, constant.INTERFACE_KEY)
- appendParam(&buffer, url, constant.VERSION_KEY)
- appendParam(&buffer, url, constant.GROUP_KEY)
+ appendParam(&buffer, url, constant.InterfaceKey)
+ appendParam(&buffer, url, constant.VersionKey)
+ appendParam(&buffer, url, constant.GroupKey)
return buffer.String()
}
diff --git a/registry/nacos/registry.go b/registry/nacos/registry.go
index 348555c0e9..531ea6ca25 100644
--- a/registry/nacos/registry.go
+++ b/registry/nacos/registry.go
@@ -60,7 +60,7 @@ type nacosRegistry struct {
}
func getCategory(url *common.URL) string {
- role, _ := strconv.Atoi(url.GetParam(constant.ROLE_KEY, strconv.Itoa(constant.NACOS_DEFAULT_ROLETYPE)))
+ role, _ := strconv.Atoi(url.GetParam(constant.RoleKey, strconv.Itoa(constant.NACOS_DEFAULT_ROLETYPE)))
category := common.DubboNodes[role]
return category
}
@@ -69,9 +69,9 @@ func getServiceName(url *common.URL) string {
var buffer bytes.Buffer
buffer.Write([]byte(getCategory(url)))
- appendParam(&buffer, url, constant.INTERFACE_KEY)
- appendParam(&buffer, url, constant.VERSION_KEY)
- appendParam(&buffer, url, constant.GROUP_KEY)
+ appendParam(&buffer, url, constant.InterfaceKey)
+ appendParam(&buffer, url, constant.VersionKey)
+ appendParam(&buffer, url, constant.GroupKey)
return buffer.String()
}
@@ -119,7 +119,7 @@ func createRegisterParam(url *common.URL, serviceName string, groupName string)
// Register will register the service @url to its nacos registry center
func (nr *nacosRegistry) Register(url *common.URL) error {
serviceName := getServiceName(url)
- groupName := nr.URL.GetParam(constant.GROUP_KEY, defaultGroup)
+ groupName := nr.URL.GetParam(constant.GroupKey, defaultGroup)
param := createRegisterParam(url, serviceName, groupName)
isRegistry, err := nr.namingClient.Client().RegisterInstance(param)
if err != nil {
@@ -151,7 +151,7 @@ func createDeregisterParam(url *common.URL, serviceName string, groupName string
func (nr *nacosRegistry) DeRegister(url *common.URL) error {
serviceName := getServiceName(url)
- groupName := nr.URL.GetParam(constant.GROUP_KEY, defaultGroup)
+ groupName := nr.URL.GetParam(constant.GroupKey, defaultGroup)
param := createDeregisterParam(url, serviceName, groupName)
isDeRegistry, err := nr.namingClient.Client().DeregisterInstance(param)
if err != nil {
@@ -175,9 +175,9 @@ func (nr *nacosRegistry) subscribe(conf *common.URL) (registry.Listener, error)
// subscribe from registry
func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) error {
// TODO
- // role, _ := strconv.Atoi(nr.URL.GetParam(constant.ROLE_KEY, ""))
- role, _ := strconv.Atoi(url.GetParam(constant.ROLE_KEY, ""))
- if role != common.CONSUMER {
+ // role, _ := strconv.Atoi(nr.URL.GetParam(constant.RoleKey, ""))
+ role, _ := strconv.Atoi(url.GetParam(constant.RoleKey, ""))
+ if role != common.Consumer {
return nil
}
@@ -187,7 +187,7 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
return perrors.New("nacosRegistry is not available.")
}
- groupName := nr.GetParam(constant.GROUP_KEY, defaultGroup)
+ groupName := nr.GetParam(constant.GroupKey, defaultGroup)
url.SetParam(constant.REGISTRY_GROUP_KEY, groupName) // update to registry.group
listener, err := nr.subscribe(url)
diff --git a/registry/nacos/registry_test.go b/registry/nacos/registry_test.go
index 4728019c42..f4c49caf19 100644
--- a/registry/nacos/registry_test.go
+++ b/registry/nacos/registry_test.go
@@ -43,16 +43,16 @@ func TestNacosRegistry_Register(t *testing.T) {
return
}
regurlMap := url.Values{}
- regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
+ regurlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))
urlMap := url.Values{}
- urlMap.Set(constant.GROUP_KEY, "guangzhou-idc")
- urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
- urlMap.Set(constant.INTERFACE_KEY, "com.ikurento.user.UserProvider")
- urlMap.Set(constant.VERSION_KEY, "1.0.0")
- urlMap.Set(constant.CLUSTER_KEY, "mock")
+ urlMap.Set(constant.GroupKey, "guangzhou-idc")
+ urlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
+ urlMap.Set(constant.InterfaceKey, "com.ikurento.user.UserProvider")
+ urlMap.Set(constant.VersionKey, "1.0.0")
+ urlMap.Set(constant.ClusterKey, "mock")
testUrl, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
reg, err := newNacosRegistry(regurl)
@@ -80,16 +80,16 @@ func TestNacosRegistry_Subscribe(t *testing.T) {
return
}
regurlMap := url.Values{}
- regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
+ regurlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))
urlMap := url.Values{}
- urlMap.Set(constant.GROUP_KEY, "guangzhou-idc")
- urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
- urlMap.Set(constant.INTERFACE_KEY, "com.dubbo.user.UserProvider")
- urlMap.Set(constant.VERSION_KEY, "1.0.0")
- urlMap.Set(constant.CLUSTER_KEY, "mock")
+ urlMap.Set(constant.GroupKey, "guangzhou-idc")
+ urlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
+ urlMap.Set(constant.InterfaceKey, "com.dubbo.user.UserProvider")
+ urlMap.Set(constant.VersionKey, "1.0.0")
+ urlMap.Set(constant.ClusterKey, "mock")
urlMap.Set(constant.NACOS_PATH_KEY, "")
testUrl, _ := common.NewURL("dubbo://127.0.0.1:20000/com.dubbo.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
@@ -101,7 +101,7 @@ func TestNacosRegistry_Subscribe(t *testing.T) {
return
}
- regurl.SetParam(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
+ regurl.SetParam(constant.RoleKey, strconv.Itoa(common.Consumer))
reg2, _ := newNacosRegistry(regurl)
listener, err := reg2.(*nacosRegistry).subscribe(testUrl)
assert.Nil(t, err)
@@ -124,16 +124,16 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) {
return
}
regurlMap := url.Values{}
- regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
+ regurlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))
urlMap := url.Values{}
- urlMap.Set(constant.GROUP_KEY, "guangzhou-idc")
- urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
- urlMap.Set(constant.INTERFACE_KEY, "com.ikurento.user.UserProvider")
- urlMap.Set(constant.VERSION_KEY, "2.0.0")
- urlMap.Set(constant.CLUSTER_KEY, "mock")
+ urlMap.Set(constant.GroupKey, "guangzhou-idc")
+ urlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
+ urlMap.Set(constant.InterfaceKey, "com.ikurento.user.UserProvider")
+ urlMap.Set(constant.VersionKey, "2.0.0")
+ urlMap.Set(constant.ClusterKey, "mock")
urlMap.Set(constant.NACOS_PATH_KEY, "")
url1, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
url2, _ := common.NewURL("dubbo://127.0.0.2:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
@@ -152,7 +152,7 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) {
return
}
- regurl.SetParam(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
+ regurl.SetParam(constant.RoleKey, strconv.Itoa(common.Consumer))
reg2, _ := newNacosRegistry(regurl)
listener, err := reg2.(*nacosRegistry).subscribe(url1)
assert.Nil(t, err)
@@ -198,16 +198,16 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) {
func TestNacosListener_Close(t *testing.T) {
regurlMap := url.Values{}
- regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
+ regurlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))
urlMap := url.Values{}
- urlMap.Set(constant.GROUP_KEY, "guangzhou-idc")
- urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
- urlMap.Set(constant.INTERFACE_KEY, "com.ikurento.user.UserProvider2")
- urlMap.Set(constant.VERSION_KEY, "1.0.0")
- urlMap.Set(constant.CLUSTER_KEY, "mock")
+ urlMap.Set(constant.GroupKey, "guangzhou-idc")
+ urlMap.Set(constant.RoleKey, strconv.Itoa(common.PROVIDER))
+ urlMap.Set(constant.InterfaceKey, "com.ikurento.user.UserProvider2")
+ urlMap.Set(constant.VersionKey, "1.0.0")
+ urlMap.Set(constant.ClusterKey, "mock")
urlMap.Set(constant.NACOS_PATH_KEY, "")
url1, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider2", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
reg, _ := newNacosRegistry(regurl)
diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go
index 01dbdf2975..566a93f7f3 100644
--- a/registry/protocol/protocol.go
+++ b/registry/protocol/protocol.go
@@ -136,7 +136,7 @@ func (proto *registryProtocol) GetRegistries() []registry.Registry {
func (proto *registryProtocol) Refer(url *common.URL) protocol.Invoker {
registryUrl := url
serviceUrl := registryUrl.SubURL
- if registryUrl.Protocol == constant.REGISTRY_PROTOCOL {
+ if registryUrl.Protocol == constant.RegistryProtocol {
registryUrl.Protocol = registryUrl.GetParam(constant.REGISTRY_KEY, "")
}
@@ -163,7 +163,7 @@ func (proto *registryProtocol) Refer(url *common.URL) protocol.Invoker {
}
// new cluster invoker
- cluster := extension.GetCluster(serviceUrl.GetParam(constant.CLUSTER_KEY, constant.DEFAULT_CLUSTER))
+ cluster := extension.GetCluster(serviceUrl.GetParam(constant.ClusterKey, constant.DEFAULT_CLUSTER))
invoker := cluster.Join(directory)
proto.invokers = append(proto.invokers, invoker)
return invoker
@@ -245,7 +245,7 @@ func registerServiceMap(invoker protocol.Invoker) error {
providerUrl := getProviderUrl(invoker)
// the bean.name param of providerUrl is the ServiceConfig id property
// such as dubbo://:20000/org.apache.dubbo.UserProvider?bean.name=UserProvider&cluster=failfast...
- id := providerUrl.GetParam(constant.BEAN_NAME_KEY, "")
+ id := providerUrl.GetParam(constant.BeanNameKey, "")
serviceConfig := config.GetProviderConfig().Services[id]
if serviceConfig == nil {
@@ -333,8 +333,8 @@ func isMatched(providerUrl *common.URL, consumerUrl *common.URL) bool {
providerUrl.Protocol == constant.OVERRIDE_PROTOCOL {
providerUrl.AddParam(constant.CATEGORY_KEY, constant.CONFIGURATORS_CATEGORY)
}
- consumerInterface := consumerUrl.GetParam(constant.INTERFACE_KEY, consumerUrl.Path)
- providerInterface := providerUrl.GetParam(constant.INTERFACE_KEY, providerUrl.Path)
+ consumerInterface := consumerUrl.GetParam(constant.InterfaceKey, consumerUrl.Path)
+ providerInterface := providerUrl.GetParam(constant.InterfaceKey, providerUrl.Path)
if !(constant.ANY_VALUE == consumerInterface ||
constant.ANY_VALUE == providerInterface ||
@@ -351,12 +351,12 @@ func isMatched(providerUrl *common.URL, consumerUrl *common.URL) bool {
consumerUrl.GetParam(constant.ENABLED_KEY, "") != constant.ANY_VALUE {
return false
}
- consumerGroup := consumerUrl.GetParam(constant.GROUP_KEY, "")
- consumerVersion := consumerUrl.GetParam(constant.VERSION_KEY, "")
+ consumerGroup := consumerUrl.GetParam(constant.GroupKey, "")
+ consumerVersion := consumerUrl.GetParam(constant.VersionKey, "")
consumerClassifier := consumerUrl.GetParam(constant.CLASSIFIER_KEY, "")
- providerGroup := providerUrl.GetParam(constant.GROUP_KEY, "")
- providerVersion := providerUrl.GetParam(constant.VERSION_KEY, "")
+ providerGroup := providerUrl.GetParam(constant.GroupKey, "")
+ providerVersion := providerUrl.GetParam(constant.VersionKey, "")
providerClassifier := providerUrl.GetParam(constant.CLASSIFIER_KEY, "")
// todo: public static boolean isContains(String values, String value) {
// return isNotEmpty(values) && isContains(COMMA_SPLIT_PATTERN.split(values), value);
@@ -411,7 +411,7 @@ func getRegistryUrl(invoker protocol.Invoker) *common.URL {
// here add * for return a new url
url := invoker.GetURL()
// if the protocol == registry, set protocol the registry value in url.params
- if url.Protocol == constant.REGISTRY_PROTOCOL {
+ if url.Protocol == constant.RegistryProtocol {
url.Protocol = url.GetParam(constant.REGISTRY_KEY, "")
}
return url
diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go
index 8c57db09c7..0bef773252 100644
--- a/registry/protocol/protocol_test.go
+++ b/registry/protocol/protocol_test.go
@@ -58,7 +58,7 @@ func referNormal(t *testing.T, regProtocol *registryProtocol) {
url, _ := common.NewURL("mock://127.0.0.1:1111")
suburl, _ := common.NewURL(
"dubbo://127.0.0.1:20000//",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
)
url.SubURL = suburl
@@ -82,7 +82,7 @@ func TestMultiRegRefer(t *testing.T) {
url2, _ := common.NewURL("mock://127.0.0.1:2222")
suburl2, _ := common.NewURL(
"dubbo://127.0.0.1:20000//",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
)
url2.SubURL = suburl2
@@ -103,7 +103,7 @@ func TestOneRegRefer(t *testing.T) {
url2, _ := common.NewURL("mock://127.0.0.1:1111")
suburl2, _ := common.NewURL(
"dubbo://127.0.0.1:20000//",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
)
url2.SubURL = suburl2
@@ -124,9 +124,9 @@ func exporterNormal(t *testing.T, regProtocol *registryProtocol) *common.URL {
url, _ := common.NewURL("mock://127.0.0.1:1111")
suburl, _ := common.NewURL(
"dubbo://127.0.0.1:20000/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"),
)
url.SubURL = suburl
@@ -150,7 +150,7 @@ func TestMultiRegAndMultiProtoExporter(t *testing.T) {
url2, _ := common.NewURL("mock://127.0.0.1:2222")
suburl2, _ := common.NewURL(
"jsonrpc://127.0.0.1:20000//",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
)
url2.SubURL = suburl2
@@ -179,9 +179,9 @@ func TestOneRegAndProtoExporter(t *testing.T) {
url2, _ := common.NewURL("mock://127.0.0.1:1111")
suburl2, _ := common.NewURL(
"dubbo://127.0.0.1:20000/org.apache.dubbo-go.mockService",
- common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
- common.WithParamsValue(constant.GROUP_KEY, "group"),
- common.WithParamsValue(constant.VERSION_KEY, "1.0.0"),
+ common.WithParamsValue(constant.ClusterKey, "mock"),
+ common.WithParamsValue(constant.GroupKey, "group"),
+ common.WithParamsValue(constant.VersionKey, "1.0.0"),
)
url2.SubURL = suburl2
@@ -245,7 +245,7 @@ func TestExportWithOverrideListener(t *testing.T) {
reg.MockEvent(event)
time.Sleep(1e9)
newUrl := url.SubURL.Clone()
- newUrl.SetParam(constant.CLUSTER_KEY, "mock1")
+ newUrl.SetParam(constant.ClusterKey, "mock1")
delKeys := gxset.NewSet("dynamic", "enabled")
key := newUrl.CloneExceptParams(delKeys).String()
v2, _ := regProtocol.bounds.Load(key)
@@ -266,7 +266,7 @@ func TestExportWithServiceConfig(t *testing.T) {
dc.(*config_center.MockDynamicConfiguration).MockServiceConfigEvent()
newUrl := url.SubURL.Clone()
- newUrl.SetParam(constant.CLUSTER_KEY, "mock1")
+ newUrl.SetParam(constant.ClusterKey, "mock1")
delKeys := gxset.NewSet("dynamic", "enabled")
key := newUrl.CloneExceptParams(delKeys).String()
@@ -289,7 +289,7 @@ func TestExportWithApplicationConfig(t *testing.T) {
dc.(*config_center.MockDynamicConfiguration).MockApplicationConfigEvent()
newUrl := url.SubURL.Clone()
- newUrl.SetParam(constant.CLUSTER_KEY, "mock1")
+ newUrl.SetParam(constant.ClusterKey, "mock1")
delKeys := gxset.NewSet("dynamic", "enabled")
key := newUrl.CloneExceptParams(delKeys).String()
v2, _ := regProtocol.bounds.Load(key)
diff --git a/registry/servicediscovery/service_discovery_registry.go b/registry/servicediscovery/service_discovery_registry.go
index c1d9839d27..19d28bb18a 100644
--- a/registry/servicediscovery/service_discovery_registry.go
+++ b/registry/servicediscovery/service_discovery_registry.go
@@ -45,7 +45,7 @@ import (
)
func init() {
- extension.SetRegistry(constant.SERVICE_REGISTRY_PROTOCOL, newServiceDiscoveryRegistry)
+ extension.SetRegistry(constant.ServiceRegistryProtocol, newServiceDiscoveryRegistry)
}
// serviceDiscoveryRegistry is the implementation of application-level registry.
@@ -180,7 +180,7 @@ func (s *serviceDiscoveryRegistry) Register(url *common.URL) error {
}
func shouldRegister(url *common.URL) bool {
- side := url.GetParam(constant.SIDE_KEY, "")
+ side := url.GetParam(constant.SideKey, "")
if side == constant.PROVIDER_PROTOCOL {
return true
}
@@ -245,8 +245,8 @@ func getUrlKey(url *common.URL) string {
bf.WriteString(url.Path)
}
bf.WriteString("?")
- appendParam(bf, constant.VERSION_KEY, url)
- appendParam(bf, constant.GROUP_KEY, url)
+ appendParam(bf, constant.VersionKey, url)
+ appendParam(bf, constant.GroupKey, url)
appendParam(bf, constant.NACOS_PROTOCOL_KEY, url)
return bf.String()
}
@@ -273,7 +273,7 @@ func shouldSubscribe(url *common.URL) bool {
func (s *serviceDiscoveryRegistry) getServices(url *common.URL) *gxset.HashSet {
services := gxset.NewSet()
- serviceNames := url.GetParam(constant.PROVIDED_BY, "")
+ serviceNames := url.GetParam(constant.ProvidedBy, "")
if len(serviceNames) > 0 {
services = parseServices(serviceNames)
}
diff --git a/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer.go b/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer.go
index aa4c84ab93..8f94c00824 100644
--- a/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer.go
+++ b/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer.go
@@ -45,10 +45,10 @@ func (r RestSubscribedURLsSynthesizer) Synthesize(subscribedURL *common.URL, ser
for i, s := range serviceInstances {
splitHost := strings.Split(s.GetHost(), ":")
u := common.NewURLWithOptions(common.WithProtocol(subscribedURL.Protocol), common.WithIp(splitHost[0]),
- common.WithPort(splitHost[1]), common.WithPath(subscribedURL.GetParam(constant.INTERFACE_KEY, subscribedURL.Path)),
+ common.WithPort(splitHost[1]), common.WithPath(subscribedURL.GetParam(constant.InterfaceKey, subscribedURL.Path)),
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
- common.WithParamsValue(constant.APPLICATION_KEY, s.GetServiceName()),
+ common.WithParamsValue(constant.SideKey, constant.PROVIDER_PROTOCOL),
+ common.WithParamsValue(constant.ApplicationKey, s.GetServiceName()),
common.WithParamsValue(constant.REGISTRY_KEY, "true"),
)
urls[i] = u
diff --git a/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go b/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go
index 3a20fdf83d..8d111ed9ac 100644
--- a/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go
+++ b/registry/servicediscovery/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go
@@ -60,14 +60,14 @@ func TestRestSubscribedURLsSynthesizer_Synthesize(t *testing.T) {
u1 := common.NewURLWithOptions(common.WithProtocol("rest"), common.WithIp("127.0.0.1"),
common.WithPort("80"), common.WithPath("org.apache.dubbo-go.mockService"),
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
- common.WithParamsValue(constant.APPLICATION_KEY, "test1"),
+ common.WithParamsValue(constant.SideKey, constant.PROVIDER_PROTOCOL),
+ common.WithParamsValue(constant.ApplicationKey, "test1"),
common.WithParamsValue(constant.REGISTRY_KEY, "true"))
u2 := common.NewURLWithOptions(common.WithProtocol("rest"), common.WithIp("127.0.0.2"),
common.WithPort("8081"), common.WithPath("org.apache.dubbo-go.mockService"),
common.WithParams(url.Values{}),
- common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
- common.WithParamsValue(constant.APPLICATION_KEY, "test2"),
+ common.WithParamsValue(constant.SideKey, constant.PROVIDER_PROTOCOL),
+ common.WithParamsValue(constant.ApplicationKey, "test2"),
common.WithParamsValue(constant.REGISTRY_KEY, "true"))
expectUrls = append(expectUrls, u1, u2)
result := syn.Synthesize(subUrl, instances)
diff --git a/remoting/getty/dubbo_codec_for_test.go b/remoting/getty/dubbo_codec_for_test.go
index b7bd064f68..9a2b84dd8b 100644
--- a/remoting/getty/dubbo_codec_for_test.go
+++ b/remoting/getty/dubbo_codec_for_test.go
@@ -59,11 +59,11 @@ func (c *DubboTestCodec) EncodeRequest(request *remoting.Request) (*bytes.Buffer
svc := impl.Service{}
svc.Path = tmpInvocation.AttachmentsByKey(constant.PATH_KEY, "")
- svc.Interface = tmpInvocation.AttachmentsByKey(constant.INTERFACE_KEY, "")
- svc.Version = tmpInvocation.AttachmentsByKey(constant.VERSION_KEY, "")
- svc.Group = tmpInvocation.AttachmentsByKey(constant.GROUP_KEY, "")
+ svc.Interface = tmpInvocation.AttachmentsByKey(constant.InterfaceKey, "")
+ svc.Version = tmpInvocation.AttachmentsByKey(constant.VersionKey, "")
+ svc.Group = tmpInvocation.AttachmentsByKey(constant.GroupKey, "")
svc.Method = tmpInvocation.MethodName()
- timeout, err := strconv.Atoi(tmpInvocation.AttachmentsByKey(constant.TIMEOUT_KEY, strconv.Itoa(constant.DEFAULT_REMOTING_TIMEOUT)))
+ timeout, err := strconv.Atoi(tmpInvocation.AttachmentsByKey(constant.TimeoutKey, strconv.Itoa(constant.DEFAULT_REMOTING_TIMEOUT)))
if err != nil {
// it will be wrapped in readwrite.Write .
return nil, perrors.WithStack(err)
@@ -71,7 +71,7 @@ func (c *DubboTestCodec) EncodeRequest(request *remoting.Request) (*bytes.Buffer
svc.Timeout = time.Duration(timeout)
header := impl.DubboHeader{}
- serialization := tmpInvocation.AttachmentsByKey(constant.SERIALIZATION_KEY, constant.HESSIAN2_SERIALIZATION)
+ serialization := tmpInvocation.AttachmentsByKey(constant.SerializationKey, constant.HESSIAN2_SERIALIZATION)
if serialization == constant.PROTOBUF_SERIALIZATION {
header.SerialID = constant.S_Proto
} else {
@@ -210,7 +210,7 @@ func (c *DubboTestCodec) decodeRequest(data []byte) (*remoting.Request, int, err
// path
attachments[constant.PATH_KEY] = pkg.Service.Path
// version
- attachments[constant.VERSION_KEY] = pkg.Service.Version
+ attachments[constant.VersionKey] = pkg.Service.Version
// method
methodName = pkg.Service.Method
args = req[impl.ArgsKey].([]interface{})
diff --git a/remoting/getty/getty_client_test.go b/remoting/getty/getty_client_test.go
index 2820681985..346bd7c4c0 100644
--- a/remoting/getty/getty_client_test.go
+++ b/remoting/getty/getty_client_test.go
@@ -58,7 +58,7 @@ func testRequestOneWay(t *testing.T, client *Client) {
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetUser", nil, nil, []interface{}{"1", "username"},
[]reflect.Value{reflect.ValueOf("1"), reflect.ValueOf("username")})
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -109,7 +109,7 @@ func testGetBigPkg(t *testing.T, c *Client) {
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetBigPkg", nil, nil, []interface{}{[]interface{}{nil}, user},
[]reflect.Value{reflect.ValueOf([]interface{}{nil}), reflect.ValueOf(user)})
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -128,7 +128,7 @@ func testGetUser(t *testing.T, c *Client) {
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetUser", nil, nil, []interface{}{"1", "username"},
[]reflect.Value{reflect.ValueOf("1"), reflect.ValueOf("username")})
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -150,7 +150,7 @@ func testGetUser0(t *testing.T, c *Client) {
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetUser0", nil, nil, []interface{}{"1", nil, "username"},
[]reflect.Value{reflect.ValueOf("1"), reflect.ValueOf(nil), reflect.ValueOf("username")})
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -169,7 +169,7 @@ func testGetUser1(t *testing.T, c *Client) {
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetUser1", nil, nil, []interface{}{},
[]reflect.Value{})
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -187,7 +187,7 @@ func testGetUser2(t *testing.T, c *Client) {
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetUser2", nil, nil, []interface{}{},
[]reflect.Value{})
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -204,7 +204,7 @@ func testGetUser3(t *testing.T, c *Client) {
invocation := createInvocation("GetUser3", nil, nil, []interface{}{},
[]reflect.Value{})
attachment := map[string]string{
- INTERFACE_KEY: "com.ikurento.user.UserProvider",
+ InterfaceKey: "com.ikurento.user.UserProvider",
}
setAttachment(invocation, attachment)
request.Data = invocation
@@ -223,7 +223,7 @@ func testGetUser4(t *testing.T, c *Client) {
var err error
request := remoting.NewRequest("2.0.2")
invocation := invocation.NewRPCInvocation("GetUser4", []interface{}{[]interface{}{"1", "username"}}, nil)
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -241,7 +241,7 @@ func testGetUser5(t *testing.T, c *Client) {
var err error
request := remoting.NewRequest("2.0.2")
invocation := invocation.NewRPCInvocation("GetUser5", []interface{}{map[interface{}]interface{}{"id": "1", "name": "username"}}, nil)
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -264,7 +264,7 @@ func testGetUser6(t *testing.T, c *Client) {
user = &User{}
request := remoting.NewRequest("2.0.2")
invocation := invocation.NewRPCInvocation("GetUser6", []interface{}{0}, nil)
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -285,7 +285,7 @@ func testGetUser61(t *testing.T, c *Client) {
user = &User{}
request := remoting.NewRequest("2.0.2")
invocation := invocation.NewRPCInvocation("GetUser6", []interface{}{1}, nil)
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
@@ -304,7 +304,7 @@ func testClient_AsyncCall(t *testing.T, client *Client) {
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetUser0", nil, nil, []interface{}{"4", nil, "username"},
[]reflect.Value{reflect.ValueOf("4"), reflect.ValueOf(nil), reflect.ValueOf("username")})
- attachment := map[string]string{INTERFACE_KEY: "com.ikurento.user.UserProvider"}
+ attachment := map[string]string{InterfaceKey: "com.ikurento.user.UserProvider"}
setAttachment(invocation, attachment)
request.Data = invocation
request.Event = false
diff --git a/remoting/getty/listener_test.go b/remoting/getty/listener_test.go
index 6d22e37dd0..a75a4e658c 100644
--- a/remoting/getty/listener_test.go
+++ b/remoting/getty/listener_test.go
@@ -38,8 +38,8 @@ import (
func TestRebuildCtx(t *testing.T) {
opentracing.SetGlobalTracer(mocktracer.New())
attach := make(map[string]interface{}, 10)
- attach[constant.VERSION_KEY] = "1.0"
- attach[constant.GROUP_KEY] = "MyGroup"
+ attach[constant.VersionKey] = "1.0"
+ attach[constant.GroupKey] = "MyGroup"
inv := invocation.NewRPCInvocation("MethodName", []interface{}{"OK", "Hello"}, attach)
// attachment doesn't contains any tracing key-value pair,
diff --git a/remoting/getty/readwriter_test.go b/remoting/getty/readwriter_test.go
index e9be67dca1..d0c20fe6ce 100644
--- a/remoting/getty/readwriter_test.go
+++ b/remoting/getty/readwriter_test.go
@@ -52,9 +52,9 @@ func testDecodeTCPPackage(t *testing.T, svr *Server, client *Client) {
rpcInvocation := createInvocation("GetAdmin", nil, nil, []interface{}{[]interface{}{"1", "username"}},
[]reflect.Value{reflect.ValueOf([]interface{}{"1", "username"}), reflect.ValueOf(ap)})
attachment := map[string]string{
- constant.INTERFACE_KEY: "com.ikurento.user.AdminProvider",
- constant.PATH_KEY: "AdminProvider",
- constant.VERSION_KEY: "1.0.0",
+ constant.InterfaceKey: "com.ikurento.user.AdminProvider",
+ constant.PATH_KEY: "AdminProvider",
+ constant.VersionKey: "1.0.0",
}
setAttachment(rpcInvocation, attachment)
request.Data = rpcInvocation
diff --git a/remoting/kubernetes/client.go b/remoting/kubernetes/client.go
index 976dd44e0b..57bbc13f76 100644
--- a/remoting/kubernetes/client.go
+++ b/remoting/kubernetes/client.go
@@ -51,7 +51,7 @@ type Client struct {
// NewClient returns Client instance for registry
func NewClient(url *common.URL) (*Client, error) {
// read type
- r, err := strconv.Atoi(url.GetParams().Get(constant.ROLE_KEY))
+ r, err := strconv.Atoi(url.GetParams().Get(constant.RoleKey))
if err != nil {
return nil, perrors.WithMessage(err, "atoi role")
}
@@ -69,7 +69,7 @@ func NewClient(url *common.URL) (*Client, error) {
controller: controller,
}
- if r == common.CONSUMER {
+ if r == common.Consumer {
// only consumer have to start informer factory
c.controller.startALLInformers()
}
@@ -194,7 +194,7 @@ func ValidateClient(container clientFacade) error {
// NewMockClient exports for registry package test
func NewMockClient(podList *v1.PodList) (*Client, error) {
ctx, cancel := context.WithCancel(context.Background())
- controller, err := newDubboRegistryController(ctx, common.CONSUMER, func() (kubernetes.Interface, error) {
+ controller, err := newDubboRegistryController(ctx, common.Consumer, func() (kubernetes.Interface, error) {
return fake.NewSimpleClientset(podList), nil
})
if err != nil {
diff --git a/remoting/kubernetes/facade_test.go b/remoting/kubernetes/facade_test.go
index 7abf736de6..31359ac821 100644
--- a/remoting/kubernetes/facade_test.go
+++ b/remoting/kubernetes/facade_test.go
@@ -60,7 +60,7 @@ func (r *mockFacade) IsAvailable() bool {
func Test_Facade(t *testing.T) {
regUrl, err := common.NewURL("registry://127.0.0.1:443",
- common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER)))
+ common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.Consumer)))
if err != nil {
t.Fatal(err)
}
diff --git a/remoting/kubernetes/registry_controller.go b/remoting/kubernetes/registry_controller.go
index f6a804aa18..8d43c55dff 100644
--- a/remoting/kubernetes/registry_controller.go
+++ b/remoting/kubernetes/registry_controller.go
@@ -521,7 +521,7 @@ func (c *dubboRegistryController) assembleDUBBOLabel(p *v1.Pod) (*v1.Pod, *v1.Po
// assign new label for current pod
switch c.role {
- case common.CONSUMER:
+ case common.Consumer:
newPod.Labels[DubboIOLabelKey] = DubboIOConsumerLabelValue
case common.PROVIDER:
newPod.Labels[DubboIOLabelKey] = DubboIOProviderLabelValue
From 2ca101895c1c392487d7eff5af11fd875ff374b2 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Fri, 29 Oct 2021 23:48:11 +0800
Subject: [PATCH 03/35] feat(adasvc): add p2c load balance
---
cluster/cluster/adasvc/cluster_invoker.go | 75 ++++++++++++++++++++++-
1 file changed, 72 insertions(+), 3 deletions(-)
diff --git a/cluster/cluster/adasvc/cluster_invoker.go b/cluster/cluster/adasvc/cluster_invoker.go
index 4c02bbaab3..4a959f265c 100644
--- a/cluster/cluster/adasvc/cluster_invoker.go
+++ b/cluster/cluster/adasvc/cluster_invoker.go
@@ -21,9 +21,16 @@ import (
"context"
"dubbo.apache.org/dubbo-go/v3/cluster/cluster/base"
"dubbo.apache.org/dubbo-go/v3/cluster/directory"
+ "dubbo.apache.org/dubbo-go/v3/cluster/metrics"
"dubbo.apache.org/dubbo-go/v3/protocol"
+ "fmt"
+ "github.com/pkg/errors"
+ "math/rand"
+ "time"
)
+var ErrUnsupportedMetricsType = errors.New("unsupported metrics type")
+
type clusterInvoker struct {
base.ClusterInvoker
}
@@ -34,7 +41,69 @@ func NewClusterInvoker(directory directory.Directory) protocol.Invoker {
}
}
-func (ivk *clusterInvoker) Invoke(_ context.Context, invocation protocol.Invocation) protocol.Result {
- // invokers for the invocation
+func (ivk *clusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
ivks := ivk.Directory.List(invocation)
-}
\ No newline at end of file
+ if len(ivks) < 2 {
+ return ivks[0].Invoke(ctx, invocation)
+ }
+ // picks two nodes randomly
+ var i, j int
+ if len(ivks) == 2 {
+ i, j = 0, 1
+ } else {
+ rand.Seed(time.Now().Unix())
+ i = rand.Intn(len(ivks))
+ j = i
+ for i == j {
+ j = rand.Intn(len(ivks))
+ }
+ }
+ // compare which node is better
+ m := metrics.LocalMetrics
+ // TODO(justxuewei): please consider get the real method name from $invoke,
+ // see also [#1511](https://github.com/apache/dubbo-go/issues/1511)
+ methodName := invocation.MethodName()
+ // viInterface, vjInterface means vegas latency of node i and node j
+ // If one of the metrics is empty, invoke the invocation to that node directly.
+ viInterface, err := m.GetMethodMetrics(ivks[i].GetURL(), methodName, "vegas")
+ if err != nil {
+ if errors.Is(err, metrics.ErrMetricsNotFound) {
+ return ivks[i].Invoke(ctx, invocation)
+ }
+ return &protocol.RPCResult{
+ Err: fmt.Errorf("get method metrics err: %w", err),
+ }
+ }
+
+ vjInterface, err := m.GetMethodMetrics(ivks[j].GetURL(), methodName, "vegas")
+ if err != nil {
+ if errors.Is(err, metrics.ErrMetricsNotFound) {
+ return ivks[j].Invoke(ctx, invocation)
+ }
+ return &protocol.RPCResult{
+ Err: fmt.Errorf("get method metrics err: %w", err),
+ }
+ }
+
+ // Convert interface to int, if the type is unexpected, return an error immediately
+ vi, ok := viInterface.(int)
+ if !ok {
+ return &protocol.RPCResult{
+ Err: ErrUnsupportedMetricsType,
+ }
+ }
+
+ vj, ok := vjInterface.(int)
+ if !ok {
+ return &protocol.RPCResult{
+ Err: ErrUnsupportedMetricsType,
+ }
+ }
+
+ // For the latency time, the smaller, the better.
+ if vi < vj {
+ return ivks[i].Invoke(ctx, invocation)
+ }
+
+ return ivks[j].Invoke(ctx, invocation)
+}
From e83a8a637fa5f040782b9720f2e051c05159baf1 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sun, 31 Oct 2021 23:44:02 +0800
Subject: [PATCH 04/35] feat(cluster): add capacity evaluator interface
---
.../{adasvc => adaptivesvc}/cluster.go | 2 +-
.../cluster/adaptivesvc/cluster_invoker.go | 55 +++++++++
cluster/cluster/adasvc/cluster_invoker.go | 109 ------------------
cluster/loadbalance/p2c/loadbalance.go | 64 +++++++++-
cluster/metrics/constants.go | 5 +
config/reference_config.go | 2 +-
.../capeva/base_capacity_evaluator.go | 41 +++++++
.../adaptivesvc/capeva/capacity_evaluator.go | 11 ++
filter/adaptivesvc/capeva/vegas.go | 23 ++++
filter/adaptivesvc/filter.go | 19 +++
10 files changed, 219 insertions(+), 112 deletions(-)
rename cluster/cluster/{adasvc => adaptivesvc}/cluster.go (98%)
create mode 100644 cluster/cluster/adaptivesvc/cluster_invoker.go
delete mode 100644 cluster/cluster/adasvc/cluster_invoker.go
create mode 100644 cluster/metrics/constants.go
create mode 100644 filter/adaptivesvc/capeva/base_capacity_evaluator.go
create mode 100644 filter/adaptivesvc/capeva/capacity_evaluator.go
create mode 100644 filter/adaptivesvc/capeva/vegas.go
create mode 100644 filter/adaptivesvc/filter.go
diff --git a/cluster/cluster/adasvc/cluster.go b/cluster/cluster/adaptivesvc/cluster.go
similarity index 98%
rename from cluster/cluster/adasvc/cluster.go
rename to cluster/cluster/adaptivesvc/cluster.go
index 9cc024ef5e..7e1a732d7c 100644
--- a/cluster/cluster/adasvc/cluster.go
+++ b/cluster/cluster/adaptivesvc/cluster.go
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package adasvc
+package adaptivesvc
import (
clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
new file mode 100644
index 0000000000..a11ed88e7d
--- /dev/null
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package adaptivesvc
+
+import (
+ "context"
+ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/base"
+ "dubbo.apache.org/dubbo-go/v3/cluster/directory"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ perrors "github.com/pkg/errors"
+)
+
+type clusterInvoker struct {
+ base.ClusterInvoker
+}
+
+func NewClusterInvoker(directory directory.Directory) protocol.Invoker {
+ return &clusterInvoker{
+ ClusterInvoker: base.NewClusterInvoker(directory),
+ }
+}
+
+func (ivk *clusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
+ invokers := ivk.Directory.List(invocation)
+ if err := ivk.CheckInvokers(invokers, invocation); err != nil {
+ return &protocol.RPCResult{Err: err}
+ }
+
+ lbKey := invokers[0].GetURL().GetParam(constant.LoadbalanceKey, constant.LoadBalanceKeyP2C)
+ if lbKey != constant.LoadBalanceKeyP2C {
+ return &protocol.RPCResult{
+ Err: perrors.Errorf("adaptive service not supports %s load balance", lbKey),
+ }
+ }
+ lb := extension.GetLoadbalance(lbKey)
+ invoker := lb.Select(invokers, invocation)
+ return invoker.Invoke(ctx, invocation)
+}
diff --git a/cluster/cluster/adasvc/cluster_invoker.go b/cluster/cluster/adasvc/cluster_invoker.go
deleted file mode 100644
index 4a959f265c..0000000000
--- a/cluster/cluster/adasvc/cluster_invoker.go
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package adasvc
-
-import (
- "context"
- "dubbo.apache.org/dubbo-go/v3/cluster/cluster/base"
- "dubbo.apache.org/dubbo-go/v3/cluster/directory"
- "dubbo.apache.org/dubbo-go/v3/cluster/metrics"
- "dubbo.apache.org/dubbo-go/v3/protocol"
- "fmt"
- "github.com/pkg/errors"
- "math/rand"
- "time"
-)
-
-var ErrUnsupportedMetricsType = errors.New("unsupported metrics type")
-
-type clusterInvoker struct {
- base.ClusterInvoker
-}
-
-func NewClusterInvoker(directory directory.Directory) protocol.Invoker {
- return &clusterInvoker{
- ClusterInvoker: base.NewClusterInvoker(directory),
- }
-}
-
-func (ivk *clusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
- ivks := ivk.Directory.List(invocation)
- if len(ivks) < 2 {
- return ivks[0].Invoke(ctx, invocation)
- }
- // picks two nodes randomly
- var i, j int
- if len(ivks) == 2 {
- i, j = 0, 1
- } else {
- rand.Seed(time.Now().Unix())
- i = rand.Intn(len(ivks))
- j = i
- for i == j {
- j = rand.Intn(len(ivks))
- }
- }
- // compare which node is better
- m := metrics.LocalMetrics
- // TODO(justxuewei): please consider get the real method name from $invoke,
- // see also [#1511](https://github.com/apache/dubbo-go/issues/1511)
- methodName := invocation.MethodName()
- // viInterface, vjInterface means vegas latency of node i and node j
- // If one of the metrics is empty, invoke the invocation to that node directly.
- viInterface, err := m.GetMethodMetrics(ivks[i].GetURL(), methodName, "vegas")
- if err != nil {
- if errors.Is(err, metrics.ErrMetricsNotFound) {
- return ivks[i].Invoke(ctx, invocation)
- }
- return &protocol.RPCResult{
- Err: fmt.Errorf("get method metrics err: %w", err),
- }
- }
-
- vjInterface, err := m.GetMethodMetrics(ivks[j].GetURL(), methodName, "vegas")
- if err != nil {
- if errors.Is(err, metrics.ErrMetricsNotFound) {
- return ivks[j].Invoke(ctx, invocation)
- }
- return &protocol.RPCResult{
- Err: fmt.Errorf("get method metrics err: %w", err),
- }
- }
-
- // Convert interface to int, if the type is unexpected, return an error immediately
- vi, ok := viInterface.(int)
- if !ok {
- return &protocol.RPCResult{
- Err: ErrUnsupportedMetricsType,
- }
- }
-
- vj, ok := vjInterface.(int)
- if !ok {
- return &protocol.RPCResult{
- Err: ErrUnsupportedMetricsType,
- }
- }
-
- // For the latency time, the smaller, the better.
- if vi < vj {
- return ivks[i].Invoke(ctx, invocation)
- }
-
- return ivks[j].Invoke(ctx, invocation)
-}
diff --git a/cluster/loadbalance/p2c/loadbalance.go b/cluster/loadbalance/p2c/loadbalance.go
index 6e20575f2b..903a6bbd58 100644
--- a/cluster/loadbalance/p2c/loadbalance.go
+++ b/cluster/loadbalance/p2c/loadbalance.go
@@ -22,7 +22,12 @@ import (
"dubbo.apache.org/dubbo-go/v3/cluster/metrics"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/protocol"
+ "errors"
+ "fmt"
+ "math/rand"
+ "time"
)
func init() {
@@ -38,8 +43,65 @@ func newLoadBalance() loadbalance.LoadBalance {
}
func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {
+ if len(invokers) == 0 {
+ return nil
+ }
+ if len(invokers) == 1 {
+ return invokers[0]
+ }
// m is the Metrics, which saves the metrics of instance, invokers and methods
// The local metrics is available only for the earlier version.
m := metrics.LocalMetrics
- panic("implement me")
+ // picks two nodes randomly
+ var i, j int
+ if len(invokers) == 2 {
+ i, j = 0, 1
+ } else {
+ rand.Seed(time.Now().Unix())
+ i = rand.Intn(len(invokers))
+ j = i
+ for i == j {
+ j = rand.Intn(len(invokers))
+ }
+ }
+ // TODO(justxuewei): please consider how to get the real method name from $invoke,
+ // see also [#1511](https://github.com/apache/dubbo-go/issues/1511)
+ methodName := invocation.MethodName()
+ // viInterface, vjInterface means vegas latency of node i and node j
+ // If one of the metrics is empty, invoke the invocation to that node directly.
+ viInterface, err := m.GetMethodMetrics(invokers[i].GetURL(), methodName, metrics.Vegas)
+ if err != nil {
+ if errors.Is(err, metrics.ErrMetricsNotFound) {
+ return invokers[i]
+ }
+ logger.Warnf("get method metrics err: %v", err)
+ return nil
+ }
+
+ vjInterface, err := m.GetMethodMetrics(invokers[j].GetURL(), methodName, metrics.Vegas)
+ if err != nil {
+ if errors.Is(err, metrics.ErrMetricsNotFound) {
+ return invokers[j]
+ }
+ logger.Warnf("get method metrics err: %v", err)
+ return nil
+ }
+
+ // Convert interface to int, if the type is unexpected, panic immediately
+ vi, ok := viInterface.(int)
+ if !ok {
+ panic(fmt.Sprintf("the type of %s expects to be int, but gets %T", metrics.Vegas, viInterface))
+ }
+
+ vj, ok := vjInterface.(int)
+ if !ok {
+ panic(fmt.Sprintf("the type of %s expects to be int, but gets %T", metrics.Vegas, viInterface))
+ }
+
+ // For the latency time, the smaller, the better.
+ if vi < vj {
+ return invokers[i]
+ }
+
+ return invokers[j]
}
\ No newline at end of file
diff --git a/cluster/metrics/constants.go b/cluster/metrics/constants.go
new file mode 100644
index 0000000000..b6a00b836f
--- /dev/null
+++ b/cluster/metrics/constants.go
@@ -0,0 +1,5 @@
+package metrics
+
+const (
+ Vegas = "vegas"
+)
diff --git a/config/reference_config.go b/config/reference_config.go
index a762818d4c..27e69eac1d 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -102,7 +102,7 @@ func (rc *ReferenceConfig) Init(root *RootConfig) error {
// Refer retrieves invokers from urls.
func (rc *ReferenceConfig) Refer(srv interface{}) {
// If adaptive service is enabled,
- // the cluster and load balance should be overridden to "adasvc" and "p2c" respectively.
+ // the cluster and load balance should be overridden to "adaptivesvc" and "p2c" respectively.
if rc.rootConfig.Consumer.AdaptiveService {
rc.Cluster = constant.ClusterKeyAdaptiveService
rc.Loadbalance = constant.LoadBalanceKeyP2C
diff --git a/filter/adaptivesvc/capeva/base_capacity_evaluator.go b/filter/adaptivesvc/capeva/base_capacity_evaluator.go
new file mode 100644
index 0000000000..e29b479a6f
--- /dev/null
+++ b/filter/adaptivesvc/capeva/base_capacity_evaluator.go
@@ -0,0 +1,41 @@
+package capeva
+
+import (
+ "errors"
+ "go.uber.org/atomic"
+)
+
+var ErrInvalidActualValue = errors.New("invalid actual value")
+
+type baseCapacityEvaluator struct {
+ estimated, actual *atomic.Int64
+}
+
+func newBaseCapacityEvaluator() *baseCapacityEvaluator {
+ return &baseCapacityEvaluator{
+ estimated: &atomic.Int64{},
+ actual: &atomic.Int64{},
+ }
+}
+
+func (ce *baseCapacityEvaluator) Estimated() int64 {
+ return ce.estimated.Load()
+}
+
+func (ce *baseCapacityEvaluator) Actual() int64 {
+ return ce.actual.Load()
+}
+
+func (ce *baseCapacityEvaluator) UpdateEstimated(value int64) error {
+ ce.actual.Store(value)
+ return nil
+}
+
+func (ce *baseCapacityEvaluator) UpdateActual(value int64) error {
+ if ce.actual.Load() > ce.estimated.Load() {
+ return ErrInvalidActualValue
+ }
+ ce.actual.Store(value)
+ return nil
+}
+
diff --git a/filter/adaptivesvc/capeva/capacity_evaluator.go b/filter/adaptivesvc/capeva/capacity_evaluator.go
new file mode 100644
index 0000000000..893f9f164b
--- /dev/null
+++ b/filter/adaptivesvc/capeva/capacity_evaluator.go
@@ -0,0 +1,11 @@
+package capeva
+
+type CapacityEvaluator interface {
+ // Estimated is estimated capacity, which reflects the maximum requests handled by the provider
+ Estimated() int64
+ UpdateEstimated(value int64) error
+
+ // Actual is actual requests on the provider
+ Actual() int64
+ UpdateActual(value int64) error
+}
\ No newline at end of file
diff --git a/filter/adaptivesvc/capeva/vegas.go b/filter/adaptivesvc/capeva/vegas.go
new file mode 100644
index 0000000000..b29f956832
--- /dev/null
+++ b/filter/adaptivesvc/capeva/vegas.go
@@ -0,0 +1,23 @@
+package capeva
+
+import "sync"
+
+type Vegas struct {
+ *baseCapacityEvaluator
+
+ // mutex protects invocationMetricsMap
+ mutex *sync.Mutex
+ invocationMetricsMap map[string]*vegasInvocationMetrics
+}
+
+func NewVegas() *Vegas {
+ return &Vegas{
+ baseCapacityEvaluator: newBaseCapacityEvaluator(),
+ mutex: &sync.Mutex{},
+ invocationMetricsMap: make(map[string]*vegasInvocationMetrics),
+ }
+}
+
+type vegasInvocationMetrics struct {
+
+}
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
new file mode 100644
index 0000000000..220d0945f1
--- /dev/null
+++ b/filter/adaptivesvc/filter.go
@@ -0,0 +1,19 @@
+package adaptivesvc
+
+import (
+ "context"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+)
+
+// Filter for adaptive service on server side.
+type Filter struct {}
+
+func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
+ panic("implement me")
+}
+
+func (f *Filter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker,
+ invocation protocol.Invocation) protocol.Result {
+ panic("implement me")
+}
+
From f0c64e64fa7128fabb76172fc062d4e5965b4104 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Mon, 1 Nov 2021 14:14:46 +0800
Subject: [PATCH 05/35] feat(cluster): add capacity updater
---
.../capeva/base_capacity_evaluator.go | 19 +++++++--------
.../adaptivesvc/capeva/capacity_evaluator.go | 14 +++++++----
filter/adaptivesvc/capeva/vegas.go | 8 +++----
.../capupd/base_capacity_updater.go | 24 +++++++++++++++++++
filter/adaptivesvc/capupd/capacity_updater.go | 8 +++++++
filter/adaptivesvc/capupd/vegas.go | 21 ++++++++++++++++
6 files changed, 75 insertions(+), 19 deletions(-)
create mode 100644 filter/adaptivesvc/capupd/base_capacity_updater.go
create mode 100644 filter/adaptivesvc/capupd/capacity_updater.go
create mode 100644 filter/adaptivesvc/capupd/vegas.go
diff --git a/filter/adaptivesvc/capeva/base_capacity_evaluator.go b/filter/adaptivesvc/capeva/base_capacity_evaluator.go
index e29b479a6f..97605a5094 100644
--- a/filter/adaptivesvc/capeva/base_capacity_evaluator.go
+++ b/filter/adaptivesvc/capeva/base_capacity_evaluator.go
@@ -1,12 +1,10 @@
package capeva
import (
- "errors"
+ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capupd"
"go.uber.org/atomic"
)
-var ErrInvalidActualValue = errors.New("invalid actual value")
-
type baseCapacityEvaluator struct {
estimated, actual *atomic.Int64
}
@@ -26,16 +24,15 @@ func (ce *baseCapacityEvaluator) Actual() int64 {
return ce.actual.Load()
}
-func (ce *baseCapacityEvaluator) UpdateEstimated(value int64) error {
+func (ce *baseCapacityEvaluator) UpdateEstimated(value int64) {
ce.actual.Store(value)
- return nil
}
-func (ce *baseCapacityEvaluator) UpdateActual(value int64) error {
- if ce.actual.Load() > ce.estimated.Load() {
- return ErrInvalidActualValue
- }
- ce.actual.Store(value)
- return nil
+func (ce *baseCapacityEvaluator) UpdateActual(delta int64) {
+ ce.actual.Add(delta)
+}
+
+func (ce *baseCapacityEvaluator) NewCapacityUpdater() capupd.CapacityUpdater {
+ panic("implement me!")
}
diff --git a/filter/adaptivesvc/capeva/capacity_evaluator.go b/filter/adaptivesvc/capeva/capacity_evaluator.go
index 893f9f164b..74f1634c0c 100644
--- a/filter/adaptivesvc/capeva/capacity_evaluator.go
+++ b/filter/adaptivesvc/capeva/capacity_evaluator.go
@@ -1,11 +1,17 @@
package capeva
+import "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capupd"
+
type CapacityEvaluator interface {
- // Estimated is estimated capacity, which reflects the maximum requests handled by the provider
+ // Estimated is estimated capacity, which reflects the maximum requests handled by the provider.
Estimated() int64
- UpdateEstimated(value int64) error
+ UpdateEstimated(value int64)
- // Actual is actual requests on the provider
+ // Actual is actual requests on the provider.
Actual() int64
- UpdateActual(value int64) error
+ // UpdateActual updates by delta, for instance, if a new request comes, the delta should be 1.
+ UpdateActual(delta int64)
+
+ // NewCapacityUpdater returns a capacity updater
+ NewCapacityUpdater() capupd.CapacityUpdater
}
\ No newline at end of file
diff --git a/filter/adaptivesvc/capeva/vegas.go b/filter/adaptivesvc/capeva/vegas.go
index b29f956832..7fbc0ca93a 100644
--- a/filter/adaptivesvc/capeva/vegas.go
+++ b/filter/adaptivesvc/capeva/vegas.go
@@ -5,19 +5,19 @@ import "sync"
type Vegas struct {
*baseCapacityEvaluator
- // mutex protects invocationMetricsMap
+ // mutex protects vegasDataMap
mutex *sync.Mutex
- invocationMetricsMap map[string]*vegasInvocationMetrics
+ vegasDataMap map[string]*vegasData
}
func NewVegas() *Vegas {
return &Vegas{
baseCapacityEvaluator: newBaseCapacityEvaluator(),
mutex: &sync.Mutex{},
- invocationMetricsMap: make(map[string]*vegasInvocationMetrics),
+ vegasDataMap: make(map[string]*vegasData),
}
}
-type vegasInvocationMetrics struct {
+type vegasData struct {
}
diff --git a/filter/adaptivesvc/capupd/base_capacity_updater.go b/filter/adaptivesvc/capupd/base_capacity_updater.go
new file mode 100644
index 0000000000..c010292325
--- /dev/null
+++ b/filter/adaptivesvc/capupd/base_capacity_updater.go
@@ -0,0 +1,24 @@
+package capupd
+
+import "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capeva"
+
+type baseCapacityUpdater struct {
+ capacityEvaluator capeva.CapacityEvaluator
+}
+
+func newBaseCapacityUpdater(eva capeva.CapacityEvaluator) *baseCapacityUpdater {
+ cu := &baseCapacityUpdater{
+ capacityEvaluator: eva,
+ }
+ cu.capacityEvaluator.UpdateActual(1)
+ return cu
+}
+
+func (b *baseCapacityUpdater) Succeed() {
+ panic("implement me")
+}
+
+func (b *baseCapacityUpdater) Failed() {
+ panic("implement me")
+}
+
diff --git a/filter/adaptivesvc/capupd/capacity_updater.go b/filter/adaptivesvc/capupd/capacity_updater.go
new file mode 100644
index 0000000000..d640d1c295
--- /dev/null
+++ b/filter/adaptivesvc/capupd/capacity_updater.go
@@ -0,0 +1,8 @@
+package capupd
+
+type CapacityUpdater interface {
+ // Succeed updates capacity evaluator if the invocation finish successfully.
+ Succeed()
+ // Failed updates capacity evaluator if the invocation finish unsuccessfully.
+ Failed()
+}
diff --git a/filter/adaptivesvc/capupd/vegas.go b/filter/adaptivesvc/capupd/vegas.go
new file mode 100644
index 0000000000..dc74642bd3
--- /dev/null
+++ b/filter/adaptivesvc/capupd/vegas.go
@@ -0,0 +1,21 @@
+package capupd
+
+import "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capeva"
+
+type Vegas struct {
+ *baseCapacityUpdater
+}
+
+func NewVegas(eva capeva.CapacityEvaluator) *Vegas {
+ return &Vegas{
+ baseCapacityUpdater: newBaseCapacityUpdater(eva),
+ }
+}
+
+func (v *Vegas) Succeed() {
+ v.capacityEvaluator.UpdateActual(-1)
+}
+
+func (v *Vegas) Failed() {
+ v.capacityEvaluator.UpdateActual(-1)
+}
From 69dd9d3c9a073e323724ed168474a307bb7f6f41 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Wed, 3 Nov 2021 14:20:43 +0800
Subject: [PATCH 06/35] feat(cluster): add capacity updater
---
cluster/cluster/adaptivesvc/cluster.go | 4 +-
cluster/loadbalance/p2c/loadbalance.go | 3 +-
cluster/metrics/local_metrics.go | 6 +-
cluster/metrics/metrics.go | 2 +-
cluster/metrics/utils.go | 2 +-
common/constant/default.go | 8 +-
common/constant/key.go | 90 +++++++++----------
config/reference_config.go | 18 ++--
filter/adaptivesvc/capeva/vegas.go | 17 ++--
.../capupd/base_capacity_updater.go | 1 -
filter/adaptivesvc/capupd/capacity_updater.go | 2 +
filter/adaptivesvc/capupd/vegas.go | 8 +-
filter/adaptivesvc/filter.go | 3 +-
13 files changed, 84 insertions(+), 80 deletions(-)
diff --git a/cluster/cluster/adaptivesvc/cluster.go b/cluster/cluster/adaptivesvc/cluster.go
index 7e1a732d7c..bd279e4b50 100644
--- a/cluster/cluster/adaptivesvc/cluster.go
+++ b/cluster/cluster/adaptivesvc/cluster.go
@@ -30,7 +30,7 @@ func init() {
}
// cluster is a cluster for adaptive service.
-type cluster struct {}
+type cluster struct{}
func newCluster() clusterpkg.Cluster {
return &cluster{}
@@ -38,4 +38,4 @@ func newCluster() clusterpkg.Cluster {
func (c *cluster) Join(directory directory.Directory) protocol.Invoker {
return clusterpkg.BuildInterceptorChain(NewClusterInvoker(directory))
-}
\ No newline at end of file
+}
diff --git a/cluster/loadbalance/p2c/loadbalance.go b/cluster/loadbalance/p2c/loadbalance.go
index 903a6bbd58..2cf472f629 100644
--- a/cluster/loadbalance/p2c/loadbalance.go
+++ b/cluster/loadbalance/p2c/loadbalance.go
@@ -35,7 +35,6 @@ func init() {
}
type loadBalance struct {
-
}
func newLoadBalance() loadbalance.LoadBalance {
@@ -104,4 +103,4 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
}
return invokers[j]
-}
\ No newline at end of file
+}
diff --git a/cluster/metrics/local_metrics.go b/cluster/metrics/local_metrics.go
index 828c9dc8ae..58fe1bb5e8 100644
--- a/cluster/metrics/local_metrics.go
+++ b/cluster/metrics/local_metrics.go
@@ -14,13 +14,13 @@ func init() {
type localMetrics struct {
// protect metrics
- lock *sync.Mutex
+ lock *sync.Mutex
metrics map[string]interface{}
}
func newLocalMetrics() *localMetrics {
return &localMetrics{
- lock: &sync.Mutex{},
+ lock: &sync.Mutex{},
metrics: make(map[string]interface{}),
}
}
@@ -53,4 +53,4 @@ func (m *localMetrics) GetInstanceMetrics(url *common.URL, key string) (interfac
func (m *localMetrics) SetInstanceMetrics(url *common.URL, key string, value interface{}) error {
panic("implement me")
-}
\ No newline at end of file
+}
diff --git a/cluster/metrics/metrics.go b/cluster/metrics/metrics.go
index 389e0ea18b..d800a08329 100644
--- a/cluster/metrics/metrics.go
+++ b/cluster/metrics/metrics.go
@@ -26,4 +26,4 @@ type Metrics interface {
// DO NOT IMPLEMENT FOR EARLIER VERSION
GetInstanceMetrics(url *common.URL, key string) (interface{}, error)
SetInstanceMetrics(url *common.URL, key string, value interface{}) error
-}
\ No newline at end of file
+}
diff --git a/cluster/metrics/utils.go b/cluster/metrics/utils.go
index 456fa0f57e..18aed82fc0 100644
--- a/cluster/metrics/utils.go
+++ b/cluster/metrics/utils.go
@@ -11,4 +11,4 @@ func getInvokerKey(url *common.URL) string {
func getInstanceKey(url *common.URL) string {
return fmt.Sprintf("%s:%s", url.Ip, url.Port)
-}
\ No newline at end of file
+}
diff --git a/common/constant/default.go b/common/constant/default.go
index 0081462304..a9facf9aaa 100644
--- a/common/constant/default.go
+++ b/common/constant/default.go
@@ -50,13 +50,13 @@ const (
)
const (
- DEFAULT_KEY = "default"
- PREFIX_DEFAULT_KEY = "default."
- DEFAULT_SERVICE_FILTERS = EchoFilterKey + "," + MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," + GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey
+ DEFAULT_KEY = "default"
+ PREFIX_DEFAULT_KEY = "default."
+ DEFAULT_SERVICE_FILTERS = EchoFilterKey + "," + MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," + GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey
DefaultReferenceFilters = GracefulShutdownConsumerFilterKey
GenericReferenceFilters = GenericFilterKey
GENERIC = "$invoke"
- ECHO = "$echo"
+ ECHO = "$echo"
)
const (
diff --git a/common/constant/key.go b/common/constant/key.go
index ffde1218c1..5b2bdef017 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -24,22 +24,22 @@ const (
)
const (
- GroupKey = "group"
- VersionKey = "version"
- InterfaceKey = "interface"
- MESSAGE_SIZE_KEY = "message_size"
+ GroupKey = "group"
+ VersionKey = "version"
+ InterfaceKey = "interface"
+ MESSAGE_SIZE_KEY = "message_size"
PATH_KEY = "path"
SERVICE_KEY = "service"
- METHODS_KEY = "methods"
- TimeoutKey = "timeout"
- CATEGORY_KEY = "category"
+ METHODS_KEY = "methods"
+ TimeoutKey = "timeout"
+ CATEGORY_KEY = "category"
CHECK_KEY = "check"
- ENABLED_KEY = "enabled"
- SideKey = "side"
- OVERRIDE_PROVIDERS_KEY = "providerAddresses"
- BeanNameKey = "bean.name"
- GenericKey = "generic"
- CLASSIFIER_KEY = "classifier"
+ ENABLED_KEY = "enabled"
+ SideKey = "side"
+ OVERRIDE_PROVIDERS_KEY = "providerAddresses"
+ BeanNameKey = "bean.name"
+ GenericKey = "generic"
+ CLASSIFIER_KEY = "classifier"
TOKEN_KEY = "token"
LOCAL_ADDR = "local-addr"
REMOTE_ADDR = "remote-addr"
@@ -53,7 +53,7 @@ const (
// DUBBO_KEY = "dubbo"
SSL_ENABLED_KEY = "ssl-enabled"
// PARAMS_TYPE_Key key used in pass through invoker factory, to define param type
- PARAMS_TYPE_Key = "parameter-type-names"
+ PARAMS_TYPE_Key = "parameter-type-names"
DEFAULT_Key = "default"
MetadatatypeKey = "metadata-type"
)
@@ -88,15 +88,15 @@ const (
)
const (
- TimestampKey = "timestamp"
- REMOTE_TIMESTAMP_KEY = "remote.timestamp"
- ClusterKey = "cluster"
- LoadbalanceKey = "loadbalance"
- WEIGHT_KEY = "weight"
- WARMUP_KEY = "warmup"
- RetriesKey = "retries"
- StickyKey = "sticky"
- BEAN_NAME = "bean.name"
+ TimestampKey = "timestamp"
+ REMOTE_TIMESTAMP_KEY = "remote.timestamp"
+ ClusterKey = "cluster"
+ LoadbalanceKey = "loadbalance"
+ WEIGHT_KEY = "weight"
+ WARMUP_KEY = "warmup"
+ RetriesKey = "retries"
+ StickyKey = "sticky"
+ BEAN_NAME = "bean.name"
FAIL_BACK_TASKS_KEY = "failbacktasks"
FORKS_KEY = "forks"
DEFAULT_FORKS = 2
@@ -125,31 +125,31 @@ const (
)
const (
- REGISTRY_KEY = "registry"
+ REGISTRY_KEY = "registry"
RegistryProtocol = "registry"
ServiceRegistryProtocol = "service-discovery-registry"
RoleKey = "registry.role"
- REGISTRY_DEFAULT_KEY = "registry.default"
- REGISTRY_TIMEOUT_KEY = "registry.timeout"
- REGISTRY_LABEL_KEY = "label"
- PREFERRED_KEY = "preferred"
- ZONE_KEY = "zone"
- ZONE_FORCE_KEY = "zone.force"
- REGISTRY_TTL_KEY = "registry.ttl"
- SIMPLIFIED_KEY = "simplified"
- NAMESPACE_KEY = "namespace"
- REGISTRY_GROUP_KEY = "registry.group"
+ REGISTRY_DEFAULT_KEY = "registry.default"
+ REGISTRY_TIMEOUT_KEY = "registry.timeout"
+ REGISTRY_LABEL_KEY = "label"
+ PREFERRED_KEY = "preferred"
+ ZONE_KEY = "zone"
+ ZONE_FORCE_KEY = "zone.force"
+ REGISTRY_TTL_KEY = "registry.ttl"
+ SIMPLIFIED_KEY = "simplified"
+ NAMESPACE_KEY = "namespace"
+ REGISTRY_GROUP_KEY = "registry.group"
)
const (
- ApplicationKey = "application"
- OrganizationKey = "organization"
- NameKey = "name"
- ModuleKey = "module"
- AppVersionKey = "app.version"
- OwnerKey = "owner"
- EnvironmentKey = "environment"
- METHOD_KEY = "method"
+ ApplicationKey = "application"
+ OrganizationKey = "organization"
+ NameKey = "name"
+ ModuleKey = "module"
+ AppVersionKey = "app.version"
+ OwnerKey = "owner"
+ EnvironmentKey = "environment"
+ METHOD_KEY = "method"
METHOD_KEYS = "methods"
RULE_KEY = "rule"
RUNTIME_KEY = "runtime"
@@ -307,9 +307,9 @@ const (
// service discovery
const (
- SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services"
- ProvidedBy = "provided-by"
- EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.metadata.revision"
+ SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services"
+ ProvidedBy = "provided-by"
+ EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.metadata.revision"
SUBSCRIBED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.subscribed-services.revision"
SERVICE_INSTANCE_SELECTOR = "service-instance-selector"
METADATA_STORAGE_TYPE_PROPERTY_NAME = "dubbo.metadata.storage-type"
diff --git a/config/reference_config.go b/config/reference_config.go
index 27e69eac1d..f31a8c27c4 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -126,15 +126,15 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
// retrieving urls from config, and appending the urls to rc.urls
if rc.URL != "" { // use user-specific urls
/*
- Two types of URL are allowed for rc.URL:
- 1. direct url: server IP, that is, no need for a registry anymore
- 2. registry url
- They will be handled in different ways:
- For example, we have a direct url and a registry url:
- 1. "tri://localhost:10000" is a direct url
- 2. "registry://localhost:2181" is a registry url.
- Then, rc.URL looks like a string seperated by semicolon: "tri://localhost:10000;registry://localhost:2181".
- The result of urlStrings is a string array: []string{"tri://localhost:10000", "registry://localhost:2181"}.
+ Two types of URL are allowed for rc.URL:
+ 1. direct url: server IP, that is, no need for a registry anymore
+ 2. registry url
+ They will be handled in different ways:
+ For example, we have a direct url and a registry url:
+ 1. "tri://localhost:10000" is a direct url
+ 2. "registry://localhost:2181" is a registry url.
+ Then, rc.URL looks like a string seperated by semicolon: "tri://localhost:10000;registry://localhost:2181".
+ The result of urlStrings is a string array: []string{"tri://localhost:10000", "registry://localhost:2181"}.
*/
urlStrings := gxstrings.RegSplit(rc.URL, "\\s*[;]+\\s*")
for _, urlStr := range urlStrings {
diff --git a/filter/adaptivesvc/capeva/vegas.go b/filter/adaptivesvc/capeva/vegas.go
index 7fbc0ca93a..770746fdc9 100644
--- a/filter/adaptivesvc/capeva/vegas.go
+++ b/filter/adaptivesvc/capeva/vegas.go
@@ -1,23 +1,22 @@
package capeva
-import "sync"
+import (
+ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capupd"
+ "go.uber.org/atomic"
+)
type Vegas struct {
*baseCapacityEvaluator
- // mutex protects vegasDataMap
- mutex *sync.Mutex
- vegasDataMap map[string]*vegasData
+ cntRTT *atomic.Uint32
}
func NewVegas() *Vegas {
return &Vegas{
baseCapacityEvaluator: newBaseCapacityEvaluator(),
- mutex: &sync.Mutex{},
- vegasDataMap: make(map[string]*vegasData),
}
}
-type vegasData struct {
-
-}
+func (v *Vegas) NewCapacityUpdater() capupd.CapacityUpdater {
+ return capupd.NewVegas(v)
+}
\ No newline at end of file
diff --git a/filter/adaptivesvc/capupd/base_capacity_updater.go b/filter/adaptivesvc/capupd/base_capacity_updater.go
index c010292325..104aec10ae 100644
--- a/filter/adaptivesvc/capupd/base_capacity_updater.go
+++ b/filter/adaptivesvc/capupd/base_capacity_updater.go
@@ -21,4 +21,3 @@ func (b *baseCapacityUpdater) Succeed() {
func (b *baseCapacityUpdater) Failed() {
panic("implement me")
}
-
diff --git a/filter/adaptivesvc/capupd/capacity_updater.go b/filter/adaptivesvc/capupd/capacity_updater.go
index d640d1c295..e23c17b7c9 100644
--- a/filter/adaptivesvc/capupd/capacity_updater.go
+++ b/filter/adaptivesvc/capupd/capacity_updater.go
@@ -1,5 +1,7 @@
package capupd
+// CapacityUpdater updates capacity evaluator.
+// Each method has a stand-alone updater instance, it could be passed by the invocation.
type CapacityUpdater interface {
// Succeed updates capacity evaluator if the invocation finish successfully.
Succeed()
diff --git a/filter/adaptivesvc/capupd/vegas.go b/filter/adaptivesvc/capupd/vegas.go
index dc74642bd3..d5dc9dccf1 100644
--- a/filter/adaptivesvc/capupd/vegas.go
+++ b/filter/adaptivesvc/capupd/vegas.go
@@ -1,14 +1,20 @@
package capupd
-import "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capeva"
+import (
+ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capeva"
+ "time"
+)
type Vegas struct {
*baseCapacityUpdater
+
+ startedTime time.Time
}
func NewVegas(eva capeva.CapacityEvaluator) *Vegas {
return &Vegas{
baseCapacityUpdater: newBaseCapacityUpdater(eva),
+ startedTime: time.Now(),
}
}
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 220d0945f1..14b4684e82 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -6,7 +6,7 @@ import (
)
// Filter for adaptive service on server side.
-type Filter struct {}
+type Filter struct{}
func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
panic("implement me")
@@ -16,4 +16,3 @@ func (f *Filter) OnResponse(ctx context.Context, result protocol.Result, invoker
invocation protocol.Invocation) protocol.Result {
panic("implement me")
}
-
From 2db43f7e16ed93eb5171c18d5553c3b0930143a6 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Wed, 3 Nov 2021 20:59:32 +0800
Subject: [PATCH 07/35] feat(cluster): add fields to vegas capeva
---
.../capeva/base_capacity_evaluator.go | 22 ++++++-
.../adaptivesvc/capeva/capacity_evaluator.go | 13 ++++-
filter/adaptivesvc/capeva/vegas.go | 57 +++++++++++++++++--
.../capupd/base_capacity_updater.go | 23 --------
filter/adaptivesvc/capupd/capacity_updater.go | 10 ----
filter/adaptivesvc/capupd/vegas.go | 27 ---------
6 files changed, 82 insertions(+), 70 deletions(-)
delete mode 100644 filter/adaptivesvc/capupd/base_capacity_updater.go
delete mode 100644 filter/adaptivesvc/capupd/capacity_updater.go
delete mode 100644 filter/adaptivesvc/capupd/vegas.go
diff --git a/filter/adaptivesvc/capeva/base_capacity_evaluator.go b/filter/adaptivesvc/capeva/base_capacity_evaluator.go
index 97605a5094..19a39f29bb 100644
--- a/filter/adaptivesvc/capeva/base_capacity_evaluator.go
+++ b/filter/adaptivesvc/capeva/base_capacity_evaluator.go
@@ -1,7 +1,6 @@
package capeva
import (
- "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capupd"
"go.uber.org/atomic"
)
@@ -32,7 +31,26 @@ func (ce *baseCapacityEvaluator) UpdateActual(delta int64) {
ce.actual.Add(delta)
}
-func (ce *baseCapacityEvaluator) NewCapacityUpdater() capupd.CapacityUpdater {
+func (ce *baseCapacityEvaluator) NewCapacityUpdater() CapacityUpdater {
panic("implement me!")
}
+type baseCapacityUpdater struct {
+ capacityEvaluator CapacityEvaluator
+}
+
+func newBaseCapacityUpdater(eva CapacityEvaluator) *baseCapacityUpdater {
+ cu := &baseCapacityUpdater{
+ capacityEvaluator: eva,
+ }
+ cu.capacityEvaluator.UpdateActual(1)
+ return cu
+}
+
+func (b *baseCapacityUpdater) Succeed() {
+ panic("implement me")
+}
+
+func (b *baseCapacityUpdater) Failed() {
+ panic("implement me")
+}
diff --git a/filter/adaptivesvc/capeva/capacity_evaluator.go b/filter/adaptivesvc/capeva/capacity_evaluator.go
index 74f1634c0c..dff147561d 100644
--- a/filter/adaptivesvc/capeva/capacity_evaluator.go
+++ b/filter/adaptivesvc/capeva/capacity_evaluator.go
@@ -1,7 +1,5 @@
package capeva
-import "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capupd"
-
type CapacityEvaluator interface {
// Estimated is estimated capacity, which reflects the maximum requests handled by the provider.
Estimated() int64
@@ -13,5 +11,14 @@ type CapacityEvaluator interface {
UpdateActual(delta int64)
// NewCapacityUpdater returns a capacity updater
- NewCapacityUpdater() capupd.CapacityUpdater
+ NewCapacityUpdater() CapacityUpdater
+}
+
+// CapacityUpdater updates capacity evaluator.
+// Each method has a stand-alone updater instance, it could be passed by the invocation.
+type CapacityUpdater interface {
+ // Succeed updates capacity evaluator if the invocation finish successfully.
+ Succeed()
+ // Failed updates capacity evaluator if the invocation finish unsuccessfully.
+ Failed()
}
\ No newline at end of file
diff --git a/filter/adaptivesvc/capeva/vegas.go b/filter/adaptivesvc/capeva/vegas.go
index 770746fdc9..5450998998 100644
--- a/filter/adaptivesvc/capeva/vegas.go
+++ b/filter/adaptivesvc/capeva/vegas.go
@@ -1,22 +1,69 @@
package capeva
import (
- "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capupd"
"go.uber.org/atomic"
+ "time"
)
+const (
+ defaultRoundSize uint64 = 100
+)
+
+// Vegas is a capacity evaluator using Vegas congestion avoid.
+// RTT is not exactly same as TCP's,
+// in this case, RTT means the time that the provider perform a method.
type Vegas struct {
*baseCapacityEvaluator
- cntRTT *atomic.Uint32
+ // RoundSize specifies the size of the round, which reflects on the speed of updating estimation.
+ // The minRTT and cntRTT will be reset in the next round.
+ RoundSize uint64
+
+ seq *atomic.Uint64
+ nextRoundSeq *atomic.Uint64
+
+ baseRTT *atomic.Uint64
+ minRTT *atomic.Uint64
+ cntRTT *atomic.Uint64
}
func NewVegas() *Vegas {
return &Vegas{
baseCapacityEvaluator: newBaseCapacityEvaluator(),
+ RoundSize: defaultRoundSize,
+ seq: &atomic.Uint64{},
+ nextRoundSeq: &atomic.Uint64{},
+ baseRTT: &atomic.Uint64{},
+ minRTT: &atomic.Uint64{},
+ cntRTT: &atomic.Uint64{},
}
}
-func (v *Vegas) NewCapacityUpdater() capupd.CapacityUpdater {
- return capupd.NewVegas(v)
-}
\ No newline at end of file
+func (v *Vegas) NewCapacityUpdater() CapacityUpdater {
+ return newVegasUpdater(v)
+}
+
+type VegasUpdater struct {
+ *baseCapacityUpdater
+
+ startedTime time.Time
+}
+
+func newVegasUpdater(eva CapacityEvaluator) CapacityUpdater {
+ return &VegasUpdater{
+ baseCapacityUpdater: newBaseCapacityUpdater(eva),
+ startedTime: time.Now(),
+ }
+}
+
+func (v *VegasUpdater) Succeed() {
+ v.update()
+}
+
+func (v *VegasUpdater) Failed() {
+ v.update()
+}
+
+func (v *VegasUpdater) update() {
+ v.capacityEvaluator.UpdateActual(-1)
+}
diff --git a/filter/adaptivesvc/capupd/base_capacity_updater.go b/filter/adaptivesvc/capupd/base_capacity_updater.go
deleted file mode 100644
index 104aec10ae..0000000000
--- a/filter/adaptivesvc/capupd/base_capacity_updater.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package capupd
-
-import "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capeva"
-
-type baseCapacityUpdater struct {
- capacityEvaluator capeva.CapacityEvaluator
-}
-
-func newBaseCapacityUpdater(eva capeva.CapacityEvaluator) *baseCapacityUpdater {
- cu := &baseCapacityUpdater{
- capacityEvaluator: eva,
- }
- cu.capacityEvaluator.UpdateActual(1)
- return cu
-}
-
-func (b *baseCapacityUpdater) Succeed() {
- panic("implement me")
-}
-
-func (b *baseCapacityUpdater) Failed() {
- panic("implement me")
-}
diff --git a/filter/adaptivesvc/capupd/capacity_updater.go b/filter/adaptivesvc/capupd/capacity_updater.go
deleted file mode 100644
index e23c17b7c9..0000000000
--- a/filter/adaptivesvc/capupd/capacity_updater.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package capupd
-
-// CapacityUpdater updates capacity evaluator.
-// Each method has a stand-alone updater instance, it could be passed by the invocation.
-type CapacityUpdater interface {
- // Succeed updates capacity evaluator if the invocation finish successfully.
- Succeed()
- // Failed updates capacity evaluator if the invocation finish unsuccessfully.
- Failed()
-}
diff --git a/filter/adaptivesvc/capupd/vegas.go b/filter/adaptivesvc/capupd/vegas.go
deleted file mode 100644
index d5dc9dccf1..0000000000
--- a/filter/adaptivesvc/capupd/vegas.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package capupd
-
-import (
- "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capeva"
- "time"
-)
-
-type Vegas struct {
- *baseCapacityUpdater
-
- startedTime time.Time
-}
-
-func NewVegas(eva capeva.CapacityEvaluator) *Vegas {
- return &Vegas{
- baseCapacityUpdater: newBaseCapacityUpdater(eva),
- startedTime: time.Now(),
- }
-}
-
-func (v *Vegas) Succeed() {
- v.capacityEvaluator.UpdateActual(-1)
-}
-
-func (v *Vegas) Failed() {
- v.capacityEvaluator.UpdateActual(-1)
-}
From 588f3926d25be635826e1cf65d3c3d5244da6ee9 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Thu, 4 Nov 2021 15:01:18 +0800
Subject: [PATCH 08/35] feat(cluster): refactor capeva interface
---
.../capeva/base_capacity_evaluator.go | 56 ------------------
.../adaptivesvc/capeva/capacity_evaluator.go | 20 ++-----
filter/adaptivesvc/capeva/capacity_updater.go | 10 ++++
filter/adaptivesvc/capeva/vegas.go | 59 +++++++------------
filter/adaptivesvc/capeva/vegas_updater.go | 42 +++++++++++++
5 files changed, 77 insertions(+), 110 deletions(-)
delete mode 100644 filter/adaptivesvc/capeva/base_capacity_evaluator.go
create mode 100644 filter/adaptivesvc/capeva/capacity_updater.go
create mode 100644 filter/adaptivesvc/capeva/vegas_updater.go
diff --git a/filter/adaptivesvc/capeva/base_capacity_evaluator.go b/filter/adaptivesvc/capeva/base_capacity_evaluator.go
deleted file mode 100644
index 19a39f29bb..0000000000
--- a/filter/adaptivesvc/capeva/base_capacity_evaluator.go
+++ /dev/null
@@ -1,56 +0,0 @@
-package capeva
-
-import (
- "go.uber.org/atomic"
-)
-
-type baseCapacityEvaluator struct {
- estimated, actual *atomic.Int64
-}
-
-func newBaseCapacityEvaluator() *baseCapacityEvaluator {
- return &baseCapacityEvaluator{
- estimated: &atomic.Int64{},
- actual: &atomic.Int64{},
- }
-}
-
-func (ce *baseCapacityEvaluator) Estimated() int64 {
- return ce.estimated.Load()
-}
-
-func (ce *baseCapacityEvaluator) Actual() int64 {
- return ce.actual.Load()
-}
-
-func (ce *baseCapacityEvaluator) UpdateEstimated(value int64) {
- ce.actual.Store(value)
-}
-
-func (ce *baseCapacityEvaluator) UpdateActual(delta int64) {
- ce.actual.Add(delta)
-}
-
-func (ce *baseCapacityEvaluator) NewCapacityUpdater() CapacityUpdater {
- panic("implement me!")
-}
-
-type baseCapacityUpdater struct {
- capacityEvaluator CapacityEvaluator
-}
-
-func newBaseCapacityUpdater(eva CapacityEvaluator) *baseCapacityUpdater {
- cu := &baseCapacityUpdater{
- capacityEvaluator: eva,
- }
- cu.capacityEvaluator.UpdateActual(1)
- return cu
-}
-
-func (b *baseCapacityUpdater) Succeed() {
- panic("implement me")
-}
-
-func (b *baseCapacityUpdater) Failed() {
- panic("implement me")
-}
diff --git a/filter/adaptivesvc/capeva/capacity_evaluator.go b/filter/adaptivesvc/capeva/capacity_evaluator.go
index dff147561d..94984f92e8 100644
--- a/filter/adaptivesvc/capeva/capacity_evaluator.go
+++ b/filter/adaptivesvc/capeva/capacity_evaluator.go
@@ -1,24 +1,12 @@
package capeva
type CapacityEvaluator interface {
- // Estimated is estimated capacity, which reflects the maximum requests handled by the provider.
- Estimated() int64
- UpdateEstimated(value int64)
+ // EstimatedCapacity is estimated capacity, which reflects the maximum requests handled by the provider.
+ EstimatedCapacity() int64
- // Actual is actual requests on the provider.
- Actual() int64
- // UpdateActual updates by delta, for instance, if a new request comes, the delta should be 1.
- UpdateActual(delta int64)
+ // ActualCapacity is actual requests on the provider.
+ ActualCapacity() int64
// NewCapacityUpdater returns a capacity updater
NewCapacityUpdater() CapacityUpdater
}
-
-// CapacityUpdater updates capacity evaluator.
-// Each method has a stand-alone updater instance, it could be passed by the invocation.
-type CapacityUpdater interface {
- // Succeed updates capacity evaluator if the invocation finish successfully.
- Succeed()
- // Failed updates capacity evaluator if the invocation finish unsuccessfully.
- Failed()
-}
\ No newline at end of file
diff --git a/filter/adaptivesvc/capeva/capacity_updater.go b/filter/adaptivesvc/capeva/capacity_updater.go
new file mode 100644
index 0000000000..be821feabe
--- /dev/null
+++ b/filter/adaptivesvc/capeva/capacity_updater.go
@@ -0,0 +1,10 @@
+package capeva
+
+// CapacityUpdater updates capacity evaluator.
+// Each method has a stand-alone updater instance, it could be passed by the invocation.
+type CapacityUpdater interface {
+ // Succeed updates capacity evaluator if the invocation finished successfully.
+ Succeed()
+ // Failed updates capacity evaluator if the invocation finished unsuccessfully.
+ Failed()
+}
diff --git a/filter/adaptivesvc/capeva/vegas.go b/filter/adaptivesvc/capeva/vegas.go
index 5450998998..32becfd64a 100644
--- a/filter/adaptivesvc/capeva/vegas.go
+++ b/filter/adaptivesvc/capeva/vegas.go
@@ -2,7 +2,6 @@ package capeva
import (
"go.uber.org/atomic"
- "time"
)
const (
@@ -13,57 +12,41 @@ const (
// RTT is not exactly same as TCP's,
// in this case, RTT means the time that the provider perform a method.
type Vegas struct {
- *baseCapacityEvaluator
+ Estimated, Actual *atomic.Uint64
// RoundSize specifies the size of the round, which reflects on the speed of updating estimation.
- // The minRTT and cntRTT will be reset in the next round.
+ // The MinRTT and CntRTT will be reset in the next round.
RoundSize uint64
- seq *atomic.Uint64
- nextRoundSeq *atomic.Uint64
+ Seq *atomic.Uint64
+ NextRoundSeq *atomic.Uint64
- baseRTT *atomic.Uint64
- minRTT *atomic.Uint64
- cntRTT *atomic.Uint64
+ BaseRTT *atomic.Uint64
+ MinRTT *atomic.Uint64
+ CntRTT *atomic.Uint64
}
func NewVegas() *Vegas {
return &Vegas{
- baseCapacityEvaluator: newBaseCapacityEvaluator(),
- RoundSize: defaultRoundSize,
- seq: &atomic.Uint64{},
- nextRoundSeq: &atomic.Uint64{},
- baseRTT: &atomic.Uint64{},
- minRTT: &atomic.Uint64{},
- cntRTT: &atomic.Uint64{},
+ Estimated: &atomic.Uint64{},
+ Actual: &atomic.Uint64{},
+ RoundSize: defaultRoundSize,
+ Seq: &atomic.Uint64{},
+ NextRoundSeq: &atomic.Uint64{},
+ BaseRTT: &atomic.Uint64{},
+ MinRTT: &atomic.Uint64{},
+ CntRTT: &atomic.Uint64{},
}
}
-func (v *Vegas) NewCapacityUpdater() CapacityUpdater {
- return newVegasUpdater(v)
-}
-
-type VegasUpdater struct {
- *baseCapacityUpdater
-
- startedTime time.Time
-}
-
-func newVegasUpdater(eva CapacityEvaluator) CapacityUpdater {
- return &VegasUpdater{
- baseCapacityUpdater: newBaseCapacityUpdater(eva),
- startedTime: time.Now(),
- }
-}
-
-func (v *VegasUpdater) Succeed() {
- v.update()
+func (v *Vegas) EstimatedCapacity() int64 {
+ panic("implement me")
}
-func (v *VegasUpdater) Failed() {
- v.update()
+func (v *Vegas) ActualCapacity() int64 {
+ panic("implement me")
}
-func (v *VegasUpdater) update() {
- v.capacityEvaluator.UpdateActual(-1)
+func (v *Vegas) NewCapacityUpdater() CapacityUpdater {
+ return newVegasUpdater(v)
}
diff --git a/filter/adaptivesvc/capeva/vegas_updater.go b/filter/adaptivesvc/capeva/vegas_updater.go
new file mode 100644
index 0000000000..f78cc945d5
--- /dev/null
+++ b/filter/adaptivesvc/capeva/vegas_updater.go
@@ -0,0 +1,42 @@
+package capeva
+
+import "time"
+
+type vegasUpdater struct {
+ eva *Vegas
+
+ startedTime time.Time
+}
+
+func newVegasUpdater(eva *Vegas) CapacityUpdater {
+ return &vegasUpdater{
+ eva: eva,
+ startedTime: time.Now(),
+ }
+}
+
+func (v *vegasUpdater) Succeed() {
+ v.updateAfterReturn()
+}
+
+func (v *vegasUpdater) Failed() {
+ v.updateAfterReturn()
+}
+
+func (v *vegasUpdater) updateAfterReturn() {
+ v.eva.Actual.Add(-1)
+ v.updateRTTs()
+}
+
+func (v *vegasUpdater) updateRTTs() {
+ // update BaseRTT
+ curRTT := uint64(time.Now().Sub(v.startedTime))
+ oldBaseRTT := v.eva.BaseRTT.Load()
+ for oldBaseRTT > curRTT {
+ if !v.eva.BaseRTT.CAS(oldBaseRTT, curRTT) {
+ oldBaseRTT = v.eva.BaseRTT.Load()
+ }
+ }
+ // update MinRTT
+ // update CntRTT
+}
From e0a4d1a1d30ef30f78b2ffca28244cd97d7ed1c6 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Thu, 4 Nov 2021 23:51:38 +0800
Subject: [PATCH 09/35] feat(cluster): add more fields to vegas capeva
---
.../adaptivesvc/capeva/capacity_evaluator.go | 4 +-
filter/adaptivesvc/capeva/utils.go | 35 +++++++++++
filter/adaptivesvc/capeva/vegas.go | 57 ++++++++++++------
filter/adaptivesvc/capeva/vegas_updater.go | 60 ++++++++++++++-----
4 files changed, 121 insertions(+), 35 deletions(-)
create mode 100644 filter/adaptivesvc/capeva/utils.go
diff --git a/filter/adaptivesvc/capeva/capacity_evaluator.go b/filter/adaptivesvc/capeva/capacity_evaluator.go
index 94984f92e8..64a411b97b 100644
--- a/filter/adaptivesvc/capeva/capacity_evaluator.go
+++ b/filter/adaptivesvc/capeva/capacity_evaluator.go
@@ -2,10 +2,10 @@ package capeva
type CapacityEvaluator interface {
// EstimatedCapacity is estimated capacity, which reflects the maximum requests handled by the provider.
- EstimatedCapacity() int64
+ EstimatedCapacity() uint64
// ActualCapacity is actual requests on the provider.
- ActualCapacity() int64
+ ActualCapacity() uint64
// NewCapacityUpdater returns a capacity updater
NewCapacityUpdater() CapacityUpdater
diff --git a/filter/adaptivesvc/capeva/utils.go b/filter/adaptivesvc/capeva/utils.go
new file mode 100644
index 0000000000..52d0a8f73f
--- /dev/null
+++ b/filter/adaptivesvc/capeva/utils.go
@@ -0,0 +1,35 @@
+package capeva
+
+import "go.uber.org/atomic"
+
+func after(crt, next *atomic.Uint64) bool {
+ return crt.Load() > next.Load()
+}
+
+// setValueIfLess sets newValue to v if newValue is less than v
+func setValueIfLess(v *atomic.Uint64, newValue uint64) {
+ vuint64 := v.Load()
+ for vuint64 > newValue {
+ if !v.CAS(vuint64, newValue) {
+ vuint64 = v.Load()
+ }
+ }
+}
+
+func slowStart(est, thresh *atomic.Uint64) {
+ var estValue, threshValue, newEst uint64
+
+ for {
+ estValue = est.Load()
+ threshValue = thresh.Load()
+
+ newEst = estValue * 2
+ if threshValue < newEst {
+ newEst = threshValue
+ }
+
+ if est.CAS(estValue, newEst) {
+ break
+ }
+ }
+}
diff --git a/filter/adaptivesvc/capeva/vegas.go b/filter/adaptivesvc/capeva/vegas.go
index 32becfd64a..3f174b66b3 100644
--- a/filter/adaptivesvc/capeva/vegas.go
+++ b/filter/adaptivesvc/capeva/vegas.go
@@ -2,49 +2,72 @@ package capeva
import (
"go.uber.org/atomic"
+ "math"
)
const (
- defaultRoundSize uint64 = 100
+ defaultThreshold uint64 = 100
+
+ defaultRoundSize uint64 = 10
+
+ defaultAlpha uint64 = 2
+ defaultBeta uint64 = 4
+ defaultGamma uint64 = 1
)
// Vegas is a capacity evaluator using Vegas congestion avoid.
// RTT is not exactly same as TCP's,
// in this case, RTT means the time that the provider perform a method.
type Vegas struct {
- Estimated, Actual *atomic.Uint64
+ Estimated, Actual, Threshold *atomic.Uint64
+
+ // TODO(justxuewei): load values from config
+ Alpha, Beta, Gamma uint64
// RoundSize specifies the size of the round, which reflects on the speed of updating estimation.
// The MinRTT and CntRTT will be reset in the next round.
+ // The smaller RoundSize is, the faster reevaluating estimated capacity is.
RoundSize uint64
- Seq *atomic.Uint64
- NextRoundSeq *atomic.Uint64
+ Seq *atomic.Uint64
+ NextRoundLeftBound *atomic.Uint64
BaseRTT *atomic.Uint64
MinRTT *atomic.Uint64
- CntRTT *atomic.Uint64
+ CntRTT *atomic.Uint64 // not used so far
}
func NewVegas() *Vegas {
+ estimated := atomic.NewUint64(1)
+ threshold := atomic.NewUint64(defaultThreshold)
+
+ minRTT := atomic.NewUint64(math.MaxUint64)
+
return &Vegas{
- Estimated: &atomic.Uint64{},
- Actual: &atomic.Uint64{},
- RoundSize: defaultRoundSize,
- Seq: &atomic.Uint64{},
- NextRoundSeq: &atomic.Uint64{},
- BaseRTT: &atomic.Uint64{},
- MinRTT: &atomic.Uint64{},
- CntRTT: &atomic.Uint64{},
+ Estimated: estimated,
+ Actual: &atomic.Uint64{},
+ Threshold: threshold,
+
+ Alpha: defaultAlpha,
+ Beta: defaultBeta,
+ Gamma: defaultGamma,
+ RoundSize: defaultRoundSize,
+
+ Seq: &atomic.Uint64{},
+ NextRoundLeftBound: &atomic.Uint64{},
+
+ BaseRTT: &atomic.Uint64{},
+ MinRTT: minRTT,
+ CntRTT: &atomic.Uint64{},
}
}
-func (v *Vegas) EstimatedCapacity() int64 {
- panic("implement me")
+func (v *Vegas) EstimatedCapacity() uint64 {
+ return v.Estimated.Load()
}
-func (v *Vegas) ActualCapacity() int64 {
- panic("implement me")
+func (v *Vegas) ActualCapacity() uint64 {
+ return v.Actual.Load()
}
func (v *Vegas) NewCapacityUpdater() CapacityUpdater {
diff --git a/filter/adaptivesvc/capeva/vegas_updater.go b/filter/adaptivesvc/capeva/vegas_updater.go
index f78cc945d5..300c4eb319 100644
--- a/filter/adaptivesvc/capeva/vegas_updater.go
+++ b/filter/adaptivesvc/capeva/vegas_updater.go
@@ -1,6 +1,10 @@
package capeva
-import "time"
+import (
+ "go.uber.org/atomic"
+ "math"
+ "time"
+)
type vegasUpdater struct {
eva *Vegas
@@ -15,28 +19,52 @@ func newVegasUpdater(eva *Vegas) CapacityUpdater {
}
}
-func (v *vegasUpdater) Succeed() {
- v.updateAfterReturn()
+func (u *vegasUpdater) Succeed() {
+ u.updateAfterReturn()
}
-func (v *vegasUpdater) Failed() {
- v.updateAfterReturn()
+func (u *vegasUpdater) Failed() {
+ u.updateAfterReturn()
}
-func (v *vegasUpdater) updateAfterReturn() {
- v.eva.Actual.Add(-1)
- v.updateRTTs()
+func (u *vegasUpdater) updateAfterReturn() {
+ u.eva.Actual.Add(-1)
+ u.updateRTTs()
+
+ u.reevaEstCap()
}
-func (v *vegasUpdater) updateRTTs() {
+func (u *vegasUpdater) updateRTTs() {
// update BaseRTT
- curRTT := uint64(time.Now().Sub(v.startedTime))
- oldBaseRTT := v.eva.BaseRTT.Load()
- for oldBaseRTT > curRTT {
- if !v.eva.BaseRTT.CAS(oldBaseRTT, curRTT) {
- oldBaseRTT = v.eva.BaseRTT.Load()
- }
- }
+ curRTT := uint64(time.Now().Sub(u.startedTime))
+ setValueIfLess(u.eva.BaseRTT, curRTT)
// update MinRTT
+ setValueIfLess(u.eva.MinRTT, curRTT)
// update CntRTT
+ u.eva.CntRTT.Add(1)
+}
+
+// reevaEstCap reevaluates estimated capacity if the round
+func (u *vegasUpdater) reevaEstCap() {
+ if after(u.eva.Seq, u.eva.NextRoundLeftBound) {
+ // update next round
+ u.eva.NextRoundLeftBound.Add(u.eva.RoundSize)
+
+ rtt := u.eva.MinRTT.Load()
+ baseRTT := u.eva.BaseRTT.Load()
+
+ thresh := u.eva.Threshold.Load()
+ estCap := u.eva.EstimatedCapacity()
+
+ targetEstCap := estCap * baseRTT / rtt
+ diff := estCap * (rtt - baseRTT) / baseRTT
+
+ if diff > u.eva.Gamma && estCap <= thresh {
+
+ }
+
+ // reset MinRTT & CntRTT
+ u.eva.MinRTT.Store(math.MaxUint64)
+ u.eva.CntRTT.Store(0)
+ }
}
From 9af855a319ac397d232602afe94100d2d46d0aa7 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Fri, 5 Nov 2021 14:04:17 +0800
Subject: [PATCH 10/35] feat(cluster): vegas evaupdater done
---
filter/adaptivesvc/capeva/vegas_updater.go | 70 ----------
.../capacity_evaluator.go | 2 +-
.../capacity_updater.go | 2 +-
.../{capeva => capevaulator}/utils.go | 24 ++--
.../{capeva => capevaulator}/vegas.go | 2 +-
.../adaptivesvc/capevaulator/vegas_updater.go | 122 ++++++++++++++++++
6 files changed, 134 insertions(+), 88 deletions(-)
delete mode 100644 filter/adaptivesvc/capeva/vegas_updater.go
rename filter/adaptivesvc/{capeva => capevaulator}/capacity_evaluator.go (94%)
rename filter/adaptivesvc/{capeva => capevaulator}/capacity_updater.go (94%)
rename filter/adaptivesvc/{capeva => capevaulator}/utils.go (54%)
rename filter/adaptivesvc/{capeva => capevaulator}/vegas.go (98%)
create mode 100644 filter/adaptivesvc/capevaulator/vegas_updater.go
diff --git a/filter/adaptivesvc/capeva/vegas_updater.go b/filter/adaptivesvc/capeva/vegas_updater.go
deleted file mode 100644
index 300c4eb319..0000000000
--- a/filter/adaptivesvc/capeva/vegas_updater.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package capeva
-
-import (
- "go.uber.org/atomic"
- "math"
- "time"
-)
-
-type vegasUpdater struct {
- eva *Vegas
-
- startedTime time.Time
-}
-
-func newVegasUpdater(eva *Vegas) CapacityUpdater {
- return &vegasUpdater{
- eva: eva,
- startedTime: time.Now(),
- }
-}
-
-func (u *vegasUpdater) Succeed() {
- u.updateAfterReturn()
-}
-
-func (u *vegasUpdater) Failed() {
- u.updateAfterReturn()
-}
-
-func (u *vegasUpdater) updateAfterReturn() {
- u.eva.Actual.Add(-1)
- u.updateRTTs()
-
- u.reevaEstCap()
-}
-
-func (u *vegasUpdater) updateRTTs() {
- // update BaseRTT
- curRTT := uint64(time.Now().Sub(u.startedTime))
- setValueIfLess(u.eva.BaseRTT, curRTT)
- // update MinRTT
- setValueIfLess(u.eva.MinRTT, curRTT)
- // update CntRTT
- u.eva.CntRTT.Add(1)
-}
-
-// reevaEstCap reevaluates estimated capacity if the round
-func (u *vegasUpdater) reevaEstCap() {
- if after(u.eva.Seq, u.eva.NextRoundLeftBound) {
- // update next round
- u.eva.NextRoundLeftBound.Add(u.eva.RoundSize)
-
- rtt := u.eva.MinRTT.Load()
- baseRTT := u.eva.BaseRTT.Load()
-
- thresh := u.eva.Threshold.Load()
- estCap := u.eva.EstimatedCapacity()
-
- targetEstCap := estCap * baseRTT / rtt
- diff := estCap * (rtt - baseRTT) / baseRTT
-
- if diff > u.eva.Gamma && estCap <= thresh {
-
- }
-
- // reset MinRTT & CntRTT
- u.eva.MinRTT.Store(math.MaxUint64)
- u.eva.CntRTT.Store(0)
- }
-}
diff --git a/filter/adaptivesvc/capeva/capacity_evaluator.go b/filter/adaptivesvc/capevaulator/capacity_evaluator.go
similarity index 94%
rename from filter/adaptivesvc/capeva/capacity_evaluator.go
rename to filter/adaptivesvc/capevaulator/capacity_evaluator.go
index 64a411b97b..c1d466cba2 100644
--- a/filter/adaptivesvc/capeva/capacity_evaluator.go
+++ b/filter/adaptivesvc/capevaulator/capacity_evaluator.go
@@ -1,4 +1,4 @@
-package capeva
+package capevaulator
type CapacityEvaluator interface {
// EstimatedCapacity is estimated capacity, which reflects the maximum requests handled by the provider.
diff --git a/filter/adaptivesvc/capeva/capacity_updater.go b/filter/adaptivesvc/capevaulator/capacity_updater.go
similarity index 94%
rename from filter/adaptivesvc/capeva/capacity_updater.go
rename to filter/adaptivesvc/capevaulator/capacity_updater.go
index be821feabe..86dc13a1f5 100644
--- a/filter/adaptivesvc/capeva/capacity_updater.go
+++ b/filter/adaptivesvc/capevaulator/capacity_updater.go
@@ -1,4 +1,4 @@
-package capeva
+package capevaulator
// CapacityUpdater updates capacity evaluator.
// Each method has a stand-alone updater instance, it could be passed by the invocation.
diff --git a/filter/adaptivesvc/capeva/utils.go b/filter/adaptivesvc/capevaulator/utils.go
similarity index 54%
rename from filter/adaptivesvc/capeva/utils.go
rename to filter/adaptivesvc/capevaulator/utils.go
index 52d0a8f73f..b872aeaeda 100644
--- a/filter/adaptivesvc/capeva/utils.go
+++ b/filter/adaptivesvc/capevaulator/utils.go
@@ -1,4 +1,4 @@
-package capeva
+package capevaulator
import "go.uber.org/atomic"
@@ -16,20 +16,14 @@ func setValueIfLess(v *atomic.Uint64, newValue uint64) {
}
}
-func slowStart(est, thresh *atomic.Uint64) {
- var estValue, threshValue, newEst uint64
-
- for {
- estValue = est.Load()
- threshValue = thresh.Load()
-
- newEst = estValue * 2
- if threshValue < newEst {
- newEst = threshValue
- }
+func slowStart(est *atomic.Uint64, estValue, threshValue uint64) bool {
+ newEst := minUint64(estValue*2, threshValue)
+ return est.CAS(estValue, newEst)
+}
- if est.CAS(estValue, newEst) {
- break
- }
+func minUint64(lhs, rhs uint64) uint64 {
+ if lhs < rhs {
+ return lhs
}
+ return rhs
}
diff --git a/filter/adaptivesvc/capeva/vegas.go b/filter/adaptivesvc/capevaulator/vegas.go
similarity index 98%
rename from filter/adaptivesvc/capeva/vegas.go
rename to filter/adaptivesvc/capevaulator/vegas.go
index 3f174b66b3..b7216c42ec 100644
--- a/filter/adaptivesvc/capeva/vegas.go
+++ b/filter/adaptivesvc/capevaulator/vegas.go
@@ -1,4 +1,4 @@
-package capeva
+package capevaulator
import (
"go.uber.org/atomic"
diff --git a/filter/adaptivesvc/capevaulator/vegas_updater.go b/filter/adaptivesvc/capevaulator/vegas_updater.go
new file mode 100644
index 0000000000..a850ee38aa
--- /dev/null
+++ b/filter/adaptivesvc/capevaulator/vegas_updater.go
@@ -0,0 +1,122 @@
+package capevaulator
+
+import (
+ "math"
+ "time"
+)
+
+type vegasUpdater struct {
+ eva *Vegas
+
+ startedTime time.Time
+}
+
+func newVegasUpdater(eva *Vegas) CapacityUpdater {
+ return &vegasUpdater{
+ eva: eva,
+ startedTime: time.Now(),
+ }
+}
+
+func (u *vegasUpdater) Succeed() {
+ u.updateAfterReturn()
+}
+
+func (u *vegasUpdater) Failed() {
+ u.updateAfterReturn()
+}
+
+func (u *vegasUpdater) updateAfterReturn() {
+ u.eva.Actual.Add(-1)
+ u.updateRTTs()
+
+ u.reevaEstCap()
+}
+
+func (u *vegasUpdater) updateRTTs() {
+ // update BaseRTT
+ curRTT := uint64(time.Now().Sub(u.startedTime))
+ setValueIfLess(u.eva.BaseRTT, curRTT)
+ // update MinRTT
+ setValueIfLess(u.eva.MinRTT, curRTT)
+ // update CntRTT
+ u.eva.CntRTT.Add(1)
+}
+
+// reevaEstCap reevaluates estimated capacity if the round
+func (u *vegasUpdater) reevaEstCap() {
+ var (
+ nextRoundLeftBound uint64
+ rtt uint64
+ baseRTT uint64
+
+ est uint64
+ newEst uint64
+ thresh uint64
+ newThresh uint64
+
+ target uint64
+ diff uint64
+ )
+Loop:
+ for after(u.eva.Seq, u.eva.NextRoundLeftBound) {
+ nextRoundLeftBound = u.eva.NextRoundLeftBound.Load()
+ rtt = u.eva.MinRTT.Load()
+ baseRTT = u.eva.BaseRTT.Load()
+
+ thresh = u.eva.Threshold.Load()
+ est = u.eva.EstimatedCapacity()
+
+ target = est * baseRTT / rtt
+ diff = est * (rtt - baseRTT) / baseRTT
+
+ if diff > u.eva.Gamma && est <= thresh {
+ // going too fast, slow down.
+ newEst = minUint64(est, target+1)
+ newThresh = minUint64(thresh, newEst-1)
+ if u.eva.Estimated.CAS(est, newEst) &&
+ u.eva.Threshold.CAS(thresh, newThresh) {
+ u.afterReevaEstCap(nextRoundLeftBound)
+ break Loop
+ }
+ } else if est <= thresh {
+ // slow start
+ if slowStart(u.eva.Estimated, est, thresh) {
+ u.afterReevaEstCap(nextRoundLeftBound)
+ break Loop
+ }
+ } else {
+ // congestion avoidance
+ if diff > u.eva.Beta {
+ // too fast, slow down
+ newEst = est - 1
+ newThresh = minUint64(thresh, newEst-1)
+ if u.eva.Estimated.CAS(est, newEst) &&
+ u.eva.Threshold.CAS(thresh, newThresh) {
+ u.afterReevaEstCap(nextRoundLeftBound)
+ break Loop
+ }
+ } else if diff < u.eva.Alpha {
+ // too slow, speed up
+ newEst = est + 1
+ if u.eva.Estimated.CAS(est, newEst) {
+ u.afterReevaEstCap(nextRoundLeftBound)
+ break Loop
+ }
+ } else {
+ // as fast as we should be
+ }
+ }
+ }
+}
+
+func (u *vegasUpdater) afterReevaEstCap(nextRoundLeftBound uint64) {
+ // update next round
+ if !u.eva.NextRoundLeftBound.CAS(nextRoundLeftBound, nextRoundLeftBound+u.eva.RoundSize) {
+ // if the round is updated, do nothing
+ return
+ }
+ // reset MinRTT & CntRTT
+ u.eva.MinRTT.Store(math.MaxUint64)
+ u.eva.CntRTT.Store(0)
+}
From 1d5fca1445e619c752eff864aaa96f93edbe252d Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sat, 6 Nov 2021 14:40:54 +0800
Subject: [PATCH 11/35] fix(common): fix typo
---
remoting/kubernetes/facade_test.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/remoting/kubernetes/facade_test.go b/remoting/kubernetes/facade_test.go
index 31359ac821..11bf274e31 100644
--- a/remoting/kubernetes/facade_test.go
+++ b/remoting/kubernetes/facade_test.go
@@ -60,7 +60,7 @@ func (r *mockFacade) IsAvailable() bool {
func Test_Facade(t *testing.T) {
regUrl, err := common.NewURL("registry://127.0.0.1:443",
- common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.Consumer)))
+ common.WithParamsValue(constant.RoleKey, strconv.Itoa(common.CONSUMER)))
if err != nil {
t.Fatal(err)
}
From 7a537ff3243aefe55b02267916557c70cfdb0dd8 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sat, 6 Nov 2021 14:45:24 +0800
Subject: [PATCH 12/35] fix(common): fix typo
---
config/reference_config.go | 8 ++++----
config/registry_config_test.go | 4 ++--
metadata/report/delegate/delegate_report.go | 8 ++++----
registry/base_registry.go | 6 +++---
remoting/kubernetes/client.go | 4 ++--
remoting/kubernetes/registry_controller.go | 2 +-
6 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/config/reference_config.go b/config/reference_config.go
index f31a8c27c4..29ea89e2a6 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -114,7 +114,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
common.WithProtocol(rc.Protocol),
common.WithParams(rc.getURLMap()),
common.WithParamsValue(constant.BeanNameKey, rc.id),
- common.WithParamsValue(constant.MetadatatypeKey, rc.metaDataType),
+ common.WithParamsValue(constant.MetadataTypeKey, rc.metaDataType),
)
SetConsumerServiceByInterfaceName(rc.InterfaceName, srv)
@@ -156,7 +156,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
}
}
} else { // use registry configs
- rc.urls = loadRegistries(rc.RegistryIDs, rc.rootConfig.Registries, common.Consumer)
+ rc.urls = loadRegistries(rc.RegistryIDs, rc.rootConfig.Registries, common.CONSUMER)
// set url to regURLs
for _, regURL := range rc.urls {
regURL.SubURL = cfgURL
@@ -252,12 +252,12 @@ func (rc *ReferenceConfig) getURLMap() url.Values {
urlMap.Set(constant.GroupKey, rc.Group)
urlMap.Set(constant.VersionKey, rc.Version)
urlMap.Set(constant.GenericKey, rc.Generic)
- urlMap.Set(constant.RoleKey, strconv.Itoa(common.Consumer))
+ urlMap.Set(constant.RoleKey, strconv.Itoa(common.CONSUMER))
urlMap.Set(constant.ProvidedBy, rc.ProvidedBy)
urlMap.Set(constant.SerializationKey, rc.Serialization)
urlMap.Set(constant.ReleaseKey, "dubbo-golang-"+constant.Version)
- urlMap.Set(constant.SideKey, (common.RoleType(common.Consumer)).Role())
+ urlMap.Set(constant.SideKey, (common.RoleType(common.CONSUMER)).Role())
if len(rc.RequestTimeout) != 0 {
urlMap.Set(constant.TimeoutKey, rc.RequestTimeout)
diff --git a/config/registry_config_test.go b/config/registry_config_test.go
index 7e94e7171e..d9c5521d02 100644
--- a/config/registry_config_test.go
+++ b/config/registry_config_test.go
@@ -41,7 +41,7 @@ func TestLoadRegistries(t *testing.T) {
Password: "pwd1",
},
}
- urls := loadRegistries(target, regs, common.Consumer)
+ urls := loadRegistries(target, regs, common.CONSUMER)
t.Logf("loadRegistries() = urls:%v", urls)
assert.Equal(t, "127.0.0.2:2181,128.0.0.1:2181", urls[0].Location)
}
@@ -59,7 +59,7 @@ func TestLoadRegistries1(t *testing.T) {
Password: "pwd1",
},
}
- urls := loadRegistries(target, regs, common.Consumer)
+ urls := loadRegistries(target, regs, common.CONSUMER)
t.Logf("loadRegistries() = urls:%v", urls)
assert.Equal(t, "127.0.0.2:2181", urls[0].Location)
}
diff --git a/metadata/report/delegate/delegate_report.go b/metadata/report/delegate/delegate_report.go
index 540ab3f8db..96e902d459 100644
--- a/metadata/report/delegate/delegate_report.go
+++ b/metadata/report/delegate/delegate_report.go
@@ -212,7 +212,7 @@ func (mr *MetadataReport) storeMetadataTask(role int, identifier *identifier.Met
report := instance.GetMetadataReportInstance()
if role == common.PROVIDER {
err = report.StoreProviderMetadata(identifier, string(data))
- } else if role == common.Consumer {
+ } else if role == common.CONSUMER {
err = report.StoreConsumerMetadata(identifier, string(data))
}
@@ -224,9 +224,9 @@ func (mr *MetadataReport) storeMetadataTask(role int, identifier *identifier.Met
// StoreConsumerMetadata will delegate to call remote metadata's sdk to store consumer side service definition
func (mr *MetadataReport) StoreConsumerMetadata(identifier *identifier.MetadataIdentifier, definer map[string]string) {
if mr.syncReport {
- mr.storeMetadataTask(common.Consumer, identifier, definer)
+ mr.storeMetadataTask(common.CONSUMER, identifier, definer)
}
- go mr.storeMetadataTask(common.Consumer, identifier, definer)
+ go mr.storeMetadataTask(common.CONSUMER, identifier, definer)
}
// SaveServiceMetadata will delegate to call remote metadata's sdk to save service metadata
@@ -307,7 +307,7 @@ func (mr *MetadataReport) doHandlerMetadataCollection(metadataMap map[*identifie
for e := range metadataMap {
if common.RoleType(common.PROVIDER).Role() == e.Side {
mr.StoreProviderMetadata(e, metadataMap[e].(*definition.ServiceDefinition))
- } else if common.RoleType(common.Consumer).Role() == e.Side {
+ } else if common.RoleType(common.CONSUMER).Role() == e.Side {
mr.StoreConsumerMetadata(e, metadataMap[e].(map[string]string))
}
}
diff --git a/registry/base_registry.go b/registry/base_registry.go
index e46d3f18d6..52f4dc181a 100644
--- a/registry/base_registry.go
+++ b/registry/base_registry.go
@@ -276,7 +276,7 @@ func (r *BaseRegistry) processURL(c *common.URL, f func(string, string) error, c
case common.PROVIDER:
dubboPath, rawURL, err = r.providerRegistry(c, params, cpf)
- case common.Consumer:
+ case common.CONSUMER:
dubboPath, rawURL, err = r.consumerRegistry(c, params, cpf)
default:
return perrors.Errorf("@c{%v} type is not referencer or provider", c)
@@ -360,7 +360,7 @@ func (r *BaseRegistry) consumerRegistry(c *common.URL, params url.Values, f crea
rawURL string
err error
)
- dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.Consumer])
+ dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.CONSUMER])
if f != nil {
err = f(dubboPath)
@@ -383,7 +383,7 @@ func (r *BaseRegistry) consumerRegistry(c *common.URL, params url.Values, f crea
params.Add("protocol", c.Protocol)
s, _ := url.QueryUnescape(params.Encode())
rawURL = fmt.Sprintf("consumer://%s%s?%s", localIP, c.Path, s)
- dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), (common.RoleType(common.Consumer)).String())
+ dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), (common.RoleType(common.CONSUMER)).String())
logger.Debugf("consumer path:%s, url:%s", dubboPath, rawURL)
return dubboPath, rawURL, nil
diff --git a/remoting/kubernetes/client.go b/remoting/kubernetes/client.go
index 57bbc13f76..b2fac83599 100644
--- a/remoting/kubernetes/client.go
+++ b/remoting/kubernetes/client.go
@@ -69,7 +69,7 @@ func NewClient(url *common.URL) (*Client, error) {
controller: controller,
}
- if r == common.Consumer {
+ if r == common.CONSUMER {
// only consumer have to start informer factory
c.controller.startALLInformers()
}
@@ -194,7 +194,7 @@ func ValidateClient(container clientFacade) error {
// NewMockClient exports for registry package test
func NewMockClient(podList *v1.PodList) (*Client, error) {
ctx, cancel := context.WithCancel(context.Background())
- controller, err := newDubboRegistryController(ctx, common.Consumer, func() (kubernetes.Interface, error) {
+ controller, err := newDubboRegistryController(ctx, common.CONSUMER, func() (kubernetes.Interface, error) {
return fake.NewSimpleClientset(podList), nil
})
if err != nil {
diff --git a/remoting/kubernetes/registry_controller.go b/remoting/kubernetes/registry_controller.go
index 8d43c55dff..f6a804aa18 100644
--- a/remoting/kubernetes/registry_controller.go
+++ b/remoting/kubernetes/registry_controller.go
@@ -521,7 +521,7 @@ func (c *dubboRegistryController) assembleDUBBOLabel(p *v1.Pod) (*v1.Pod, *v1.Po
// assign new label for current pod
switch c.role {
- case common.Consumer:
+ case common.CONSUMER:
newPod.Labels[DubboIOLabelKey] = DubboIOConsumerLabelValue
case common.PROVIDER:
newPod.Labels[DubboIOLabelKey] = DubboIOProviderLabelValue
From 6d866b58e484f31871977f14e0d1faed32fd7859 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sat, 6 Nov 2021 17:20:57 +0800
Subject: [PATCH 13/35] fix(cluster): add apache license
---
cluster/metrics/constants.go | 17 +++++++++++++++++
cluster/metrics/local_metrics.go | 17 +++++++++++++++++
cluster/metrics/metrics.go | 17 +++++++++++++++++
cluster/metrics/utils.go | 17 +++++++++++++++++
.../capevaulator/capacity_evaluator.go | 17 +++++++++++++++++
.../capevaulator/capacity_updater.go | 17 +++++++++++++++++
filter/adaptivesvc/capevaulator/utils.go | 17 +++++++++++++++++
filter/adaptivesvc/capevaulator/vegas.go | 17 +++++++++++++++++
.../adaptivesvc/capevaulator/vegas_updater.go | 17 +++++++++++++++++
filter/adaptivesvc/filter.go | 17 +++++++++++++++++
10 files changed, 170 insertions(+)
diff --git a/cluster/metrics/constants.go b/cluster/metrics/constants.go
index b6a00b836f..15f58b7189 100644
--- a/cluster/metrics/constants.go
+++ b/cluster/metrics/constants.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package metrics
const (
diff --git a/cluster/metrics/local_metrics.go b/cluster/metrics/local_metrics.go
index 58fe1bb5e8..9cd3a35c41 100644
--- a/cluster/metrics/local_metrics.go
+++ b/cluster/metrics/local_metrics.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package metrics
import (
diff --git a/cluster/metrics/metrics.go b/cluster/metrics/metrics.go
index d800a08329..257539ce68 100644
--- a/cluster/metrics/metrics.go
+++ b/cluster/metrics/metrics.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package metrics
import (
diff --git a/cluster/metrics/utils.go b/cluster/metrics/utils.go
index 18aed82fc0..b07a290783 100644
--- a/cluster/metrics/utils.go
+++ b/cluster/metrics/utils.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package metrics
import (
diff --git a/filter/adaptivesvc/capevaulator/capacity_evaluator.go b/filter/adaptivesvc/capevaulator/capacity_evaluator.go
index c1d466cba2..607bb5b468 100644
--- a/filter/adaptivesvc/capevaulator/capacity_evaluator.go
+++ b/filter/adaptivesvc/capevaulator/capacity_evaluator.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package capevaulator
type CapacityEvaluator interface {
diff --git a/filter/adaptivesvc/capevaulator/capacity_updater.go b/filter/adaptivesvc/capevaulator/capacity_updater.go
index 86dc13a1f5..ba65368b28 100644
--- a/filter/adaptivesvc/capevaulator/capacity_updater.go
+++ b/filter/adaptivesvc/capevaulator/capacity_updater.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package capevaulator
// CapacityUpdater updates capacity evaluator.
diff --git a/filter/adaptivesvc/capevaulator/utils.go b/filter/adaptivesvc/capevaulator/utils.go
index b872aeaeda..c0cd1d232e 100644
--- a/filter/adaptivesvc/capevaulator/utils.go
+++ b/filter/adaptivesvc/capevaulator/utils.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package capevaulator
import "go.uber.org/atomic"
diff --git a/filter/adaptivesvc/capevaulator/vegas.go b/filter/adaptivesvc/capevaulator/vegas.go
index b7216c42ec..d0bbca1c3e 100644
--- a/filter/adaptivesvc/capevaulator/vegas.go
+++ b/filter/adaptivesvc/capevaulator/vegas.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package capevaulator
import (
diff --git a/filter/adaptivesvc/capevaulator/vegas_updater.go b/filter/adaptivesvc/capevaulator/vegas_updater.go
index a850ee38aa..a1c728ff32 100644
--- a/filter/adaptivesvc/capevaulator/vegas_updater.go
+++ b/filter/adaptivesvc/capevaulator/vegas_updater.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package capevaulator
import (
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 14b4684e82..ef7673d12c 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package adaptivesvc
import (
From 865c058979cab34661b31c4a7759f5f18c05a200 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Mon, 15 Nov 2021 13:54:08 +0800
Subject: [PATCH 14/35] feat(cluster): define limiter & update interface
---
config/reference_config.go | 2 +-
.../adaptivesvc/capacity_evaluator_mapper.go | 68 +++++++++++
filter/adaptivesvc/filter.go | 1 +
filter/adaptivesvc/limiter/hill_climbing.go | 115 ++++++++++++++++++
filter/adaptivesvc/limiter/limiter.go | 21 ++++
filter/adaptivesvc/limiter/utils.go | 17 +++
6 files changed, 223 insertions(+), 1 deletion(-)
create mode 100644 filter/adaptivesvc/capacity_evaluator_mapper.go
create mode 100644 filter/adaptivesvc/limiter/hill_climbing.go
create mode 100644 filter/adaptivesvc/limiter/limiter.go
create mode 100644 filter/adaptivesvc/limiter/utils.go
diff --git a/config/reference_config.go b/config/reference_config.go
index 29ea89e2a6..8aa972daa9 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -133,7 +133,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
For example, we have a direct url and a registry url:
1. "tri://localhost:10000" is a direct url
2. "registry://localhost:2181" is a registry url.
- Then, rc.URL looks like a string seperated by semicolon: "tri://localhost:10000;registry://localhost:2181".
+ Then, rc.URL looks like a string separated by semicolon: "tri://localhost:10000;registry://localhost:2181".
The result of urlStrings is a string array: []string{"tri://localhost:10000", "registry://localhost:2181"}.
*/
urlStrings := gxstrings.RegSplit(rc.URL, "\\s*[;]+\\s*")
diff --git a/filter/adaptivesvc/capacity_evaluator_mapper.go b/filter/adaptivesvc/capacity_evaluator_mapper.go
new file mode 100644
index 0000000000..7bffd85d2a
--- /dev/null
+++ b/filter/adaptivesvc/capacity_evaluator_mapper.go
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package adaptivesvc
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capevaulator"
+ "fmt"
+ "sync"
+)
+
+var (
+ capacityEvaluatorMapperSingleton *capacityEvaluatorMapper
+
+ ErrCapEvaluatorNotFound = fmt.Errorf("capacity evaluator not found")
+)
+
+func init() {
+ capacityEvaluatorMapperSingleton = newCapacityEvaluatorMapper()
+}
+
+type capacityEvaluatorMapper struct {
+ mutex *sync.Mutex
+ mapper map[string]capevaulator.CapacityEvaluator
+}
+
+func newCapacityEvaluatorMapper() *capacityEvaluatorMapper {
+ return &capacityEvaluatorMapper{
+ mutex: new(sync.Mutex),
+ mapper: make(map[string]capevaulator.CapacityEvaluator),
+ }
+}
+
+func (m *capacityEvaluatorMapper) setMethodCapacityEvaluator(url *common.URL, methodName string,
+ eva capevaulator.CapacityEvaluator) error {
+ key := fmt.Sprintf("%s%s", url.Path, methodName)
+ m.mutex.Lock()
+ capacityEvaluatorMapperSingleton.mapper[key] = eva
+ m.mutex.Unlock()
+ return nil
+}
+
+func (m *capacityEvaluatorMapper) getMethodCapacityEvaluator(url *common.URL, methodName string) (
+ capevaulator.CapacityEvaluator, error) {
+ key := fmt.Sprintf("%s%s", url.Path, methodName)
+ m.mutex.Lock()
+ eva, ok := capacityEvaluatorMapperSingleton.mapper[key]
+ m.mutex.Unlock()
+ if !ok {
+ return nil, ErrCapEvaluatorNotFound
+ }
+ return eva, nil
+}
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index ef7673d12c..74e5b5ebcc 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -26,6 +26,7 @@ import (
type Filter struct{}
func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
+ //eva, err := capacityEvaluatorMapperSingleton.getMethodCapacityEvaluator(invoker.GetURL(), invocation.MethodName(), )
panic("implement me")
}
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
new file mode 100644
index 0000000000..cdc5448760
--- /dev/null
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -0,0 +1,115 @@
+package limiter
+
+import (
+ "go.uber.org/atomic"
+ "time"
+)
+
+var (
+ _ Limiter = (*HillClimbing)(nil)
+ _ Updater = (*HillClimbingUpdater)(nil)
+)
+
+type HillClimbingOption int64
+
+const (
+ HillClimbingOptionShrinkPlus HillClimbingOption = -2
+ HillClimbingOptionShrink HillClimbingOption = -1
+ HillClimbingOptionDoNothing HillClimbingOption = 0
+ HillClimbingOptionExtend HillClimbingOption = 1
+ HillClimbingOptionExtendPlus HillClimbingOption = 2
+)
+
+// HillClimbing is a limiter using HillClimbing algorithm
+type HillClimbing struct {
+ seq *atomic.Uint64
+
+ inflight *atomic.Uint64
+ limitation *atomic.Uint64
+
+ cpu uint64
+}
+
+func NewHillClimbing() Limiter {
+ l := &HillClimbing{
+ seq: new(atomic.Uint64),
+ inflight: new(atomic.Uint64),
+ limitation: new(atomic.Uint64),
+ }
+
+ // get cpu usage statistics regularly
+ go l.cpuStat()
+
+ return l
+}
+
+func (l *HillClimbing) cpuStat() {
+
+}
+
+func (l *HillClimbing) Inflight() uint64 {
+ return l.inflight.Load()
+}
+
+func (l *HillClimbing) Remaining() uint64 {
+ limitation := l.limitation.Load()
+ inflight := l.Inflight()
+ if limitation < inflight {
+ return 0
+ }
+ return limitation - inflight
+}
+
+func (l *HillClimbing) Acquire() (Updater, error) {
+ if l.Remaining() == 0 {
+ return nil, ErrReachLimitation
+ }
+ return NewHillClimbingUpdater(l), nil
+}
+
+type HillClimbingUpdater struct {
+ startTime time.Time
+ seq uint64
+ limiter *HillClimbing
+}
+
+func NewHillClimbingUpdater(limiter *HillClimbing) *HillClimbingUpdater {
+ inflight := limiter.inflight.Add(1)
+ u := &HillClimbingUpdater{
+ startTime: time.Now(),
+ seq: limiter.seq.Add(1) - 1,
+ limiter: limiter,
+ }
+ VerboseDebugf("[NewHillClimbingUpdater] A new request arrived, seq: %d, inflight: %d, time: %s.",
+ u.seq, inflight, u.startTime.String())
+ return u
+}
+
+func (u *HillClimbingUpdater) DoUpdate(rtt, inflight uint64) error {
+ defer func() {
+ u.limiter.inflight.Add(-1)
+ }()
+ VerboseDebugf("[HillClimbingUpdater.DoUpdate] A request finished, the limiter will be updated, seq: %d.", u.seq)
+ option, err := u.getOption(rtt, inflight)
+ if err != nil {
+ return err
+ }
+ if err = u.adjustLimitation(option); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (u *HillClimbingUpdater) getOption(rtt, inflight uint64) (HillClimbingOption, error) {
+ var option HillClimbingOption
+
+ return option, nil
+}
+
+func (u *HillClimbingUpdater) shouldShrink(counter uint64, rttAvg float64) bool {
+ return false
+}
+
+func (u *HillClimbingUpdater) adjustLimitation(option HillClimbingOption) error {
+ return nil
+}
diff --git a/filter/adaptivesvc/limiter/limiter.go b/filter/adaptivesvc/limiter/limiter.go
new file mode 100644
index 0000000000..ff6b9206e7
--- /dev/null
+++ b/filter/adaptivesvc/limiter/limiter.go
@@ -0,0 +1,21 @@
+package limiter
+
+import (
+ "fmt"
+)
+
+var ErrReachLimitation = fmt.Errorf("reach limitation")
+
+var (
+ Verbose = false
+)
+
+type Limiter interface {
+ Inflight() uint64
+ Remaining() uint64
+ Acquire() (Updater, error)
+}
+
+type Updater interface {
+ DoUpdate(rtt, inflight uint64) error
+}
diff --git a/filter/adaptivesvc/limiter/utils.go b/filter/adaptivesvc/limiter/utils.go
new file mode 100644
index 0000000000..8b75e0130c
--- /dev/null
+++ b/filter/adaptivesvc/limiter/utils.go
@@ -0,0 +1,17 @@
+package limiter
+
+import "dubbo.apache.org/dubbo-go/v3/common/logger"
+
+func VerboseDebugf(msg string, args ...interface{}) {
+ if !Verbose {
+ return
+ }
+ logger.Debugf(msg, args...)
+}
+
+func minUint64(lhs, rhs uint64) uint64 {
+ if lhs < rhs {
+ return lhs
+ }
+ return rhs
+}
From c3f9dbe747d1d999020318d6736e2a826f78aa23 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Tue, 16 Nov 2021 14:11:49 +0800
Subject: [PATCH 15/35] feat(cluster): remove cpu stat temporarily
---
filter/adaptivesvc/limiter/hill_climbing.go | 13 +++-----
filter/adaptivesvc/limiter/utils.go | 34 ++++++++++++++++++++-
2 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index cdc5448760..d516ffcd3a 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -26,8 +26,6 @@ type HillClimbing struct {
inflight *atomic.Uint64
limitation *atomic.Uint64
-
- cpu uint64
}
func NewHillClimbing() Limiter {
@@ -37,16 +35,9 @@ func NewHillClimbing() Limiter {
limitation: new(atomic.Uint64),
}
- // get cpu usage statistics regularly
- go l.cpuStat()
-
return l
}
-func (l *HillClimbing) cpuStat() {
-
-}
-
func (l *HillClimbing) Inflight() uint64 {
return l.inflight.Load()
}
@@ -71,6 +62,10 @@ type HillClimbingUpdater struct {
startTime time.Time
seq uint64
limiter *HillClimbing
+
+ updateInterval *atomic.Uint64
+ lastUpdatedTime time.Time
+ successCounter *atomic.Uint64
}
func NewHillClimbingUpdater(limiter *HillClimbing) *HillClimbingUpdater {
diff --git a/filter/adaptivesvc/limiter/utils.go b/filter/adaptivesvc/limiter/utils.go
index 8b75e0130c..088e67dd08 100644
--- a/filter/adaptivesvc/limiter/utils.go
+++ b/filter/adaptivesvc/limiter/utils.go
@@ -1,6 +1,38 @@
package limiter
-import "dubbo.apache.org/dubbo-go/v3/common/logger"
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
+)
+
+//var (
+// decay = 0.95
+// // cpu statistics interval (ms)
+// statInterval time.Duration = 500
+// cpu *atomic.Uint64
+//)
+//
+//func init() {
+// cpu = new(atomic.Uint64)
+// // get cpu usage statistics regularly
+// go cpuStat()
+//}
+//
+//func cpuStat() {
+// t := time.NewTicker(time.Microsecond * statInterval)
+//
+// // prevent cpuStat method from crashing unexpectedly
+// defer func() {
+// t.Stop()
+// if err := recover(); err != nil {
+// logger.Warnf("[HillClimbing] cpuStat went down, err: %v, attempting to restart...", err)
+// go cpuStat()
+// }
+// }()
+//
+// for range t.C {
+// stat :=
+// }
+//}
func VerboseDebugf(msg string, args ...interface{}) {
if !Verbose {
From ff4e60bdc748a99275cb645177dd7806ab4dc69e Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Wed, 17 Nov 2021 21:11:25 +0800
Subject: [PATCH 16/35] feat(cluster): update hill climbing limiter
---
filter/adaptivesvc/limiter/hill_climbing.go | 142 ++++++++++++++++++--
1 file changed, 132 insertions(+), 10 deletions(-)
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index d516ffcd3a..99c8b4db77 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -2,6 +2,7 @@ package limiter
import (
"go.uber.org/atomic"
+ "sync"
"time"
)
@@ -20,19 +21,52 @@ const (
HillClimbingOptionExtendPlus HillClimbingOption = 2
)
+var (
+ initialLimitation uint64 = 50
+ maxLimitation uint64 = 500
+ radicalPeriod uint64 = 1000
+ stablePeriod uint64 = 32000
+)
+
// HillClimbing is a limiter using HillClimbing algorithm
type HillClimbing struct {
seq *atomic.Uint64
inflight *atomic.Uint64
limitation *atomic.Uint64
+
+ lastUpdatedTimeMutex *sync.Mutex
+ // nextUpdateTime = lastUpdatedTime + updateInterval
+ updateInterval *atomic.Uint64
+ lastUpdatedTime *atomic.Time
+
+ // indicators of the current round
+ successCounter *atomic.Uint64
+ rttAvg *atomic.Float64
+
+ bestMutex *sync.Mutex
+ // indicators of history
+ bestConcurrency *atomic.Uint64
+ bestRTTAvg *atomic.Float64
+ bestLimitation *atomic.Uint64
+ bestSuccessRate *atomic.Uint64
}
func NewHillClimbing() Limiter {
l := &HillClimbing{
- seq: new(atomic.Uint64),
- inflight: new(atomic.Uint64),
- limitation: new(atomic.Uint64),
+ seq: new(atomic.Uint64),
+ inflight: new(atomic.Uint64),
+ limitation: new(atomic.Uint64),
+ lastUpdatedTimeMutex: new(sync.Mutex),
+ updateInterval: atomic.NewUint64(radicalPeriod),
+ lastUpdatedTime: atomic.NewTime(time.Now()),
+ successCounter: new(atomic.Uint64),
+ rttAvg: new(atomic.Float64),
+ bestMutex: new(sync.Mutex),
+ bestConcurrency: new(atomic.Uint64),
+ bestRTTAvg: new(atomic.Float64),
+ bestLimitation: new(atomic.Uint64),
+ bestSuccessRate: new(atomic.Uint64),
}
return l
@@ -60,20 +94,18 @@ func (l *HillClimbing) Acquire() (Updater, error) {
type HillClimbingUpdater struct {
startTime time.Time
- seq uint64
limiter *HillClimbing
- updateInterval *atomic.Uint64
- lastUpdatedTime time.Time
- successCounter *atomic.Uint64
+ // for debug purposes
+ seq uint64
}
func NewHillClimbingUpdater(limiter *HillClimbing) *HillClimbingUpdater {
inflight := limiter.inflight.Add(1)
u := &HillClimbingUpdater{
startTime: time.Now(),
- seq: limiter.seq.Add(1) - 1,
limiter: limiter,
+ seq: limiter.seq.Add(1) - 1,
}
VerboseDebugf("[NewHillClimbingUpdater] A new request arrived, seq: %d, inflight: %d, time: %s.",
u.seq, inflight, u.startTime.String())
@@ -84,11 +116,21 @@ func (u *HillClimbingUpdater) DoUpdate(rtt, inflight uint64) error {
defer func() {
u.limiter.inflight.Add(-1)
}()
- VerboseDebugf("[HillClimbingUpdater.DoUpdate] A request finished, the limiter will be updated, seq: %d.", u.seq)
+ VerboseDebugf("[HillClimbingUpdater] A request finished, the limiter will be updated, seq: %d.", u.seq)
+
+ u.limiter.lastUpdatedTimeMutex.Lock()
+ // if lastUpdatedTime is updated, terminate DoUpdate immediately
+ lastUpdatedTime := u.limiter.lastUpdatedTime.Load()
+ u.limiter.lastUpdatedTimeMutex.Unlock()
+
option, err := u.getOption(rtt, inflight)
if err != nil {
return err
}
+ if u.shouldDrop(lastUpdatedTime) {
+ return nil
+ }
+
if err = u.adjustLimitation(option); err != nil {
return err
}
@@ -96,15 +138,95 @@ func (u *HillClimbingUpdater) DoUpdate(rtt, inflight uint64) error {
}
func (u *HillClimbingUpdater) getOption(rtt, inflight uint64) (HillClimbingOption, error) {
- var option HillClimbingOption
+ now := time.Now()
+ option := HillClimbingOptionDoNothing
+
+ lastUpdatedTime := u.limiter.lastUpdatedTime.Load()
+ updateInterval := u.limiter.updateInterval.Load()
+ rttAvg := u.limiter.rttAvg.Load()
+ successCounter := u.limiter.successCounter.Load()
+ limitation := u.limiter.limitation.Load()
+
+ if now.Sub(lastUpdatedTime) > time.Duration(updateInterval) ||
+ rttAvg == 0 {
+ // Current req is at the next round or no rttAvg.
+
+ // FIXME(justxuewei): If all requests in one round
+ // not receive responses, rttAvg will be 0, and
+ // concurrency will be 0 as well, the actual
+ // concurrency, however, is not 0.
+ concurrency := float64(successCounter) * rttAvg / float64(updateInterval)
+
+ // Consider extending limitation if concurrent is
+ // about to reach the limitation.
+ if uint64(concurrency*1.5) > limitation {
+ if updateInterval == radicalPeriod {
+ option = HillClimbingOptionExtendPlus
+ } else {
+ option = HillClimbingOptionExtend
+ }
+ }
+
+ successRate := uint64(1000.0 * float64(successCounter) / float64(updateInterval))
+
+ // Wrap the code into an anonymous function due to
+ // use defer to ensure the bestMutex is unlocked
+ // once the best-indicators is updated.
+ isUpdated := func() bool {
+ u.limiter.bestMutex.Lock()
+ defer u.limiter.bestMutex.Unlock()
+ if successRate > u.limiter.bestSuccessRate.Load() {
+ // successRate is the best in the history, update
+ // all best-indicators.
+ u.limiter.bestSuccessRate.Store(successRate)
+ u.limiter.bestRTTAvg.Store(rttAvg)
+ u.limiter.bestConcurrency.Store(uint64(concurrency))
+ u.limiter.bestLimitation.Store(u.limiter.limitation.Load())
+ VerboseDebugf("[HillClimbingUpdater] Best-indicators are up-to-date, " +
+ "seq: %d, bestSuccessRate: %d, bestRTTAvg: %.4f, bestConcurrency: %d," +
+ " bestLimitation: %d.", u.seq, u.limiter.bestSuccessRate.Load(),
+ u.limiter.bestRTTAvg.Load(), u.limiter.bestConcurrency.Load(),
+ u.limiter.bestLimitation.Load())
+ return true
+ }
+ return false
+ }()
+
+ if !isUpdated && u.shouldShrink(successCounter, rttAvg) {
+
+ }
+
+ // reset data for the last round
+ u.limiter.successCounter.Store(0)
+ u.limiter.rttAvg.Store(float64(rtt))
+ } else {
+ // still in the current round
+ // TODO(justxuewei): [TBD] if needs to protect here using mutex??
+ u.limiter.successCounter.Add(1)
+ }
return option, nil
}
func (u *HillClimbingUpdater) shouldShrink(counter uint64, rttAvg float64) bool {
+
+
return false
}
+// TODO(justxuewei): update lastUpdatedTime
func (u *HillClimbingUpdater) adjustLimitation(option HillClimbingOption) error {
+ u.limiter.lastUpdatedTimeMutex.Lock()
+ defer u.limiter.lastUpdatedTimeMutex.Unlock()
+
return nil
}
+
+func (u *HillClimbingUpdater) shouldDrop(lastUpdatedTime time.Time) (isDropped bool) {
+ if !u.limiter.lastUpdatedTime.Load().Equal(lastUpdatedTime) {
+ VerboseDebugf("[HillClimbingUpdater] The limitation is updated by others, drop this update, seq: %d.", u.seq)
+ isDropped = true
+ return
+ }
+ return
+}
From 0472bf108b63bfcfffdcd6a01a6798722f53d766 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Fri, 19 Nov 2021 21:48:03 +0800
Subject: [PATCH 17/35] feat(cluster): hill climbing done
---
.../capevaulator/capacity_evaluator.go | 29 ---
.../capevaulator/capacity_updater.go | 27 ---
filter/adaptivesvc/capevaulator/utils.go | 46 -----
filter/adaptivesvc/capevaulator/vegas.go | 92 ----------
.../adaptivesvc/capevaulator/vegas_updater.go | 139 --------------
filter/adaptivesvc/filter.go | 2 +-
filter/adaptivesvc/limiter/hill_climbing.go | 172 ++++++++++++------
..._evaluator_mapper.go => limiter_mapper.go} | 28 +--
8 files changed, 131 insertions(+), 404 deletions(-)
delete mode 100644 filter/adaptivesvc/capevaulator/capacity_evaluator.go
delete mode 100644 filter/adaptivesvc/capevaulator/capacity_updater.go
delete mode 100644 filter/adaptivesvc/capevaulator/utils.go
delete mode 100644 filter/adaptivesvc/capevaulator/vegas.go
delete mode 100644 filter/adaptivesvc/capevaulator/vegas_updater.go
rename filter/adaptivesvc/{capacity_evaluator_mapper.go => limiter_mapper.go} (61%)
diff --git a/filter/adaptivesvc/capevaulator/capacity_evaluator.go b/filter/adaptivesvc/capevaulator/capacity_evaluator.go
deleted file mode 100644
index 607bb5b468..0000000000
--- a/filter/adaptivesvc/capevaulator/capacity_evaluator.go
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package capevaulator
-
-type CapacityEvaluator interface {
- // EstimatedCapacity is estimated capacity, which reflects the maximum requests handled by the provider.
- EstimatedCapacity() uint64
-
- // ActualCapacity is actual requests on the provider.
- ActualCapacity() uint64
-
- // NewCapacityUpdater returns a capacity updater
- NewCapacityUpdater() CapacityUpdater
-}
diff --git a/filter/adaptivesvc/capevaulator/capacity_updater.go b/filter/adaptivesvc/capevaulator/capacity_updater.go
deleted file mode 100644
index ba65368b28..0000000000
--- a/filter/adaptivesvc/capevaulator/capacity_updater.go
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package capevaulator
-
-// CapacityUpdater updates capacity evaluator.
-// Each method has a stand-alone updater instance, it could be passed by the invocation.
-type CapacityUpdater interface {
- // Succeed updates capacity evaluator if the invocation finished successfully.
- Succeed()
- // Failed updates capacity evaluator if the invocation finished unsuccessfully.
- Failed()
-}
diff --git a/filter/adaptivesvc/capevaulator/utils.go b/filter/adaptivesvc/capevaulator/utils.go
deleted file mode 100644
index c0cd1d232e..0000000000
--- a/filter/adaptivesvc/capevaulator/utils.go
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package capevaulator
-
-import "go.uber.org/atomic"
-
-func after(crt, next *atomic.Uint64) bool {
- return crt.Load() > next.Load()
-}
-
-// setValueIfLess sets newValue to v if newValue is less than v
-func setValueIfLess(v *atomic.Uint64, newValue uint64) {
- vuint64 := v.Load()
- for vuint64 > newValue {
- if !v.CAS(vuint64, newValue) {
- vuint64 = v.Load()
- }
- }
-}
-
-func slowStart(est *atomic.Uint64, estValue, threshValue uint64) bool {
- newEst := minUint64(estValue*2, threshValue)
- return est.CAS(estValue, newEst)
-}
-
-func minUint64(lhs, rhs uint64) uint64 {
- if lhs < rhs {
- return lhs
- }
- return rhs
-}
diff --git a/filter/adaptivesvc/capevaulator/vegas.go b/filter/adaptivesvc/capevaulator/vegas.go
deleted file mode 100644
index d0bbca1c3e..0000000000
--- a/filter/adaptivesvc/capevaulator/vegas.go
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package capevaulator
-
-import (
- "go.uber.org/atomic"
- "math"
-)
-
-const (
- defaultThreshold uint64 = 100
-
- defaultRoundSize uint64 = 10
-
- defaultAlpha uint64 = 2
- defaultBeta uint64 = 4
- defaultGamma uint64 = 1
-)
-
-// Vegas is a capacity evaluator using Vegas congestion avoid.
-// RTT is not exactly same as TCP's,
-// in this case, RTT means the time that the provider perform a method.
-type Vegas struct {
- Estimated, Actual, Threshold *atomic.Uint64
-
- // TODO(justxuewei): load values from config
- Alpha, Beta, Gamma uint64
-
- // RoundSize specifies the size of the round, which reflects on the speed of updating estimation.
- // The MinRTT and CntRTT will be reset in the next round.
- // The smaller RoundSize is, the faster reevaluating estimated capacity is.
- RoundSize uint64
-
- Seq *atomic.Uint64
- NextRoundLeftBound *atomic.Uint64
-
- BaseRTT *atomic.Uint64
- MinRTT *atomic.Uint64
- CntRTT *atomic.Uint64 // not used so far
-}
-
-func NewVegas() *Vegas {
- estimated := atomic.NewUint64(1)
- threshold := atomic.NewUint64(defaultThreshold)
-
- minRTT := atomic.NewUint64(math.MaxUint64)
-
- return &Vegas{
- Estimated: estimated,
- Actual: &atomic.Uint64{},
- Threshold: threshold,
-
- Alpha: defaultAlpha,
- Beta: defaultBeta,
- Gamma: defaultGamma,
- RoundSize: defaultRoundSize,
-
- Seq: &atomic.Uint64{},
- NextRoundLeftBound: &atomic.Uint64{},
-
- BaseRTT: &atomic.Uint64{},
- MinRTT: minRTT,
- CntRTT: &atomic.Uint64{},
- }
-}
-
-func (v *Vegas) EstimatedCapacity() uint64 {
- return v.Estimated.Load()
-}
-
-func (v *Vegas) ActualCapacity() uint64 {
- return v.Actual.Load()
-}
-
-func (v *Vegas) NewCapacityUpdater() CapacityUpdater {
- return newVegasUpdater(v)
-}
diff --git a/filter/adaptivesvc/capevaulator/vegas_updater.go b/filter/adaptivesvc/capevaulator/vegas_updater.go
deleted file mode 100644
index a1c728ff32..0000000000
--- a/filter/adaptivesvc/capevaulator/vegas_updater.go
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package capevaulator
-
-import (
- "math"
- "time"
-)
-
-type vegasUpdater struct {
- eva *Vegas
-
- startedTime time.Time
-}
-
-func newVegasUpdater(eva *Vegas) CapacityUpdater {
- return &vegasUpdater{
- eva: eva,
- startedTime: time.Now(),
- }
-}
-
-func (u *vegasUpdater) Succeed() {
- u.updateAfterReturn()
-}
-
-func (u *vegasUpdater) Failed() {
- u.updateAfterReturn()
-}
-
-func (u *vegasUpdater) updateAfterReturn() {
- u.eva.Actual.Add(-1)
- u.updateRTTs()
-
- u.reevaEstCap()
-}
-
-func (u *vegasUpdater) updateRTTs() {
- // update BaseRTT
- curRTT := uint64(time.Now().Sub(u.startedTime))
- setValueIfLess(u.eva.BaseRTT, curRTT)
- // update MinRTT
- setValueIfLess(u.eva.MinRTT, curRTT)
- // update CntRTT
- u.eva.CntRTT.Add(1)
-}
-
-// reevaEstCap reevaluates estimated capacity if the round
-func (u *vegasUpdater) reevaEstCap() {
- var (
- nextRoundLeftBound uint64
- rtt uint64
- baseRTT uint64
-
- est uint64
- newEst uint64
- thresh uint64
- newThresh uint64
-
- target uint64
- diff uint64
- )
-Loop:
- for after(u.eva.Seq, u.eva.NextRoundLeftBound) {
- nextRoundLeftBound = u.eva.NextRoundLeftBound.Load()
- rtt = u.eva.MinRTT.Load()
- baseRTT = u.eva.BaseRTT.Load()
-
- thresh = u.eva.Threshold.Load()
- est = u.eva.EstimatedCapacity()
-
- target = est * baseRTT / rtt
- diff = est * (rtt - baseRTT) / baseRTT
-
- if diff > u.eva.Gamma && est <= thresh {
- // going too fast, slow down.
- newEst = minUint64(est, target+1)
- newThresh = minUint64(thresh, newEst-1)
- if u.eva.Estimated.CAS(est, newEst) &&
- u.eva.Threshold.CAS(thresh, newThresh) {
- u.afterReevaEstCap(nextRoundLeftBound)
- break Loop
- }
- } else if est <= thresh {
- // slow start
- if slowStart(u.eva.Estimated, est, thresh) {
- u.afterReevaEstCap(nextRoundLeftBound)
- break Loop
- }
- } else {
- // congestion avoidance
- if diff > u.eva.Beta {
- // too fast, slow down
- newEst = est - 1
- newThresh = minUint64(thresh, newEst-1)
- if u.eva.Estimated.CAS(est, newEst) &&
- u.eva.Threshold.CAS(thresh, newThresh) {
- u.afterReevaEstCap(nextRoundLeftBound)
- break Loop
- }
- } else if diff < u.eva.Alpha {
- // too slow, speed up
- newEst = est + 1
- if u.eva.Estimated.CAS(est, newEst) {
- u.afterReevaEstCap(nextRoundLeftBound)
- break Loop
- }
- } else {
- // as fast as we should be
- }
- }
- }
-}
-
-func (u *vegasUpdater) afterReevaEstCap(nextRoundLeftBound uint64) {
- // update next round
- if !u.eva.NextRoundLeftBound.CAS(nextRoundLeftBound, nextRoundLeftBound+u.eva.RoundSize) {
- // if the round is updated, do nothing
- return
- }
- // reset MinRTT & CntRTT
- u.eva.MinRTT.Store(math.MaxUint64)
- u.eva.CntRTT.Store(0)
-}
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 74e5b5ebcc..417d9b9e80 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -26,7 +26,7 @@ import (
type Filter struct{}
func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
- //eva, err := capacityEvaluatorMapperSingleton.getMethodCapacityEvaluator(invoker.GetURL(), invocation.MethodName(), )
+ //eva, err := limiterMapperSingleton.getMethodCapacityEvaluator(invoker.GetURL(), invocation.MethodName(), )
panic("implement me")
}
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index 99c8b4db77..1cbf0c98fe 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -2,6 +2,7 @@ package limiter
import (
"go.uber.org/atomic"
+ "math"
"sync"
"time"
)
@@ -30,12 +31,13 @@ var (
// HillClimbing is a limiter using HillClimbing algorithm
type HillClimbing struct {
- seq *atomic.Uint64
+ seq *atomic.Uint64
+ round *atomic.Uint64
inflight *atomic.Uint64
limitation *atomic.Uint64
- lastUpdatedTimeMutex *sync.Mutex
+ mutex *sync.Mutex
// nextUpdateTime = lastUpdatedTime + updateInterval
updateInterval *atomic.Uint64
lastUpdatedTime *atomic.Time
@@ -44,7 +46,6 @@ type HillClimbing struct {
successCounter *atomic.Uint64
rttAvg *atomic.Float64
- bestMutex *sync.Mutex
// indicators of history
bestConcurrency *atomic.Uint64
bestRTTAvg *atomic.Float64
@@ -54,19 +55,19 @@ type HillClimbing struct {
func NewHillClimbing() Limiter {
l := &HillClimbing{
- seq: new(atomic.Uint64),
- inflight: new(atomic.Uint64),
- limitation: new(atomic.Uint64),
- lastUpdatedTimeMutex: new(sync.Mutex),
- updateInterval: atomic.NewUint64(radicalPeriod),
- lastUpdatedTime: atomic.NewTime(time.Now()),
- successCounter: new(atomic.Uint64),
- rttAvg: new(atomic.Float64),
- bestMutex: new(sync.Mutex),
- bestConcurrency: new(atomic.Uint64),
- bestRTTAvg: new(atomic.Float64),
- bestLimitation: new(atomic.Uint64),
- bestSuccessRate: new(atomic.Uint64),
+ seq: new(atomic.Uint64),
+ round: new(atomic.Uint64),
+ inflight: new(atomic.Uint64),
+ limitation: new(atomic.Uint64),
+ mutex: new(sync.Mutex),
+ updateInterval: atomic.NewUint64(radicalPeriod),
+ lastUpdatedTime: atomic.NewTime(time.Now()),
+ successCounter: new(atomic.Uint64),
+ rttAvg: new(atomic.Float64),
+ bestConcurrency: new(atomic.Uint64),
+ bestRTTAvg: new(atomic.Float64),
+ bestLimitation: new(atomic.Uint64),
+ bestSuccessRate: new(atomic.Uint64),
}
return l
@@ -118,26 +119,20 @@ func (u *HillClimbingUpdater) DoUpdate(rtt, inflight uint64) error {
}()
VerboseDebugf("[HillClimbingUpdater] A request finished, the limiter will be updated, seq: %d.", u.seq)
- u.limiter.lastUpdatedTimeMutex.Lock()
- // if lastUpdatedTime is updated, terminate DoUpdate immediately
- lastUpdatedTime := u.limiter.lastUpdatedTime.Load()
- u.limiter.lastUpdatedTimeMutex.Unlock()
-
option, err := u.getOption(rtt, inflight)
if err != nil {
return err
}
- if u.shouldDrop(lastUpdatedTime) {
- return nil
- }
-
if err = u.adjustLimitation(option); err != nil {
return err
}
return nil
}
-func (u *HillClimbingUpdater) getOption(rtt, inflight uint64) (HillClimbingOption, error) {
+func (u *HillClimbingUpdater) getOption(rtt, _ uint64) (HillClimbingOption, error) {
+ u.limiter.mutex.Lock()
+ defer u.limiter.mutex.Unlock()
+
now := time.Now()
option := HillClimbingOptionDoNothing
@@ -169,56 +164,121 @@ func (u *HillClimbingUpdater) getOption(rtt, inflight uint64) (HillClimbingOptio
successRate := uint64(1000.0 * float64(successCounter) / float64(updateInterval))
- // Wrap the code into an anonymous function due to
- // use defer to ensure the bestMutex is unlocked
- // once the best-indicators is updated.
- isUpdated := func() bool {
- u.limiter.bestMutex.Lock()
- defer u.limiter.bestMutex.Unlock()
- if successRate > u.limiter.bestSuccessRate.Load() {
- // successRate is the best in the history, update
- // all best-indicators.
- u.limiter.bestSuccessRate.Store(successRate)
- u.limiter.bestRTTAvg.Store(rttAvg)
- u.limiter.bestConcurrency.Store(uint64(concurrency))
- u.limiter.bestLimitation.Store(u.limiter.limitation.Load())
- VerboseDebugf("[HillClimbingUpdater] Best-indicators are up-to-date, " +
- "seq: %d, bestSuccessRate: %d, bestRTTAvg: %.4f, bestConcurrency: %d," +
- " bestLimitation: %d.", u.seq, u.limiter.bestSuccessRate.Load(),
- u.limiter.bestRTTAvg.Load(), u.limiter.bestConcurrency.Load(),
- u.limiter.bestLimitation.Load())
- return true
+ if successRate > u.limiter.bestSuccessRate.Load() {
+ // successRate is the best in the history, update
+ // all best-indicators.
+ u.limiter.bestSuccessRate.Store(successRate)
+ u.limiter.bestRTTAvg.Store(rttAvg)
+ u.limiter.bestConcurrency.Store(uint64(concurrency))
+ u.limiter.bestLimitation.Store(u.limiter.limitation.Load())
+ VerboseDebugf("[HillClimbingUpdater] Best-indicators are up-to-date, "+
+ "seq: %d, bestSuccessRate: %d, bestRTTAvg: %.4f, bestConcurrency: %d,"+
+ " bestLimitation: %d.", u.seq, u.limiter.bestSuccessRate.Load(),
+ u.limiter.bestRTTAvg.Load(), u.limiter.bestConcurrency.Load(),
+ u.limiter.bestLimitation.Load())
+ } else {
+ if u.shouldShrink(successCounter, uint64(concurrency), successRate, rttAvg) {
+ if updateInterval == radicalPeriod {
+ option = HillClimbingOptionShrinkPlus
+ } else {
+ option = HillClimbingOptionShrink
+ }
+ // shrinking limitation means the process of adjusting
+ // limitation goes to stable, so extends the update
+ // interval to avoid adjusting frequently.
+ u.limiter.updateInterval.Store(minUint64(updateInterval*2, stablePeriod))
}
- return false
- }()
-
- if !isUpdated && u.shouldShrink(successCounter, rttAvg) {
-
}
- // reset data for the last round
+ // reset indicators for the new round
u.limiter.successCounter.Store(0)
u.limiter.rttAvg.Store(float64(rtt))
+ u.limiter.lastUpdatedTime.Store(time.Now())
+ VerboseDebugf("[HillClimbingUpdater] A new round is applied, all indicators are reset.")
} else {
// still in the current round
- // TODO(justxuewei): [TBD] if needs to protect here using mutex??
+
u.limiter.successCounter.Add(1)
+ // ra = (ra * c + r) / (c + 1), where ra denotes rttAvg,
+ // c denotes successCounter, r denotes rtt.
+ u.limiter.rttAvg.Store((rttAvg*float64(successCounter) + float64(rtt)) / float64(successCounter+1))
+ option = HillClimbingOptionDoNothing
}
return option, nil
}
-func (u *HillClimbingUpdater) shouldShrink(counter uint64, rttAvg float64) bool {
+func (u *HillClimbingUpdater) shouldShrink(counter, concurrency, successRate uint64, rttAvg float64) bool {
+ bestSuccessRate := u.limiter.bestSuccessRate.Load()
+ bestRTTAvg := u.limiter.bestRTTAvg.Load()
+ diff := bestSuccessRate - successRate
+ diffPct := uint64(100.0 * float64(successRate) / float64(bestSuccessRate))
+
+ if diff <= 300 && diffPct <= 10 {
+ // diff is acceptable, shouldn't shrink
+ return false
+ }
+
+ if concurrency > bestSuccessRate || rttAvg > bestRTTAvg {
+ // The unacceptable diff dues to too large
+ // concurrency or rttAvg.
+ concDiff := concurrency - bestSuccessRate
+ concDiffPct := uint64(100.0 * float64(concurrency) / float64(bestSuccessRate))
+ rttAvgDiff := rttAvg - bestRTTAvg
+ rttAvgPctDiff := uint64(100.0 * rttAvg / bestRTTAvg)
+
+ // TODO(justxuewei): Hard-coding here is not proper, but
+ // it should refactor after testing.
+ var (
+ rttAvgDiffThreshold uint64
+ rttAvgPctDiffThreshold uint64
+ )
+ if bestRTTAvg < 5 {
+ rttAvgDiffThreshold = 3
+ rttAvgPctDiffThreshold = 80
+ } else if bestRTTAvg < 10 {
+ rttAvgDiffThreshold = 2
+ rttAvgPctDiffThreshold = 30
+ } else if bestRTTAvg < 50 {
+ rttAvgDiffThreshold = 5
+ rttAvgPctDiffThreshold = 20
+ } else if bestRTTAvg < 100 {
+ rttAvgDiffThreshold = 10
+ rttAvgPctDiffThreshold = 10
+ } else {
+ rttAvgDiffThreshold = 20
+ rttAvgPctDiffThreshold = 5
+ }
+
+ return (concDiffPct > 10 && concDiff > 5) && (uint64(rttAvgDiff) > rttAvgDiffThreshold || rttAvgPctDiff >= rttAvgPctDiffThreshold)
+ }
return false
}
-// TODO(justxuewei): update lastUpdatedTime
func (u *HillClimbingUpdater) adjustLimitation(option HillClimbingOption) error {
- u.limiter.lastUpdatedTimeMutex.Lock()
- defer u.limiter.lastUpdatedTimeMutex.Unlock()
+ limitation := float64(u.limiter.limitation.Load())
+ oldLimitation := limitation
+ bestLimitation := float64(u.limiter.bestLimitation.Load())
+ alpha := 1.5 * math.Log(limitation)
+ beta := 0.8 * math.Log(limitation)
+ logUpdateInterval := math.Log2(float64(u.limiter.updateInterval.Load()) / 1000.0)
+
+ switch option {
+ case HillClimbingOptionExtendPlus:
+ limitation += alpha / logUpdateInterval
+ case HillClimbingOptionExtend:
+ limitation += beta / logUpdateInterval
+ case HillClimbingOptionShrinkPlus:
+ limitation = bestLimitation - alpha/logUpdateInterval
+ case HillClimbingOptionShrink:
+ limitation = bestLimitation - beta/logUpdateInterval
+ }
+ limitation = math.Max(1.0, math.Min(limitation, float64(maxLimitation)))
+ u.limiter.limitation.Store(uint64(limitation))
+ VerboseDebugf("[HillClimbingUpdater] The limitation is update from %d to %d.", oldLimitation, uint64(limitation))
return nil
}
diff --git a/filter/adaptivesvc/capacity_evaluator_mapper.go b/filter/adaptivesvc/limiter_mapper.go
similarity index 61%
rename from filter/adaptivesvc/capacity_evaluator_mapper.go
rename to filter/adaptivesvc/limiter_mapper.go
index 7bffd85d2a..61af068baf 100644
--- a/filter/adaptivesvc/capacity_evaluator_mapper.go
+++ b/filter/adaptivesvc/limiter_mapper.go
@@ -19,47 +19,47 @@ package adaptivesvc
import (
"dubbo.apache.org/dubbo-go/v3/common"
- "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/capevaulator"
+ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
"fmt"
"sync"
)
var (
- capacityEvaluatorMapperSingleton *capacityEvaluatorMapper
+ limiterMapperSingleton *limiterMapper
ErrCapEvaluatorNotFound = fmt.Errorf("capacity evaluator not found")
)
func init() {
- capacityEvaluatorMapperSingleton = newCapacityEvaluatorMapper()
+ limiterMapperSingleton = newLimiterMapper()
}
-type capacityEvaluatorMapper struct {
+type limiterMapper struct {
mutex *sync.Mutex
- mapper map[string]capevaulator.CapacityEvaluator
+ mapper map[string]limiter.Limiter
}
-func newCapacityEvaluatorMapper() *capacityEvaluatorMapper {
- return &capacityEvaluatorMapper{
+func newLimiterMapper() *limiterMapper {
+ return &limiterMapper{
mutex: new(sync.Mutex),
- mapper: make(map[string]capevaulator.CapacityEvaluator),
+ mapper: make(map[string]limiter.Limiter),
}
}
-func (m *capacityEvaluatorMapper) setMethodCapacityEvaluator(url *common.URL, methodName string,
- eva capevaulator.CapacityEvaluator) error {
+func (m *limiterMapper) setMethodCapacityEvaluator(url *common.URL, methodName string,
+ eva limiter.Limiter) error {
key := fmt.Sprintf("%s%s", url.Path, methodName)
m.mutex.Lock()
- capacityEvaluatorMapperSingleton.mapper[key] = eva
+ limiterMapperSingleton.mapper[key] = eva
m.mutex.Unlock()
return nil
}
-func (m *capacityEvaluatorMapper) getMethodCapacityEvaluator(url *common.URL, methodName string) (
- capevaulator.CapacityEvaluator, error) {
+func (m *limiterMapper) getMethodCapacityEvaluator(url *common.URL, methodName string) (
+ limiter.Limiter, error) {
key := fmt.Sprintf("%s%s", url.Path, methodName)
m.mutex.Lock()
- eva, ok := capacityEvaluatorMapperSingleton.mapper[key]
+ eva, ok := limiterMapperSingleton.mapper[key]
m.mutex.Unlock()
if !ok {
return nil, ErrCapEvaluatorNotFound
From 70ca4874d81b2d770c310ff155b1283a62a354ba Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sat, 20 Nov 2021 12:10:11 +0800
Subject: [PATCH 18/35] fix(cluster): fix issue where init limitation is 0
---
filter/adaptivesvc/limiter/hill_climbing.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index 1cbf0c98fe..951737c695 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -58,7 +58,7 @@ func NewHillClimbing() Limiter {
seq: new(atomic.Uint64),
round: new(atomic.Uint64),
inflight: new(atomic.Uint64),
- limitation: new(atomic.Uint64),
+ limitation: atomic.NewUint64(initialLimitation),
mutex: new(sync.Mutex),
updateInterval: atomic.NewUint64(radicalPeriod),
lastUpdatedTime: atomic.NewTime(time.Now()),
From ece019ff2a57e3b285d6ce2875122bb640902d0b Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sat, 20 Nov 2021 17:25:26 +0800
Subject: [PATCH 19/35] feat(cluster): provder-side filter done
---
cluster/cluster/adaptivesvc/cluster.go | 25 ++++--
.../cluster/adaptivesvc/cluster_invoker.go | 26 ++++--
cluster/loadbalance/p2c/loadbalance.go | 34 ++++---
cluster/metrics/constants.go | 2 +-
common/constant/key.go | 12 ++-
config/provider_config.go | 20 +++--
filter/adaptivesvc/filter.go | 88 +++++++++++++++++--
filter/adaptivesvc/limiter/hill_climbing.go | 22 ++++-
filter/adaptivesvc/limiter/limiter.go | 23 ++++-
filter/adaptivesvc/limiter/utils.go | 19 +++-
filter/adaptivesvc/limiter_mapper.go | 48 ++++++----
11 files changed, 258 insertions(+), 61 deletions(-)
diff --git a/cluster/cluster/adaptivesvc/cluster.go b/cluster/cluster/adaptivesvc/cluster.go
index bd279e4b50..4a2d4875df 100644
--- a/cluster/cluster/adaptivesvc/cluster.go
+++ b/cluster/cluster/adaptivesvc/cluster.go
@@ -23,19 +23,30 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/protocol"
+ "sync"
+)
+
+var (
+ once sync.Once
+ instance clusterpkg.Cluster
)
func init() {
- extension.SetCluster(constant.ClusterKeyAdaptiveService, newCluster)
+ extension.SetCluster(constant.ClusterKeyAdaptiveService, newAdaptiveServiceCluster)
}
-// cluster is a cluster for adaptive service.
-type cluster struct{}
+// adaptiveServiceCluster is a cluster for adaptive service.
+type adaptiveServiceCluster struct{}
-func newCluster() clusterpkg.Cluster {
- return &cluster{}
+func newAdaptiveServiceCluster() clusterpkg.Cluster {
+ if instance == nil {
+ once.Do(func() {
+ instance = &adaptiveServiceCluster{}
+ })
+ }
+ return instance
}
-func (c *cluster) Join(directory directory.Directory) protocol.Invoker {
- return clusterpkg.BuildInterceptorChain(NewClusterInvoker(directory))
+func (c *adaptiveServiceCluster) Join(directory directory.Directory) protocol.Invoker {
+ return clusterpkg.BuildInterceptorChain(newAdaptiveServiceClusterInvoker(directory))
}
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index a11ed88e7d..444f428c68 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -21,28 +21,30 @@ import (
"context"
"dubbo.apache.org/dubbo-go/v3/cluster/cluster/base"
"dubbo.apache.org/dubbo-go/v3/cluster/directory"
+ "dubbo.apache.org/dubbo-go/v3/cluster/metrics"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/protocol"
perrors "github.com/pkg/errors"
)
-type clusterInvoker struct {
+type adaptiveServiceClusterInvoker struct {
base.ClusterInvoker
}
-func NewClusterInvoker(directory directory.Directory) protocol.Invoker {
- return &clusterInvoker{
+func newAdaptiveServiceClusterInvoker(directory directory.Directory) protocol.Invoker {
+ return &adaptiveServiceClusterInvoker{
ClusterInvoker: base.NewClusterInvoker(directory),
}
}
-func (ivk *clusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
+func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
invokers := ivk.Directory.List(invocation)
if err := ivk.CheckInvokers(invokers, invocation); err != nil {
return &protocol.RPCResult{Err: err}
}
+ // get loadBalance
lbKey := invokers[0].GetURL().GetParam(constant.LoadbalanceKey, constant.LoadBalanceKeyP2C)
if lbKey != constant.LoadBalanceKeyP2C {
return &protocol.RPCResult{
@@ -50,6 +52,20 @@ func (ivk *clusterInvoker) Invoke(ctx context.Context, invocation protocol.Invoc
}
}
lb := extension.GetLoadbalance(lbKey)
+
+ // select a node by the loadBalance
invoker := lb.Select(invokers, invocation)
- return invoker.Invoke(ctx, invocation)
+
+ // invoke
+ result := invoker.Invoke(ctx, invocation)
+
+ // update metrics
+ remaining := invocation.Attachments()[constant.AdaptiveServiceRemainingKey]
+ err := metrics.LocalMetrics.SetMethodMetrics(invoker.GetURL(),
+ invocation.MethodName(), metrics.HillClimbing, remaining)
+ if err != nil {
+ return &protocol.RPCResult{Err: err}
+ }
+
+ return result
}
diff --git a/cluster/loadbalance/p2c/loadbalance.go b/cluster/loadbalance/p2c/loadbalance.go
index 2cf472f629..e9223fd4bf 100644
--- a/cluster/loadbalance/p2c/loadbalance.go
+++ b/cluster/loadbalance/p2c/loadbalance.go
@@ -27,6 +27,7 @@ import (
"errors"
"fmt"
"math/rand"
+ "sync"
"time"
)
@@ -34,11 +35,20 @@ func init() {
extension.SetLoadbalance(constant.LoadBalanceKeyP2C, newLoadBalance)
}
-type loadBalance struct {
-}
+var (
+ once sync.Once
+ instance loadbalance.LoadBalance
+)
+
+type loadBalance struct{}
func newLoadBalance() loadbalance.LoadBalance {
- return &loadBalance{}
+ if instance == nil {
+ once.Do(func() {
+ instance = &loadBalance{}
+ })
+ }
+ return instance
}
func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {
@@ -66,9 +76,9 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
// TODO(justxuewei): please consider how to get the real method name from $invoke,
// see also [#1511](https://github.com/apache/dubbo-go/issues/1511)
methodName := invocation.MethodName()
- // viInterface, vjInterface means vegas latency of node i and node j
+ // remainingIIface, remainingJIface means remaining capacity of node i and node j.
// If one of the metrics is empty, invoke the invocation to that node directly.
- viInterface, err := m.GetMethodMetrics(invokers[i].GetURL(), methodName, metrics.Vegas)
+ remainingIIface, err := m.GetMethodMetrics(invokers[i].GetURL(), methodName, metrics.HillClimbing)
if err != nil {
if errors.Is(err, metrics.ErrMetricsNotFound) {
return invokers[i]
@@ -77,7 +87,7 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
return nil
}
- vjInterface, err := m.GetMethodMetrics(invokers[j].GetURL(), methodName, metrics.Vegas)
+ remainingJIface, err := m.GetMethodMetrics(invokers[j].GetURL(), methodName, metrics.HillClimbing)
if err != nil {
if errors.Is(err, metrics.ErrMetricsNotFound) {
return invokers[j]
@@ -87,18 +97,18 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
}
// Convert interface to int, if the type is unexpected, panic immediately
- vi, ok := viInterface.(int)
+ remainingI, ok := remainingIIface.(uint64)
if !ok {
- panic(fmt.Sprintf("the type of %s expects to be int, but gets %T", metrics.Vegas, viInterface))
+ panic(fmt.Sprintf("the type of %s expects to be uint64, but gets %T", metrics.HillClimbing, remainingIIface))
}
- vj, ok := vjInterface.(int)
+ remainingJ, ok := remainingJIface.(uint64)
if !ok {
- panic(fmt.Sprintf("the type of %s expects to be int, but gets %T", metrics.Vegas, viInterface))
+ panic(fmt.Sprintf("the type of %s expects to be uint64, but gets %T", metrics.HillClimbing, remainingJIface))
}
- // For the latency time, the smaller, the better.
- if vi < vj {
+ // For the remaining capacity, the bigger, the better.
+ if remainingI > remainingJ {
return invokers[i]
}
diff --git a/cluster/metrics/constants.go b/cluster/metrics/constants.go
index 15f58b7189..2bc6b4fea2 100644
--- a/cluster/metrics/constants.go
+++ b/cluster/metrics/constants.go
@@ -18,5 +18,5 @@
package metrics
const (
- Vegas = "vegas"
+ HillClimbing = "hill-climbing"
)
diff --git a/common/constant/key.go b/common/constant/key.go
index d317979b0d..4b467afdb6 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -65,6 +65,7 @@ const (
const (
AccessLogFilterKey = "accesslog"
ActiveFilterKey = "active"
+ AdaptiveServiceProviderFilterKey = "adaptive-service-provider"
AuthConsumerFilterKey = "sign"
AuthProviderFilterKey = "auth"
EchoFilterKey = "echo"
@@ -340,10 +341,19 @@ const (
)
// Generic Filter
-
const (
GenericSerializationDefault = "true"
// disable "protobuf-json" temporarily
//GenericSerializationProtobuf = "protobuf-json"
GenericSerializationGson = "gson"
)
+
+// AdaptiveService Filter
+// goland:noinspection ALL
+const (
+ // attribute keys
+ AdaptiveServiceUpdaterKey = "adaptive-service.updater"
+ // attachment keys
+ AdaptiveServiceRemainingKey = "adaptive-service.remaining"
+ AdaptiveServiceInflightKey = "adaptive-service.inflight"
+)
diff --git a/config/provider_config.go b/config/provider_config.go
index 6d02358de8..1258c8b045 100644
--- a/config/provider_config.go
+++ b/config/provider_config.go
@@ -28,6 +28,7 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/logger"
+ aslimiter "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
)
// ProviderConfig is the default configuration of service provider
@@ -40,14 +41,13 @@ type ProviderConfig struct {
// TracingKey is tracing ids list
TracingKey string `yaml:"tracing-key" json:"tracing-key" property:"tracing-key"`
// Services services
- Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"`
-
- ProxyFactory string `default:"default" yaml:"proxy" json:"proxy,omitempty" property:"proxy"`
-
- FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf"`
- ConfigType map[string]string `yaml:"config_type" json:"config_type,omitempty" property:"config_type"`
-
- rootConfig *RootConfig
+ Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"`
+ ProxyFactory string `default:"default" yaml:"proxy" json:"proxy,omitempty" property:"proxy"`
+ FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf"`
+ ConfigType map[string]string `yaml:"config_type" json:"config_type,omitempty" property:"config_type"`
+ // adaptive service
+ AdaptiveServiceVerbose bool `default:"false" yaml:"adaptive-service-verbose" json:"adaptive-service-verbose" property:"adaptive-service-verbose"`
+ rootConfig *RootConfig
}
func (ProviderConfig) Prefix() string {
@@ -83,6 +83,10 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
if err := c.check(); err != nil {
return err
}
+ // enable adaptive service verbose
+ if c.AdaptiveServiceVerbose {
+ aslimiter.Verbose = true
+ }
return nil
}
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 417d9b9e80..6cfed0bfc2 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -19,18 +19,92 @@ package adaptivesvc
import (
"context"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/filter"
+ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
"dubbo.apache.org/dubbo-go/v3/protocol"
+ "fmt"
+ "github.com/pkg/errors"
+ "sync"
)
-// Filter for adaptive service on server side.
-type Filter struct{}
+var (
+ adaptiveServiceProviderFilterOnce sync.Once
+ instance filter.Filter
-func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
- //eva, err := limiterMapperSingleton.getMethodCapacityEvaluator(invoker.GetURL(), invocation.MethodName(), )
- panic("implement me")
+ ErrUpdaterNotFound = fmt.Errorf("updater not found")
+ ErrUnexpectedUpdaterType = fmt.Errorf("unexpected updater type")
+)
+
+func init() {
+ extension.SetFilter(constant.AdaptiveServiceProviderFilterKey, newAdaptiveServiceProviderFilter)
+}
+
+// adaptiveServiceProviderFilter is for adaptive service on the provider side.
+type adaptiveServiceProviderFilter struct{}
+
+func newAdaptiveServiceProviderFilter() filter.Filter {
+ if instance == nil {
+ adaptiveServiceProviderFilterOnce.Do(func() {
+ instance = &adaptiveServiceProviderFilter{}
+ })
+ }
+ return instance
+}
+
+func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
+ l, err := limiterMapperSingleton.getMethodLimiter(invoker.GetURL(), invocation.MethodName())
+ if err != nil {
+ if errors.Is(err, ErrLimiterNotFoundOnMapper) {
+ // limiter is not found on the mapper, just create
+ // a new limiter
+ if l, err = limiterMapperSingleton.newAndSetMethodLimiter(invoker.GetURL(),
+ invocation.MethodName(), limiter.HillClimbingLimiter); err != nil {
+ return &protocol.RPCResult{Err: err}
+ }
+ } else {
+ // unexpected errors
+ return &protocol.RPCResult{Err: err}
+ }
+ }
+
+ updater, err := l.Acquire()
+ if err != nil {
+ return &protocol.RPCResult{Err: err}
+ }
+
+ invocation.Attributes()[constant.AdaptiveServiceUpdaterKey] = updater
+
+ return invoker.Invoke(ctx, invocation)
}
-func (f *Filter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker,
+func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result protocol.Result, invoker protocol.Invoker,
invocation protocol.Invocation) protocol.Result {
- panic("implement me")
+ // get updater from the attributes
+ updaterIface := invocation.AttributeByKey(constant.AdaptiveServiceUpdaterKey, nil)
+ if updaterIface == nil {
+ return &protocol.RPCResult{Err: ErrUpdaterNotFound}
+ }
+ updater, ok := updaterIface.(limiter.Updater)
+ if !ok {
+ return &protocol.RPCResult{Err: ErrUnexpectedUpdaterType}
+ }
+
+ err := updater.DoUpdate()
+ if err != nil {
+ return &protocol.RPCResult{Err: err}
+ }
+
+ // get limiter for the mapper
+ l, err := limiterMapperSingleton.getMethodLimiter(invoker.GetURL(), invocation.MethodName())
+ if err != nil {
+ return &protocol.RPCResult{Err: err}
+ }
+
+ // set attachments to inform consumer of provider status
+ invocation.SetAttachments(constant.AdaptiveServiceRemainingKey, l.Remaining())
+ invocation.SetAttachments(constant.AdaptiveServiceInflightKey, l.Inflight())
+
+ return result
}
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index 951737c695..c0ed91fb29 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package limiter
import (
@@ -113,12 +130,15 @@ func NewHillClimbingUpdater(limiter *HillClimbing) *HillClimbingUpdater {
return u
}
-func (u *HillClimbingUpdater) DoUpdate(rtt, inflight uint64) error {
+func (u *HillClimbingUpdater) DoUpdate() error {
defer func() {
u.limiter.inflight.Add(-1)
}()
VerboseDebugf("[HillClimbingUpdater] A request finished, the limiter will be updated, seq: %d.", u.seq)
+ rtt := uint64(time.Now().Sub(u.startTime))
+ inflight := u.limiter.Inflight()
+
option, err := u.getOption(rtt, inflight)
if err != nil {
return err
diff --git a/filter/adaptivesvc/limiter/limiter.go b/filter/adaptivesvc/limiter/limiter.go
index ff6b9206e7..cdc730ed12 100644
--- a/filter/adaptivesvc/limiter/limiter.go
+++ b/filter/adaptivesvc/limiter/limiter.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package limiter
import (
@@ -10,6 +27,10 @@ var (
Verbose = false
)
+const (
+ HillClimbingLimiter = iota
+)
+
type Limiter interface {
Inflight() uint64
Remaining() uint64
@@ -17,5 +38,5 @@ type Limiter interface {
}
type Updater interface {
- DoUpdate(rtt, inflight uint64) error
+ DoUpdate() error
}
diff --git a/filter/adaptivesvc/limiter/utils.go b/filter/adaptivesvc/limiter/utils.go
index 088e67dd08..2842be3ed1 100644
--- a/filter/adaptivesvc/limiter/utils.go
+++ b/filter/adaptivesvc/limiter/utils.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package limiter
import (
@@ -34,7 +51,7 @@ import (
// }
//}
-func VerboseDebugf(msg string, args ...interface{}) {
+func VerboseDebugf(msg string, args ...interface{}) {
if !Verbose {
return
}
diff --git a/filter/adaptivesvc/limiter_mapper.go b/filter/adaptivesvc/limiter_mapper.go
index 61af068baf..62a5cab526 100644
--- a/filter/adaptivesvc/limiter_mapper.go
+++ b/filter/adaptivesvc/limiter_mapper.go
@@ -27,7 +27,8 @@ import (
var (
limiterMapperSingleton *limiterMapper
- ErrCapEvaluatorNotFound = fmt.Errorf("capacity evaluator not found")
+ ErrLimiterNotFoundOnMapper = fmt.Errorf("limiter not found on mapper")
+ ErrLimiterTypeNotFound = fmt.Errorf("limiter type not found")
)
func init() {
@@ -35,34 +36,47 @@ func init() {
}
type limiterMapper struct {
- mutex *sync.Mutex
- mapper map[string]limiter.Limiter
+ rwMutex *sync.RWMutex
+ mapper map[string]limiter.Limiter
}
func newLimiterMapper() *limiterMapper {
return &limiterMapper{
- mutex: new(sync.Mutex),
- mapper: make(map[string]limiter.Limiter),
+ rwMutex: new(sync.RWMutex),
+ mapper: make(map[string]limiter.Limiter),
}
}
-func (m *limiterMapper) setMethodCapacityEvaluator(url *common.URL, methodName string,
- eva limiter.Limiter) error {
+func (m *limiterMapper) newAndSetMethodLimiter(url *common.URL, methodName string, limiterType int) (limiter.Limiter, error) {
key := fmt.Sprintf("%s%s", url.Path, methodName)
- m.mutex.Lock()
- limiterMapperSingleton.mapper[key] = eva
- m.mutex.Unlock()
- return nil
+
+ var (
+ l limiter.Limiter
+ ok bool
+ )
+ m.rwMutex.Lock()
+ if l, ok = limiterMapperSingleton.mapper[key]; ok {
+ return l, nil
+ }
+ switch limiterType {
+ case limiter.HillClimbingLimiter:
+ l = limiter.NewHillClimbing()
+ default:
+ return nil, ErrLimiterTypeNotFound
+ }
+ limiterMapperSingleton.mapper[key] = l
+ m.rwMutex.Unlock()
+ return l, nil
}
-func (m *limiterMapper) getMethodCapacityEvaluator(url *common.URL, methodName string) (
+func (m *limiterMapper) getMethodLimiter(url *common.URL, methodName string) (
limiter.Limiter, error) {
key := fmt.Sprintf("%s%s", url.Path, methodName)
- m.mutex.Lock()
- eva, ok := limiterMapperSingleton.mapper[key]
- m.mutex.Unlock()
+ m.rwMutex.RLock()
+ l, ok := limiterMapperSingleton.mapper[key]
+ m.rwMutex.RUnlock()
if !ok {
- return nil, ErrCapEvaluatorNotFound
+ return nil, ErrLimiterNotFoundOnMapper
}
- return eva, nil
+ return l, nil
}
From bf43b0bfaead86a4a88f7c465f630e0153704197 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sat, 20 Nov 2021 17:33:26 +0800
Subject: [PATCH 20/35] fix(cluster): fix uint64 subtraction issue
---
filter/adaptivesvc/limiter/hill_climbing.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index c0ed91fb29..171d89e75f 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -132,7 +132,7 @@ func NewHillClimbingUpdater(limiter *HillClimbing) *HillClimbingUpdater {
func (u *HillClimbingUpdater) DoUpdate() error {
defer func() {
- u.limiter.inflight.Add(-1)
+ u.limiter.inflight.Dec()
}()
VerboseDebugf("[HillClimbingUpdater] A request finished, the limiter will be updated, seq: %d.", u.seq)
From d8ca7f15b567afdd97e97f13e1721d77e2239f91 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Mon, 22 Nov 2021 14:30:17 +0800
Subject: [PATCH 21/35] fix(cluster): add adaptivesvc filter to default service
filters
---
common/constant/default.go | 16 ++++++++++++----
config/reference_config.go | 2 +-
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/common/constant/default.go b/common/constant/default.go
index 58784e7897..030dc23dff 100644
--- a/common/constant/default.go
+++ b/common/constant/default.go
@@ -50,14 +50,22 @@ const (
const (
DefaultKey = "default"
- PrefixDefaultKey = "default."
- DefaultServiceFilters = EchoFilterKey + "," + MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," + GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey
- DefaultReferenceFilters = GracefulShutdownConsumerFilterKey
- GenericReferenceFilters = GenericFilterKey
Generic = "$invoke"
Echo = "$echo"
)
+// default filters
+const (
+ // DefaultServiceFilters defines default service filters, it is highly recommended
+ // that put the AdaptiveServiceProviderFilterKey at the end.
+ DefaultServiceFilters = EchoFilterKey + "," +
+ MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," +
+ GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey + "," +
+ AdaptiveServiceProviderFilterKey
+
+ DefaultReferenceFilters = GracefulShutdownConsumerFilterKey
+)
+
const (
AnyValue = "*"
AnyhostValue = "0.0.0.0"
diff --git a/config/reference_config.go b/config/reference_config.go
index bf4c3b7327..a897686075 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -286,7 +286,7 @@ func (rc *ReferenceConfig) getURLMap() url.Values {
// filter
defaultReferenceFilter := constant.DefaultReferenceFilters
if rc.Generic != "" {
- defaultReferenceFilter = constant.GenericReferenceFilters + "," + defaultReferenceFilter
+ defaultReferenceFilter = constant.GenericFilterKey + "," + defaultReferenceFilter
}
urlMap.Set(constant.ReferenceFilterKey, mergeValue(rc.rootConfig.Consumer.Filter, "", defaultReferenceFilter))
From 30dcb14f9957423c991d36fed273d9a207b96cb1 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Mon, 22 Nov 2021 14:44:48 +0800
Subject: [PATCH 22/35] style: go fmt
---
common/constant/default.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/common/constant/default.go b/common/constant/default.go
index 030dc23dff..59f18c0360 100644
--- a/common/constant/default.go
+++ b/common/constant/default.go
@@ -49,16 +49,16 @@ const (
)
const (
- DefaultKey = "default"
- Generic = "$invoke"
- Echo = "$echo"
+ DefaultKey = "default"
+ Generic = "$invoke"
+ Echo = "$echo"
)
// default filters
const (
// DefaultServiceFilters defines default service filters, it is highly recommended
// that put the AdaptiveServiceProviderFilterKey at the end.
- DefaultServiceFilters = EchoFilterKey + "," +
+ DefaultServiceFilters = EchoFilterKey + "," +
MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," +
GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey + "," +
AdaptiveServiceProviderFilterKey
From 5b48b403f9a13bba3447d308b1d8543eb361e5fc Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Mon, 22 Nov 2021 14:55:36 +0800
Subject: [PATCH 23/35] fix(filter): import adaptivesvc
---
filter/filter_impl/import.go | 1 +
imports/imports.go | 1 +
2 files changed, 2 insertions(+)
diff --git a/filter/filter_impl/import.go b/filter/filter_impl/import.go
index f54bf8250f..015a5da987 100644
--- a/filter/filter_impl/import.go
+++ b/filter/filter_impl/import.go
@@ -23,6 +23,7 @@ package filter_impl
import (
_ "dubbo.apache.org/dubbo-go/v3/filter/accesslog"
_ "dubbo.apache.org/dubbo-go/v3/filter/active"
+ _ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc"
_ "dubbo.apache.org/dubbo-go/v3/filter/auth"
_ "dubbo.apache.org/dubbo-go/v3/filter/echo"
_ "dubbo.apache.org/dubbo-go/v3/filter/exec_limit"
diff --git a/imports/imports.go b/imports/imports.go
index 443e97af6f..27c004fb98 100644
--- a/imports/imports.go
+++ b/imports/imports.go
@@ -37,6 +37,7 @@ import (
_ "dubbo.apache.org/dubbo-go/v3/config_center/zookeeper"
_ "dubbo.apache.org/dubbo-go/v3/filter/accesslog"
_ "dubbo.apache.org/dubbo-go/v3/filter/active"
+ _ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc"
_ "dubbo.apache.org/dubbo-go/v3/filter/auth"
_ "dubbo.apache.org/dubbo-go/v3/filter/echo"
_ "dubbo.apache.org/dubbo-go/v3/filter/exec_limit"
From c7edac5a9fd6ac5532313727fffa13dd1648a1ef Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Fri, 26 Nov 2021 17:32:15 +0800
Subject: [PATCH 24/35] fix(imports): import adaptivesvc cluster and p2c
loadbalance
---
cluster/cluster_impl/import.go | 1 +
config/provider_config.go | 2 ++
imports/imports.go | 2 ++
3 files changed, 5 insertions(+)
diff --git a/cluster/cluster_impl/import.go b/cluster/cluster_impl/import.go
index 68908ab6e2..8ba974918a 100644
--- a/cluster/cluster_impl/import.go
+++ b/cluster/cluster_impl/import.go
@@ -21,6 +21,7 @@ package cluster_impl
// This package may be DEPRECATED OR REMOVED in the future.
import (
+ _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/adaptivesvc"
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/available"
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/broadcast"
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/failback"
diff --git a/config/provider_config.go b/config/provider_config.go
index 17efb3cb41..3e09a17f56 100644
--- a/config/provider_config.go
+++ b/config/provider_config.go
@@ -117,6 +117,8 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
}
// enable adaptive service verbose
if c.AdaptiveServiceVerbose {
+ logger.Infof("adaptive service verbose is enabled, the current logging level is %s.",
+ c.rootConfig.Logger.ZapConfig.Level)
aslimiter.Verbose = true
}
return nil
diff --git a/imports/imports.go b/imports/imports.go
index ca7f6b4bff..7c401642e8 100644
--- a/imports/imports.go
+++ b/imports/imports.go
@@ -18,6 +18,7 @@
package imports
import (
+ _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/adaptivesvc"
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/available"
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/broadcast"
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/failback"
@@ -28,6 +29,7 @@ import (
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/zoneaware"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/consistenthashing"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/leastactive"
+ _ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/p2c"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/roundrobin"
_ "dubbo.apache.org/dubbo-go/v3/cluster/router/v3router"
From 73b4f703d4143a8d3ec46dae1f51560f74c4e07a Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Fri, 26 Nov 2021 18:38:41 +0800
Subject: [PATCH 25/35] fix(config): fix unexpectedly panic
---
config/provider_config.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/config/provider_config.go b/config/provider_config.go
index 3e09a17f56..bd7cb71707 100644
--- a/config/provider_config.go
+++ b/config/provider_config.go
@@ -117,8 +117,8 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
}
// enable adaptive service verbose
if c.AdaptiveServiceVerbose {
- logger.Infof("adaptive service verbose is enabled, the current logging level is %s.",
- c.rootConfig.Logger.ZapConfig.Level)
+ logger.Infof("adaptive service verbose is enabled.")
+ logger.Debugf("debug-level info could be shown.")
aslimiter.Verbose = true
}
return nil
From 1fa48ca28c13dbba0cff16bf1fed6310412e40b5 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Wed, 1 Dec 2021 19:51:33 +0800
Subject: [PATCH 26/35] feat(adasvc): add debug logs
---
cluster/cluster/adaptivesvc/cluster_invoker.go | 3 +++
filter/adaptivesvc/filter.go | 9 ++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index 444f428c68..fb6c7cde94 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -24,6 +24,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/cluster/metrics"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/protocol"
perrors "github.com/pkg/errors"
)
@@ -61,6 +62,8 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation
// update metrics
remaining := invocation.Attachments()[constant.AdaptiveServiceRemainingKey]
+ logger.Debugf("[adasvc cluster] The server status was received successfully, %s: %#v",
+ constant.AdaptiveServiceRemainingKey, remaining)
err := metrics.LocalMetrics.SetMethodMetrics(invoker.GetURL(),
invocation.MethodName(), metrics.HillClimbing, remaining)
if err != nil {
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 6cfed0bfc2..61d543d458 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -21,6 +21,7 @@ import (
"context"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/filter"
"dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
"dubbo.apache.org/dubbo-go/v3/protocol"
@@ -93,7 +94,10 @@ func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result pro
err := updater.DoUpdate()
if err != nil {
- return &protocol.RPCResult{Err: err}
+ // DoUpdate was failed, but the invocation is not failed.
+ // Printing the error to logs is better than returning a
+ // result with an error.
+ logger.Errorf("[adasvc filter] The DoUpdate method was failed, err: %s.", err)
}
// get limiter for the mapper
@@ -105,6 +109,9 @@ func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result pro
// set attachments to inform consumer of provider status
invocation.SetAttachments(constant.AdaptiveServiceRemainingKey, l.Remaining())
invocation.SetAttachments(constant.AdaptiveServiceInflightKey, l.Inflight())
+ logger.Debugf("[adasvc filter] The attachments are set, %s: %d, %s: %d.",
+ constant.AdaptiveServiceRemainingKey, l.Remaining(),
+ constant.AdaptiveServiceInflightKey, l.Inflight())
return result
}
From 0acc52eebe95beee1abb4aa21691c1ad03034d63 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Wed, 1 Dec 2021 20:56:44 +0800
Subject: [PATCH 27/35] fix(adasvc): pass attachements with string
---
cluster/cluster/adaptivesvc/cluster_invoker.go | 13 ++++++++++---
cluster/metrics/local_metrics.go | 8 ++++++--
filter/adaptivesvc/filter.go | 4 ++--
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index fb6c7cde94..0a10ae5135 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -27,6 +27,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/protocol"
perrors "github.com/pkg/errors"
+ "strconv"
)
type adaptiveServiceClusterInvoker struct {
@@ -61,12 +62,18 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation
result := invoker.Invoke(ctx, invocation)
// update metrics
- remaining := invocation.Attachments()[constant.AdaptiveServiceRemainingKey]
+ remainingStr := invocation.AttachmentsByKey(constant.AdaptiveServiceRemainingKey, "")
+ remaining, err := strconv.Atoi(remainingStr)
+ if err != nil {
+ logger.Warnf("the remaining is unexpected, we need a int type, but we got %d, err: %v.", remainingStr, err)
+ return result
+ }
logger.Debugf("[adasvc cluster] The server status was received successfully, %s: %#v",
- constant.AdaptiveServiceRemainingKey, remaining)
- err := metrics.LocalMetrics.SetMethodMetrics(invoker.GetURL(),
+ constant.AdaptiveServiceRemainingKey, remainingStr)
+ err = metrics.LocalMetrics.SetMethodMetrics(invoker.GetURL(),
invocation.MethodName(), metrics.HillClimbing, remaining)
if err != nil {
+ logger.Warnf("adaptive service metrics update is failed, err: %v", err)
return &protocol.RPCResult{Err: err}
}
diff --git a/cluster/metrics/local_metrics.go b/cluster/metrics/local_metrics.go
index 9cd3a35c41..b3b5eac95b 100644
--- a/cluster/metrics/local_metrics.go
+++ b/cluster/metrics/local_metrics.go
@@ -31,18 +31,20 @@ func init() {
type localMetrics struct {
// protect metrics
- lock *sync.Mutex
+ lock *sync.RWMutex
metrics map[string]interface{}
}
func newLocalMetrics() *localMetrics {
return &localMetrics{
- lock: &sync.Mutex{},
+ lock: new(sync.RWMutex),
metrics: make(map[string]interface{}),
}
}
func (m *localMetrics) GetMethodMetrics(url *common.URL, methodName, key string) (interface{}, error) {
+ m.lock.RLock()
+ defer m.lock.RUnlock()
metricsKey := fmt.Sprintf("%s.%s.%s.%s", getInstanceKey(url), getInvokerKey(url), methodName, key)
if metrics, ok := m.metrics[metricsKey]; ok {
return metrics, nil
@@ -51,6 +53,8 @@ func (m *localMetrics) GetMethodMetrics(url *common.URL, methodName, key string)
}
func (m *localMetrics) SetMethodMetrics(url *common.URL, methodName, key string, value interface{}) error {
+ m.lock.Lock()
+ defer m.lock.Unlock()
metricsKey := fmt.Sprintf("%s.%s.%s.%s", getInstanceKey(url), getInvokerKey(url), methodName, key)
m.metrics[metricsKey] = value
return nil
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 61d543d458..0ac0b0b161 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -107,8 +107,8 @@ func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result pro
}
// set attachments to inform consumer of provider status
- invocation.SetAttachments(constant.AdaptiveServiceRemainingKey, l.Remaining())
- invocation.SetAttachments(constant.AdaptiveServiceInflightKey, l.Inflight())
+ invocation.SetAttachments(constant.AdaptiveServiceRemainingKey, fmt.Sprintf("%d", l.Remaining()))
+ invocation.SetAttachments(constant.AdaptiveServiceInflightKey, fmt.Sprintf("%d", l.Inflight()))
logger.Debugf("[adasvc filter] The attachments are set, %s: %d, %s: %d.",
constant.AdaptiveServiceRemainingKey, l.Remaining(),
constant.AdaptiveServiceInflightKey, l.Inflight())
From e5de62f7e63169081b66bbc615a1b8baf82849d9 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Thu, 2 Dec 2021 11:42:57 +0800
Subject: [PATCH 28/35] feat(adasvc): detail debug logs
---
filter/adaptivesvc/filter.go | 11 ++++++++++-
protocol/invoker.go | 9 +++++++++
protocol/protocolwrapper/protocol_filter_wrapper.go | 7 +++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 0ac0b0b161..98934d098c 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -54,7 +54,12 @@ func newAdaptiveServiceProviderFilter() filter.Filter {
return instance
}
-func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
+func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker protocol.Invoker,
+ invocation protocol.Invocation) protocol.Result {
+ // TODO(justxuewei): remove after test
+ logger.Debugf("adaptiveServiceProviderFilter.Invoker is called, invoker: %s, methodName: %s",
+ invoker, invocation.MethodName())
+
l, err := limiterMapperSingleton.getMethodLimiter(invoker.GetURL(), invocation.MethodName())
if err != nil {
if errors.Is(err, ErrLimiterNotFoundOnMapper) {
@@ -82,6 +87,10 @@ func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker prot
func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result protocol.Result, invoker protocol.Invoker,
invocation protocol.Invocation) protocol.Result {
+ // TODO(justxuewei): remove after test
+ logger.Debugf("adaptiveServiceProviderFilter.Invoker is called, invoker: %s, methodName: %s, result: %s",
+ invoker, invocation.MethodName(), result)
+
// get updater from the attributes
updaterIface := invocation.AttributeByKey(constant.AdaptiveServiceUpdaterKey, nil)
if updaterIface == nil {
diff --git a/protocol/invoker.go b/protocol/invoker.go
index af63dd6702..cb6e8d1287 100644
--- a/protocol/invoker.go
+++ b/protocol/invoker.go
@@ -19,6 +19,7 @@ package protocol
import (
"context"
+ "fmt"
)
import (
@@ -98,3 +99,11 @@ func (bi *BaseInvoker) Destroy() {
bi.destroyed.Store(true)
bi.available.Store(false)
}
+
+func (bi *BaseInvoker) String() string {
+ if bi.url != nil {
+ return fmt.Sprintf("invoker{protocol: %s, host: %s:%s, path: %s}",
+ bi.url.Protocol, bi.url.Ip, bi.url.Port, bi.url.Path)
+ }
+ return fmt.Sprintf("%#v", bi)
+}
diff --git a/protocol/protocolwrapper/protocol_filter_wrapper.go b/protocol/protocolwrapper/protocol_filter_wrapper.go
index 2c24178582..d14378cb5a 100644
--- a/protocol/protocolwrapper/protocol_filter_wrapper.go
+++ b/protocol/protocolwrapper/protocol_filter_wrapper.go
@@ -19,6 +19,7 @@ package protocolwrapper
import (
"context"
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
"strings"
)
@@ -85,6 +86,12 @@ func BuildInvokerChain(invoker protocol.Invoker, key string) protocol.Invoker {
fi := &FilterInvoker{next: next, invoker: invoker, filter: flt}
next = fi
}
+
+ if key == constant.ServiceFilterKey {
+ logger.Debugf("[BuildInvokerChain] The provider filters are %s, invoker: %s", filterNames, invoker)
+ } else if key == constant.ReferenceFilterKey {
+ logger.Debugf("[BuildInvokerChain] The consumer filters are %s, invoker: %s", filterNames, invoker)
+ }
return next
}
From 6f1d7bf02e92678371ecc32f4ad3c1e84949a005 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Thu, 2 Dec 2021 13:04:55 +0800
Subject: [PATCH 29/35] fix(adasvc): fix log info
---
cluster/cluster/adaptivesvc/cluster_invoker.go | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index 0a10ae5135..2a7bc8b5ff 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -61,11 +61,14 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation
// invoke
result := invoker.Invoke(ctx, invocation)
+ // TODO(justxuewei): remove after test
+ logger.Debugf("%#v", result.Result())
+
// update metrics
remainingStr := invocation.AttachmentsByKey(constant.AdaptiveServiceRemainingKey, "")
remaining, err := strconv.Atoi(remainingStr)
if err != nil {
- logger.Warnf("the remaining is unexpected, we need a int type, but we got %d, err: %v.", remainingStr, err)
+ logger.Warnf("the remaining is unexpected, we need a int type, but we got %s, err: %v.", remainingStr, err)
return result
}
logger.Debugf("[adasvc cluster] The server status was received successfully, %s: %#v",
From 4a04d4a7d5613c0f61003db38f38eb221035c9e7 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sun, 5 Dec 2021 18:46:55 +0800
Subject: [PATCH 30/35] feat: detail dubbo logs
---
cluster/cluster/adaptivesvc/cluster_invoker.go | 4 ++--
cluster/loadbalance/p2c/loadbalance.go | 12 +++++++++++-
common/constant/key.go | 2 +-
filter/adaptivesvc/filter.go | 4 ++--
filter/adaptivesvc/limiter/hill_climbing.go | 2 +-
protocol/dubbo/dubbo_invoker.go | 3 ++-
protocol/dubbo/dubbo_protocol.go | 1 +
.../protocolwrapper/protocol_filter_wrapper.go | 6 ++++--
protocol/result.go | 6 ++++++
remoting/codec.go | 1 +
remoting/exchange.go | 6 ++++++
remoting/exchange_client.go | 4 ++++
remoting/getty/listener.go | 17 +++++++++++------
13 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index 2a7bc8b5ff..5678778c44 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -62,10 +62,10 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation
result := invoker.Invoke(ctx, invocation)
// TODO(justxuewei): remove after test
- logger.Debugf("%#v", result.Result())
+ logger.Debugf("result: Result: %#v", result.Attachments())
// update metrics
- remainingStr := invocation.AttachmentsByKey(constant.AdaptiveServiceRemainingKey, "")
+ remainingStr := result.Attachment(constant.AdaptiveServiceRemainingKey, "").(string)
remaining, err := strconv.Atoi(remainingStr)
if err != nil {
logger.Warnf("the remaining is unexpected, we need a int type, but we got %s, err: %v.", remainingStr, err)
diff --git a/cluster/loadbalance/p2c/loadbalance.go b/cluster/loadbalance/p2c/loadbalance.go
index e9223fd4bf..174032da87 100644
--- a/cluster/loadbalance/p2c/loadbalance.go
+++ b/cluster/loadbalance/p2c/loadbalance.go
@@ -73,6 +73,9 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
j = rand.Intn(len(invokers))
}
}
+ logger.Debugf("[P2C select] Two invokers were selected, i: %d, j: %d, invoker[i]: %s, invoker[j]: %s.",
+ i, j, invokers[i], invokers[j])
+
// TODO(justxuewei): please consider how to get the real method name from $invoke,
// see also [#1511](https://github.com/apache/dubbo-go/issues/1511)
methodName := invocation.MethodName()
@@ -81,6 +84,7 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
remainingIIface, err := m.GetMethodMetrics(invokers[i].GetURL(), methodName, metrics.HillClimbing)
if err != nil {
if errors.Is(err, metrics.ErrMetricsNotFound) {
+ logger.Debugf("[P2C select] The invoker[i] was selected, because it hasn't been selected before.")
return invokers[i]
}
logger.Warnf("get method metrics err: %v", err)
@@ -90,6 +94,7 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
remainingJIface, err := m.GetMethodMetrics(invokers[j].GetURL(), methodName, metrics.HillClimbing)
if err != nil {
if errors.Is(err, metrics.ErrMetricsNotFound) {
+ logger.Debugf("[P2C select] The invoker[j] was selected, because it hasn't been selected before.")
return invokers[j]
}
logger.Warnf("get method metrics err: %v", err)
@@ -99,7 +104,8 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
// Convert interface to int, if the type is unexpected, panic immediately
remainingI, ok := remainingIIface.(uint64)
if !ok {
- panic(fmt.Sprintf("the type of %s expects to be uint64, but gets %T", metrics.HillClimbing, remainingIIface))
+ panic(fmt.Sprintf("[P2C select] the type of %s expects to be uint64, but gets %T",
+ metrics.HillClimbing, remainingIIface))
}
remainingJ, ok := remainingJIface.(uint64)
@@ -107,10 +113,14 @@ func (l *loadBalance) Select(invokers []protocol.Invoker, invocation protocol.In
panic(fmt.Sprintf("the type of %s expects to be uint64, but gets %T", metrics.HillClimbing, remainingJIface))
}
+ logger.Debugf("[P2C select] The invoker[i] remaining is %d, and the invoker[j] is %d.", remainingI, remainingJ)
+
// For the remaining capacity, the bigger, the better.
if remainingI > remainingJ {
+ logger.Debugf("[P2C select] The invoker[i] was selected.")
return invokers[i]
}
+ logger.Debugf("[P2C select] The invoker[j] was selected.")
return invokers[j]
}
diff --git a/common/constant/key.go b/common/constant/key.go
index 4b467afdb6..cde0561f10 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -65,7 +65,7 @@ const (
const (
AccessLogFilterKey = "accesslog"
ActiveFilterKey = "active"
- AdaptiveServiceProviderFilterKey = "adaptive-service-provider"
+ AdaptiveServiceProviderFilterKey = "padasvc"
AuthConsumerFilterKey = "sign"
AuthProviderFilterKey = "auth"
EchoFilterKey = "echo"
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 98934d098c..f2d7d1bfec 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -116,8 +116,8 @@ func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result pro
}
// set attachments to inform consumer of provider status
- invocation.SetAttachments(constant.AdaptiveServiceRemainingKey, fmt.Sprintf("%d", l.Remaining()))
- invocation.SetAttachments(constant.AdaptiveServiceInflightKey, fmt.Sprintf("%d", l.Inflight()))
+ result.AddAttachment(constant.AdaptiveServiceRemainingKey, fmt.Sprintf("%d", l.Remaining()))
+ result.AddAttachment(constant.AdaptiveServiceInflightKey, fmt.Sprintf("%d", l.Inflight()))
logger.Debugf("[adasvc filter] The attachments are set, %s: %d, %s: %d.",
constant.AdaptiveServiceRemainingKey, l.Remaining(),
constant.AdaptiveServiceInflightKey, l.Inflight())
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index 171d89e75f..10727e65e3 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -298,7 +298,7 @@ func (u *HillClimbingUpdater) adjustLimitation(option HillClimbingOption) error
limitation = math.Max(1.0, math.Min(limitation, float64(maxLimitation)))
u.limiter.limitation.Store(uint64(limitation))
- VerboseDebugf("[HillClimbingUpdater] The limitation is update from %d to %d.", oldLimitation, uint64(limitation))
+ VerboseDebugf("[HillClimbingUpdater] The limitation is update from %d to %d.", uint64(oldLimitation), uint64(limitation))
return nil
}
diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go
index 0f23070f36..232eeaffb9 100644
--- a/protocol/dubbo/dubbo_invoker.go
+++ b/protocol/dubbo/dubbo_invoker.go
@@ -158,7 +158,8 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
result.Rest = inv.Reply()
result.Attrs = rest.Attrs
}
- logger.Debugf("result.Err: %v, result.Rest: %v", result.Err, result.Rest)
+
+ logger.Debugf("[DubboInvoker.Invoke] received rpc result form server: %s", result)
return &result
}
diff --git a/protocol/dubbo/dubbo_protocol.go b/protocol/dubbo/dubbo_protocol.go
index 58c06012d7..8b46983e13 100644
--- a/protocol/dubbo/dubbo_protocol.go
+++ b/protocol/dubbo/dubbo_protocol.go
@@ -167,6 +167,7 @@ func doHandleRequest(rpcInvocation *invocation.RPCInvocation) protocol.RPCResult
// p.Header.ResponseStatus = hessian.Response_OK
// p.Body = hessian.NewResponse(res, nil, result.Attachments())
}
+ result.Attrs = invokeResult.Attachments()
} else {
result.Err = fmt.Errorf("don't have the invoker, key: %s", rpcInvocation.ServiceKey())
}
diff --git a/protocol/protocolwrapper/protocol_filter_wrapper.go b/protocol/protocolwrapper/protocol_filter_wrapper.go
index d14378cb5a..da07694469 100644
--- a/protocol/protocolwrapper/protocol_filter_wrapper.go
+++ b/protocol/protocolwrapper/protocol_filter_wrapper.go
@@ -88,9 +88,11 @@ func BuildInvokerChain(invoker protocol.Invoker, key string) protocol.Invoker {
}
if key == constant.ServiceFilterKey {
- logger.Debugf("[BuildInvokerChain] The provider filters are %s, invoker: %s", filterNames, invoker)
+ logger.Debugf("[BuildInvokerChain] The provider invocation link is %s, invoker: %s",
+ strings.Join(append(filterNames, "proxyInvoker"), " -> "), invoker)
} else if key == constant.ReferenceFilterKey {
- logger.Debugf("[BuildInvokerChain] The consumer filters are %s, invoker: %s", filterNames, invoker)
+ logger.Debugf("[BuildInvokerChain] The consumer filters are %s, invoker: %s",
+ strings.Join(append(filterNames, "proxyInvoker"), " -> "), invoker)
}
return next
}
diff --git a/protocol/result.go b/protocol/result.go
index a36b16d1cc..16d76ec48a 100644
--- a/protocol/result.go
+++ b/protocol/result.go
@@ -17,6 +17,8 @@
package protocol
+import "fmt"
+
// Result is a RPC result
type Result interface {
// SetError sets error.
@@ -92,3 +94,7 @@ func (r *RPCResult) Attachment(key string, defaultValue interface{}) interface{}
}
return v
}
+
+func (r *RPCResult) String() string {
+ return fmt.Sprintf("&RPCResult{Rest: %v, Attrs: %v, Err: %v}", r.Rest, r.Attrs, r.Err)
+}
diff --git a/remoting/codec.go b/remoting/codec.go
index e1d1c8b603..8e09490d4b 100644
--- a/remoting/codec.go
+++ b/remoting/codec.go
@@ -29,6 +29,7 @@ type Codec interface {
}
type DecodeResult struct {
+ // IsRequest indicates whether the current request is a heartbeat request
IsRequest bool
Result interface{}
}
diff --git a/remoting/exchange.go b/remoting/exchange.go
index 1fda038d1c..aa81689b84 100644
--- a/remoting/exchange.go
+++ b/remoting/exchange.go
@@ -18,6 +18,7 @@
package remoting
import (
+ "fmt"
"sync"
"time"
)
@@ -115,6 +116,11 @@ func (response *Response) Handle() {
}
}
+func (response *Response) String() string {
+ return fmt.Sprintf("&remoting.Response{ID: %d, Version: %s, SerialID: %d, Status: %d, Event: %v, Error: %v, Result: %v}",
+ response.ID, response.Version, response.SerialID, response.Status, response.Event, response.Error, response.Result)
+}
+
type Options struct {
// connect timeout
ConnectTimeout time.Duration
diff --git a/remoting/exchange_client.go b/remoting/exchange_client.go
index 08098f7eb1..23d33e877e 100644
--- a/remoting/exchange_client.go
+++ b/remoting/exchange_client.go
@@ -134,6 +134,10 @@ func (client *ExchangeClient) Request(invocation *protocol.Invocation, url *comm
result.Rest = resultTmp.Rest
result.Attrs = resultTmp.Attrs
result.Err = resultTmp.Err
+ logger.Debugf("[ExchangeClient.Request] RPCResult from server: %v", resultTmp)
+ } else {
+ logger.Warnf("[ExchangeClient.Request] The type of result is unexpected, we want *protocol.RPCResult, "+
+ "but we got %T", rsp.response.Result)
}
return nil
}
diff --git a/remoting/getty/listener.go b/remoting/getty/listener.go
index 78b0f61e0f..65371f3290 100644
--- a/remoting/getty/listener.go
+++ b/remoting/getty/listener.go
@@ -102,14 +102,14 @@ func (h *RpcClientHandler) OnClose(session getty.Session) {
func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
result, ok := pkg.(remoting.DecodeResult)
if !ok {
- logger.Errorf("illegal package")
+ logger.Errorf("[RpcClientHandler.OnMessage] getty client gets an unexpected rpc result: %#v", result)
return
}
// get heartbeat request from server
if result.IsRequest {
req := result.Result.(*remoting.Request)
if req.Event {
- logger.Debugf("get rpc heartbeat request{%#v}", req)
+ logger.Debugf("[RpcClientHandler.OnMessage] getty client gets a heartbeat request: %#v", req)
resp := remoting.NewResponse(req.ID, req.Version)
resp.Status = hessian.Response_OK
resp.Event = req.Event
@@ -118,22 +118,23 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
reply(session, resp)
return
}
- logger.Errorf("illegal request but not heartbeat. {%#v}", req)
+ logger.Errorf("[RpcClientHandler.OnMessage] unexpected heartbeat request: %#v", req)
return
}
h.timeoutTimes = 0
p := result.Result.(*remoting.Response)
// get heartbeat
if p.Event {
- logger.Debugf("get rpc heartbeat response{%#v}", p)
+ logger.Debugf("[RpcClientHandler.OnMessage] getty client received a heartbeat response: %s", p)
if p.Error != nil {
- logger.Errorf("rpc heartbeat response{error: %#v}", p.Error)
+ logger.Errorf("[RpcClientHandler.OnMessage] a heartbeat response received by the getty client "+
+ "encounters an error: %v", p.Error)
}
p.Handle()
return
}
- logger.Debugf("get rpc response{%#v}", p)
+ logger.Debugf("[RpcClientHandler.OnMessage] getty client received a response: %s", p)
h.conn.updateSession(session)
@@ -303,11 +304,15 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
attachments[constant.LocalAddr] = session.LocalAddr()
attachments[constant.RemoteAddr] = session.RemoteAddr()
+ logger.Debugf("[RpcServerHandler.OnMessage] invoc.Attrs: %v, invoc.MethodName: %s",
+ invoc.Attachments(), invoc.MethodName())
+
result := h.server.requestHandler(invoc)
if !req.TwoWay {
return
}
resp.Result = result
+ logger.Debugf("[RpcServerHandler.OnMessage] result attrs: %v, req: %v", result.Attrs, req)
reply(session, resp)
}
From 4ed75059e55a69a2793ff22b9d193cfc2ad75c28 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sun, 5 Dec 2021 19:45:12 +0800
Subject: [PATCH 31/35] feat: remove useless logs
---
common/proxy/proxy.go | 6 +++---
filter/adaptivesvc/filter.go | 7 -------
protocol/dubbo/dubbo_invoker.go | 2 --
remoting/exchange_client.go | 1 -
remoting/getty/listener.go | 4 ----
5 files changed, 3 insertions(+), 17 deletions(-)
diff --git a/common/proxy/proxy.go b/common/proxy/proxy.go
index c32eedc57c..1676e75fb4 100644
--- a/common/proxy/proxy.go
+++ b/common/proxy/proxy.go
@@ -204,12 +204,12 @@ func DefaultProxyImplementFunc(p *Proxy, v common.RPCService) {
err = perrors.Cause(err)
// if some error happened, it should be log some info in the separate file.
if throwabler, ok := err.(java_exception.Throwabler); ok {
- logger.Warnf("invoke service throw exception: %v , stackTraceElements: %v", err.Error(), throwabler.GetStackTrace())
+ logger.Warnf("[CallProxy] invoke service throw exception: %v , stackTraceElements: %v", err.Error(), throwabler.GetStackTrace())
} else {
- logger.Warnf("result err: %v", err)
+ logger.Warnf("[CallProxy] received rpc err: %v", err)
}
} else {
- logger.Debugf("[makeDubboCallProxy] result: %v, err: %v", result.Result(), err)
+ logger.Debugf("[CallProxy] received rpc result successfully: %s", result)
}
if len(outs) == 1 {
return []reflect.Value{reflect.ValueOf(&err).Elem()}
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index f2d7d1bfec..834c16e184 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -56,9 +56,6 @@ func newAdaptiveServiceProviderFilter() filter.Filter {
func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker protocol.Invoker,
invocation protocol.Invocation) protocol.Result {
- // TODO(justxuewei): remove after test
- logger.Debugf("adaptiveServiceProviderFilter.Invoker is called, invoker: %s, methodName: %s",
- invoker, invocation.MethodName())
l, err := limiterMapperSingleton.getMethodLimiter(invoker.GetURL(), invocation.MethodName())
if err != nil {
@@ -87,10 +84,6 @@ func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker prot
func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result protocol.Result, invoker protocol.Invoker,
invocation protocol.Invocation) protocol.Result {
- // TODO(justxuewei): remove after test
- logger.Debugf("adaptiveServiceProviderFilter.Invoker is called, invoker: %s, methodName: %s, result: %s",
- invoker, invocation.MethodName(), result)
-
// get updater from the attributes
updaterIface := invocation.AttributeByKey(constant.AdaptiveServiceUpdaterKey, nil)
if updaterIface == nil {
diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go
index 232eeaffb9..904bfb036c 100644
--- a/protocol/dubbo/dubbo_invoker.go
+++ b/protocol/dubbo/dubbo_invoker.go
@@ -159,8 +159,6 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
result.Attrs = rest.Attrs
}
- logger.Debugf("[DubboInvoker.Invoke] received rpc result form server: %s", result)
-
return &result
}
diff --git a/remoting/exchange_client.go b/remoting/exchange_client.go
index 23d33e877e..f75c6d0640 100644
--- a/remoting/exchange_client.go
+++ b/remoting/exchange_client.go
@@ -134,7 +134,6 @@ func (client *ExchangeClient) Request(invocation *protocol.Invocation, url *comm
result.Rest = resultTmp.Rest
result.Attrs = resultTmp.Attrs
result.Err = resultTmp.Err
- logger.Debugf("[ExchangeClient.Request] RPCResult from server: %v", resultTmp)
} else {
logger.Warnf("[ExchangeClient.Request] The type of result is unexpected, we want *protocol.RPCResult, "+
"but we got %T", rsp.response.Result)
diff --git a/remoting/getty/listener.go b/remoting/getty/listener.go
index 65371f3290..337d634f4c 100644
--- a/remoting/getty/listener.go
+++ b/remoting/getty/listener.go
@@ -304,15 +304,11 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
attachments[constant.LocalAddr] = session.LocalAddr()
attachments[constant.RemoteAddr] = session.RemoteAddr()
- logger.Debugf("[RpcServerHandler.OnMessage] invoc.Attrs: %v, invoc.MethodName: %s",
- invoc.Attachments(), invoc.MethodName())
-
result := h.server.requestHandler(invoc)
if !req.TwoWay {
return
}
resp.Result = result
- logger.Debugf("[RpcServerHandler.OnMessage] result attrs: %v, req: %v", result.Attrs, req)
reply(session, resp)
}
From 8b12eacc18bc90a7a85f7ea2c8c40f77b43fb795 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sun, 5 Dec 2021 19:45:29 +0800
Subject: [PATCH 32/35] fix(adasvc): fix incorrect type
---
cluster/cluster/adaptivesvc/cluster_invoker.go | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index 5678778c44..8c9c40d22a 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -61,9 +61,6 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation
// invoke
result := invoker.Invoke(ctx, invocation)
- // TODO(justxuewei): remove after test
- logger.Debugf("result: Result: %#v", result.Attachments())
-
// update metrics
remainingStr := result.Attachment(constant.AdaptiveServiceRemainingKey, "").(string)
remaining, err := strconv.Atoi(remainingStr)
@@ -74,7 +71,7 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation
logger.Debugf("[adasvc cluster] The server status was received successfully, %s: %#v",
constant.AdaptiveServiceRemainingKey, remainingStr)
err = metrics.LocalMetrics.SetMethodMetrics(invoker.GetURL(),
- invocation.MethodName(), metrics.HillClimbing, remaining)
+ invocation.MethodName(), metrics.HillClimbing, uint64(remaining))
if err != nil {
logger.Warnf("adaptive service metrics update is failed, err: %v", err)
return &protocol.RPCResult{Err: err}
From c23612b1b90c7ccf7dd5024f67ce635090e22b92 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sun, 5 Dec 2021 19:48:39 +0800
Subject: [PATCH 33/35] style: go fmt & dubbofmt
---
cluster/cluster/adaptivesvc/cluster.go | 5 ++++-
cluster/cluster/adaptivesvc/cluster_invoker.go | 10 ++++++++--
cluster/loadbalance/p2c/loadbalance.go | 13 ++++++++-----
cluster/metrics/local_metrics.go | 5 ++++-
cluster/metrics/metrics.go | 5 ++++-
cluster/metrics/utils.go | 5 ++++-
filter/adaptivesvc/filter.go | 12 +++++++++---
filter/adaptivesvc/limiter/hill_climbing.go | 5 ++++-
filter/adaptivesvc/limiter/utils.go | 1 -
filter/adaptivesvc/limiter_mapper.go | 7 +++++--
protocol/protocolwrapper/protocol_filter_wrapper.go | 2 +-
protocol/result.go | 4 +++-
12 files changed, 54 insertions(+), 20 deletions(-)
diff --git a/cluster/cluster/adaptivesvc/cluster.go b/cluster/cluster/adaptivesvc/cluster.go
index 4a2d4875df..71abf865d8 100644
--- a/cluster/cluster/adaptivesvc/cluster.go
+++ b/cluster/cluster/adaptivesvc/cluster.go
@@ -17,13 +17,16 @@
package adaptivesvc
+import (
+ "sync"
+)
+
import (
clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
"dubbo.apache.org/dubbo-go/v3/cluster/directory"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/protocol"
- "sync"
)
var (
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index 8c9c40d22a..88c7df5d31 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -19,6 +19,14 @@ package adaptivesvc
import (
"context"
+ "strconv"
+)
+
+import (
+ perrors "github.com/pkg/errors"
+)
+
+import (
"dubbo.apache.org/dubbo-go/v3/cluster/cluster/base"
"dubbo.apache.org/dubbo-go/v3/cluster/directory"
"dubbo.apache.org/dubbo-go/v3/cluster/metrics"
@@ -26,8 +34,6 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/protocol"
- perrors "github.com/pkg/errors"
- "strconv"
)
type adaptiveServiceClusterInvoker struct {
diff --git a/cluster/loadbalance/p2c/loadbalance.go b/cluster/loadbalance/p2c/loadbalance.go
index 174032da87..3b3678aaeb 100644
--- a/cluster/loadbalance/p2c/loadbalance.go
+++ b/cluster/loadbalance/p2c/loadbalance.go
@@ -17,6 +17,14 @@
package p2c
+import (
+ "errors"
+ "fmt"
+ "math/rand"
+ "sync"
+ "time"
+)
+
import (
"dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
"dubbo.apache.org/dubbo-go/v3/cluster/metrics"
@@ -24,11 +32,6 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/protocol"
- "errors"
- "fmt"
- "math/rand"
- "sync"
- "time"
)
func init() {
diff --git a/cluster/metrics/local_metrics.go b/cluster/metrics/local_metrics.go
index b3b5eac95b..e9f976a193 100644
--- a/cluster/metrics/local_metrics.go
+++ b/cluster/metrics/local_metrics.go
@@ -18,11 +18,14 @@
package metrics
import (
- "dubbo.apache.org/dubbo-go/v3/common"
"fmt"
"sync"
)
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+)
+
var LocalMetrics Metrics
func init() {
diff --git a/cluster/metrics/metrics.go b/cluster/metrics/metrics.go
index 257539ce68..0f61dcf1c2 100644
--- a/cluster/metrics/metrics.go
+++ b/cluster/metrics/metrics.go
@@ -18,10 +18,13 @@
package metrics
import (
- "dubbo.apache.org/dubbo-go/v3/common"
"github.com/pkg/errors"
)
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+)
+
var (
ErrMetricsNotFound = errors.New("metrics not found")
)
diff --git a/cluster/metrics/utils.go b/cluster/metrics/utils.go
index b07a290783..65cc9e249d 100644
--- a/cluster/metrics/utils.go
+++ b/cluster/metrics/utils.go
@@ -18,10 +18,13 @@
package metrics
import (
- "dubbo.apache.org/dubbo-go/v3/common"
"fmt"
)
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+)
+
func getInvokerKey(url *common.URL) string {
return url.Path
}
diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go
index 834c16e184..04dde942ba 100644
--- a/filter/adaptivesvc/filter.go
+++ b/filter/adaptivesvc/filter.go
@@ -19,15 +19,21 @@ package adaptivesvc
import (
"context"
+ "fmt"
+ "sync"
+)
+
+import (
+ "github.com/pkg/errors"
+)
+
+import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/filter"
"dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
"dubbo.apache.org/dubbo-go/v3/protocol"
- "fmt"
- "github.com/pkg/errors"
- "sync"
)
var (
diff --git a/filter/adaptivesvc/limiter/hill_climbing.go b/filter/adaptivesvc/limiter/hill_climbing.go
index 10727e65e3..070a6dc735 100644
--- a/filter/adaptivesvc/limiter/hill_climbing.go
+++ b/filter/adaptivesvc/limiter/hill_climbing.go
@@ -18,12 +18,15 @@
package limiter
import (
- "go.uber.org/atomic"
"math"
"sync"
"time"
)
+import (
+ "go.uber.org/atomic"
+)
+
var (
_ Limiter = (*HillClimbing)(nil)
_ Updater = (*HillClimbingUpdater)(nil)
diff --git a/filter/adaptivesvc/limiter/utils.go b/filter/adaptivesvc/limiter/utils.go
index 2842be3ed1..fb446ae26f 100644
--- a/filter/adaptivesvc/limiter/utils.go
+++ b/filter/adaptivesvc/limiter/utils.go
@@ -50,7 +50,6 @@ import (
// stat :=
// }
//}
-
func VerboseDebugf(msg string, args ...interface{}) {
if !Verbose {
return
diff --git a/filter/adaptivesvc/limiter_mapper.go b/filter/adaptivesvc/limiter_mapper.go
index 62a5cab526..f4c2aac6aa 100644
--- a/filter/adaptivesvc/limiter_mapper.go
+++ b/filter/adaptivesvc/limiter_mapper.go
@@ -18,12 +18,15 @@
package adaptivesvc
import (
- "dubbo.apache.org/dubbo-go/v3/common"
- "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
"fmt"
"sync"
)
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
+)
+
var (
limiterMapperSingleton *limiterMapper
diff --git a/protocol/protocolwrapper/protocol_filter_wrapper.go b/protocol/protocolwrapper/protocol_filter_wrapper.go
index da07694469..2ad6cb0b85 100644
--- a/protocol/protocolwrapper/protocol_filter_wrapper.go
+++ b/protocol/protocolwrapper/protocol_filter_wrapper.go
@@ -19,7 +19,6 @@ package protocolwrapper
import (
"context"
- "dubbo.apache.org/dubbo-go/v3/common/logger"
"strings"
)
@@ -27,6 +26,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/filter"
"dubbo.apache.org/dubbo-go/v3/protocol"
)
diff --git a/protocol/result.go b/protocol/result.go
index 16d76ec48a..3e2301ad8a 100644
--- a/protocol/result.go
+++ b/protocol/result.go
@@ -17,7 +17,9 @@
package protocol
-import "fmt"
+import (
+ "fmt"
+)
// Result is a RPC result
type Result interface {
From 0f7459bf2113c9648649751effce2fb1a47f4b9e Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sun, 5 Dec 2021 20:15:30 +0800
Subject: [PATCH 34/35] fix: rpc result attrs is not initialized
---
cluster/cluster/adaptivesvc/cluster_invoker.go | 8 +++-----
cluster/cluster/available/cluster_invoker.go | 6 +++---
cluster/cluster/available/cluster_invoker_test.go | 2 +-
filter/seata/filter_test.go | 2 +-
filter/sentinel/filter.go | 5 +----
.../service/local/metadata_service_proxy_factory_test.go | 4 +---
protocol/result.go | 8 ++++++++
7 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go
index 88c7df5d31..90384ba803 100644
--- a/cluster/cluster/adaptivesvc/cluster_invoker.go
+++ b/cluster/cluster/adaptivesvc/cluster_invoker.go
@@ -49,15 +49,13 @@ func newAdaptiveServiceClusterInvoker(directory directory.Directory) protocol.In
func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
invokers := ivk.Directory.List(invocation)
if err := ivk.CheckInvokers(invokers, invocation); err != nil {
- return &protocol.RPCResult{Err: err}
+ return protocol.NewRPCResult(nil, err)
}
// get loadBalance
lbKey := invokers[0].GetURL().GetParam(constant.LoadbalanceKey, constant.LoadBalanceKeyP2C)
if lbKey != constant.LoadBalanceKeyP2C {
- return &protocol.RPCResult{
- Err: perrors.Errorf("adaptive service not supports %s load balance", lbKey),
- }
+ return protocol.NewRPCResult(nil, perrors.Errorf("adaptive service not supports %s load balance", lbKey))
}
lb := extension.GetLoadbalance(lbKey)
@@ -80,7 +78,7 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation
invocation.MethodName(), metrics.HillClimbing, uint64(remaining))
if err != nil {
logger.Warnf("adaptive service metrics update is failed, err: %v", err)
- return &protocol.RPCResult{Err: err}
+ return protocol.NewRPCResult(nil, err)
}
return result
diff --git a/cluster/cluster/available/cluster_invoker.go b/cluster/cluster/available/cluster_invoker.go
index fc6dea3170..1a20a3fdb3 100644
--- a/cluster/cluster/available/cluster_invoker.go
+++ b/cluster/cluster/available/cluster_invoker.go
@@ -47,12 +47,12 @@ func (invoker *clusterInvoker) Invoke(ctx context.Context, invocation protocol.I
invokers := invoker.Directory.List(invocation)
err := invoker.CheckInvokers(invokers, invocation)
if err != nil {
- return &protocol.RPCResult{Err: err}
+ return protocol.NewRPCResult(nil, err)
}
err = invoker.CheckWhetherDestroyed()
if err != nil {
- return &protocol.RPCResult{Err: err}
+ return protocol.NewRPCResult(nil, err)
}
for _, ivk := range invokers {
@@ -60,5 +60,5 @@ func (invoker *clusterInvoker) Invoke(ctx context.Context, invocation protocol.I
return ivk.Invoke(ctx, invocation)
}
}
- return &protocol.RPCResult{Err: errors.New(fmt.Sprintf("no provider available in %v", invokers))}
+ return protocol.NewRPCResult(nil, errors.New(fmt.Sprintf("no provider available in %v", invokers)))
}
diff --git a/cluster/cluster/available/cluster_invoker_test.go b/cluster/cluster/available/cluster_invoker_test.go
index ca60a8d792..36dcda7189 100644
--- a/cluster/cluster/available/cluster_invoker_test.go
+++ b/cluster/cluster/available/cluster_invoker_test.go
@@ -65,7 +65,7 @@ func TestAvailableClusterInvokerSuccess(t *testing.T) {
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := registerAvailable(invoker)
- mockResult := &protocol.RPCResult{Rest: clusterpkg.Rest{Tried: 0, Success: true}}
+ mockResult := protocol.NewRPCResult(clusterpkg.Rest{Tried: 0, Success: true}, nil)
invoker.EXPECT().IsAvailable().Return(true)
invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult)
diff --git a/filter/seata/filter_test.go b/filter/seata/filter_test.go
index cdbf0a06ba..4db50b0fb3 100644
--- a/filter/seata/filter_test.go
+++ b/filter/seata/filter_test.go
@@ -43,7 +43,7 @@ func (iv *testMockSeataInvoker) Invoke(ctx context.Context, _ protocol.Invocatio
return &protocol.RPCResult{Rest: xid}
}
}
- return &protocol.RPCResult{}
+ return protocol.NewRPCResult(nil, nil)
}
func TestSeataFilter_Invoke(t *testing.T) {
diff --git a/filter/sentinel/filter.go b/filter/sentinel/filter.go
index 2fe2341bcd..4b08cfa49a 100644
--- a/filter/sentinel/filter.go
+++ b/filter/sentinel/filter.go
@@ -212,10 +212,7 @@ func SetDubboProviderFallback(f DubboFallback) {
func getDefaultDubboFallback() DubboFallback {
return func(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation, blockError *base.BlockError) protocol.Result {
- result := &protocol.RPCResult{}
- result.SetResult(nil)
- result.SetError(blockError)
- return result
+ return protocol.NewRPCResult(nil, blockError)
}
}
diff --git a/metadata/service/local/metadata_service_proxy_factory_test.go b/metadata/service/local/metadata_service_proxy_factory_test.go
index 95665baf24..f38d63c3f3 100644
--- a/metadata/service/local/metadata_service_proxy_factory_test.go
+++ b/metadata/service/local/metadata_service_proxy_factory_test.go
@@ -91,7 +91,5 @@ func (m *mockInvoker) Destroy() {
}
func (m *mockInvoker) Invoke(context.Context, protocol.Invocation) protocol.Result {
- return &protocol.RPCResult{
- Rest: []string{"dubbo://localhost"},
- }
+ return protocol.NewRPCResult([]string{"dubbo://localhost"}, nil)
}
diff --git a/protocol/result.go b/protocol/result.go
index 3e2301ad8a..2ed6974d88 100644
--- a/protocol/result.go
+++ b/protocol/result.go
@@ -53,6 +53,14 @@ type RPCResult struct {
Rest interface{}
}
+func NewRPCResult(result interface{}, err error) *RPCResult {
+ return &RPCResult{
+ Rest: result,
+ Err: err,
+ Attrs: make(map[string]interface{}),
+ }
+}
+
// SetError sets error.
func (r *RPCResult) SetError(err error) {
r.Err = err
From 429a3360b5c210bc6c578c4d26ea93ca61b970b8 Mon Sep 17 00:00:00 2001
From: XavierNiu
Date: Sun, 5 Dec 2021 20:20:37 +0800
Subject: [PATCH 35/35] fix(protocol): fix result panic when attrs is not
initialized
---
protocol/result.go | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/protocol/result.go b/protocol/result.go
index 2ed6974d88..34de34ceb6 100644
--- a/protocol/result.go
+++ b/protocol/result.go
@@ -88,16 +88,26 @@ func (r *RPCResult) SetAttachments(attr map[string]interface{}) {
// Attachments gets all attachments
func (r *RPCResult) Attachments() map[string]interface{} {
+ if r.Attrs == nil {
+ r.Attrs = make(map[string]interface{})
+ }
return r.Attrs
}
// AddAttachment adds the specified map to existing attachments in this instance.
func (r *RPCResult) AddAttachment(key string, value interface{}) {
+ if r.Attrs == nil {
+ r.Attrs = make(map[string]interface{})
+ }
r.Attrs[key] = value
}
// Attachment gets attachment by key with default value.
func (r *RPCResult) Attachment(key string, defaultValue interface{}) interface{} {
+ if r.Attrs == nil {
+ r.Attrs = make(map[string]interface{})
+ return nil
+ }
v, ok := r.Attrs[key]
if !ok {
v = defaultValue