Skip to content

Commit

Permalink
skip service lookup when using dns or unix transport
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Jun 27, 2024
1 parent 39a7a48 commit 0affac1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
3 changes: 0 additions & 3 deletions cmd/revad/internal/grace/grace.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ func (w *Watcher) WritePID() error {
}

func newListener(network, addr string) (net.Listener, error) {
if network == "dns" {
network = "tcp"
}
return net.Listen(network, addr)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func GetRegistry() mRegistry.Registry {
}

// GetNodeAddress returns a random address from the service nodes
func GetNodeAddress(services []*mRegistry.Service) (string, string, error) {
func GetNodeAddress(services []*mRegistry.Service) (string, error) {
next := selector.Random(services)
node, err := next()
if err != nil {
return "", "", err
return "", err
}

return node.Metadata["transport"], node.Address, nil
return node.Address, nil
}
33 changes: 17 additions & 16 deletions pkg/rgrpc/todo/pool/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package pool

import (
"fmt"
"strings"
"sync"

appProvider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
Expand Down Expand Up @@ -94,22 +95,22 @@ func (s *Selector[T]) Next(opts ...Option) (T, error) {
}

target := s.id
if options.registry != nil {
services, err := options.registry.GetService(s.id)
if err != nil {
return *new(T), fmt.Errorf("%s: %w", s.id, err)
}

transport, nodeAddress, err := registry.GetNodeAddress(services)
if err != nil {
return *new(T), fmt.Errorf("%s: %w", s.id, err)
}
switch transport {
case "dns":
target = "dns:///" + nodeAddress
case "unix":
target = transport + ":" + nodeAddress
default:
prefix := strings.SplitN(s.id, ":", 2)[0]
switch prefix {
case "dns", "unix":
// use target as is
default:
// use service registry to look up address
if options.registry != nil {
services, err := options.registry.GetService(s.id)
if err != nil {
return *new(T), fmt.Errorf("%s: %w", s.id, err)
}

nodeAddress, err := registry.GetNodeAddress(services)
if err != nil {
return *new(T), fmt.Errorf("%s: %w", s.id, err)
}
target = nodeAddress
}
}
Expand Down

0 comments on commit 0affac1

Please sign in to comment.