-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeta.go
139 lines (118 loc) · 3.41 KB
/
meta.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package prophet
// ResourceKind distinguishes different kinds of resources.
type ResourceKind int
const (
// LeaderKind leader
LeaderKind ResourceKind = iota
// ReplicaKind replication of resource
ReplicaKind
)
// State is the state
type State int
const (
// UP is normal state
UP State = iota
// Down is the unavailable state
Down
// Tombstone is the destory state
Tombstone
)
// Serializable serializable
type Serializable interface {
}
type codecSerializable interface {
Serializable
Prepare() error
Init(adapter Adapter) error
}
// Peer is the resource peer
type Peer struct {
ID uint64 `json:"id"`
ContainerID uint64 `json:"cid"`
}
// Clone returns a clone value
func (p *Peer) Clone() *Peer {
return &Peer{
ID: p.ID,
ContainerID: p.ContainerID,
}
}
// PeerStats peer stats
type PeerStats struct {
Peer *Peer
DownSeconds uint64
}
// Clone returns a clone value
func (ps *PeerStats) Clone() *PeerStats {
return &PeerStats{
Peer: ps.Peer.Clone(),
DownSeconds: ps.DownSeconds,
}
}
// Resource is an abstraction of data shard in a distributed system.
// Each Resource has multiple replication and is distributed on different nodes.
type Resource interface {
Serializable
// SetID update the resource id
SetID(id uint64)
// ID returns the resource id
ID() uint64
// Peers returns the repication peers
Peers() []*Peer
// SetPeers update the repication peers
SetPeers(peers []*Peer)
// Stale returns true if the other resource is older than current resource
Stale(other Resource) bool
// Changed returns true if the other resource is newer than current resource
Changed(other Resource) bool
// Labels returns the label pairs that determine which the resources will be scheduled to which nodes
Labels() []Pair
// Clone returns the cloned value
Clone() Resource
// ScaleCompleted returns true if the current resource has been successfully scaled according to the specified container
ScaleCompleted(uint64) bool
// Marshal returns error if marshal failed
Marshal() ([]byte, error)
// Unmarshal returns error if unmarshal failed
Unmarshal(data []byte) error
// SupportRebalance support rebalance the resource
SupportRebalance() bool
// SupportTransferLeader support transfer leader
SupportTransferLeader() bool
}
// Pair key value pair
type Pair struct {
Key string `json:"key"`
Value string `json:"value"`
}
// Container is an abstraction of the node in a distributed system.
// Usually a container has many resoruces
type Container interface {
Serializable
// ShardAddr returns address that used for communication between the resource replications
ShardAddr() string
// SetID update the container id
SetID(id uint64)
// ID returns the container id
ID() uint64
// Labels returns the lable tag of the container
Labels() []Pair
// State returns the state of the container
State() State
// Clone returns the cloned value
Clone() Container
// ActionOnJoinCluster returns the cluster will do what when a new container join the cluster
ActionOnJoinCluster() Action
// Marshal returns error if marshal failed
Marshal() ([]byte, error)
// Unmarshal returns error if unmarshal failed
Unmarshal(data []byte) error
}
// Action the action on the cluster join the cluster
type Action int
const (
// NoneAction none action
NoneAction = Action(0)
// ScaleOutAction all resources will received a scale operation when a new container join the cluster
ScaleOutAction = Action(1)
)