@@ -7,7 +7,6 @@ package base
7
7
8
8
import (
9
9
"fmt"
10
- "strconv"
11
10
"strings"
12
11
"sync"
13
12
"sync/atomic"
@@ -65,9 +64,10 @@ type MigrationContext struct {
65
64
ThrottleControlReplicaKeys * mysql.InstanceKeyMap
66
65
ThrottleFlagFile string
67
66
ThrottleAdditionalFlagFile string
67
+ ThrottleQuery string
68
68
ThrottleCommandedByUser int64
69
- maxLoad map [ string ] int64
70
- maxLoadMutex * sync. Mutex
69
+ maxLoad LoadMap
70
+ criticalLoad LoadMap
71
71
PostponeCutOverFlagFile string
72
72
SwapTablesTimeoutSeconds int64
73
73
PanicFlagFile string
@@ -148,8 +148,8 @@ func newMigrationContext() *MigrationContext {
148
148
ApplierConnectionConfig : mysql .NewConnectionConfig (),
149
149
MaxLagMillisecondsThrottleThreshold : 1000 ,
150
150
SwapTablesTimeoutSeconds : 3 ,
151
- maxLoad : make ( map [ string ] int64 ),
152
- maxLoadMutex : & sync. Mutex {} ,
151
+ maxLoad : NewLoadMap ( ),
152
+ criticalLoad : NewLoadMap () ,
153
153
throttleMutex : & sync.Mutex {},
154
154
ThrottleControlReplicaKeys : mysql .NewInstanceKeyMap (),
155
155
configMutex : & sync.Mutex {},
@@ -278,46 +278,64 @@ func (this *MigrationContext) IsThrottled() (bool, string) {
278
278
return this .isThrottled , this .throttleReason
279
279
}
280
280
281
- func (this * MigrationContext ) GetMaxLoad () map [string ]int64 {
282
- this .maxLoadMutex .Lock ()
283
- defer this .maxLoadMutex .Unlock ()
281
+ func (this * MigrationContext ) GetThrottleQuery () string {
282
+ var query string
284
283
285
- tmpMaxLoadMap := make (map [string ]int64 )
286
- for k , v := range this .maxLoad {
287
- tmpMaxLoadMap [k ] = v
288
- }
289
- return tmpMaxLoadMap
284
+ this .throttleMutex .Lock ()
285
+ defer this .throttleMutex .Unlock ()
286
+
287
+ query = this .ThrottleQuery
288
+ return query
289
+ }
290
+
291
+ func (this * MigrationContext ) SetThrottleQuery (newQuery string ) {
292
+ this .throttleMutex .Lock ()
293
+ defer this .throttleMutex .Unlock ()
294
+
295
+ this .ThrottleQuery = newQuery
296
+ }
297
+
298
+ func (this * MigrationContext ) GetMaxLoad () LoadMap {
299
+ this .throttleMutex .Lock ()
300
+ defer this .throttleMutex .Unlock ()
301
+
302
+ return this .maxLoad .Duplicate ()
303
+ }
304
+
305
+ func (this * MigrationContext ) GetCriticalLoad () LoadMap {
306
+ this .throttleMutex .Lock ()
307
+ defer this .throttleMutex .Unlock ()
308
+
309
+ return this .criticalLoad .Duplicate ()
290
310
}
291
311
292
312
// ReadMaxLoad parses the `--max-load` flag, which is in multiple key-value format,
293
313
// such as: 'Threads_running=100,Threads_connected=500'
294
314
// It only applies changes in case there's no parsing error.
295
315
func (this * MigrationContext ) ReadMaxLoad (maxLoadList string ) error {
296
- if maxLoadList == "" {
297
- return nil
316
+ loadMap , err := ParseLoadMap (maxLoadList )
317
+ if err != nil {
318
+ return err
298
319
}
299
- this .maxLoadMutex .Lock ()
300
- defer this .maxLoadMutex .Unlock ()
320
+ this .throttleMutex .Lock ()
321
+ defer this .throttleMutex .Unlock ()
301
322
302
- tmpMaxLoadMap := make (map [string ]int64 )
323
+ this .maxLoad = loadMap
324
+ return nil
325
+ }
303
326
304
- maxLoadConditions := strings .Split (maxLoadList , "," )
305
- for _ , maxLoadCondition := range maxLoadConditions {
306
- maxLoadTokens := strings .Split (maxLoadCondition , "=" )
307
- if len (maxLoadTokens ) != 2 {
308
- return fmt .Errorf ("Error parsing max-load condition: %s" , maxLoadCondition )
309
- }
310
- if maxLoadTokens [0 ] == "" {
311
- return fmt .Errorf ("Error parsing status variable in max-load condition: %s" , maxLoadCondition )
312
- }
313
- if n , err := strconv .ParseInt (maxLoadTokens [1 ], 10 , 0 ); err != nil {
314
- return fmt .Errorf ("Error parsing numeric value in max-load condition: %s" , maxLoadCondition )
315
- } else {
316
- tmpMaxLoadMap [maxLoadTokens [0 ]] = n
317
- }
327
+ // ReadMaxLoad parses the `--max-load` flag, which is in multiple key-value format,
328
+ // such as: 'Threads_running=100,Threads_connected=500'
329
+ // It only applies changes in case there's no parsing error.
330
+ func (this * MigrationContext ) ReadCriticalLoad (criticalLoadList string ) error {
331
+ loadMap , err := ParseLoadMap (criticalLoadList )
332
+ if err != nil {
333
+ return err
318
334
}
335
+ this .throttleMutex .Lock ()
336
+ defer this .throttleMutex .Unlock ()
319
337
320
- this .maxLoad = tmpMaxLoadMap
338
+ this .criticalLoad = loadMap
321
339
return nil
322
340
}
323
341
0 commit comments