-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
64 lines (54 loc) · 1.77 KB
/
util.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
package goutube
import (
"os"
"path/filepath"
"github.com/Brijeshlakkad/ring"
)
// min returns the minimum.
func min(a, b uint64) uint64 {
if a <= b {
return a
}
return b
}
// max returns the maximum.
func max(a, b uint64) uint64 {
if a >= b {
return a
}
return b
}
// createDirectory creates the directory under parentDir.
func createDirectory(parentDir, dataDir string) (string, error) {
dir := filepath.Join(parentDir, dataDir)
// Create a hierarchy of directories if necessary
if err := os.MkdirAll(dir, 0755); err != nil {
return "", err
}
return dir, nil
}
// toRingMemberType gets the member type in ring.MemberType from the rule.
func toRingMemberType(rule ParticipationRule) (ring.MemberType, bool) {
if rule == LeaderRule || rule == StandaloneLeaderRule {
return ring.ShardMember, true
} else if rule == LoadBalancerRule {
return ring.LoadBalancerMember, true
}
return 0, false
}
// shouldImplementFollowerResolver if the server should implement the Follower Resolver service.
func shouldImplementFollowerResolver(rule ParticipationRule) bool {
return rule != FollowerRule && rule != StandaloneLeaderRule
}
// shouldImplementLoci if the server should implement the DistributedLoci.
func shouldImplementLoci(rule ParticipationRule) bool {
return rule != LoadBalancerRule
}
// shouldImplementReplicationCluster if the server should be the part of a replication cluster.
func shouldImplementReplicationCluster(rule ParticipationRule) bool {
return rule != LoadBalancerRule && rule != StandaloneLeaderRule
}
// shouldImplementLoadBalancer if the server should implement the load balancer server. If yes, the server will not implement streaming server and vice versa.
func shouldImplementLoadBalancer(rule ParticipationRule) bool {
return rule == LoadBalancerRule
}