hanahmily commented on code in PR #324:
URL: 
https://github.com/apache/skywalking-banyandb/pull/324#discussion_r1330032441


##########
test/integration/distributed/setup/node_test.go:
##########
@@ -86,4 +92,64 @@ var _ = Describe("Node registration", func() {
                        return helpers.ListKeys(etcdEndpoint, 
fmt.Sprintf("/%s/nodes/%s:%d", namespace, nodeHost, ports[0]))
                }, flags.EventuallyTimeout).Should(BeNil())
        })
+
+       It("should register multiple data nodes in the node selector 
successfully", func() {
+               namespace := "data-test"
+               nodeDataHosts := []string{"data-node-1", "data-node-2"}
+               nodeDataIDs := make([]string, len(nodeDataHosts))
+               ports, err := test.AllocateFreePorts(2)
+               Expect(err).NotTo(HaveOccurred())
+
+               var closeFns []func()
+               for i, nodeDataHost := range nodeDataHosts {
+                       addr := fmt.Sprintf("%s:%d", host, ports[i])
+                       closeFns = append(closeFns, setup.CMD("data",
+                               "--namespace", namespace,
+                               "--grpc-host="+host,
+                               fmt.Sprintf("--grpc-port=%d", ports[i]),
+                               "--etcd-endpoints", etcdEndpoint,
+                               "--node-host-provider", "flag",
+                               "--node-host", nodeDataHost))
+                       nodeDataIDs[i] = fmt.Sprintf("%s:%d", nodeDataHost, 
ports[i])
+                       Eventually(
+                               helpers.HealthCheck(addr, 10*time.Second, 
10*time.Second, grpc.WithTransportCredentials(insecure.NewCredentials())),
+                               flags.EventuallyTimeout).Should(Succeed())
+                       Eventually(func() (map[string]*databasev1.Node, error) {
+                               return helpers.ListKeys(etcdEndpoint, 
fmt.Sprintf("/%s/nodes/%s:%d", namespace, nodeDataHost, ports[i]))
+                       }, flags.EventuallyTimeout).Should(HaveLen(1))
+               }
+
+               // TODO: refactor the following startup logic

Review Comment:
   Would you be able to use a mock to test the behavior of the selector? 
   
   I have introduced a cluster integration in #333 . We can use it to test the 
cluster selector.



##########
banyand/liaison/grpc/node.go:
##########
@@ -0,0 +1,110 @@
+// Licensed to 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. Apache Software Foundation (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 grpc
+
+import (
+       "sync"
+
+       "github.com/pkg/errors"
+
+       databasev1 
"github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
+       "github.com/apache/skywalking-banyandb/banyand/metadata"
+       "github.com/apache/skywalking-banyandb/banyand/metadata/schema"
+       "github.com/apache/skywalking-banyandb/pkg/node"
+)
+
+var (
+       _ schema.EventHandler = (*clusterNodeService)(nil)
+       _ NodeRegistry        = (*clusterNodeService)(nil)
+)
+
+// NodeRegistry is for locating data node with group/name of the metadata
+// together with the shardID calculated from the incoming data.
+type NodeRegistry interface {
+       Initialize() error
+       Locate(group, name string, shardID uint32) (string, error)
+}
+
+type clusterNodeService struct {
+       metaRepo metadata.Repo
+       sel      node.Selector
+       sync.Once
+}
+
+// NewClusterNodeRegistry creates a cluster-aware node registry.
+func NewClusterNodeRegistry(metaRepo metadata.Repo, selector node.Selector) 
NodeRegistry {

Review Comment:
   #333 will use `queue.Client` to listen to node events, reducing the need for 
the liaison node to set up two etcd watchers. Please merge this once PR is 
merged.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@skywalking.apache.org

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

Reply via email to