This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/master by this push:
     new c1a069825 [ISSUE #2172] Fix/polaris governance (#2171)
c1a069825 is described below

commit c1a06982596e2d0c969ff59174e42bfe42430735
Author: liaochuntao <[email protected]>
AuthorDate: Sun Jan 1 13:18:08 2023 +0800

    [ISSUE #2172] Fix/polaris governance (#2171)
    
    * 解决 consumer 不断重连已下线的 provider meta service 问题 (#2166)
    
    * registry type support all
    
    * fix test
    
    * set default to interface
    
    * use default protocol registry
    
    * fix unit test
    
    * use swith to judge
    
    * add registry support all test
    
    * Resolve registry name conflicts
    
    * fix ut err
    
    * fix https://github.com/apache/dubbo-go/issues/2159
    
    * del front
    
    * del front
    
    Co-authored-by: bobtthp <[email protected]>
    Co-authored-by: bob <[email protected]>
    Co-authored-by: bobtthp <[email protected]>
    Co-authored-by: bob <[email protected]>
    
    * build(deps): bump github.com/hashicorp/vault/sdk from 0.6.0 to 0.6.2 
(#2169)
    
    Bumps [github.com/hashicorp/vault/sdk](https://github.com/hashicorp/vault) 
from 0.6.0 to 0.6.2.
    - [Release notes](https://github.com/hashicorp/vault/releases)
    - [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/hashicorp/vault/compare/v0.6.0...v0.6.2)
    
    ---
    updated-dependencies:
    - dependency-name: github.com/hashicorp/vault/sdk
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: dependabot[bot] 
<49699333+dependabot[bot]@users.noreply.github.com>
    
    * refactor:polaris ability open judge
    
    * refactor:polaris ability open judge
    
    Signed-off-by: dependabot[bot] <[email protected]>
    Co-authored-by: bobtthp <[email protected]>
    Co-authored-by: bobtthp <[email protected]>
    Co-authored-by: bob <[email protected]>
    Co-authored-by: bobtthp <[email protected]>
    Co-authored-by: bob <[email protected]>
    Co-authored-by: dependabot[bot] 
<49699333+dependabot[bot]@users.noreply.github.com>
---
 cluster/router/polaris/router.go        | 19 ++++++++++++++++-
 filter/polaris/limit/limiter.go         |  6 ++++++
 go.mod                                  |  2 +-
 go.sum                                  |  8 +++----
 metadata/service/local/service_proxy.go |  2 ++
 metadata/service/local_service.go       |  7 +-----
 remoting/polaris/builder.go             | 38 ++++++++++++++++++++++-----------
 7 files changed, 58 insertions(+), 24 deletions(-)

diff --git a/cluster/router/polaris/router.go b/cluster/router/polaris/router.go
index ab71ab3dd..d29636dd7 100644
--- a/cluster/router/polaris/router.go
+++ b/cluster/router/polaris/router.go
@@ -53,6 +53,12 @@ var (
 )
 
 func newPolarisRouter() (*polarisRouter, error) {
+       if err := remotingpolaris.Check(); errors.Is(err, 
remotingpolaris.ErrorNoOpenPolarisAbility) {
+               return &polarisRouter{
+                       openRoute: false,
+               }, nil
+       }
+
        routerAPI, err := remotingpolaris.GetRouterAPI()
        if err != nil {
                return nil, err
@@ -63,12 +69,15 @@ func newPolarisRouter() (*polarisRouter, error) {
        }
 
        return &polarisRouter{
+               openRoute:   true,
                routerAPI:   routerAPI,
                consumerAPI: consumerAPI,
        }, nil
 }
 
 type polarisRouter struct {
+       openRoute bool
+
        routerAPI   polaris.RouterAPI
        consumerAPI polaris.ConsumerAPI
 
@@ -82,8 +91,13 @@ type polarisRouter struct {
 func (p *polarisRouter) Route(invokers []protocol.Invoker, url *common.URL,
        invoaction protocol.Invocation) []protocol.Invoker {
 
+       if !p.openRoute {
+               logger.Debug("[Router][Polaris] not open polaris route ability")
+               return invokers
+       }
+
        if len(invokers) == 0 {
-               logger.Warnf("[tag router] invokers from previous router is 
empty")
+               logger.Warn("[Router][Polaris] invokers from previous router is 
empty")
                return invokers
        }
 
@@ -280,6 +294,9 @@ func (p *polarisRouter) Priority() int64 {
 
 // Notify the router the invoker list
 func (p *polarisRouter) Notify(invokers []protocol.Invoker) {
+       if !p.openRoute {
+               return
+       }
        if len(invokers) == 0 {
                return
        }
diff --git a/filter/polaris/limit/limiter.go b/filter/polaris/limit/limiter.go
index 47d70528d..4d68660f6 100644
--- a/filter/polaris/limit/limiter.go
+++ b/filter/polaris/limit/limiter.go
@@ -18,6 +18,7 @@
 package limit
 
 import (
+       "errors"
        "fmt"
        "time"
 )
@@ -45,6 +46,11 @@ type polarisTpsLimiter struct {
 }
 
 func (pl *polarisTpsLimiter) IsAllowable(url *common.URL, invocation 
protocol.Invocation) bool {
+       if err := remotingpolaris.Check(); errors.Is(err, 
remotingpolaris.ErrorNoOpenPolarisAbility) {
+               logger.Debug("[TpsLimiter][Polaris] not open polaris ratelimit 
ability")
+               return true
+       }
+
        var err error
 
        pl.limitAPI, err = remotingpolaris.GetLimiterAPI()
diff --git a/go.mod b/go.mod
index 87354bbea..7d95c6e50 100644
--- a/go.mod
+++ b/go.mod
@@ -29,7 +29,7 @@ require (
        github.com/google/go-cmp v0.5.9
        github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 // 
indirect
        github.com/grpc-ecosystem/grpc-opentracing 
v0.0.0-20180507213350-8e809c8a8645
-       github.com/hashicorp/vault/sdk v0.6.0
+       github.com/hashicorp/vault/sdk v0.6.2
        github.com/jinzhu/copier v0.3.5
        github.com/knadh/koanf v1.4.4
        github.com/magiconair/properties v1.8.7
diff --git a/go.sum b/go.sum
index c47b8db4d..8f774f97f 100644
--- a/go.sum
+++ b/go.sum
@@ -414,7 +414,7 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod 
h1:spPvp8C1qA32ftKqdAHm4hHTbPw+
 github.com/hashicorp/go-multierror v1.1.1 
h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
 github.com/hashicorp/go-multierror v1.1.1/go.mod 
h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
 github.com/hashicorp/go-plugin v1.0.1/go.mod 
h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
-github.com/hashicorp/go-plugin v1.4.3/go.mod 
h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ=
+github.com/hashicorp/go-plugin v1.4.5/go.mod 
h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
 github.com/hashicorp/go-retryablehttp v0.5.3/go.mod 
h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
 github.com/hashicorp/go-retryablehttp v0.5.4/go.mod 
h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
 github.com/hashicorp/go-rootcerts v1.0.0/go.mod 
h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
@@ -427,7 +427,7 @@ github.com/hashicorp/go-secure-stdlib/parseutil 
v0.1.6/go.mod h1:QmrqtbKuxxSWTN3
 github.com/hashicorp/go-secure-stdlib/password v0.1.1/go.mod 
h1:9hH302QllNwu1o2TGYtSk8I8kTAN0ca1EHpwhm5Mmzo=
 github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod 
h1:gKOamz3EwoIoJq7mlMIRBpVTAUn8qPCrEclOKKWhD3U=
 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod 
h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4=
-github.com/hashicorp/go-secure-stdlib/tlsutil v0.1.1/go.mod 
h1:l8slYwnJA26yBz+ErHpp2IRCLr0vuOMGBORIz4rRiAs=
+github.com/hashicorp/go-secure-stdlib/tlsutil v0.1.2/go.mod 
h1:l8slYwnJA26yBz+ErHpp2IRCLr0vuOMGBORIz4rRiAs=
 github.com/hashicorp/go-sockaddr v1.0.0/go.mod 
h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
 github.com/hashicorp/go-sockaddr v1.0.2/go.mod 
h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A=
 github.com/hashicorp/go-syslog v1.0.0/go.mod 
h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
@@ -451,8 +451,8 @@ github.com/hashicorp/serf v0.8.2/go.mod 
h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
 github.com/hashicorp/serf v0.9.6/go.mod 
h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
 github.com/hashicorp/vault/api v1.0.4/go.mod 
h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoIospckxBxk6Q=
 github.com/hashicorp/vault/sdk v0.1.13/go.mod 
h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M=
-github.com/hashicorp/vault/sdk v0.6.0 
h1:6Z+In5DXHiUfZvIZdMx7e2loL1PPyDjA4bVh9ZTIAhs=
-github.com/hashicorp/vault/sdk v0.6.0/go.mod 
h1:+DRpzoXIdMvKc88R4qxr+edwy/RvH5QK8itmxLiDHLc=
+github.com/hashicorp/vault/sdk v0.6.2 
h1:LtWXUM+WheM5T8pOO/6nOTiFwnE+4y3bPztFf15Oz24=
+github.com/hashicorp/vault/sdk v0.6.2/go.mod 
h1:KyfArJkhooyba7gYCKSq8v66QdqJmnbAxtV/OX1+JTs=
 github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod 
h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
 github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod 
h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
 github.com/hjson/hjson-go/v4 v4.0.0 
h1:wlm6IYYqHjOdXH1gHev4VoXCaW20HdQAGCxdOEEg2cs=
diff --git a/metadata/service/local/service_proxy.go 
b/metadata/service/local/service_proxy.go
index 711058d8e..98243509a 100644
--- a/metadata/service/local/service_proxy.go
+++ b/metadata/service/local/service_proxy.go
@@ -181,6 +181,8 @@ func (m *MetadataServiceProxy) GetMetadataInfo(revision 
string) (*common.Metadat
                
invocation.WithAttachments(map[string]interface{}{constant.AsyncKey: "false"}),
                invocation.WithParameterValues([]reflect.Value{rV}))
        res := m.invkr.Invoke(context.Background(), inv)
+       // when request finished, invoker will colse
+       defer m.invkr.Destroy()
        if res.Error() != nil {
                logger.Errorf("could not get the metadata info from remote 
provider: %v", res.Error())
                return nil, res.Error()
diff --git a/metadata/service/local_service.go 
b/metadata/service/local_service.go
index 0d882370f..909af3c01 100644
--- a/metadata/service/local_service.go
+++ b/metadata/service/local_service.go
@@ -116,12 +116,7 @@ func NewBaseMetadataServiceProxyFactory(creator 
MetadataServiceProxyCreator) *Ba
 }
 
 func (b *BaseMetadataServiceProxyFactory) GetProxy(ins 
registry.ServiceInstance) MetadataService {
-       key := ins.GetServiceName() + "##" + getExportedServicesRevision(ins)
-       if proxy, ok := b.proxies.Load(key); ok {
-               return proxy.(MetadataService)
-       }
-       v, _ := b.proxies.LoadOrStore(key, b.creator(ins))
-       return v.(MetadataService)
+       return b.creator(ins).(MetadataService)
 }
 
 func getExportedServicesRevision(serviceInstance registry.ServiceInstance) 
string {
diff --git a/remoting/polaris/builder.go b/remoting/polaris/builder.go
index f384345e1..389e80466 100644
--- a/remoting/polaris/builder.go
+++ b/remoting/polaris/builder.go
@@ -40,19 +40,21 @@ import (
 )
 
 var (
-       once      sync.Once
-       namesapce string
-       sdkCtx    api.SDKContext
+       once               sync.Once
+       namesapce          string
+       sdkCtx             api.SDKContext
+       openPolarisAbility bool
 )
 
 var (
-       ErrorSDKContextNotInit = errors.New("polaris SDKContext not init")
+       ErrorNoOpenPolarisAbility = errors.New("polaris ability not open")
+       ErrorSDKContextNotInit    = errors.New("polaris SDKContext not init")
 )
 
 // GetConsumerAPI creates one polaris ConsumerAPI instance
 func GetConsumerAPI() (polaris.ConsumerAPI, error) {
-       if sdkCtx == nil {
-               return nil, ErrorSDKContextNotInit
+       if err := Check(); err != nil {
+               return nil, err
        }
 
        return polaris.NewConsumerAPIByContext(sdkCtx), nil
@@ -60,8 +62,8 @@ func GetConsumerAPI() (polaris.ConsumerAPI, error) {
 
 // GetProviderAPI creates one polaris ProviderAPI instance
 func GetProviderAPI() (polaris.ProviderAPI, error) {
-       if sdkCtx == nil {
-               return nil, ErrorSDKContextNotInit
+       if err := Check(); err != nil {
+               return nil, err
        }
 
        return polaris.NewProviderAPIByContext(sdkCtx), nil
@@ -69,8 +71,8 @@ func GetProviderAPI() (polaris.ProviderAPI, error) {
 
 // GetRouterAPI create one polaris RouterAPI instance
 func GetRouterAPI() (polaris.RouterAPI, error) {
-       if sdkCtx == nil {
-               return nil, ErrorSDKContextNotInit
+       if err := Check(); err != nil {
+               return nil, err
        }
 
        return polaris.NewRouterAPIByContext(sdkCtx), nil
@@ -78,13 +80,23 @@ func GetRouterAPI() (polaris.RouterAPI, error) {
 
 // GetLimiterAPI creates one polaris LimiterAPI instance
 func GetLimiterAPI() (polaris.LimitAPI, error) {
-       if sdkCtx == nil {
-               return nil, ErrorSDKContextNotInit
+       if err := Check(); err != nil {
+               return nil, err
        }
 
        return polaris.NewLimitAPIByContext(sdkCtx), nil
 }
 
+func Check() error {
+       if !openPolarisAbility {
+               return ErrorNoOpenPolarisAbility
+       }
+       if sdkCtx == nil {
+               return ErrorSDKContextNotInit
+       }
+       return nil
+}
+
 // GetNamespace gets user defined namespace info
 func GetNamespace() string {
        return namesapce
@@ -96,6 +108,8 @@ func InitSDKContext(url *common.URL) error {
                return errors.New("url is empty!")
        }
 
+       openPolarisAbility = true
+
        var rerr error
        once.Do(func() {
                addresses := strings.Split(url.Location, ",")

Reply via email to