@@ -89,6 +89,10 @@ type ClusterChecker struct {
89
89
endPollonProxyCh chan error
90
90
91
91
pollonMutex sync.Mutex
92
+
93
+ proxyCheckInterval time.Duration
94
+ proxyTimeout time.Duration
95
+ configMutex sync.Mutex
92
96
}
93
97
94
98
func NewClusterChecker (uid string , cfg config ) (* ClusterChecker , error ) {
@@ -104,6 +108,9 @@ func NewClusterChecker(uid string, cfg config) (*ClusterChecker, error) {
104
108
stopListening : cfg .stopListening ,
105
109
e : e ,
106
110
endPollonProxyCh : make (chan error ),
111
+
112
+ proxyCheckInterval : cluster .DefaultProxyCheckInterval ,
113
+ proxyTimeout : cluster .DefaultProxyTimeout ,
107
114
}, nil
108
115
}
109
116
@@ -164,15 +171,16 @@ func (c *ClusterChecker) sendPollonConfData(confData pollon.ConfData) {
164
171
}
165
172
}
166
173
167
- func (c * ClusterChecker ) SetProxyInfo (e store.Store , generation int64 , ttl time.Duration ) error {
174
+ func (c * ClusterChecker ) SetProxyInfo (e store.Store , generation int64 , proxyTimeout time.Duration ) error {
168
175
proxyInfo := & cluster.ProxyInfo {
169
- InfoUID : common .UID (),
170
- UID : c .uid ,
171
- Generation : generation ,
176
+ InfoUID : common .UID (),
177
+ UID : c .uid ,
178
+ Generation : generation ,
179
+ ProxyTimeout : proxyTimeout ,
172
180
}
173
181
log .Debugf ("proxyInfo dump: %s" , spew .Sdump (proxyInfo ))
174
182
175
- if err := c .e .SetProxyInfo (context .TODO (), proxyInfo , ttl ); err != nil {
183
+ if err := c .e .SetProxyInfo (context .TODO (), proxyInfo , 2 * proxyTimeout ); err != nil {
176
184
return err
177
185
}
178
186
return nil
@@ -205,13 +213,31 @@ func (c *ClusterChecker) Check() error {
205
213
return fmt .Errorf ("clusterdata validation failed: %v" , err )
206
214
}
207
215
216
+ cdProxyCheckInterval := cd .Cluster .DefSpec ().ProxyCheckInterval .Duration
217
+ cdProxyTimeout := cd .Cluster .DefSpec ().ProxyTimeout .Duration
218
+
219
+ // use the greater between the current proxy timeout and the one defined in the cluster spec if they're different.
220
+ // in this way we're updating our proxyInfo using a timeout that is greater or equal the current active timeout timer.
221
+ c .configMutex .Lock ()
222
+ proxyTimeout := c .proxyTimeout
223
+ if cdProxyTimeout > proxyTimeout {
224
+ proxyTimeout = cdProxyTimeout
225
+ }
226
+ c .configMutex .Unlock ()
227
+
208
228
proxy := cd .Proxy
209
229
if proxy == nil {
210
230
log .Infow ("no proxy object available, closing connections to master" )
211
231
c .sendPollonConfData (pollon.ConfData {DestAddr : nil })
212
232
// ignore errors on setting proxy info
213
- if err = c .SetProxyInfo (c .e , cluster .NoGeneration , 2 * cluster . DefaultProxyTimeoutInterval ); err != nil {
233
+ if err = c .SetProxyInfo (c .e , cluster .NoGeneration , proxyTimeout ); err != nil {
214
234
log .Errorw ("failed to update proxyInfo" , zap .Error (err ))
235
+ } else {
236
+ // update proxyCheckinterval and proxyTimeout only if we successfully updated our proxy info
237
+ c .configMutex .Lock ()
238
+ c .proxyCheckInterval = cdProxyCheckInterval
239
+ c .proxyTimeout = cdProxyTimeout
240
+ c .configMutex .Unlock ()
215
241
}
216
242
return nil
217
243
}
@@ -221,8 +247,14 @@ func (c *ClusterChecker) Check() error {
221
247
log .Infow ("no db object available, closing connections to master" , "db" , proxy .Spec .MasterDBUID )
222
248
c .sendPollonConfData (pollon.ConfData {DestAddr : nil })
223
249
// ignore errors on setting proxy info
224
- if err = c .SetProxyInfo (c .e , proxy .Generation , 2 * cluster . DefaultProxyTimeoutInterval ); err != nil {
250
+ if err = c .SetProxyInfo (c .e , proxy .Generation , proxyTimeout ); err != nil {
225
251
log .Errorw ("failed to update proxyInfo" , zap .Error (err ))
252
+ } else {
253
+ // update proxyCheckinterval and proxyTimeout only if we successfully updated our proxy info
254
+ c .configMutex .Lock ()
255
+ c .proxyCheckInterval = cdProxyCheckInterval
256
+ c .proxyTimeout = cdProxyTimeout
257
+ c .configMutex .Unlock ()
226
258
}
227
259
return nil
228
260
}
@@ -234,12 +266,18 @@ func (c *ClusterChecker) Check() error {
234
266
return nil
235
267
}
236
268
log .Infow ("master address" , "address" , addr )
237
- if err = c .SetProxyInfo (c .e , proxy .Generation , 2 * cluster . DefaultProxyTimeoutInterval ); err != nil {
269
+ if err = c .SetProxyInfo (c .e , proxy .Generation , proxyTimeout ); err != nil {
238
270
// if we failed to update our proxy info when a master is defined we
239
271
// cannot ignore this error since the sentinel won't know that we exist
240
272
// and are sending connections to a master so, when electing a new
241
273
// master, it'll not wait for us to close connections to the old one.
242
274
return fmt .Errorf ("failed to update proxyInfo: %v" , err )
275
+ } else {
276
+ // update proxyCheckinterval and proxyTimeout only if we successfully updated our proxy info
277
+ c .configMutex .Lock ()
278
+ c .proxyCheckInterval = cdProxyCheckInterval
279
+ c .proxyTimeout = cdProxyTimeout
280
+ c .configMutex .Unlock ()
243
281
}
244
282
245
283
// start proxing only if we are inside enabledProxies, this ensures that the
@@ -256,7 +294,9 @@ func (c *ClusterChecker) Check() error {
256
294
}
257
295
258
296
func (c * ClusterChecker ) TimeoutChecker (checkOkCh chan struct {}) {
259
- timeoutTimer := time .NewTimer (cluster .DefaultProxyTimeoutInterval )
297
+ c .configMutex .Lock ()
298
+ timeoutTimer := time .NewTimer (c .proxyTimeout )
299
+ c .configMutex .Unlock ()
260
300
261
301
for {
262
302
select {
@@ -275,7 +315,10 @@ func (c *ClusterChecker) TimeoutChecker(checkOkCh chan struct{}) {
275
315
276
316
// ignore if stop succeeded or not due to timer already expired
277
317
timeoutTimer .Stop ()
278
- timeoutTimer = time .NewTimer (cluster .DefaultProxyTimeoutInterval )
318
+
319
+ c .configMutex .Lock ()
320
+ timeoutTimer = time .NewTimer (c .proxyTimeout )
321
+ c .configMutex .Unlock ()
279
322
}
280
323
}
281
324
}
@@ -305,7 +348,10 @@ func (c *ClusterChecker) Start() error {
305
348
// report that check was ok
306
349
checkOkCh <- struct {}{}
307
350
}
308
- timerCh = time .NewTimer (cluster .DefaultProxyCheckInterval ).C
351
+ c .configMutex .Lock ()
352
+ timerCh = time .NewTimer (c .proxyCheckInterval ).C
353
+ c .configMutex .Unlock ()
354
+
309
355
case err := <- c .endPollonProxyCh :
310
356
if err != nil {
311
357
return fmt .Errorf ("proxy error: %v" , err )
0 commit comments