-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
67 lines (52 loc) · 1.73 KB
/
types.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
60
61
62
63
64
65
66
67
package ring
import (
"net"
"time"
)
// Handler interface to get notified when a new member joins or existing member leaves the ring.
type Handler interface {
Join(nodeName string, tags map[string]string) error
Leave(nodeName string, tags map[string]string) error
}
// HashFunction hashes key (string) to uint64.
type HashFunction interface {
Hash(key string) uint64
}
type MemberType uint8
const (
ShardMember MemberType = iota // RingMember takes part in the sharding.
LoadBalancerMember // Doesn't take part in the sharding, but knows the addresses of member.
)
// ShardResponsibilityHandler to listen to responsibility change when any new member joins the ring at the next position of the current node.
type ShardResponsibilityHandler interface {
// OnChange This will be fired if the current node is affected by the new members.
OnChange([]ShardResponsibility)
}
// ServerID is a unique string identifying a server for all time.
type ServerID string
// ServerAddress is a network address for a server that a transport can contact.
type ServerAddress string
// Server tracks the information about a single server in a configuration.
type Server struct {
// Address is its network address that a transport can contact.
Address ServerAddress
}
type RequestType uint8
const (
RingRequestType RequestType = iota
PaxosRequestType
)
type PaxosMessageType uint8
const (
PrepareMsgType PaxosMessageType = iota
ProposalMsgType
PromiseMsgType
AcceptMsgType
)
// StreamLayer is used with the NetworkTransport to provide
// the low level stream abstraction.
type StreamLayer interface {
net.Listener
// Dial is used to create a new outgoing connection
Dial(address ServerAddress, timeout time.Duration) (net.Conn, error)
}