This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new a85fe25a4 refactor: add more params when calculating the revision.
(#3224)
a85fe25a4 is described below
commit a85fe25a4857d010310cac793f2201a98f48081f
Author: yangpixi <[email protected]>
AuthorDate: Sun Mar 1 23:16:08 2026 +0800
refactor: add more params when calculating the revision. (#3224)
* refactor: add more params when calculating the revision.
* refactor: refactor another revision calculation function
* chore: add comment
* refactor: remove duplicated revision calculation function
---
go.mod | 2 +-
metadata/info/metadata_info.go | 42 ----------------------
metadata/info/metadata_info_test.go | 16 ---------
.../customizer/service_revision_customizer.go | 13 +++----
.../servicediscovery/service_discovery_registry.go | 2 +-
5 files changed, 7 insertions(+), 68 deletions(-)
diff --git a/go.mod b/go.mod
index 8c20a2481..4c2746e16 100644
--- a/go.mod
+++ b/go.mod
@@ -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
@@ -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
diff --git a/metadata/info/metadata_info.go b/metadata/info/metadata_info.go
index 126d27c91..724b65d1a 100644
--- a/metadata/info/metadata_info.go
+++ b/metadata/info/metadata_info.go
@@ -18,10 +18,7 @@
package info
import (
- "fmt"
- "hash/crc32"
"net/url"
- "sort"
"strconv"
"strings"
)
@@ -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)
diff --git a/metadata/info/metadata_info_test.go
b/metadata/info/metadata_info_test.go
index ec8a110c5..64a549d9b 100644
--- a/metadata/info/metadata_info_test.go
+++ b/metadata/info/metadata_info_test.go
@@ -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)
diff --git
a/registry/servicediscovery/customizer/service_revision_customizer.go
b/registry/servicediscovery/customizer/service_revision_customizer.go
index e8e3eaa09..e3201c2ad 100644
--- a/registry/servicediscovery/customizer/service_revision_customizer.go
+++ b/registry/servicediscovery/customizer/service_revision_customizer.go
@@ -84,10 +84,8 @@ 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"
@@ -95,18 +93,17 @@ func resolveRevision(urls []*common.URL) string {
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)
diff --git a/registry/servicediscovery/service_discovery_registry.go
b/registry/servicediscovery/service_discovery_registry.go
index 4760a77ff..fd54a19a8 100644
--- a/registry/servicediscovery/service_discovery_registry.go
+++ b/registry/servicediscovery/service_discovery_registry.go
@@ -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")