Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Apr 19, 2022
1 parent dbac5f1 commit dab6419
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
21 changes: 10 additions & 11 deletions ddl/ddl_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,23 +526,20 @@ func (c *testCase) execParaDDLSQL(taskCh chan *ddlJobTask, num int) error {
defer wg.Done()
opStart := time.Now()
db := c.pickupDB()
err := c.executeWithTimeout(db, task)
if !ddlIgnoreError(err) {
log.Infof("[ddl] [instance %d] TiDB execute %s , err %v, elapsed time:%v", c.caseIndex, task.sql, err, time.Since(opStart).Seconds())
task.err = err
db := c.dbs[0]
conn, err := db.Conn(context.Background())
if err != nil {
unExpectedErr = err
return
}
defer func() {
err := conn.Close()
if err != nil {
log.Errorf("error when closes conn %s", err.Error())
}
}()
if err != nil {
unExpectedErr = err
return
}
_, ddlErr := conn.ExecContext(context.Background(), task.sql)
ddlErr := c.executeWithTimeout(task, func(ctx context.Context, s string) (sql.Result, error) {
return conn.ExecContext(ctx, s)
})
if !ddlIgnoreError(ddlErr) {
log.Infof("[ddl] [instance %d] TiDB execute %s , err %v, elapsed time:%v", c.caseIndex, task.sql, err, time.Since(opStart).Seconds())
task.err = ddlErr
Expand Down Expand Up @@ -626,7 +623,9 @@ func (c *testCase) execSerialDDLSQL(taskCh chan *ddlJobTask) error {
task := <-taskCh
db := c.pickupDB()
opStart := time.Now()
err := c.executeWithTimeout(db, task)
err := c.executeWithTimeout(task, func(ctx context.Context, s string) (sql.Result, error) {
return db.ExecContext(ctx, task.sql)
})
log.Infof("[ddl] [instance %d] %s, err: %v, elapsed time:%v", c.caseIndex, task.sql, err, time.Since(opStart).Seconds())
if err != nil {
if ddlIgnoreError(err) {
Expand Down
5 changes: 2 additions & 3 deletions ddl/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type testCase struct {
lastDDLID int
charsets []string
charsetsCollates map[string][]string
updateSchemaMu sync.Mutex
}

type ddlTestErrorConflict struct {
Expand Down Expand Up @@ -104,7 +103,7 @@ func (c *testCase) pickupDB() *sql.DB {
return c.dbs[rand.Intn(len(c.dbs)-1)]
}

func (c *testCase) executeWithTimeout(db *sql.DB, task *ddlJobTask) error {
func (c *testCase) executeWithTimeout(task *ddlJobTask, f func(ctx context.Context, s string) (sql.Result, error)) error {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(30)))
t := time.Second * 30
switch task.k {
Expand All @@ -116,7 +115,7 @@ func (c *testCase) executeWithTimeout(db *sql.DB, task *ddlJobTask) error {
t = t * time.Duration(runningDDLCount)
ctx, cancel := context.WithTimeout(context.Background(), t)
defer cancel()
_, err := db.ExecContext(ctx, task.sql)
_, err := f(ctx, task.sql)
return errors.Annotate(err, task.sql)
}

Expand Down

0 comments on commit dab6419

Please sign in to comment.