-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.go
56 lines (49 loc) 路 1.23 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
package cluster
import (
"context"
"fmt"
"github.com/vx-labs/wasp/cluster/raft"
"google.golang.org/grpc"
)
type Node interface {
Run(context.Context)
RunFromAppliedIndex(ctx context.Context, idx uint64)
Shutdown() error
Apply(context.Context, []byte) error
Ready() <-chan struct{}
Call(id uint64, f func(*grpc.ClientConn) error) error
Index() uint64
}
type MultiNode interface {
Node(cluster string, config RaftConfig) Node
Shutdown() error
}
type NodeConfig struct {
ID uint64
ServiceName string
DataDirectory string
GossipConfig GossipConfig
RaftConfig RaftConfig
}
type RaftConfig struct {
ExpectedNodeCount int
AppliedIndex uint64
DisableProposalForwarding bool
LeaderFunc func(context.Context) error
Network NetworkConfig
GetStateSnapshot func() ([]byte, error)
CommitApplier raft.CommitApplier
SnapshotApplier raft.SnapshotApplier
}
type NetworkConfig struct {
AdvertizedHost string
AdvertizedPort int
ListeningPort int
}
func (n NetworkConfig) AdvertizedAddress() string {
return fmt.Sprintf("%s:%d", n.AdvertizedHost, n.AdvertizedPort)
}
type GossipConfig struct {
JoinList []string
Network NetworkConfig
}