-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.go
102 lines (91 loc) · 2.53 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
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
package zanredisdb
import (
"errors"
"strings"
"time"
)
var (
FailedOnClusterChanged = "ERR_CLUSTER_CHANGED"
FailedOnNotLeader = "E_FAILED_ON_NOT_LEADER"
FailedOnNotWritable = "E_FAILED_ON_NOT_WRITABLE"
FailedOnNodeStopped = "the node stopped"
errNoNodeForPartition = errors.New("no partition node")
errNoConnForHost = errors.New("no any connection for host")
)
func IsConnectRefused(err error) bool {
if err != nil {
return strings.Contains(strings.ToLower(err.Error()), "connection refused")
}
return false
}
func IsFailedOnClusterChanged(err error) bool {
if err != nil {
return strings.HasPrefix(err.Error(), FailedOnClusterChanged) ||
err == errNoNodeForPartition ||
strings.Contains(err.Error(), FailedOnNodeStopped)
}
return false
}
func IsFailedOnNotWritable(err error) bool {
if err != nil {
return strings.HasPrefix(err.Error(), FailedOnNotWritable)
}
return false
}
type Conf struct {
LookupList []string
DialTimeout time.Duration
ReadTimeout time.Duration
RangeReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
MaxActiveConn int
// idle num that will be kept for all idle connections
MaxIdleConn int
// default 0.4
RangeConnRatio float64
TendInterval int64
Namespace string
Password string
// the datacenter info
DC string
}
// api data response type
type node struct {
BroadcastAddress string `json:"broadcast_address"`
Hostname string `json:"hostname"`
RedisPort string `json:"redis_port"`
HTTPPort string `json:"http_port"`
GrpcPort string `json:"grpc_port"`
Version string `json:"version"`
DCInfo string `json:"dc_info"`
}
type PartitionNodeInfo struct {
Leader node `json:"leader"`
Replicas []node `json:"replicas"`
}
type queryNamespaceResp struct {
Epoch int64 `json:"epoch"`
EngType string `json:"eng_type"`
Partitions map[int]PartitionNodeInfo `json:"partitions"`
PartitionNum int `json:"partition_num"`
}
type NodeInfo struct {
RegID uint64
ID string
NodeIP string
Hostname string
RedisPort string
HttpPort string
RpcPort string
RaftTransportAddr string
Version string
Tags map[string]bool
DataRoot string
RsyncModule string
Epoch int64
}
type listPDResp struct {
PDNodes []NodeInfo `json:"pdnodes"`
PDLeader NodeInfo `json:"pdleader"`
}