You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/02/01 04:51:45 UTC

[GitHub] [dubbo-go] cvictory commented on a change in pull request #1023: Ftr: Use invoker with same ip as client first.

cvictory commented on a change in pull request #1023:
URL: https://github.com/apache/dubbo-go/pull/1023#discussion_r567562767



##########
File path: cluster/router/self/self_priority_route.go
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package self
+
+import (
+	"github.com/RoaringBitmap/roaring"
+)
+
+import (
+	"github.com/apache/dubbo-go/cluster/router"
+	"github.com/apache/dubbo-go/cluster/router/utils"
+	"github.com/apache/dubbo-go/common"
+	"github.com/apache/dubbo-go/common/logger"
+	"github.com/apache/dubbo-go/protocol"
+)
+
+const (
+	selfPriority = "self-priority"
+	name         = "self-priority-router"
+)
+
+// SelfPriorityRouter 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 SelfPriorityRouter struct {
+	url     *common.URL
+	localIP string
+}
+
+// NewSelfPriorityRouter construct an SelfPriorityRouter via url
+func NewSelfPriorityRouter(url *common.URL) (router.PriorityRouter, error) {
+	r := &SelfPriorityRouter{
+		url:     url,
+		localIP: url.Ip,
+	}
+	return r, nil
+}
+
+// Route gets a list of match-logic invoker
+func (r *SelfPriorityRouter) Route(invokers *roaring.Bitmap, cache router.Cache, url *common.URL, invocation protocol.Invocation) *roaring.Bitmap {
+	addrPool := cache.FindAddrPool(r)
+	// Add selfPriority invoker to the list
+	selectedInvokers := utils.JoinIfNotEqual(addrPool[selfPriority], invokers)
+	// 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())

Review comment:
       maybe it should be logger.Debugf




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org