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

DATA RACE github.com/tikv/client-go/v2/internal/unionstore/rbt.(*RBT) #56178

Open
hawkingrei opened this issue Sep 20, 2024 · 3 comments · May be fixed by #59219
Open

DATA RACE github.com/tikv/client-go/v2/internal/unionstore/rbt.(*RBT) #56178

hawkingrei opened this issue Sep 20, 2024 · 3 comments · May be fixed by #59219
Assignees
Labels
affects-8.5 This bug affects the 8.5.x(LTS) versions. component/test severity/major sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@hawkingrei
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

2. What did you expect to see? (Required)

3. What did you see instead (Required)

==================
WARNING: DATA RACE
Read at 0x00c00833a831 by goroutine 15338:
  github.com/tikv/client-go/v2/internal/unionstore/rbt.(*RBT).Dirty()
      external/com_github_tikv_client_go_v2/internal/unionstore/rbt/rbt.go:310 +0x57
  github.com/tikv/client-go/v2/internal/unionstore.(*rbtDBWithContext).Dirty()
      <autogenerated>:1 +0x17
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).IsReadOnly()
      external/com_github_tikv_client_go_v2/txnkv/transaction/txn.go:1676 +0x5e
  github.com/pingcap/tidb/pkg/store/driver/txn.(*tikvTxn).IsReadOnly()
      <autogenerated>:1 +0x3e
  github.com/pingcap/tidb/pkg/session.(*LazyTxn).IsReadOnly()
      <autogenerated>:1 +0x46
  github.com/pingcap/tidb/pkg/executor.(*PointGetExecutor).get()
      pkg/executor/point_get.go:636 +0xe3
  github.com/pingcap/tidb/pkg/executor.(*PointGetExecutor).getAndLock()
      pkg/executor/point_get.go:549 +0x2c4
  github.com/pingcap/tidb/pkg/executor.(*PointGetExecutor).Next()
      pkg/executor/point_get.go:382 +0x1136
  github.com/pingcap/tidb/pkg/executor/internal/exec.Next()
      pkg/executor/internal/exec/executor.go:451 +0x418
  github.com/pingcap/tidb/pkg/executor.(*SelectLockExec).Next()
      pkg/executor/executor.go:1190 +0xde
  github.com/pingcap/tidb/pkg/executor/internal/exec.Next()
      pkg/executor/internal/exec/executor.go:451 +0x418
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).resultPuller()
      pkg/executor/unionexec/union.go:164 +0x969
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).initialize.func1()
      pkg/executor/unionexec/union.go:117 +0x5d
Previous write at 0x00c00833a831 by goroutine 15337:
  github.com/tikv/client-go/v2/internal/unionstore/rbt.(*RBT).Set()
      external/com_github_tikv_client_go_v2/internal/unionstore/rbt/rbt.go:344 +0x2b1
  github.com/tikv/client-go/v2/internal/unionstore.(*rbtDBWithContext).set()
      external/com_github_tikv_client_go_v2/internal/unionstore/memdb_rbt.go:54 +0x16e
  github.com/tikv/client-go/v2/internal/unionstore.(*rbtDBWithContext).UpdateFlags()
      external/com_github_tikv_client_go_v2/internal/unionstore/memdb_rbt.go:59 +0x94
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).lockKeys()
      external/com_github_tikv_client_go_v2/txnkv/transaction/txn.go:1524 +0x2aa2
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).LockKeysFunc()
      external/com_github_tikv_client_go_v2/txnkv/transaction/txn.go:1207 +0x1c6
  github.com/pingcap/tidb/pkg/store/driver/txn.(*tikvTxn).LockKeysFunc()
      pkg/store/driver/txn/txn_driver.go:106 +0x174
  github.com/pingcap/tidb/pkg/session.(*LazyTxn).LockKeysFunc()
      pkg/session/txn.go:497 +0x377
  github.com/pingcap/tidb/pkg/session.(*LazyTxn).LockKeys()
      pkg/session/txn.go:472 +0x84
  github.com/pingcap/tidb/pkg/executor.doLockKeys()
      pkg/executor/executor.go:1312 +0x30c
  github.com/pingcap/tidb/pkg/executor.(*SelectLockExec).Next()
      pkg/executor/executor.go:1241 +0x82e
  github.com/pingcap/tidb/pkg/executor/internal/exec.Next()
      pkg/executor/internal/exec/executor.go:451 +0x418
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).resultPuller()
      pkg/executor/unionexec/union.go:164 +0x969
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).initialize.func1()
      pkg/executor/unionexec/union.go:117 +0x5d
