pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.2k stars 5.84k forks source link

DATA RACE on the SchemaOutOfDateRetryTimes #31812

Closed hawkingrei closed 2 years ago

hawkingrei commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

==================
WARNING: DATA RACE
Write at 0x0000079633a8 by goroutine 190:
  github.com/pingcap/tidb/ddl/failtest_test.TestFailSchemaSyncer()
      /go/tidb/ddl/failtest/fail_db_test.go:234 +0x1d0
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /usr/local/go/src/testing/testing.go:1306 +0x47
Previous read at 0x0000079633a8 by goroutine 187:
  sync/atomic.LoadInt32()
      /usr/local/go/src/runtime/race_amd64.s:226 +0xb
  sync/atomic.LoadInt32()
      <autogenerated>:1 +0x16
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).checkSchemaValid()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-rc.0.20211229051614-62d6b4a2e8f7/txnkv/transaction/2pc.go:1658 +0x18a
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).execute()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-rc.0.20211229051614-62d6b4a2e8f7/txnkv/transaction/2pc.go:1354 +0x276d
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).Commit()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-rc.0.20211229051614-62d6b4a2e8f7/txnkv/transaction/txn.go:427 +0xc04
  github.com/pingcap/tidb/store/driver/txn.(*tikvTxn).Commit()
      /go/tidb/store/driver/txn/txn_driver.go:77 +0x53
  github.com/pingcap/tidb/session.(*LazyTxn).Commit()
      /go/tidb/session/txn.go:365 +0x78c
  github.com/pingcap/tidb/session.(*session).commitTxnWithTemporaryData()
      /go/tidb/session/session.go:692 +0x2c4
  github.com/pingcap/tidb/session.(*session).doCommit()
      /go/tidb/session/session.go:602 +0x1484
  github.com/pingcap/tidb/session.(*session).doCommitWithRetry()
      /go/tidb/session/session.go:823 +0x3db
  github.com/pingcap/tidb/session.(*session).CommitTxn()
      /go/tidb/session/session.go:889 +0x2f7
  github.com/pingcap/tidb/session.autoCommitAfterStmt()
      /go/tidb/session/tidb.go:272 +0x3d8
  github.com/pingcap/tidb/session.finishStmt()
      /go/tidb/session/tidb.go:238 +0x3ab
  github.com/pingcap/tidb/session.runStmt()
      /go/tidb/session/session.go:1852 +0x95d
  github.com/pingcap/tidb/session.(*session).ExecuteStmt()
      /go/tidb/session/session.go:1718 +0xdb3
  github.com/pingcap/tidb/session.(*session).ExecuteInternal()
      /go/tidb/session/session.go:1429 +0x4ce
  github.com/pingcap/tidb/statistics/handle.finishTransaction()
      /go/tidb/statistics/handle/ddl.go:284 +0xdd
  github.com/pingcap/tidb/statistics/handle.(*Handle).insertTableStats2KV.func1()
      /go/tidb/statistics/handle/ddl.go:188 +0x7d
  github.com/pingcap/tidb/statistics/handle.(*Handle).insertTableStats2KV()
      /go/tidb/statistics/handle/ddl.go:208 +0x933
  github.com/pingcap/tidb/statistics/handle.(*Handle).HandleDDLEvent()
      /go/tidb/statistics/handle/ddl.go:38 +0x48c
  github.com/pingcap/tidb/domain.(*Domain).updateStatsWorker()
      /go/tidb/domain/domain.go:1425 +0x53e
  github.com/pingcap/tidb/domain.(*Domain).UpdateTableStatsLoop·dwrap·20()
      /go/tidb/domain/domain.go:1293 +0x71
Goroutine 190 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1306 +0x726
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1598 +0x99
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1259 +0x22f
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1596 +0x7ca
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1504 +0x9d1
  go.uber.org/goleak.VerifyTestMain()
      /home/prow/go/pkg/mod/go.uber.org/goleak@v1.1.12/testmain.go:53 +0x59
  github.com/pingcap/tidb/ddl/failtest_test.TestMain()
      /go/tidb/ddl/failtest/main_test.go:42 +0x244
  main.main()
      _testmain.go:65 +0x264
Goroutine 187 (running) created at:
  github.com/pingcap/tidb/domain.(*Domain).UpdateTableStatsLoop()
      /go/tidb/domain/domain.go:1293 +0x464
  github.com/pingcap/tidb/session.BootstrapSession()
      /go/tidb/session/session.go:2708 +0x804
  github.com/pingcap/tidb/ddl/failtest_test.createFailDBSuite()
      /go/tidb/ddl/failtest/fail_db_test.go:58 +0x25d
  github.com/pingcap/tidb/ddl/failtest_test.TestFailSchemaSyncer()
      /go/tidb/ddl/failtest/fail_db_test.go:226 +0x4a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /usr/local/go/src/testing/testing.go:1306 +0x47
==================

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

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

github-actions[bot] commented 2 years ago

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.