Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
664e03f
refact metadata
FoghostCn Nov 22, 2023
bf150ce
fix cycle import
FoghostCn Nov 24, 2023
54116b3
Initially completed
FoghostCn Nov 25, 2023
dda0ba8
register success
FoghostCn Nov 28, 2023
f2134b4
refect serviceDiscoveryRegistry Server size api
FoghostCn Nov 29, 2023
20d02c0
move customizer to service discovery dir
FoghostCn Nov 29, 2023
d13afea
client call success
FoghostCn Dec 2, 2023
77983e5
mv metadata client to metadata dir
FoghostCn Dec 2, 2023
41f7474
refactor
FoghostCn Dec 5, 2023
5eadaae
refactor metadata exporter
FoghostCn Dec 11, 2023
2ac1b8e
mv metadata client to metadata dir
FoghostCn Dec 11, 2023
6b2fd9d
mv metadata info to metadata module
FoghostCn Dec 11, 2023
157e9c2
associate metadataReport with registry
FoghostCn Jan 2, 2024
8ab3557
unit test not done
FoghostCn Jan 4, 2024
a179a3d
update warn log
FoghostCn Jan 5, 2024
1a11af1
unit test tmp fix
FoghostCn Jan 5, 2024
c29963b
fix integrate_test
FoghostCn Jan 5, 2024
25d8711
fix some logic
FoghostCn Jan 8, 2024
e3ef66e
change RegistryType default value
FoghostCn Jan 9, 2024
88a537d
code review fix
FoghostCn Jan 15, 2024
328eeeb
change metadata to options style
FoghostCn Jan 16, 2024
d7097b1
fix unit test
FoghostCn Jan 16, 2024
5c6e8d7
fix integration test
FoghostCn Jan 16, 2024
e461a39
add doc for metadata report option WithAddress
FoghostCn Jan 22, 2024
ee77794
Merge branch 'main' into refect-metadata
FoghostCn Jan 23, 2024
b0c75a5
modify README.md (#2585)
FinalT Jan 26, 2024
a134e1b
feat:add internal service extension (#2577)
FinalT Jan 26, 2024
23bdc04
Merge remote-tracking branch 'origin/main' into refect-metadata
FoghostCn Jan 29, 2024
38a1cf0
Merge branch 'main' into refect-metadata
FoghostCn Jan 29, 2024
e283246
Merge branch 'dev-3.3' into refect-metadata
FoghostCn Feb 18, 2024
da7de7f
Merge branch 'dev-3.3' into refect-metadata
chickenlj Feb 29, 2024
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
Prev Previous commit
Next Next commit
refect serviceDiscoveryRegistry Server size api
  • Loading branch information
FoghostCn committed Jan 16, 2024
commit f2134b4cebb6181062dc945cc197f144928ab2d1
2 changes: 1 addition & 1 deletion config/root_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package config

import (
"dubbo.apache.org/dubbo-go/v3/registry/servicediscovery"
"sync"
)

Expand All @@ -35,6 +34,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/metadata"
"dubbo.apache.org/dubbo-go/v3/registry/servicediscovery"
)

var (
Expand Down
5 changes: 4 additions & 1 deletion metadata/exporter/service_exporter.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package exporter

import (
"github.com/dubbogo/gost/log/logger"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/metadata"
"github.com/dubbogo/gost/log/logger"
)

func init() {
Expand Down
21 changes: 3 additions & 18 deletions metadata/info/metadata_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,27 @@ var IncludeKeys = gxset.NewSet(

// MetadataInfo the metadata information of instance
type MetadataInfo struct {
Reported bool `json:"-"`
App string `json:"app,omitempty" hessian:"app"`
Revision string `json:"revision,omitempty" hessian:"revision"`
Services map[string]*ServiceInfo `json:"services,omitempty" hessian:"services"`
exportedServiceURLs map[string][]*common.URL // server exported service urls
subscribedServiceURLs map[string][]*common.URL // client subscribed service urls
}

// nolint
func NewMetadataInfWithApp(app string) *MetadataInfo {
return NewMetadataInfo(app, "", make(map[string]*ServiceInfo))
func NewMetadataInfWithApp() *MetadataInfo {
return NewMetadataInfo("", "", make(map[string]*ServiceInfo))
}

// nolint
func NewMetadataInfo(app string, revision string, services map[string]*ServiceInfo) *MetadataInfo {
return &MetadataInfo{
App: app,
Revision: revision,
Services: services,
Reported: false,
exportedServiceURLs: make(map[string][]*common.URL),
subscribedServiceURLs: make(map[string][]*common.URL),
}
}

// nolint
func (info *MetadataInfo) JavaClassName() string {
return "org.apache.dubbo.metadata.MetadataInfo"
}
Expand All @@ -93,7 +88,7 @@ func (info *MetadataInfo) JavaClassName() string {
// 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 != "" && info.Reported {
if info.Revision != "" {
return info.Revision
}
if len(info.Services) == 0 {
Expand Down Expand Up @@ -127,16 +122,6 @@ func (info *MetadataInfo) CalAndGetRevision() string {

}

// nolint
func (info *MetadataInfo) HasReported() bool {
return info.Reported
}

// nolint
func (info *MetadataInfo) MarkReported() {
info.Reported = true
}

// AddService add provider service info to MetadataInfo
func (info *MetadataInfo) AddService(url *common.URL) {
service := NewServiceInfoWithURL(url)
Expand Down
5 changes: 4 additions & 1 deletion metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
package metadata

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"sync"
)

import (
"github.com/dubbogo/gost/log/logger"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
)

var (
GlobalMetadataService MetadataService = &DefaultMetadataService{}
exportOnce sync.Once
Expand Down
2 changes: 1 addition & 1 deletion metadata/metadata_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type ServiceExporter interface {
UnExport()
}

// MetadataService is store and query the metadata info in memory when each service registry
// DefaultMetadataService is store and query the metadata info in memory when each service registry
type DefaultMetadataService struct {
url *common.URL
}
Expand Down
4 changes: 2 additions & 2 deletions registry/event/metadata_service_url_params_customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package event

import (
metadataService "dubbo.apache.org/dubbo-go/v3/metadata"
"encoding/json"
)

Expand All @@ -31,6 +30,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/metadata"
"dubbo.apache.org/dubbo-go/v3/metadata/info"
"dubbo.apache.org/dubbo-go/v3/registry"
)
Expand All @@ -56,7 +56,7 @@ func (m *metadataServiceURLParamsMetadataCustomizer) GetPriority() int {
}

func (m *metadataServiceURLParamsMetadataCustomizer) Customize(instance registry.ServiceInstance) {
url, err := metadataService.GlobalMetadataService.GetMetadataServiceURL()
url, err := metadata.GlobalMetadataService.GetMetadataServiceURL()
if err != nil {
logger.Errorf("get metadata service url is error, %v", err)
return
Expand Down
4 changes: 2 additions & 2 deletions registry/event/protocol_ports_metadata_customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package event

import (
metadataService "dubbo.apache.org/dubbo-go/v3/metadata"
"encoding/json"
"strconv"
)
Expand All @@ -30,6 +29,7 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/metadata"
"dubbo.apache.org/dubbo-go/v3/registry"
)

Expand All @@ -48,7 +48,7 @@ func (p *ProtocolPortsMetadataCustomizer) GetPriority() int {

// Customize put the the string like [{"protocol": "dubbo", "port": 123}] into instance's metadata
func (p *ProtocolPortsMetadataCustomizer) Customize(instance registry.ServiceInstance) {
list, err := metadataService.GlobalMetadataService.GetExportedServiceURLs()
list, err := metadata.GlobalMetadataService.GetExportedServiceURLs()
if err != nil {
logger.Errorf("get metadata exported service url is error, %v", err)
return
Expand Down
11 changes: 7 additions & 4 deletions registry/event/service_revision_customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
package event

import (
metadataService "dubbo.apache.org/dubbo-go/v3/metadata"
"fmt"
"github.com/dubbogo/gost/log/logger"
"hash/crc32"
"sort"
)

import (
"github.com/dubbogo/gost/log/logger"
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/metadata"
"dubbo.apache.org/dubbo-go/v3/registry"
)

Expand All @@ -48,7 +51,7 @@ func (e *exportedServicesRevisionMetadataCustomizer) GetPriority() int {

// Customize calculate the revision for exported urls and then put it into instance metadata
func (e *exportedServicesRevisionMetadataCustomizer) Customize(instance registry.ServiceInstance) {
urls, err := metadataService.GlobalMetadataService.GetExportedServiceURLs()
urls, err := metadata.GlobalMetadataService.GetExportedServiceURLs()
if err != nil {
logger.Errorf("get metadata service url is error, %v", err)
return
Expand All @@ -69,7 +72,7 @@ func (e *subscribedServicesRevisionMetadataCustomizer) GetPriority() int {

// Customize calculate the revision for subscribed urls and then put it into instance metadata
func (e *subscribedServicesRevisionMetadataCustomizer) Customize(instance registry.ServiceInstance) {
urls, err := metadataService.GlobalMetadataService.GetSubscribedURLs()
urls, err := metadata.GlobalMetadataService.GetSubscribedURLs()
if err != nil {
logger.Errorf("get metadata subscribed url is error, %v", err)
return
Expand Down
2 changes: 0 additions & 2 deletions registry/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,4 @@ type ServiceDiscoveryRegistry interface {
UnRegisterService() error
// GetLocalMetadata get local metadata info
GetLocalMetadata() *info.MetadataInfo
// GetRemoteMetadata get remote server metadata info
GetRemoteMetadata(revision string, instance ServiceInstance) (*info.MetadataInfo, error)
}
68 changes: 20 additions & 48 deletions registry/servicediscovery/service_discovery_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package servicediscovery

import (
"bytes"
"dubbo.apache.org/dubbo-go/v3/metadata/info"
"dubbo.apache.org/dubbo-go/v3/metadata/report/instance"
"strings"
"sync"
"time"
Expand All @@ -37,7 +35,9 @@ import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/metadata/info"
"dubbo.apache.org/dubbo-go/v3/metadata/mapping"
"dubbo.apache.org/dubbo-go/v3/metadata/report/instance"
"dubbo.apache.org/dubbo-go/v3/metrics"
metricMetadata "dubbo.apache.org/dubbo-go/v3/metrics/metadata"
metricsRegistry "dubbo.apache.org/dubbo-go/v3/metrics/registry"
Expand Down Expand Up @@ -71,38 +71,26 @@ func RegisterServiceInstance() error {
// In order to keep compatible with interface-level registry,
// serviceDiscoveryRegistry = ServiceDiscovery + metadata
type serviceDiscoveryRegistry struct {
lock sync.RWMutex
url *common.URL
serviceDiscovery registry.ServiceDiscovery
serviceMeta *serviceMeta
subscribedServices *gxset.HashSet
serviceNameMapping mapping.ServiceNameMapping
registeredListeners *gxset.HashSet
subscribedURLsSynthesizers []synthesizer.SubscribedURLsSynthesizer
serviceListeners map[string]registry.ServiceInstancesChangedListener
serviceMappingListeners map[string]mapping.MappingListener
lock sync.RWMutex
url *common.URL
serviceDiscovery registry.ServiceDiscovery
serviceMeta *ServiceMeta
serviceNameMapping mapping.ServiceNameMapping
serviceListeners map[string]registry.ServiceInstancesChangedListener
serviceMappingListeners map[string]mapping.MappingListener
}

func newServiceDiscoveryRegistry(url *common.URL) (registry.Registry, error) {
serviceDiscovery, err := creatServiceDiscovery(url)
serviceDiscovery, err := extension.GetServiceDiscovery(url)
if err != nil {
return nil, err
}
subscribedServices := parseServices(url.GetParam(constant.SubscribedServiceNamesKey, ""))
subscribedURLsSynthesizers := synthesizer.GetAllSynthesizer()
serviceNameMapping := extension.GetGlobalServiceNameMapping()
if err != nil {
return nil, perrors.WithMessage(err, "could not init metadata service")
return nil, perrors.WithMessage(err, "Create service discovery failed")
}
return &serviceDiscoveryRegistry{
url: url,
serviceDiscovery: serviceDiscovery,
serviceMeta: NewServiceMeta(url.GetParam(constant.ApplicationKey, "")),
subscribedServices: subscribedServices,
subscribedURLsSynthesizers: subscribedURLsSynthesizers,
registeredListeners: gxset.NewSet(),
serviceNameMapping: serviceNameMapping,
serviceListeners: make(map[string]registry.ServiceInstancesChangedListener),
url: url,
serviceDiscovery: serviceDiscovery,
serviceMeta: NewServiceMeta(),
serviceNameMapping: extension.GetGlobalServiceNameMapping(),
serviceListeners: make(map[string]registry.ServiceInstancesChangedListener),
// cache for mapping listener
serviceMappingListeners: make(map[string]mapping.MappingListener),
}, nil
Expand All @@ -115,8 +103,7 @@ func (s *serviceDiscoveryRegistry) RegisterService() error {
if err != nil {
return err
}
s.serviceMeta.createInstance()
return s.serviceDiscovery.Register(s.serviceMeta.instance)
return s.serviceDiscovery.Register(s.serviceMeta.createInstance())
}

func (s *serviceDiscoveryRegistry) UnRegisterService() error {
Expand All @@ -127,10 +114,6 @@ func (s *serviceDiscoveryRegistry) GetLocalMetadata() *info.MetadataInfo {
return s.serviceMeta.metadataInfo
}

func (s *serviceDiscoveryRegistry) GetRemoteMetadata(revision string, instance registry.ServiceInstance) (*info.MetadataInfo, error) {
return s.serviceMeta.GetRemoteMetadata(revision, instance)
}

func (s *serviceDiscoveryRegistry) UnRegister(url *common.URL) error {
if !shouldRegister(url) {
return nil
Expand Down Expand Up @@ -160,14 +143,6 @@ func (s *serviceDiscoveryRegistry) UnSubscribe(url *common.URL, listener registr
return nil
}

func creatServiceDiscovery(url *common.URL) (registry.ServiceDiscovery, error) {
originServiceDiscovery, err := extension.GetServiceDiscovery(url)
if err != nil {
return nil, perrors.WithMessage(err, "Create service discovery failed")
}
return originServiceDiscovery, nil
}

func parseServices(literalServices string) *gxset.HashSet {
set := gxset.NewSet()
if len(literalServices) == 0 {
Expand Down Expand Up @@ -216,7 +191,7 @@ func (s *serviceDiscoveryRegistry) Register(url *common.URL) error {

func shouldRegister(url *common.URL) bool {
side := url.GetParam(constant.SideKey, "")
if side == constant.ProviderProtocol {
if side == constant.SideProvider {
return true
}
logger.Debugf("The URL should not be register.", url.String())
Expand All @@ -229,7 +204,7 @@ func (s *serviceDiscoveryRegistry) Subscribe(url *common.URL, notify registry.No
return nil
}
s.serviceMeta.GetLocalMetadata().AddSubscribeURL(url)
mappingListener := NewMappingListener(s.url, url, s.subscribedServices, notify)
mappingListener := NewMappingListener(s.url, url, parseServices(url.GetParam(constant.ProvidedBy, "")), notify)
services := s.getServices(url, mappingListener)
if services.Empty() {
return perrors.Errorf("Should has at least one way to know which services this interface belongs to,"+
Expand Down Expand Up @@ -319,7 +294,7 @@ func appendParam(buffer bytes.Buffer, paramKey string, url *common.URL) {

func (s *serviceDiscoveryRegistry) synthesizeSubscribedURLs(subscribedURL *common.URL, serviceInstances []registry.ServiceInstance) []*common.URL {
var urls []*common.URL
for _, syn := range s.subscribedURLsSynthesizers {
for _, syn := range synthesizer.GetAllSynthesizer() {
if syn.Support(subscribedURL) {
urls = append(urls, syn.Synthesize(subscribedURL, serviceInstances)...)
}
Expand All @@ -339,9 +314,6 @@ func (s *serviceDiscoveryRegistry) getServices(url *common.URL, listener mapping
}
if services.Empty() {
services = s.findMappedServices(url, listener)
if services.Empty() {
return s.subscribedServices
}
}
return services
}
Expand Down
Loading