Goroutine 15338 (running) created at:
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).initialize()
      pkg/executor/unionexec/union.go:117 +0x52a
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).Next()
      pkg/executor/unionexec/union.go:190 +0xb7
  github.com/pingcap/tidb/pkg/executor/internal/exec.Next()
      pkg/executor/internal/exec/executor.go:451 +0x418
  github.com/pingcap/tidb/pkg/executor/aggregate.(*HashAggExec).fetchChildData()
      pkg/executor/aggregate/agg_hash_executor.go:482 +0x2b8
  github.com/pingcap/tidb/pkg/executor/aggregate.(*HashAggExec).prepare4ParallelExec.func3()
      pkg/executor/aggregate/agg_hash_executor.go:561 +0x5d
Goroutine 15337 (finished) created at:
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).initialize()
      pkg/executor/unionexec/union.go:117 +0x52a
  github.com/pingcap/tidb/pkg/executor/unionexec.(*UnionExec).Next()
      pkg/executor/unionexec/union.go:190 +0xb7
  github.com/pingcap/tidb/pkg/executor/internal/exec.Next()
      pkg/executor/internal/exec/executor.go:451 +0x418
  github.com/pingcap/tidb/pkg/executor/aggregate.(*HashAggExec).fetchChildData()
      pkg/executor/aggregate/agg_hash_executor.go:482 +0x2b8
  github.com/pingcap/tidb/pkg/executor/aggregate.(*HashAggExec).prepare4ParallelExec.func3()
      pkg/executor/aggregate/agg_hash_executor.go:561 +0x5d
================== 

4. What is your TiDB version? (Required)

@hawkingrei hawkingrei added the type/bug The issue is confirmed as a bug. label Sep 20, 2024
@cfzjywxk
Copy link
Contributor

@you06 Is this introduced by the recent refactor?

@you06
Copy link
Contributor

you06 commented Oct 17, 2024

@you06 Is this introduced by the recent refactor?

This is not introduced by the refactor, I made a reproduce test and found that this race also happens in TiDB 8.1

func TestMemDBRaceInUnionExec(t *testing.T) {
	store := testkit.CreateMockStore(t)
	tk := testkit.NewTestKit(t, store)
	tk.MustExec("use test")
	tables := 5
	for i := 0; i < tables; i++ {
		tk.MustExec(fmt.Sprintf("create table t%d(id int primary key, v int)", i))
	}

	tk.MustExec("insert into t0 values(1, 1), (2, 2), (3, 3), (4, 4)")
	for i := 1; i < tables; i++ {
		tk.MustExec(fmt.Sprintf("insert into t%d select * from t0", i))
	}

	tk.MustExec("set tidb_pessimistic_txn_fair_locking=0")
	for i := 0; i < 1001; i++ {
		tk.MustExec("begin pessimistic")
		tk.MustQuery(`select * from t0 where id = 1 for update union
select * from t1 where id = 1 for update union
select * from t2 where id = 1 for update union
select * from t3 where id = 1 for update union
select * from t4 where id = 1 for update`)
		tk.MustExec("rollback")
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-8.5 This bug affects the 8.5.x(LTS) versions. component/test severity/major sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.
Projects
None yet
4 participants