Skip to content

Commit

Permalink
Merge pull request #1 from apache/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Isaac-Zhang committed May 31, 2020
2 parents b910c18 + 7d4f1ed commit b4a9c7c
Show file tree
Hide file tree
Showing 172 changed files with 4,468 additions and 1,110 deletions.
5 changes: 5 additions & 0 deletions .asf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
notifications:
commits: commits@dubbo.apache.org
issues: notifications@dubbo.apache.org
pullrequests: notifications@dubbo.apache.org
jira_options: link label link label
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
language: go
dist: trusty
sudo: required

# define the dependence env
language: go
os:
- linux

go:
- "1.13"

services:
- docker
env:
- GO111MODULE=on

install: true

# define ci-stage
script:
# license-check
- echo 'start license check'
- go fmt ./... && [[ -z `git status -s` ]]
- sh before_validate_license.sh
- chmod u+x /tmp/tools/license/license-header-checker
- /tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
# unit-test
- echo 'start unit-test'
- chmod u+x before_ut.sh && ./before_ut.sh
- go mod vendor && go test ./... -coverprofile=coverage.txt -covermode=atomic
# integrate-test
- chmod +x integrate_test.sh && ./integrate_test.sh

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Apache License, Version 2.0

## Release note ##

[v1.4.0 - Mar 17, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)

[v1.3.0 - Mar 1, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)

