forked from pachyderm/pachyderm
/
route.go
59 lines (49 loc) · 1.29 KB
/
route.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package route
import (
"github.com/pachyderm/pachyderm/src/pfs"
"github.com/pachyderm/pachyderm/src/pfs/discovery"
"google.golang.org/grpc"
)
type Sharder interface {
NumShards() int
GetShard(path *pfs.Path) (int, error)
}
func NewSharder(numShards int) Sharder {
return newSharder(numShards)
}
type Addresser interface {
GetMasterShards(address string) (map[int]bool, error)
GetSlaveShards(address string) (map[int]bool, error)
GetAllAddresses() ([]string, error)
}
func NewSingleAddresser(address string, numShards int) Addresser {
return newSingleAddresser(address, numShards)
}
func NewDiscoveryAddresser(discoveryClient discovery.Client) Addresser {
return newDiscoveryAddresser(discoveryClient)
}
type Dialer interface {
Dial(address string) (*grpc.ClientConn, error)
Clean() error
}
func NewDialer(opts ...grpc.DialOption) Dialer {
return newDialer(opts...)
}
type Router interface {
GetMasterShards() (map[int]bool, error)
GetSlaveShards() (map[int]bool, error)
GetMasterClientConn(shard int) (*grpc.ClientConn, error)
GetMasterOrSlaveClientConn(shard int) (*grpc.ClientConn, error)
GetAllClientConns() ([]*grpc.ClientConn, error)
}
func NewRouter(
addresser Addresser,
dialer Dialer,
localAddress string,
) Router {
return newRouter(
addresser,
dialer,
localAddress,
)
}