Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: Make column test stable and fix prepare statement issue #2473

Merged
merged 3 commits into from
Jan 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,19 @@ LOOP:
// delete some rows, and add some data
for i := num; i < num+step; i++ {
n := rand.Intn(num)
s.tk.MustExec("begin")
s.tk.MustExec("delete from t2 where c1 = ?", n)
s.tk.MustExec("commit")

// Make sure that statement of insert and show use the same infoSchema.
s.tk.MustExec("begin")
_, err := s.tk.Exec("insert into t2 values (?, ?, ?)", i, i, i)
if err != nil {
// if err is failed, the column number must be 4 now.
values := s.showColumns(c, "t2")
c.Assert(values, HasLen, 4, Commentf("err:%v", err))
c.Assert(values, HasLen, 4, Commentf("err:%v", errors.ErrorStack(err)))
}
s.tk.MustExec("commit")
}
num += step
}
Expand Down Expand Up @@ -681,16 +687,15 @@ LOOP:
case <-ticker.C:
// delete some rows, and add some data
for i := num; i < num+step; i++ {
// Make sure that statement of insert and show use the same infoSchema.
s.tk.MustExec("begin")
_, err := s.tk.Exec("insert into t2 values (?, ?, ?)", i, i, i)
if err == nil {
continue
}
// If executing is failed, the column number must be 4 now.
values := s.showColumns(c, "t2")
if len(values) != 4 {
c.Log(errors.ErrorStack(err))
c.FailNow()
if err != nil {
// If executing is failed, the column number must be 4 now.
values := s.showColumns(c, "t2")
c.Assert(values, HasLen, 4, Commentf("err:%v", errors.ErrorStack(err)))
}
s.tk.MustExec("commit")
}
num += step
}
Expand Down
8 changes: 6 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ type session struct {

func (s *session) cleanRetryInfo() {
if !s.sessionVars.RetryInfo.Retrying {
s.sessionVars.RetryInfo.Clean()
retryInfo := s.sessionVars.RetryInfo
for _, stmtID := range retryInfo.DroppedPreparedStmtIDs {
delete(s.sessionVars.PreparedStmts, stmtID)
}
retryInfo.Clean()
}
}

Expand Down Expand Up @@ -567,7 +571,7 @@ func (s *session) DropPreparedStmt(stmtID uint32) error {
if _, ok := vars.PreparedStmts[stmtID]; !ok {
return executor.ErrStmtNotFound
}
delete(vars.PreparedStmts, stmtID)
vars.RetryInfo.DroppedPreparedStmtIDs = append(vars.RetryInfo.DroppedPreparedStmtIDs, stmtID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not drop statement here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retry, ExecutePreparedStmt will execute with the same stmtID, so we should not dropping the preparedStmts until finished the transaction, dropping it in ClearRetryInfo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we retry prepare statement? Or we only retry execute statement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only retry execute statement.
Session.PrepareStmt do not add statement history.

return nil
}

Expand Down
10 changes: 7 additions & 3 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ var (

// RetryInfo saves retry information.
type RetryInfo struct {
Retrying bool
currRetryOff int
autoIncrementIDs []int64
Retrying bool
DroppedPreparedStmtIDs []uint32
currRetryOff int
autoIncrementIDs []int64
}

// Clean does some clean work.
Expand All @@ -47,6 +48,9 @@ func (r *RetryInfo) Clean() {
if len(r.autoIncrementIDs) > 0 {
r.autoIncrementIDs = r.autoIncrementIDs[:0]
}
if len(r.DroppedPreparedStmtIDs) > 0 {
r.DroppedPreparedStmtIDs = r.DroppedPreparedStmtIDs[:0]
}
}

// AddAutoIncrementID adds id to AutoIncrementIDs.
Expand Down