-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdht.go
39 lines (29 loc) · 1020 Bytes
/
dht.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
package dht
import "errors"
var (
ErrDHTNotInitialised = errors.New("dht is not initialised")
ErrDHTAlreadyInitialised = errors.New("dht is already initialised")
ErrReplicasLessThanNodes = errors.New("replicas are lesser than physical nodes")
)
type ShardID int
type NodeID string
type NodeDetails struct {
ID NodeID
}
type ShardLocation struct {
ID ShardID
Leader NodeDetails
Followers []NodeDetails
}
// DHT contains the location of a given key in a distributed data system.
type DHT interface {
// GetLocation returns the location of the leader and follower slot and corresponding node
GetShard(key string) (ShardLocation, error)
GetLeaderShardsForNode(nodeID NodeID) []ShardID
GetAllShardsForNode(nodeID NodeID) []ShardID
// Load loads data from an already existing configuration.
// This must be taken called after confirmation from the master
Load(shards map[ShardID]ShardLocation)
// Snapshot returns the current node vs slot ids map
Snapshot() map[ShardID]ShardLocation
}