github.com/pachyderm/pachyderm@v1.13.4/src/client/pkg/shard/shard.go (about) 1 package shard 2 3 import ( 4 "github.com/pachyderm/pachyderm/src/client/pkg/discovery" 5 "github.com/pachyderm/pachyderm/src/client/pkg/grpcutil" 6 "google.golang.org/grpc" 7 ) 8 9 // Sharder distributes shards between a set of servers. 10 type Sharder interface { 11 GetAddress(shard uint64, version int64) (string, bool, error) 12 GetShardToAddress(version int64) (map[uint64]string, error) 13 14 Register(address string, servers []Server) error 15 RegisterFrontends(address string, frontends []Frontend) error 16 AssignRoles(address string) error 17 } 18 19 // NewSharder creates a Sharder using a discovery client. 20 func NewSharder(discoveryClient discovery.Client, numShards uint64, namespace string) Sharder { 21 return newSharder(discoveryClient, numShards, namespace) 22 } 23 24 // NewLocalSharder creates a Sharder user a list of addresses. 25 func NewLocalSharder(addresses []string, numShards uint64) Sharder { 26 return newLocalSharder(addresses, numShards) 27 } 28 29 // A Server represents a server that has roles for shards. 30 type Server interface { 31 // AddShard tells the server it now has a role for a shard. 32 AddShard(shard uint64) error 33 // RemoveShard tells the server it no longer has a role for a shard. 34 DeleteShard(shard uint64) error 35 } 36 37 // A Frontend represents a frontend which receives new versions. 38 type Frontend interface { 39 // Version tells the Frontend a new version exists. 40 // Version should block until the Frontend is done using the previous version. 41 Version(version int64) error 42 } 43 44 // Router represents a router from shard id and version to grpc connections. 45 type Router interface { 46 GetShards(version int64) (map[uint64]bool, error) 47 GetClientConn(shard uint64, version int64) (*grpc.ClientConn, error) 48 GetAllClientConns(version int64) ([]*grpc.ClientConn, error) 49 CloseClientConns() error // close all outstanding client connections 50 } 51 52 // NewRouter creates a Router. 53 func NewRouter( 54 sharder Sharder, 55 dialer grpcutil.Dialer, 56 localAddress string, 57 ) Router { 58 return newRouter( 59 sharder, 60 dialer, 61 localAddress, 62 ) 63 }