@@ -136,7 +136,11 @@ func (w *Worker) stepBatch() error {
136136}
137137
138138func (w * Worker ) StepBatchByTimeSplitKey () error {
139- wg := & sync.WaitGroup {}
139+ // Time-based splitting uses LIMIT/OFFSET over a non-unique, mutable key,
140+ // so running multiple goroutines risks duplicates/omissions.
141+ if w .Cfg .MaxThread > 1 {
142+ return fmt .Errorf ("time split does not support MaxThread > 1; use auto increment split key" )
143+ }
140144 minSplitKey , maxSplitKey , err := w .Src .GetMinMaxTimeSplitKey ()
141145 if err != nil {
142146 return err
@@ -150,36 +154,22 @@ func (w *Worker) StepBatchByTimeSplitKey() error {
150154 }
151155 fmt .Println ("allConditions: " , len (allConditions ))
152156 fmt .Println ("all split conditions" , allConditions )
153- slimedRange := source .SplitTimeConditionsByMaxThread (allConditions , w .Cfg .MaxThread )
154- fmt .Println (len (slimedRange ))
155- fmt .Println ("slimedRange" , slimedRange )
156- wg .Add (w .Cfg .MaxThread )
157- for i := 0 ; i < 1 ; i ++ {
158- go func (idx int ) {
159- defer wg .Done ()
160- conditions := slimedRange [idx ]
161- logrus .Infof ("conditions in one routine: %d" , len (conditions ))
162- if err != nil {
163- logrus .Errorf ("stepBatchWithCondition failed: %v" , err )
164- }
165- for _ , condition := range conditions {
166- logrus .Infof ("condition: %s" , condition )
167- switch w .Cfg .DatabaseType {
168- case "mysql" :
169- err = w .stepBatchWithTimeCondition (condition , w .Cfg .BatchSize )
170- case "mssql" :
171- err = w .stepBatchWithTimeConditionMssql (condition , w .Cfg .BatchSize )
172- default :
173- err = w .stepBatchWithTimeCondition (condition , w .Cfg .BatchSize )
174- }
175- if err != nil {
176- logrus .Errorf ("stepBatchWithCondition failed: %v" , err )
177- }
178- }
179- }(i )
180- }
181- wg .Wait ()
182157
158+ for _ , condition := range allConditions {
159+ logrus .Infof ("condition: %s" , condition )
160+ switch w .Cfg .DatabaseType {
161+ case "mysql" :
162+ err = w .stepBatchWithTimeCondition (condition , w .Cfg .BatchSize )
163+ case "mssql" :
164+ err = w .stepBatchWithTimeConditionMssql (condition , w .Cfg .BatchSize )
165+ default :
166+ err = w .stepBatchWithTimeCondition (condition , w .Cfg .BatchSize )
167+ }
168+ if err != nil {
169+ logrus .Errorf ("stepBatchWithCondition failed: %v" , err )
170+ return err
171+ }
172+ }
183173 return nil
184174}
185175
0 commit comments