@@ -21,8 +21,8 @@ import (
21
21
"errors"
22
22
"fmt"
23
23
"math/rand"
24
- "sync/atomic"
25
24
"strings"
25
+ "sync/atomic"
26
26
"time"
27
27
28
28
"github.com/paypal/hera/cal"
@@ -118,28 +118,31 @@ type BindCount struct {
118
118
Workers map [string ]* WorkerClient // lookup by ticket
119
119
}
120
120
121
- func bindEvictNameOk (bindName string ) ( bool ) {
121
+ func bindEvictNameOk (bindName string ) bool {
122
122
commaNames := GetConfig ().BindEvictionNames
123
123
if len (commaNames ) == 0 {
124
124
// for tests, allow all names to be subject to bind eviction
125
125
return true
126
126
}
127
127
commaNames = strings .ToLower (commaNames )
128
128
bindName = strings .ToLower (bindName )
129
- for _ , okSubname := range strings .Split (commaNames ,"," ) {
129
+ for _ , okSubname := range strings .Split (commaNames , "," ) {
130
130
if strings .Contains (bindName , okSubname ) {
131
131
return true
132
132
}
133
133
}
134
134
return false
135
135
}
136
136
137
- /* A bad query with multiple binds will add independent bind throttles to all
138
- bind name and values */
139
- func (mgr * adaptiveQueueManager ) doBindEviction () (int ) {
137
+ /*
138
+ A bad query with multiple binds will add independent bind throttles to all
139
+
140
+ bind name and values
141
+ */
142
+ func (mgr * adaptiveQueueManager ) doBindEviction () int {
140
143
throttleCount := 0
141
144
GetBindEvict ().lock .Lock ()
142
- for _ ,keyValues := range GetBindEvict ().BindThrottle {
145
+ for _ , keyValues := range GetBindEvict ().BindThrottle {
143
146
throttleCount += len (keyValues )
144
147
}
145
148
GetBindEvict ().lock .Unlock ()
@@ -172,14 +175,14 @@ func (mgr *adaptiveQueueManager) doBindEviction() (int) {
172
175
}
173
176
continue
174
177
}
175
- contextBinds := parseBinds (request )
176
- sqlsrcPrefix := worker .clientHostPrefix .Load ().(string )
177
- sqlsrcApp := worker .clientApp .Load ().(string )
178
+ contextBinds := parseBinds (request )
179
+ sqlsrcPrefix := worker .clientHostPrefix .Load ().(string )
180
+ sqlsrcApp := worker .clientApp .Load ().(string )
178
181
if sqlsrcPrefix != "" {
179
182
contextBinds [SrcPrefixAppKey ] = fmt .Sprintf ("%s%s" , sqlsrcPrefix , sqlsrcApp )
180
183
if logger .GetLogger ().V (logger .Debug ) {
181
- msg := fmt .Sprintf ("Req info: Add AZ+App to contextBinds: %s" , contextBinds [SrcPrefixAppKey ])
182
- logger .GetLogger ().Log (logger .Debug , msg )
184
+ msg := fmt .Sprintf ("Req info: Add AZ+App to contextBinds: %s" , contextBinds [SrcPrefixAppKey ])
185
+ logger .GetLogger ().Log (logger .Debug , msg )
183
186
}
184
187
}
185
188
for bindName0 , bindValue := range contextBinds {
@@ -200,8 +203,8 @@ func (mgr *adaptiveQueueManager) doBindEviction() (int) {
200
203
}
201
204
concatKey := fmt .Sprintf ("%d|%s|%s" , sqlhash , bindName , bindValue )
202
205
if logger .GetLogger ().V (logger .Debug ) {
203
- msg := fmt .Sprintf ("Req info: lookup concatKey = %s in bindCounts" , concatKey )
204
- logger .GetLogger ().Log (logger .Debug , msg )
206
+ msg := fmt .Sprintf ("Req info: lookup concatKey = %s in bindCounts" , concatKey )
207
+ logger .GetLogger ().Log (logger .Debug , msg )
205
208
}
206
209
entry , ok := bindCounts [concatKey ]
207
210
if ! ok {
@@ -210,7 +213,7 @@ func (mgr *adaptiveQueueManager) doBindEviction() (int) {
210
213
Name : bindName ,
211
214
Value : bindValue ,
212
215
Workers : make (map [string ]* WorkerClient ),
213
- }
216
+ }
214
217
bindCounts [concatKey ] = entry
215
218
}
216
219
@@ -227,7 +230,7 @@ func (mgr *adaptiveQueueManager) doBindEviction() (int) {
227
230
bindName := entry .Name
228
231
bindValue := entry .Value
229
232
230
- if len (entry .Workers ) < int ( float64 (GetConfig ().BindEvictionThresholdPct )/ 100. * float64 (numDispatchedWorkers ) ) {
233
+ if len (entry .Workers ) < int (float64 (GetConfig ().BindEvictionThresholdPct )/ 100. * float64 (numDispatchedWorkers )) {
231
234
continue
232
235
}
233
236
// evict sqlhash, bindvalue
@@ -241,7 +244,7 @@ func (mgr *adaptiveQueueManager) doBindEviction() (int) {
241
244
242
245
if mgr .dispatchedWorkers [worker ] != ticket ||
243
246
worker .Status == wsFnsh ||
244
- worker .isUnderRecovery == 1 /* Recover() uses compare & swap */ {
247
+ atomic . LoadInt32 ( & worker .isUnderRecovery ) == 1 /* Recover() uses compare & swap */ {
245
248
246
249
continue
247
250
}
@@ -274,10 +277,10 @@ func (mgr *adaptiveQueueManager) doBindEviction() (int) {
274
277
throttle .incrAllowEveryX ()
275
278
} else {
276
279
throttle := BindThrottle {
277
- Name : bindName ,
278
- Value : bindValue ,
279
- Sqlhash : sqlhash ,
280
- AllowEveryX : 3 * len (entry .Workers ) + 1 ,
280
+ Name : bindName ,
281
+ Value : bindValue ,
282
+ Sqlhash : sqlhash ,
283
+ AllowEveryX : 3 * len (entry .Workers ) + 1 ,
281
284
}
282
285
now := time .Now ()
283
286
throttle .RecentAttempt .Store (& now )
@@ -464,7 +467,7 @@ func (mgr *adaptiveQueueManager) getWorkerToRecover() (*WorkerClient, bool) {
464
467
}
465
468
}
466
469
} else {
467
- if worker != nil && worker .Status == wsFnsh {
470
+ if worker != nil && worker .Status == wsFnsh {
468
471
if logger .GetLogger ().V (logger .Warning ) {
469
472
logger .GetLogger ().Log (logger .Warning , "worker.pid state is in FNSH, so skipping" , worker .pid )
470
473
}
0 commit comments