pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.62k stars 5.77k forks source link

DATA RACE in the (*MemDB).Dirty #39773

Open hawkingrei opened 1 year ago

hawkingrei commented 1 year ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

==================
WARNING: DATA RACE
Read at 0x00c005c54b21 by goroutine 305800:
  github.com/tikv/client-go/v2/internal/unionstore.(*MemDB).Dirty()
      external/com_github_tikv_client_go_v2/internal/unionstore/memdb.go:311 +0x97
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).IsReadOnly()
      external/com_github_tikv_client_go_v2/txnkv/transaction/txn.go:1251 +0x52
  github.com/pingcap/tidb/store/driver/txn.(*tikvTxn).IsReadOnly()
      <autogenerated>:1 +0x29
  github.com/pingcap/tidb/session.(*LazyTxn).IsReadOnly()
      <autogenerated>:1 +0x4c
  github.com/pingcap/tidb/executor.(*PointGetExecutor).get()
      executor/point_get.go:471 +0xea
  github.com/pingcap/tidb/executor.(*PointGetExecutor).getAndLock()
      executor/point_get.go:369 +0x1ba
  github.com/pingcap/tidb/executor.(*PointGetExecutor).Next()
      executor/point_get.go:321 +0xf88
  github.com/pingcap/tidb/executor.Next()
      executor/executor.go:328 +0x5c3
  github.com/pingcap/tidb/executor.(*SelectLockExec).Next()
      executor/executor.go:1164 +0xeb
  github.com/pingcap/tidb/executor.Next()
      executor/executor.go:328 +0x5c3
  github.com/pingcap/tidb/executor.(*UnionExec).resultPuller()
      executor/executor.go:1861 +0x8e9
  github.com/pingcap/tidb/executor.(*UnionExec).initialize.func1()
      executor/executor.go:1814 +0x64
Previous write at 0x00c005c54b21 by goroutine 305799:
  github.com/tikv/client-go/v2/internal/unionstore.(*MemDB).set()
      external/com_github_tikv_client_go_v2/internal/unionstore/memdb.go:348 +0x326
  github.com/tikv/client-go/v2/internal/unionstore.(*MemDB).UpdateFlags()
      external/com_github_tikv_client_go_v2/internal/unionstore/memdb.go:250 +0x213a
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).LockKeys()
      external/com_github_tikv_client_go_v2/txnkv/transaction/txn.go:1110 +0x20a5
  github.com/pingcap/tidb/store/driver/txn.(*tikvTxn).LockKeys()
      store/driver/txn/txn_driver.go:75 +0x105
  github.com/pingcap/tidb/session.(*LazyTxn).LockKeys()
      session/txn.go:442 +0x22e
  github.com/pingcap/tidb/executor.doLockKeys()
      executor/executor.go:1283 +0x30d
  github.com/pingcap/tidb/executor.(*SelectLockExec).Next()
      executor/executor.go:1215 +0x78f
  github.com/pingcap/tidb/executor.Next()
      executor/executor.go:328 +0x5c3
  github.com/pingcap/tidb/executor.(*UnionExec).resultPuller()
      executor/executor.go:1861 +0x8e9
  github.com/pingcap/tidb/executor.(*UnionExec).initialize.func1()
      executor/executor.go:1814 +0x64
Goroutine 305800 (running) created at:
  github.com/pingcap/tidb/executor.(*UnionExec).initialize()
      executor/executor.go:1814 +0x4d7
  github.com/pingcap/tidb/executor.(*UnionExec).Next()
      executor/executor.go:1887 +0xca
  github.com/pingcap/tidb/executor.Next()
      executor/executor.go:328 +0x5c3
  github.com/pingcap/tidb/executor.(*HashAggExec).fetchChildData()
      executor/aggregate.go:817 +0x325
  github.com/pingcap/tidb/executor.(*HashAggExec).prepare4ParallelExec.func3()
      executor/aggregate.go:854 +0x64
Goroutine 305799 (finished) created at:
  github.com/pingcap/tidb/executor.(*UnionExec).initialize()
      executor/executor.go:1814 +0x4d7
  github.com/pingcap/tidb/executor.(*UnionExec).Next()
      executor/executor.go:1887 +0xca
  github.com/pingcap/tidb/executor.Next()
      executor/executor.go:328 +0x5c3
  github.com/pingcap/tidb/executor.(*HashAggExec).fetchChildData()
      executor/aggregate.go:817 +0x325
  github.com/pingcap/tidb/executor.(*HashAggExec).prepare4ParallelExec.func3()
      executor/aggregate.go:854 +0x64
================== 

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

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

hawkingrei commented 1 year ago

https://prow.pingcap.net/view/gs/pingcapprow/logs/tidb_race/1600837814566522880

Defined2014 commented 1 year ago

Always happended on TestRcTSOCmdCountForPrepareExecuteExtra, so close data race in sessiontxn folder first.

https://github.com/pingcap/tidb/pull/41226/files#diff-427e00ff84fb93e3d48f145caaebe1f9bb3615a733654d6116a17d1a7726456aL30