-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
156 lines (136 loc) · 3.6 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package aerospike
import (
"fmt"
as "github.com/aerospike/aerospike-client-go/v6"
"net/url"
"strconv"
"time"
)
// Config represent Connection config
type Config struct {
host string
port int
namespace string
batchSize int
concurrency int
maxConcurrentWrite int
Values url.Values
// expiry options
/*
Key string
Secret string
Region string
CredURL string
CredKey string
Token string
RoleArn string
*/
}
func (c *Config) adjustClientPolicy(policy *as.ClientPolicy) error {
name := "clientPolConnectionQueueSize"
if v, ok := c.Values[name]; ok {
value, err := strconv.Atoi(v[0])
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.ConnectionQueueSize = value
}
name = "clientPolTimeout"
if v, ok := c.Values[name]; ok {
value, err := time.ParseDuration(v[0] + "s")
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.Timeout = value
}
name = "clientPolIdleTimeout"
if v, ok := c.Values[name]; ok {
value, err := time.ParseDuration(v[0] + "s")
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.IdleTimeout = value
}
name = "clientPolLoginTimeout"
if v, ok := c.Values[name]; ok {
value, err := time.ParseDuration(v[0] + "s")
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.LoginTimeout = value
}
name = "clientPolOpeningConnectionThreshold"
if v, ok := c.Values[name]; ok {
value, err := strconv.Atoi(v[0])
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.OpeningConnectionThreshold = value
}
name = "clientPolTendInterval"
if v, ok := c.Values[name]; ok {
value, err := time.ParseDuration(v[0] + "s")
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.TendInterval = value
}
name = "clientPolMaxErrorRate"
if v, ok := c.Values[name]; ok {
value, err := strconv.Atoi(v[0])
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.MaxErrorRate = value
}
name = "clientPolErrorRateWindow"
if v, ok := c.Values[name]; ok {
value, err := strconv.Atoi(v[0])
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.ErrorRateWindow = value
}
return nil
}
func (c *Config) adjustDefaultPolicy(policy *as.BasePolicy) error {
return c.adjustBasePolicy(policy, "defPol")
}
func (c *Config) adjustDefaultWritePolicy(policy *as.WritePolicy) error {
return c.adjustBasePolicy(policy.GetBasePolicy(), "defWritePol")
}
func (c *Config) adjustBasePolicy(policy *as.BasePolicy, prefix string) error {
name := prefix + "TotalTimeout"
if v, ok := c.Values[name]; ok {
value, err := time.ParseDuration(v[0] + "s")
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.TotalTimeout = value
}
name = prefix + "SocketTimeout"
if v, ok := c.Values[name]; ok {
value, err := time.ParseDuration(v[0] + "s")
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.SocketTimeout = value
}
name = prefix + "MaxRetries"
if v, ok := c.Values[name]; ok {
value, err := strconv.Atoi(v[0])
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.MaxRetries = value
}
name = prefix + "SleepBetweenRetries"
if v, ok := c.Values[name]; ok {
value, err := time.ParseDuration(v[0] + "ms")
if err != nil {
return fmt.Errorf("invalid dsn param %v: %v", name, err)
}
policy.SleepBetweenRetries = value
}
return nil
}