Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/apache/dubbo-getty v1.4.10
github.com/apache/dubbo-go-hessian2 v1.12.5
github.com/apolloconfig/agollo/v4 v4.4.0
github.com/cenkalti/backoff/v4 v4.2.1
github.com/creasty/defaults v1.5.2
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d
Expand Down Expand Up @@ -80,7 +81,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
Expand Down
42 changes: 0 additions & 42 deletions metadata/info/metadata_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
package info

import (
"fmt"
"hash/crc32"
"net/url"
"sort"
"strconv"
"strings"
)
Expand Down Expand Up @@ -95,45 +92,6 @@ func (info *MetadataInfo) JavaClassName() string {
return "org.apache.dubbo.metadata.MetadataInfo"
}

// CalAndGetRevision is different from Dubbo because golang doesn't support overload
// so that we should use interface + method name as identifier and ignore the method params
// in my opinion, it's enough because Dubbo actually ignore the URL params.
// please refer org.apache.dubbo.common.URL#toParameterString(java.lang.String...)
func (info *MetadataInfo) CalAndGetRevision() string {
if info.Revision != "" {
return info.Revision
}
if len(info.Services) == 0 {
return "0"
}
candidates := make([]string, 0, 8)

for _, s := range info.Services {
iface := s.URL.GetParam(constant.InterfaceKey, "")
ms := s.URL.Methods
if len(ms) == 0 {
candidates = append(candidates, iface)
} else {
for _, m := range ms {
// methods are part of candidates
candidates = append(candidates, iface+constant.KeySeparator+m)
}
}

// append URL params if we need it
}
sort.Strings(candidates)

// it's nearly impossible to be overflow
res := uint64(0)
for _, c := range candidates {
res += uint64(crc32.ChecksumIEEE([]byte(c)))
}
info.Revision = fmt.Sprint(res)
return info.Revision

}

// AddService add provider service info to MetadataInfo
func (info *MetadataInfo) AddService(url *common.URL) {
service := NewServiceInfoWithURL(url)
Expand Down
16 changes: 0 additions & 16 deletions metadata/info/metadata_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,6 @@ func TestMetadataInfoAddSubscribeURL(t *testing.T) {
assert.Empty(t, info.GetSubscribedURLs())
}

func TestMetadataInfoCalAndGetRevision(t *testing.T) {
metadata := NewAppMetadataInfo("dubbo")
assert.Equalf(t, "0", metadata.CalAndGetRevision(), "CalAndGetRevision()")
metadata.AddService(serviceUrl)
assert.NotEqual(t, "0", metadata.CalAndGetRevision())

v := metadata.Revision
assert.Equal(t, v, metadata.CalAndGetRevision(), "CalAndGetRevision() test cache")

metadata = NewAppMetadataInfo("dubbo")
url1 := serviceUrl.Clone()
url1.Methods = []string{}
metadata.AddService(url1)
assert.NotEqual(t, "0", metadata.CalAndGetRevision(), "CalAndGetRevision() test empty methods")
}

func TestNewMetadataInfo(t *testing.T) {
info := NewMetadataInfo("dubbo", "tag")
assert.Equal(t, "dubbo", info.App)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,26 @@ func (e *subscribedServicesRevisionMetadataCustomizer) Customize(instance regist
instance.GetMetadata()[constant.SubscribedServicesRevisionPropertyName] = revision
}

// resolveRevision is different from Dubbo because golang doesn't support overload
// so that we could use interface + method name as identifier and ignore the method params
// per my understanding, it's enough because Dubbo actually ignore the url params.
// please refer org.apache.dubbo.common.URL#toParameterString(java.lang.String...)
// resolveRevision provides the actual pattern to calculate the revision.
// please refer to dubbo-java's method, org.apache.dubbo.metadata.Metadata#calAndGetRevision
func resolveRevision(urls []*common.URL) string {
if len(urls) == 0 {
return "0"
}
candidates := make([]string, 0, len(urls))

for _, u := range urls {
sk := u.GetParam(constant.InterfaceKey, "")
desc := u.GetParam(constant.ApplicationKey, "") + u.Path + u.GetParam(constant.VersionKey, "") + u.Port

if len(u.Methods) == 0 {
candidates = append(candidates, sk)
candidates = append(candidates, desc)
} else {
for _, m := range u.Methods {
// methods are part of candidates
candidates = append(candidates, sk+constant.KeySeparator+m)
candidates = append(candidates, desc+constant.KeySeparator+m)
}
}

// append url params if we need it
}
sort.Strings(candidates)

Expand Down
2 changes: 1 addition & 1 deletion registry/servicediscovery/service_discovery_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *serviceDiscoveryRegistry) RegisterService() error {
urls := metaInfo.GetExportedServiceURLs()
for _, url := range urls {
instance := createInstance(metaInfo, url)
metaInfo.CalAndGetRevision()
metaInfo.Revision = instance.GetMetadata()[constant.ExportedServicesRevisionPropertyName]
if metadata.GetMetadataType() == constant.RemoteMetadataStorageType {
if s.metadataReport == nil {
return perrors.New("can not publish app metadata cause report instance not found")
Expand Down
Loading