diff --git a/cluster/router/selfDiscovery/factory.go b/cluster/router/selfDiscovery/factory.go index dd035a6659b5f0ed3ad3e8330359427b84308019..854e528dad7338698fd9b6a6012dcc3172ed0b53 100644 --- a/cluster/router/selfDiscovery/factory.go +++ b/cluster/router/selfDiscovery/factory.go @@ -32,12 +32,12 @@ func init() { type SelfDiscRouteFactory struct { } -// newHealthCheckRouteFactory construct a new HealthCheckRouteFactory +// newSelfDiscRouteFactory construct a new SelfDiscRouteFactory func newSelfDiscRouteFactory() router.PriorityRouterFactory { return &SelfDiscRouteFactory{} } -// NewPriorityRouter construct a new NewHealthCheckRouter via url +// NewPriorityRouter construct a new NewSelfDiscRouter via url func (f *SelfDiscRouteFactory) NewPriorityRouter(url *common.URL) (router.PriorityRouter, error) { return NewSelfDiscRouter(url) } diff --git a/cluster/router/selfDiscovery/factory_test.go b/cluster/router/selfDiscovery/factory_test.go index 4fcdd32f16b21e8b8e44267392a2e9b2a40bdbb5..5e3fa5e16436dc78cb3ba9e8207ffb528a4424a0 100644 --- a/cluster/router/selfDiscovery/factory_test.go +++ b/cluster/router/selfDiscovery/factory_test.go @@ -68,7 +68,7 @@ func (bi *MockInvoker) Destroy() { } // nolint -func TestHealthCheckRouteFactory(t *testing.T) { +func TestSelfDiscRouteFactory(t *testing.T) { factory := newSelfDiscRouteFactory() assert.NotNil(t, factory) } diff --git a/cluster/router/selfDiscovery/self_disc_route.go b/cluster/router/selfDiscovery/self_disc_route.go index ca697bfc43fac77e65391904d9e2f87ce183260f..d0fde4d86510a2a92fb0a5add3bce2d48f2df014 100644 --- a/cluster/router/selfDiscovery/self_disc_route.go +++ b/cluster/router/selfDiscovery/self_disc_route.go @@ -30,18 +30,19 @@ import ( ) const ( - HEALTH_ROUTE_ENABLED_KEY = "health.route.enabled" - selfDesc = "self-desc" - name = "health-check-router" + selfDesc = "self-desc" + name = "self-desc-router" ) -// SelfDiscRouter provides a health-first routing mechanism through HealthChecker +// SelfDiscRouter provides a ip-same-first routing logic +// if there is not provider with same ip as consumer, it would not filter any invoker +// if exists same ip invoker, it would retains this invoker only type SelfDiscRouter struct { url *common.URL localIP string } -// NewSelfDiscRouter construct an HealthCheckRouter via url +// NewSelfDiscRouter construct an SelfDiscRouter via url func NewSelfDiscRouter(url *common.URL) (router.PriorityRouter, error) { r := &SelfDiscRouter{ url: url, @@ -50,12 +51,12 @@ func NewSelfDiscRouter(url *common.URL) (router.PriorityRouter, error) { return r, nil } -// Route gets a list of healthy invoker +// Route gets a list of match-logic invoker func (r *SelfDiscRouter) Route(invokers *roaring.Bitmap, cache router.Cache, url *common.URL, invocation protocol.Invocation) *roaring.Bitmap { addrPool := cache.FindAddrPool(r) - // Add healthy invoker to the list + // Add selfDesc invoker to the list selectedInvokers := utils.JoinIfNotEqual(addrPool[selfDesc], invokers) - // If all invokers are considered unhealthy, downgrade to all invoker + // If all invokers are considered not match, downgrade to all invoker if selectedInvokers.IsEmpty() { logger.Warnf(" Now all invokers are not match, so downgraded to all! Service: [%s]", url.ServiceKey()) return invokers @@ -63,12 +64,11 @@ func (r *SelfDiscRouter) Route(invokers *roaring.Bitmap, cache router.Cache, url return selectedInvokers } -// Pool separates healthy invokers from others. +// Pool separates same ip invoker from others. func (r *SelfDiscRouter) Pool(invokers []protocol.Invoker) (router.AddrPool, router.AddrMetadata) { rb := make(router.AddrPool, 8) rb[selfDesc] = roaring.NewBitmap() selfDescFound := false - logger.Debug("local ip = ", r.localIP) for i, invoker := range invokers { if invoker.GetUrl().Ip == r.localIP { rb[selfDesc].Add(uint32(i)) @@ -86,7 +86,7 @@ func (r *SelfDiscRouter) Pool(invokers []protocol.Invoker) (router.AddrPool, rou return rb, nil } -// ShouldPool will always return true to make sure healthy check constantly. +// ShouldPool will always return true to make sure self call logic constantly. func (r *SelfDiscRouter) ShouldPool() bool { return true } diff --git a/cluster/router/selfDiscovery/self_disc_route_test.go b/cluster/router/selfDiscovery/self_disc_route_test.go index fcb90948402097b5735b834ba57bdd5675817f1d..7a1e48bd65c27b95bd7cafb7d48109f62d80dbb9 100644 --- a/cluster/router/selfDiscovery/self_disc_route_test.go +++ b/cluster/router/selfDiscovery/self_disc_route_test.go @@ -36,20 +36,19 @@ import ( ) const ( - healthCheckRoute1010IP = "192.168.10.10" - healthCheckRoute1011IP = "192.168.10.11" - healthCheckRoute1012IP = "192.168.10.12" - healthCheckRouteMethodNameTest = "test" - healthCheck1001URL = "dubbo://192.168.10.1/com.ikurento.user.UserProvider" - healthCheckRouteUrlFormat = "dubbo://%s:20000/com.ikurento.user.UserProvider" + selfDiscRoute1010IP = "192.168.10.10" + selfDiscRoute1011IP = "192.168.10.11" + selfDiscRoute1012IP = "192.168.10.12" + selfDiscRouteMethodNameTest = "test" + selfDiscRouteUrlFormat = "dubbo://%s:20000/com.ikurento.user.UserProvider" ) -func TestHealthCheckRouterRoute(t *testing.T) { +func TestSelfDiscRouterRoute(t *testing.T) { defer protocol.CleanAllStatus() - consumerURL, _ := common.NewURL(fmt.Sprintf(healthCheckRouteUrlFormat, healthCheckRoute1010IP)) - url1, _ := common.NewURL(fmt.Sprintf(healthCheckRouteUrlFormat, healthCheckRoute1010IP)) - url2, _ := common.NewURL(fmt.Sprintf(healthCheckRouteUrlFormat, healthCheckRoute1011IP)) - url3, _ := common.NewURL(fmt.Sprintf(healthCheckRouteUrlFormat, healthCheckRoute1012IP)) + consumerURL, _ := common.NewURL(fmt.Sprintf(selfDiscRouteUrlFormat, selfDiscRoute1010IP)) + url1, _ := common.NewURL(fmt.Sprintf(selfDiscRouteUrlFormat, selfDiscRoute1010IP)) + url2, _ := common.NewURL(fmt.Sprintf(selfDiscRouteUrlFormat, selfDiscRoute1011IP)) + url3, _ := common.NewURL(fmt.Sprintf(selfDiscRouteUrlFormat, selfDiscRoute1012IP)) hcr, _ := NewSelfDiscRouter(consumerURL) var invokers []protocol.Invoker @@ -57,11 +56,12 @@ func TestHealthCheckRouterRoute(t *testing.T) { invoker2 := NewMockInvoker(url2) invoker3 := NewMockInvoker(url3) invokers = append(invokers, invoker1, invoker2, invoker3) - inv := invocation.NewRPCInvocation(healthCheckRouteMethodNameTest, nil, nil) + inv := invocation.NewRPCInvocation(selfDiscRouteMethodNameTest, nil, nil) res := hcr.Route(utils.ToBitmap(invokers), setUpAddrCache(hcr.(*SelfDiscRouter), invokers), consumerURL, inv) - // now all invokers are healthy + // now only same ip invoker is selected assert.True(t, len(res.ToArray()) == 1) + // now all invoker with ip that not match client are selected invokers = invokers[1:] res = hcr.Route(utils.ToBitmap(invokers), setUpAddrCache(hcr.(*SelfDiscRouter), invokers), consumerURL, inv) assert.True(t, len(res.ToArray()) == 2)