You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/02/05 15:38:20 UTC

[dubbo-go] 01/01: Merge pull request #1043 from xiaoliu10/replace_ci_icon

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

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

commit 53302a318d95b7070e9c97c8b7981911bb902b82
Merge: 7d0b63a e396a96
Author: Xin.Zh <dr...@foxmail.com>
AuthorDate: Thu Feb 4 20:10:13 2021 +0800

    Merge pull request #1043 from xiaoliu10/replace_ci_icon
    
    Replace ci icon

 README.md                       |  2 +-
 README_CN.md                    |  2 +-
 protocol/dubbo/dubbo_invoker.go | 22 ++++++++++++----------
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --cc protocol/dubbo/dubbo_invoker.go
index 8134a90,59202d5..7f2f8ad
--- a/protocol/dubbo/dubbo_invoker.go
+++ b/protocol/dubbo/dubbo_invoker.go
@@@ -20,15 -20,14 +20,15 @@@ package dubb
  import (
  	"context"
  	"strconv"
 +	"strings"
  	"sync"
--	"sync/atomic"
  	"time"
  )
  
  import (
  	"github.com/opentracing/opentracing-go"
  	perrors "github.com/pkg/errors"
++	uatomic "go.uber.org/atomic"
  )
  
  import (
@@@ -49,36 -46,25 +49,38 @@@ var 
  )
  
  var (
 -	attachmentKey = []string{constant.INTERFACE_KEY, constant.GROUP_KEY, constant.TOKEN_KEY, constant.TIMEOUT_KEY}
 +	attachmentKey = []string{constant.INTERFACE_KEY, constant.GROUP_KEY, constant.TOKEN_KEY, constant.TIMEOUT_KEY,
 +		constant.VERSION_KEY}
  )
  
 -// DubboInvoker is dubbo client invoker.
 +// DubboInvoker is implement of protocol.Invoker. A dubboInvoker refer to one service and ip.
  type DubboInvoker struct {
  	protocol.BaseInvoker
 -	client   *Client
 +	// the exchange layer, it is focus on network communication.
 +	client   *remoting.ExchangeClient
  	quitOnce sync.Once
 +	// timeout for service(interface) level.
 +	timeout time.Duration
  	// Used to record the number of requests. -1 represent this DubboInvoker is destroyed
--	reqNum int64
++	reqNum uatomic.Int64
  }
  
 -// NewDubboInvoker create dubbo client invoker.
 -func NewDubboInvoker(url common.URL, client *Client) *DubboInvoker {
 -	return &DubboInvoker{
 +// NewDubboInvoker constructor
 +func NewDubboInvoker(url *common.URL, client *remoting.ExchangeClient) *DubboInvoker {
 +	requestTimeout := config.GetConsumerConfig().RequestTimeout
 +
 +	requestTimeoutStr := url.GetParam(constant.TIMEOUT_KEY, config.GetConsumerConfig().Request_Timeout)
 +	if t, err := time.ParseDuration(requestTimeoutStr); err == nil {
 +		requestTimeout = t
 +	}
- 	return &DubboInvoker{
++	di := &DubboInvoker{
  		BaseInvoker: *protocol.NewBaseInvoker(url),
  		client:      client,
--		reqNum:      0,
 +		timeout:     requestTimeout,
  	}
++	di.reqNum.Store(0)
++
++	return di
  }
  
  // Invoke call remoting.
@@@ -87,19 -73,17 +89,19 @@@ func (di *DubboInvoker) Invoke(ctx cont
  		err    error
  		result protocol.RPCResult
  	)
- 	if atomic.LoadInt64(&di.reqNum) < 0 {
 -	if di.reqNum < 0 {
++	if di.reqNum.Load() < 0 {
  		// Generally, the case will not happen, because the invoker has been removed
  		// from the invoker list before destroy,so no new request will enter the destroyed invoker
  		logger.Warnf("this dubboInvoker is destroyed")
  		result.Err = ErrDestroyedInvoker
  		return &result
  	}
--	atomic.AddInt64(&(di.reqNum), 1)
--	defer atomic.AddInt64(&(di.reqNum), -1)
++	di.reqNum.Add(1)
++	defer di.reqNum.Add(-1)
  
  	inv := invocation.(*invocation_impl.RPCInvocation)
 +	// init param
 +	inv.SetAttachments(constant.PATH_KEY, di.GetUrl().GetParam(constant.INTERFACE_KEY, ""))
  	for _, k := range attachmentKey {
  		if v := di.GetUrl().GetParam(k, ""); len(v) > 0 {
  			inv.SetAttachments(k, v)
@@@ -169,8 -127,8 +171,8 @@@ func (di *DubboInvoker) IsAvailable() b
  func (di *DubboInvoker) Destroy() {
  	di.quitOnce.Do(func() {
  		for {
--			if di.reqNum == 0 {
--				di.reqNum = -1
++			if di.reqNum.Load() == 0 {
++				di.reqNum.Store(-1)
  				logger.Infof("dubboInvoker is destroyed,url:{%s}", di.GetUrl().Key())
  				di.BaseInvoker.Destroy()
  				if di.client != nil {
@@@ -179,7 -137,7 +181,7 @@@
  				}
  				break
  			}
--			logger.Warnf("DubboInvoker is to be destroyed, wait {%v} req end,url:{%s}", di.reqNum, di.GetUrl().Key())
++			logger.Warnf("DubboInvoker is to be destroyed, wait {%v} req end,url:{%s}", di.reqNum.Load(), di.GetUrl().Key())
  			time.Sleep(1 * time.Second)
  		}