Skip to content

Commit

Permalink
Merge branch 'master' into zimuxia/dist-reorg-ptbl
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored Feb 9, 2023
2 parents 7f73929 + 09d3fa9 commit 2491947
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/domain"
Expand Down Expand Up @@ -2490,6 +2491,13 @@ func doDMLWorks(s Session) {
case variable.TiDBEnableMutationChecker:
vVal = variable.On
}

failpoint.Inject("enableAggressiveLockingOnBootstrap", func() {
if v.Name == variable.TiDBPessimisticTransactionAggressiveLocking {
vVal = variable.On
}
})

// sanitize k and vVal
value := fmt.Sprintf(`("%s", "%s")`, sqlexec.EscapeString(k), sqlexec.EscapeString(vVal))
values = append(values, value)
Expand Down
5 changes: 4 additions & 1 deletion sessiontxn/isolation/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,10 @@ func (p *basePessimisticTxnContextProvider) OnHandlePessimisticStmtStart(ctx con
if err := p.baseTxnContextProvider.OnHandlePessimisticStmtStart(ctx); err != nil {
return err
}
if p.sctx.GetSessionVars().PessimisticTransactionAggressiveLocking && p.txn != nil {
if p.sctx.GetSessionVars().PessimisticTransactionAggressiveLocking &&
p.txn != nil &&
p.sctx.GetSessionVars().ConnectionID != 0 &&
!p.sctx.GetSessionVars().InRestrictedSQL {
if err := p.txn.StartAggressiveLocking(); err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions sessiontxn/isolation/repeatable_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,18 @@ func TestRRWaitTSTimeInSlowLog(t *testing.T) {
require.NotEqual(t, waitTS1, waitTS3)
require.NotEqual(t, waitTS2, waitTS3)
}

func TestIssue41194(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/session/enableAggressiveLockingOnBootstrap", "return"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/session/enableAggressiveLockingOnBootstrap"))
}()

store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("create table t (id int primary key, v int)")
tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3)")
tk.MustExec("analyze table t")
}
4 changes: 4 additions & 0 deletions statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,10 @@ func SaveTableStatsToStorage(sctx sessionctx.Context, results *statistics.Analyz
if err != nil {
return err
}
err = rs.Close()
if err != nil {
return err
}
var curCnt, curModifyCnt int64
if len(rows) > 0 {
snapshot := rows[0].GetUint64(0)
Expand Down

0 comments on commit 2491947

Please sign in to comment.