@@ -18,8 +18,8 @@ import (
1818 "github.com/gosuri/uiprogress"
1919 "github.com/kr/pretty"
2020
21- log "github.com/sirupsen/logrus"
22- kingpin "gopkg.in/alecthomas/kingpin.v2"
21+ "github.com/sirupsen/logrus"
22+ "gopkg.in/alecthomas/kingpin.v2"
2323)
2424
2525type cliOptions struct {
@@ -55,10 +55,7 @@ type mysqlOptions struct {
5555}
5656
5757var (
58- opts * cliOptions
59-
60- validFunctions = []string {"int" , "string" , "date" , "date_in_range" }
61- maxValues = map [string ]int64 {
58+ maxValues = map [string ]int64 {
6259 "tinyint" : 0xF ,
6360 "smallint" : 0xFF ,
6461 "mediumint" : 0x7FFFF ,
@@ -95,7 +92,7 @@ func main() {
9592
9693 opts , err := processCliParams ()
9794 if err != nil {
98- log .Fatal (err .Error ())
95+ logrus .Fatal (err .Error ())
9996 }
10097
10198 if * opts .Version {
@@ -134,36 +131,36 @@ func main() {
134131
135132 // SET TimeZone to UTC to avoid errors due to random dates & daylight saving valid values
136133 if _ , err = db .Exec (`SET @@session.time_zone = "+00:00"` ); err != nil {
137- log .Printf ("Cannot set time zone to UTC: %s\n " , err )
134+ logrus .Printf ("Cannot set time zone to UTC: %s\n " , err )
138135 db .Close ()
139136 os .Exit (1 )
140137 }
141138
142139 table , err := tableparser .NewTable (db , * opts .Schema , * opts .TableName )
143140 if err != nil {
144- log .Printf ("cannot get table %s struct: %s" , * opts .TableName , err )
141+ logrus .Printf ("cannot get table %s struct: %s" , * opts .TableName , err )
145142 db .Close ()
146143 os .Exit (1 )
147144 }
148145
149- log .SetFormatter (& log .TextFormatter {FullTimestamp : true })
146+ logrus .SetFormatter (& logrus .TextFormatter {FullTimestamp : true })
150147 if * opts .Debug {
151- log .SetLevel (log .DebugLevel )
148+ logrus .SetLevel (logrus .DebugLevel )
152149 * opts .NoProgress = true
153150 }
154- log .Debug (pretty .Sprint (table ))
151+ logrus .Debug (pretty .Sprint (table ))
155152
156153 if len (table .Triggers ) > 0 {
157- log .Warnf ("There are triggers on the %s table that might affect this process:" , * opts .TableName )
154+ logrus .Warnf ("There are triggers on the %s table that might affect this process:" , * opts .TableName )
158155 for _ , t := range table .Triggers {
159- log .Warnf ("Trigger %q, %s %s" , t .Trigger , t .Timing , t .Event )
160- log .Warnf ("Statement: %s" , t .Statement )
156+ logrus .Warnf ("Trigger %q, %s %s" , t .Trigger , t .Timing , t .Event )
157+ logrus .Warnf ("Statement: %s" , t .Statement )
161158 }
162159 }
163160
164161 if * opts .Rows < 1 {
165162 db .Close () // golint:noerror
166- log .Warnf ("Number of rows < 1. There is nothing to do. Exiting" )
163+ logrus .Warnf ("Number of rows < 1. There is nothing to do. Exiting" )
167164 os .Exit (1 )
168165 }
169166
@@ -183,7 +180,7 @@ func main() {
183180 }
184181
185182 if ! * opts .Print {
186- log .Info ("Starting" )
183+ logrus .Info ("Starting" )
187184 }
188185
189186 // Example: want 11 rows with bulksize 4:
@@ -198,7 +195,7 @@ func main() {
198195 remainder := * opts .Rows - count * * opts .BulkSize
199196 semaphores := makeSemaphores (* opts .MaxThreads )
200197 rowValues := makeValueFuncs (db , table .Fields , * opts .Samples )
201- log .Debugf ("Must run %d bulk inserts having %d rows each" , count , * opts .BulkSize )
198+ logrus .Debugf ("Must run %d bulk inserts having %d rows each" , count , * opts .BulkSize )
202199
203200 runInsertFunc := runInsert
204201 if * opts .Print {
@@ -220,14 +217,14 @@ func main() {
220217
221218 okCount , err := run (db , table , bar , semaphores , rowValues , count , * opts .BulkSize , runInsertFunc , newLineOnEachRow )
222219 if err != nil {
223- log .Errorln (err )
220+ logrus .Errorln (err )
224221 }
225222 var okrCount , okiCount int // remainder & individual inserts OK count
226223 if remainder > 0 {
227- log .Debugf ("Must run 1 extra bulk insert having %d rows, to complete %d rows" , remainder , * opts .Rows )
224+ logrus .Debugf ("Must run 1 extra bulk insert having %d rows, to complete %d rows" , remainder , * opts .Rows )
228225 okrCount , err = run (db , table , bar , semaphores , rowValues , 1 , remainder , runInsertFunc , newLineOnEachRow )
229226 if err != nil {
230- log .Errorln (err )
227+ logrus .Errorln (err )
231228 }
232229 }
233230
@@ -236,12 +233,12 @@ func main() {
236233 totalOkCount := okCount + okrCount
237234 retries := 0
238235 if totalOkCount < * opts .Rows {
239- log .Debugf ("Running extra %d individual inserts (duplicated keys?)" , * opts .Rows - totalOkCount )
236+ logrus .Debugf ("Running extra %d individual inserts (duplicated keys?)" , * opts .Rows - totalOkCount )
240237 }
241238 for totalOkCount < * opts .Rows && retries < * opts .MaxRetries {
242239 okiCount , err = run (db , table , bar , semaphores , rowValues , * opts .Rows - totalOkCount , 1 , runInsertFunc , newLineOnEachRow )
243240 if err != nil {
244- log .Errorf ("Cannot run extra insert: %s" , err )
241+ logrus .Errorf ("Cannot run extra insert: %s" , err )
245242 }
246243
247244 retries ++
@@ -250,7 +247,7 @@ func main() {
250247
251248 time .Sleep (500 * time .Millisecond ) // Let the progress bar to update
252249 if ! * opts .Print {
253- log .Printf ("%d rows inserted" , totalOkCount )
250+ logrus .Printf ("%d rows inserted" , totalOkCount )
254251 }
255252 db .Close ()
256253}
@@ -370,7 +367,7 @@ func generateInsertStmt(table *tableparser.Table) string {
370367func runInsert (db * sql.DB , insertQuery string , resultsChan chan int , sem chan bool , wg * sync.WaitGroup ) {
371368 result , err := db .Exec (insertQuery )
372369 if err != nil {
373- log .Debugf ("Cannot run insert: %s" , err )
370+ logrus .Debugf ("Cannot run insert: %s" , err )
374371 resultsChan <- 0
375372 sem <- true
376373 wg .Done ()
@@ -379,7 +376,7 @@ func runInsert(db *sql.DB, insertQuery string, resultsChan chan int, sem chan bo
379376
380377 rowsAffected , err := result .RowsAffected ()
381378 if err != nil {
382- log .Errorf ("Cannot get rows affected after insert: %s" , err )
379+ logrus .Errorf ("Cannot get rows affected after insert: %s" , err )
383380 }
384381 resultsChan <- int (rowsAffected )
385382 sem <- true
@@ -399,7 +396,7 @@ func makeValueFuncs(conn *sql.DB, fields []tableparser.Field, samples int64) ins
399396 field .Constraint .ReferencedColumnName ,
400397 samples , field .DataType )
401398 if err != nil {
402- log .Printf ("cannot get samples for field %q: %s\n " , field .ColumnName , err )
399+ logrus .Printf ("cannot get samples for field %q: %s\n " , field .ColumnName , err )
403400 continue
404401 }
405402 values = append (values , getters .NewRandomSample (field .ColumnName , samples , field .IsNullable ))
@@ -435,7 +432,7 @@ func makeValueFuncs(conn *sql.DB, fields []tableparser.Field, samples int64) ins
435432 case "binary" , "varbinary" :
436433 values = append (values , getters .NewRandomBinary (field .ColumnName , field .CharacterMaximumLength .Int64 , field .IsNullable ))
437434 default :
438- log .Printf ("cannot get field type: %s: %s\n " , field .ColumnName , field .DataType )
435+ logrus .Printf ("cannot get field type: %s: %s\n " , field .ColumnName , field .DataType )
439436 }
440437 }
441438
0 commit comments