Skip to content

Commit

Permalink
ttl: enable 1pc for ttl delete
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao committed Dec 15, 2022
1 parent c26a6b5 commit f12daf7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ttl/ttlworker/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"fmt"
"time"

"github.com/pingcap/tidb/parser/terror"

"github.com/ngaut/pools"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx"
Expand Down Expand Up @@ -61,12 +63,24 @@ func getSession(pool sessionPool) (session.Session, error) {
}

originalRetryLimit := sctx.GetSessionVars().RetryLimit
originalEnable1PC := sctx.GetSessionVars().Enable1PC
originalEnableAsyncCommit := sctx.GetSessionVars().EnableAsyncCommit
se := session.NewSession(sctx, exec, func(se session.Session) {
_, err = se.ExecuteSQL(context.Background(), fmt.Sprintf("set tidb_retry_limit=%d", originalRetryLimit))
if err != nil {
logutil.BgLogger().Error("fail to reset tidb_retry_limit", zap.Int64("originalRetryLimit", originalRetryLimit), zap.Error(err))
}

if !originalEnable1PC {
_, err = se.ExecuteSQL(context.Background(), "set tidb_enable_1pc=OFF")
terror.Log(err)
}

if !originalEnableAsyncCommit {
_, err = se.ExecuteSQL(context.Background(), "set tidb_enable_async_commit=OFF")
terror.Log(err)
}

pool.Put(resource)
})

Expand All @@ -77,6 +91,20 @@ func getSession(pool sessionPool) (session.Session, error) {
return nil, err
}

// set enable 1pc to ON
_, err = se.ExecuteSQL(context.Background(), "set tidb_enable_1pc=ON")
if err != nil {
se.Close()
return nil, err
}

// set enable async commit to ON
_, err = se.ExecuteSQL(context.Background(), "set tidb_enable_async_commit=ON")
if err != nil {
se.Close()
return nil, err
}

// Force rollback the session to guarantee the session is not in any explicit transaction
if _, err = se.ExecuteSQL(context.Background(), "ROLLBACK"); err != nil {
se.Close()
Expand Down

0 comments on commit f12daf7

Please sign in to comment.