[v1.2.0 - Nov 15, 2019](https://github.com/apache/dubbo-go/releases/tag/v1.2.0)
Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Apache License, Version 2.0

## 发布日志 ##

[v1.4.0 - 2020年3月17日](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)

[v1.3.0 - 2020年3月1日](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)

[v1.2.0 - 2019年11月15日](https://github.com/apache/dubbo-go/releases/tag/v1.2.0)
Expand Down
6 changes: 3 additions & 3 deletions cluster/cluster_impl/available_cluster_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
availableUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)

func registerAvailable(t *testing.T, invoker *mock.MockInvoker) protocol.Invoker {
func registerAvailable(invoker *mock.MockInvoker) protocol.Invoker {
extension.SetLoadbalance("random", loadbalance.NewRandomLoadBalance)
availableCluster := NewAvailableCluster()

Expand All @@ -60,7 +60,7 @@ func TestAvailableClusterInvokerSuccess(t *testing.T) {
defer ctrl.Finish()

invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := registerAvailable(t, invoker)
clusterInvoker := registerAvailable(invoker)

mockResult := &protocol.RPCResult{Rest: rest{tried: 0, success: true}}
invoker.EXPECT().IsAvailable().Return(true)
Expand All @@ -76,7 +76,7 @@ func TestAvailableClusterInvokerNoAvail(t *testing.T) {
defer ctrl.Finish()

invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := registerAvailable(t, invoker)
clusterInvoker := registerAvailable(invoker)

invoker.EXPECT().IsAvailable().Return(false)

Expand Down
1 change: 0 additions & 1 deletion cluster/cluster_impl/base_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (invoker *baseClusterInvoker) checkWhetherDestroyed() error {
}

func (invoker *baseClusterInvoker) doSelect(lb cluster.LoadBalance, invocation protocol.Invocation, invokers []protocol.Invoker, invoked []protocol.Invoker) protocol.Invoker {

var selectedInvoker protocol.Invoker
url := invokers[0].GetUrl()
sticky := url.GetParamBool(constant.STICKY_KEY, false)
Expand Down
4 changes: 2 additions & 2 deletions cluster/cluster_impl/failover_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func normalInvoke(t *testing.T, successCount int, urlParam url.Values, invocatio

invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i), common.WithParams(urlParam))
invokers = append(invokers, NewMockInvoker(url, successCount))
newUrl, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i), common.WithParams(urlParam))
invokers = append(invokers, NewMockInvoker(newUrl, successCount))
}

staticDir := directory.NewStaticDirectory(invokers)
Expand Down
2 changes: 1 addition & 1 deletion cluster/directory/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (dir *BaseDirectory) SetRouters(urls []*common.URL) {
factory := extension.GetRouterFactory(url.Protocol)
r, err := factory.NewRouter(url)
if err != nil {
logger.Errorf("Create router fail. router key: %s, error: %v", routerKey, url.Service(), err)
logger.Errorf("Create router fail. router key: %s, url:%s, error: %+v", routerKey, url.Service(), err)
return
}
routers = append(routers, r)
Expand Down
5 changes: 2 additions & 3 deletions cluster/directory/base_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package directory

import (
"encoding/base64"
"fmt"
"testing"
)

Expand All @@ -35,7 +34,7 @@ import (
)

func TestNewBaseDirectory(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider"))
url, _ := common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
directory := NewBaseDirectory(&url)

assert.NotNil(t, directory)
Expand All @@ -46,7 +45,7 @@ func TestNewBaseDirectory(t *testing.T) {
}

func TestBuildRouterChain(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider"))
url, _ := common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
directory := NewBaseDirectory(&url)

assert.NotNil(t, directory)
Expand Down
2 changes: 1 addition & 1 deletion cluster/directory/static_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (dir *staticDirectory) IsAvailable() bool {
// List List invokers
func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invoker {
l := len(dir.invokers)
invokers := make([]protocol.Invoker, l, l)
invokers := make([]protocol.Invoker, l)
copy(invokers, dir.invokers)
routerChain := dir.RouterChain()

Expand Down
33 changes: 10 additions & 23 deletions cluster/loadbalance/consistent_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"strconv"
"strings"
)

import (
gxsort "github.com/dubbogo/gost/sort"
)
import (
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common/constant"
Expand All @@ -40,7 +42,7 @@ const (
ConsistentHash = "consistenthash"
// HashNodes ...
HashNodes = "hash.nodes"
// HashArguments ...
// HashArguments key of hash arguments in url
HashArguments = "hash.arguments"
)

Expand All @@ -53,16 +55,16 @@ func init() {
extension.SetLoadbalance(ConsistentHash, NewConsistentHashLoadBalance)
}

// ConsistentHashLoadBalance ...
// ConsistentHashLoadBalance implementation of load balancing: using consistent hashing
type ConsistentHashLoadBalance struct {
}

// NewConsistentHashLoadBalance ...
// NewConsistentHashLoadBalance creates NewConsistentHashLoadBalance
func NewConsistentHashLoadBalance() cluster.LoadBalance {
return &ConsistentHashLoadBalance{}
}

// Select ...
// Select gets invoker based on load balancing strategy
func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {
methodName := invocation.MethodName()
key := invokers[0].GetUrl().ServiceKey() + "." + methodName
Expand All @@ -85,27 +87,12 @@ func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocat
return selector.Select(invocation)
}

// Uint32Slice ...
type Uint32Slice []uint32

func (s Uint32Slice) Len() int {
return len(s)
}

func (s Uint32Slice) Less(i, j int) bool {
return s[i] < s[j]
}

func (s Uint32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

// ConsistentHashSelector ...
// ConsistentHashSelector implementation of Selector:get invoker based on load balancing strategy
type ConsistentHashSelector struct {
hashCode uint32
replicaNum int
virtualInvokers map[uint32]protocol.Invoker
keys Uint32Slice
keys gxsort.Uint32Slice
argumentIndex []int
}

Expand Down Expand Up @@ -141,7 +128,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
return selector
}

// Select ...
// Select gets invoker based on load balancing strategy
func (c *ConsistentHashSelector) Select(invocation protocol.Invocation) protocol.Invoker {
key := c.toKey(invocation.Arguments())
digest := md5.Sum([]byte(key))
Expand Down
21 changes: 11 additions & 10 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ var (
once sync.Once
)

// GetEnvInstance ...
// GetEnvInstance gets env instance by singleton
func GetEnvInstance() *Environment {
once.Do(func() {
instance = &Environment{configCenterFirst: true}
})
return instance
}

// NewEnvInstance ...
// NewEnvInstance creates Environment instance
func NewEnvInstance() {
instance = &Environment{configCenterFirst: true}
}
Expand All @@ -67,21 +67,22 @@ func NewEnvInstance() {
// return env.configCenterFirst
//}

// UpdateExternalConfigMap ...
// UpdateExternalConfigMap updates env externalConfigMap field
func (env *Environment) UpdateExternalConfigMap(externalMap map[string]string) {
for k, v := range externalMap {
env.externalConfigMap.Store(k, v)
}
}

// UpdateAppExternalConfigMap ...
// UpdateAppExternalConfigMap updates env appExternalConfigMap field
func (env *Environment) UpdateAppExternalConfigMap(externalMap map[string]string) {
for k, v := range externalMap {
env.appExternalConfigMap.Store(k, v)
}
}

// Configuration ...
// Configuration puts externalConfigMap and appExternalConfigMap into list
// List represents a doubly linked list.
func (env *Environment) Configuration() *list.List {
cfgList := list.New()
// The sequence would be: SystemConfiguration -> ExternalConfiguration -> AppExternalConfiguration -> AbstractConfig -> PropertiesConfiguration
Expand All @@ -90,17 +91,17 @@ func (env *Environment) Configuration() *list.List {
return cfgList
}

// SetDynamicConfiguration ...
// SetDynamicConfiguration sets value for dynamicConfiguration
func (env *Environment) SetDynamicConfiguration(dc config_center.DynamicConfiguration) {
env.dynamicConfiguration = dc
}

// GetDynamicConfiguration ...
// GetDynamicConfiguration gets dynamicConfiguration
func (env *Environment) GetDynamicConfiguration() config_center.DynamicConfiguration {
return env.dynamicConfiguration
}

// InmemoryConfiguration ...
// InmemoryConfiguration stores config in memory
type InmemoryConfiguration struct {
store *sync.Map
}
Expand All @@ -109,7 +110,7 @@ func newInmemoryConfiguration(p *sync.Map) *InmemoryConfiguration {
return &InmemoryConfiguration{store: p}
}

// GetProperty ...
// GetProperty gets value from InmemoryConfiguration instance by @key
func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
if conf.store == nil {
return false, ""
Expand All @@ -123,7 +124,7 @@ func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
return false, ""
}

// GetSubProperty ...
// GetSubProperty gets sub property from InmemoryConfiguration instance by @subkey
func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]struct{} {
if conf.store == nil {
return nil
Expand Down
28 changes: 26 additions & 2 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const (
ProviderConfigPrefix = "dubbo.provider."
ConsumerConfigPrefix = "dubbo.consumer."
ShutdownConfigPrefix = "dubbo.shutdown."
MetadataReportPrefix = "dubbo.metadata-report."
RouterConfigPrefix = "dubbo.router."
)

Expand Down Expand Up @@ -179,6 +180,9 @@ const (
// ForceUseTag is the tag in attachment
ForceUseTag = "dubbo.force.tag"
Tagkey = "dubbo.tag"

// Attachment key in context in invoker
AttachmentKey = "attachment"
)

const (
Expand Down Expand Up @@ -209,9 +213,23 @@ const (
// consumer
CONSUMER = "consumer"
// key of access key id
ACCESS_KEY_ID_KEY = "accessKeyId"
ACCESS_KEY_ID_KEY = ".accessKeyId"
// key of secret access key
SECRET_ACCESS_KEY_KEY = "secretAccessKey"
SECRET_ACCESS_KEY_KEY = ".secretAccessKey"
)

// metadata report

const (
METACONFIG_REMOTE = "remote"
METACONFIG_LOCAL = "local"
KEY_SEPARATOR = ":"
DEFAULT_PATH_TAG = "metadata"
KEY_REVISON_PREFIX = "revision"
PATH_SEPARATOR = "/"

// metadata service
METADATA_SERVICE_NAME = "org.apache.dubbo.metadata.MetadataService"
)

// HealthCheck Router
Expand All @@ -235,3 +253,9 @@ const (
// The default time window of circuit-tripped in millisecond if not specfied
MAX_CIRCUIT_TRIPPED_TIMEOUT_IN_MS = 30000
)

// service discovery

const (
NACOS_GROUP = "nacos.group"
)
8 changes: 4 additions & 4 deletions common/extension/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ var (
accesskeyStorages = make(map[string]func() filter.AccessKeyStorage)
)

// SetAuthenticator put the fcn into map with name
// SetAuthenticator puts the @fcn into map with name
func SetAuthenticator(name string, fcn func() filter.Authenticator) {
authenticators[name] = fcn
}

// GetAuthenticator find the Authenticator with name
// GetAuthenticator finds the Authenticator with @name
// if not found, it will panic
func GetAuthenticator(name string) filter.Authenticator {
if authenticators[name] == nil {
Expand All @@ -40,12 +40,12 @@ func GetAuthenticator(name string) filter.Authenticator {
return authenticators[name]()
}

// SetAccesskeyStorages will set the fcn into map with this name
// SetAccesskeyStorages will set the @fcn into map with this name
func SetAccesskeyStorages(name string, fcn func() filter.AccessKeyStorage) {
accesskeyStorages[name] = fcn
}

// GetAccesskeyStorages find the storage with the name.
// GetAccesskeyStorages finds the storage with the @name.
// If not found, it will panic.
func GetAccesskeyStorages(name string) filter.AccessKeyStorage {
if accesskeyStorages[name] == nil {
Expand Down
Loading

0 comments on commit b4a9c7c

Please sign in to comment.