-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
63 lines (51 loc) · 1.08 KB
/
config.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
package raftgrp
import (
"fmt"
"log"
"path/filepath"
"strconv"
"strings"
"time"
"go.uber.org/zap"
)
// config
type GroupConfig struct {
*zap.Logger
GID uint64
ID uint64
Peers []*Peer
NewCluster bool
DataDir string
TickMs int
ElectionTicks int
PreVote bool
SnapshotCount uint64
SnapshotCatchUpEntries uint64
}
func (g GroupConfig) MemberDir() string {
return filepath.Join(g.DataDir, fmt.Sprintf("member-%d", g.ID))
}
// TODO: contact gid
func (g GroupConfig) RaftDir() string {
return filepath.Join(g.MemberDir(), "raft")
}
func (g GroupConfig) peerDialTimeout() time.Duration {
return time.Second * time.Duration(g.ElectionTicks*int(g.TickMs)) * time.Millisecond
}
type Peer struct {
ID uint64
Addr string
}
// peers => "1=http://127.0.0.1:9527"
func ParsePeers(ps []string) []*Peer {
peers := make([]*Peer, len(ps))
for i := range ps {
peer := &Peer{}
p := strings.Split(ps[i], "=")
log.Println(p)
peer.ID, _ = strconv.ParseUint(p[0], 10, 64)
peer.Addr = p[1]
peers[i] = peer
}
return peers
}