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 in the TestConstraintCheckForUniqueIndex #30612

Open hawkingrei opened 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 0x00c00e0475e0 by goroutine 696:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex.func1()
      /go/tidb/table/tables/tables_test.go:706 +0xa4
Previous write at 0x00c00e0475e0 by goroutine 144:
  ??()
      -:0 +0xffffffffffffffff
  github.com/pingcap/tidb/store/mockstore/unistore/tikv.(*writeBatch).Commit()
      /go/tidb/store/mockstore/unistore/tikv/write.go:250 +0xa9
  github.com/pingcap/tidb/store/mockstore/unistore/tikv.(*MVCCStore).Commit()
      /go/tidb/store/mockstore/unistore/tikv/mvcc.go:961 +0xd19
  github.com/pingcap/tidb/store/mockstore/unistore/tikv.(*Server).KvCommit()
      /go/tidb/store/mockstore/unistore/tikv/server.go:353 +0x41a
  github.com/pingcap/tidb/store/mockstore/unistore.(*RPCClient).SendRequest()
      /go/tidb/store/mockstore/unistore/rpc.go:173 +0x1993
  github.com/pingcap/tidb/store/mockstore.(*clientRedirector).SendRequest()
      /go/tidb/store/mockstore/redirector.go:61 +0x176
  github.com/tikv/client-go/v2/internal/client.reqCollapse.SendRequest()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/internal/client/client_collapse.go:74 +0x130
  github.com/tikv/client-go/v2/internal/client.(*reqCollapse).SendRequest()
      <autogenerated>:1 +0xb6
  github.com/tikv/client-go/v2/internal/locate.(*RegionRequestSender).sendReqToRegion()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/internal/locate/region_request.go:1130 +0xd4e
  github.com/tikv/client-go/v2/internal/locate.(*RegionRequestSender).SendReqCtx()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/internal/locate/region_request.go:982 +0x196e
  github.com/tikv/client-go/v2/internal/locate.(*RegionRequestSender).SendReq()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/internal/locate/region_request.go:231 +0xaf0
  github.com/tikv/client-go/v2/txnkv/transaction.actionCommit.handleSingleBatch()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/commit.go:91 +0xa94
  github.com/tikv/client-go/v2/txnkv/transaction.(*actionCommit).handleSingleBatch()
      <autogenerated>:1 +0x113
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).doActionOnBatches()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/2pc.go:824 +0x482
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).doActionOnGroupMutations()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/2pc.go:763 +0xdb7
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).doActionOnMutations()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/2pc.go:588 +0x14c
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).commitMutations()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/commit.go:213 +0x333
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).commitTxn()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/2pc.go:1412 +0x464
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).execute()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/2pc.go:1403 +0x3589
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).Commit()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211206072923-c0e876615440/txnkv/transaction/txn.go:391 +0xb64
  github.com/pingcap/tidb/store/driver/txn.(*tikvTxn).Commit()
      /go/tidb/store/driver/txn/txn_driver.go:74 +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:569 +0x2c4
  github.com/pingcap/tidb/session.(*session).doCommit()
      /go/tidb/session/session.go:562 +0x105a
  github.com/pingcap/tidb/session.(*session).doCommitWithRetry()
      /go/tidb/session/session.go:699 +0x3db
  github.com/pingcap/tidb/session.(*session).CommitTxn()
      /go/tidb/session/session.go:761 +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:1707 +0x83d
  github.com/pingcap/tidb/session.(*session).ExecuteStmt()
      /go/tidb/session/session.go:1580 +0xd93
  github.com/pingcap/tidb/testkit.(*TestKit).Exec()
      /go/tidb/testkit/testkit.go:145 +0x6bc
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex()
      /go/tidb/table/tables/tables_test.go:714 +0x7b2
  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
Goroutine 696 (running) created at:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex()
      /go/tidb/table/tables/tables_test.go:704 +0x773
  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
Goroutine 144 (finished) 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/table/tables_test.TestMain()
      /go/tidb/table/tables/main_test.go:31 +0x316
  main.main()
      _testmain.go:133 +0x264 

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

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

hawkingrei commented 2 years ago

 WARNING: DATA RACE
Write at 0x00c01a2fce80 by goroutine 210:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex.func1()
      /go/tidb/table/tables/tables_test.go:706 +0xa4
Previous write at 0x00c01a2fce80 by goroutine 60:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex()
      /go/tidb/table/tables/tables_test.go:714 +0x7cf
  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
Goroutine 210 (running) created at:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex()
      /go/tidb/table/tables/tables_test.go:704 +0x773
  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
Goroutine 60 (finished) 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/table/tables_test.TestMain()
      /go/tidb/table/tables/main_test.go:31 +0x316
  main.main()
      _testmain.go:133 +0x264  WARNING: DATA RACE
Write at 0x00c01a2fce80 by goroutine 210:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex.func1()
      /go/tidb/table/tables/tables_test.go:706 +0xa4
Previous write at 0x00c01a2fce80 by goroutine 60:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex()
      /go/tidb/table/tables/tables_test.go:714 +0x7cf
  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
Goroutine 210 (running) created at:
  github.com/pingcap/tidb/table/tables_test.TestConstraintCheckForUniqueIndex()
      /go/tidb/table/tables/tables_test.go:704 +0x773
  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
Goroutine 60 (finished) 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/table/tables_test.TestMain()
      /go/tidb/table/tables/main_test.go:31 +0x316
  main.main()
      _testmain.go:133 +0x264 
bb7133 commented 2 years ago

The test code:

Line 704: https://github.com/pingcap/tidb/pull/27902/files#diff-692ed72f4504f1d5122002b138cbfeb3fbbc78081131d8ee566ef21f5f0dbfd7R706

_, err = tk2.Exec("insert into ttt(k,c) values(3, 'tidb')")

Line 714: https://github.com/pingcap/tidb/pull/27902/files#diff-692ed72f4504f1d5122002b138cbfeb3fbbc78081131d8ee566ef21f5f0dbfd7R714

_, err = tk1.Exec("commit")

Looks that we have a potential data race for concurrent execution for unistore?

bb7133 commented 2 years ago

I think it is either a case for unistore, or something wrong with TestConstraintCheckForUniqueIndex...