Skip to content

Commit

Permalink
ttl: enable 1pc for ttl delete (#39958) (#39960)
Browse files Browse the repository at this point in the history
close #39957
  • Loading branch information
ti-chi-bot authored Dec 20, 2022
1 parent f2ca43e commit b88538b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ttl/ttlworker/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/ngaut/pools"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/ttl/cache"
Expand Down Expand Up @@ -61,12 +62,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 +90,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 b88538b

Please sign in to comment.