@@ -54,9 +54,9 @@ func GetBindEvict() *BindEvict {
54
54
}
55
55
return cfg .(* BindEvict )
56
56
}
57
- func (this * BindEvict ) Copy () * BindEvict {
57
+ func (bindEvict * BindEvict ) Copy () * BindEvict {
58
58
out := BindEvict {BindThrottle :make (map [uint32 ]map [string ]* BindThrottle )}
59
- for k ,v := range this .BindThrottle {
59
+ for k ,v := range bindEvict .BindThrottle {
60
60
out .BindThrottle [k ] = v
61
61
}
62
62
return & out
@@ -85,41 +85,44 @@ func (entry *BindThrottle) decrAllowEveryX(y int) {
85
85
return
86
86
}
87
87
entry .AllowEveryX = 0
88
- GetBindEvict ().lock .Lock ()
89
- defer GetBindEvict ().lock .Unlock ()
88
+ }
89
+ func (entry * BindThrottle ) incrAllowEveryX () {
90
+ if logger .GetLogger ().V (logger .Warning ) {
91
+ info := fmt .Sprintf ("hash:%d bindName:%s val:%s prev:%d" ,entry .Sqlhash , entry .Name , entry .Value , entry .AllowEveryX )
92
+ logger .GetLogger ().Log (logger .Warning , "bind throttle incr" , info )
93
+ }
94
+ entry .AllowEveryX = 3 * entry .AllowEveryX + 1
95
+ if entry .AllowEveryX > 10000 {
96
+ entry .AllowEveryX = 10000
97
+ }
98
+ }
99
+
100
+ func (bindEvict * BindEvict ) updateThrottle (entry * BindThrottle ) {
90
101
// delete entry
91
- if len (GetBindEvict () .BindThrottle [entry .Sqlhash ]) == 1 {
92
- updateCopy := GetBindEvict () .Copy ()
102
+ if len (bindEvict .BindThrottle [entry .Sqlhash ]) == 1 {
103
+ updateCopy := bindEvict .Copy ()
93
104
delete (updateCopy .BindThrottle , entry .Sqlhash )
94
105
gBindEvict .Store (updateCopy )
95
106
} else {
96
107
// copy everything except bindKV (skipping it is deleting it)
97
108
bindKV := fmt .Sprintf ("%s|%s" , entry .Name , entry .Value )
98
- updateCopy := make (map [string ]* BindThrottle )
99
- for k ,v := range GetBindEvict ().BindThrottle [entry .Sqlhash ] {
109
+ updateCopy := bindEvict .Copy ()
110
+ updateBindThrottleCopy := make (map [string ]* BindThrottle )
111
+ for k ,v := range bindEvict .BindThrottle [entry .Sqlhash ] {
100
112
if k == bindKV {
101
113
continue
102
114
}
103
- updateCopy [k ] = v
115
+ updateBindThrottleCopy [k ] = v
104
116
}
105
- GetBindEvict ().BindThrottle [entry .Sqlhash ] = updateCopy
106
- }
107
- }
108
- func (entry * BindThrottle ) incrAllowEveryX () {
109
- if logger .GetLogger ().V (logger .Warning ) {
110
- info := fmt .Sprintf ("hash:%d bindName:%s val:%s prev:%d" ,entry .Sqlhash , entry .Name , entry .Value , entry .AllowEveryX )
111
- logger .GetLogger ().Log (logger .Warning , "bind throttle incr" , info )
112
- }
113
- entry .AllowEveryX = 3 * entry .AllowEveryX + 1
114
- if entry .AllowEveryX > 10000 {
115
- entry .AllowEveryX = 10000
117
+ updateCopy .BindThrottle [entry .Sqlhash ] = updateBindThrottleCopy
118
+ gBindEvict .Store (updateCopy )
116
119
}
117
120
}
118
121
119
- func (be * BindEvict ) ShouldBlock (sqlhash uint32 , bindKV map [string ]string , heavyUsage bool ) (bool , * BindThrottle ) {
120
- GetBindEvict () .lock .Lock ()
121
- sqlBinds := GetBindEvict (). BindThrottle [ sqlhash ]
122
- GetBindEvict (). lock . Unlock ()
122
+ func (bindEvict * BindEvict ) ShouldBlock (sqlhash uint32 , bindKV map [string ]string , heavyUsage bool ) (bool , * BindThrottle ) {
123
+ bindEvict .lock .Lock ()
124
+ defer bindEvict . lock . Unlock ()
125
+ sqlBinds := bindEvict . BindThrottle [ sqlhash ]
123
126
for k0 , v := range bindKV /*parseBinds(request)*/ {
124
127
k := NormalizeBindName (k0 )
125
128
concatKey := fmt .Sprintf ("%s|%s" , k , v )
@@ -143,6 +146,7 @@ func (be *BindEvict) ShouldBlock(sqlhash uint32, bindKV map[string]string, heavy
143
146
gap := now .Sub (* recent ).Seconds () * GetConfig ().BindEvictionDecrPerSec
144
147
entry .decrAllowEveryX (int (gap ))
145
148
if entry .AllowEveryX == 0 {
149
+ bindEvict .updateThrottle (entry )
146
150
return false , nil
147
151
}
148
152
0 commit comments