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 tests/pessimistictest package test cases #34504

Closed tiancaiamao closed 2 years ago

tiancaiamao commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

cd tests/pessimistictest
go test -race ./...

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

No data race

3. What did you see instead (Required)

WARNING: DATA RACE
Read at 0x00000805e7c0 by goroutine 135:
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).execute()
      /home/genius/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.1-0.20220406091203-f73ec0e675f4/txnkv/transaction/2pc.go:1372 +0x2c8
  github.com/tikv/client-go/v2/txnkv/transaction.(*KVTxn).Commit()
      /home/genius/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.1-0.20220406091203-f73ec0e675f4/txnkv/transaction/txn.go:436 +0xc7b
  github.com/pingcap/tidb/store/driver/txn.(*tikvTxn).Commit()
      /home/genius/project/src/github.com/pingcap/tidb/store/driver/txn/txn_driver.go:77 +0x53
  github.com/pingcap/tidb/kv.RunInNewTxn()
      /home/genius/project/src/github.com/pingcap/tidb/kv/txn.go:155 +0x221
  github.com/pingcap/tidb/meta/autoid.(*allocator).alloc4Signed()
      /home/genius/project/src/github.com/pingcap/tidb/meta/autoid/autoid.go:761 +0x49b
  github.com/pingcap/tidb/meta/autoid.(*allocator).Alloc()
      /home/genius/project/src/github.com/pingcap/tidb/meta/autoid/autoid.go:579 +0x3cb
  github.com/pingcap/tidb/table/tables.allocHandleIDs()
      /home/genius/project/src/github.com/pingcap/tidb/table/tables/tables.go:1484 +0xee
  github.com/pingcap/tidb/table/tables.AllocHandle()
      /home/genius/project/src/github.com/pingcap/tidb/table/tables/tables.go:1478 +0x11d
  github.com/pingcap/tidb/table/tables.(*TableCommon).AddRecord()
      /home/genius/project/src/github.com/pingcap/tidb/table/tables/tables.go:743 +0x10bc
  github.com/pingcap/tidb/executor.(*InsertValues).addRecordWithAutoIDHint()
      /home/genius/project/src/github.com/pingcap/tidb/executor/insert_common.go:1204 +0x3fb
  github.com/pingcap/tidb/executor.(*InsertValues).addRecord()
      /home/genius/project/src/github.com/pingcap/tidb/executor/insert_common.go:1193 +0x71
  github.com/pingcap/tidb/executor.(*InsertValues).addRecord-fm()
      <autogenerated>:1 +0x77
  github.com/pingcap/tidb/executor.(*InsertValues).batchCheckAndInsert()
      /home/genius/project/src/github.com/pingcap/tidb/executor/insert_common.go:1128 +0xcc8
  github.com/pingcap/tidb/executor.(*InsertExec).exec()
      /home/genius/project/src/github.com/pingcap/tidb/executor/insert.go:85 +0x544
  github.com/pingcap/tidb/executor.insertRowsFromSelect()
      /home/genius/project/src/github.com/pingcap/tidb/executor/insert_common.go:490 +0x7ef
  github.com/pingcap/tidb/executor.(*InsertExec).Next()
      /home/genius/project/src/github.com/pingcap/tidb/executor/insert.go:311 +0x2a4
  github.com/pingcap/tidb/executor.Next()
      /home/genius/project/src/github.com/pingcap/tidb/executor/executor.go:306 +0x5af
  github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor()
      /home/genius/project/src/github.com/pingcap/tidb/executor/adapter.go:661 +0x6a4
  github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelay()
      /home/genius/project/src/github.com/pingcap/tidb/executor/adapter.go:516 +0x29c
  github.com/pingcap/tidb/executor.(*ExecStmt).Exec()
      /home/genius/project/src/github.com/pingcap/tidb/executor/adapter.go:465 +0xab9
  github.com/pingcap/tidb/session.runStmt()
      /home/genius/project/src/github.com/pingcap/tidb/session/session.go:2056 +0x5a1
  github.com/pingcap/tidb/session.(*session).ExecuteStmt()
      /home/genius/project/src/github.com/pingcap/tidb/session/session.go:1932 +0xcfa
  github.com/pingcap/tidb/session.(*session).ExecuteInternal()
      /home/genius/project/src/github.com/pingcap/tidb/session/session.go:1465 +0x464
  github.com/pingcap/tidb/ddl/util.CompleteDeleteRange()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/util/util.go:115 +0x209
  github.com/pingcap/tidb/ddl.(*delRange).doTask()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/delete_range.go:220 +0x4b1
  github.com/pingcap/tidb/ddl.(*delRange).doDelRangeWork()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/delete_range.go:169 +0x64b
  github.com/pingcap/tidb/ddl.(*delRange).startEmulator()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/delete_range.go:148 +0x1c8
  github.com/pingcap/tidb/ddl.(*delRange).start.func1()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/delete_range.go:124 +0x39

Previous write at 0x00000805e7c0 by goroutine 105:
  github.com/pingcap/tidb/tests/pessimistictest.createMockStoreAndSetup.func2()
      /home/genius/project/src/github.com/pingcap/tidb/tests/pessimistictest/pessimistic_test.go:159 +0x51
  runtime.deferreturn()
      /home/genius/project/go/src/runtime/panic.go:436 +0x32
  testing.tRunner()
      /home/genius/project/go/src/testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      /home/genius/project/go/src/testing/testing.go:1486 +0x47

Goroutine 135 (running) created at:
  github.com/pingcap/tidb/ddl.(*delRange).start()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/delete_range.go:124 +0xb6
  github.com/pingcap/tidb/ddl.(*ddl).newDeleteRangeManager()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/ddl.go:373 +0x245
  github.com/pingcap/tidb/ddl.(*ddl).Start()
      /home/genius/project/src/github.com/pingcap/tidb/ddl/ddl.go:395 +0x4eb
  github.com/pingcap/tidb/domain.(*Domain).Init()
      /home/genius/project/src/github.com/pingcap/tidb/domain/domain.go:861 +0x10d6
  github.com/pingcap/tidb/session.(*domainMap).Get.func1()
      /home/genius/project/src/github.com/pingcap/tidb/session/tidb.go:85 +0x664
  github.com/pingcap/tidb/util.RunWithRetry()
      /home/genius/project/src/github.com/pingcap/tidb/util/misc.go:64 +0x93
  github.com/pingcap/tidb/session.(*domainMap).Get()
      /home/genius/project/src/github.com/pingcap/tidb/session/tidb.go:73 +0x319
  github.com/pingcap/tidb/session.createSessionWithOpt()
      /home/genius/project/src/github.com/pingcap/tidb/session/session.go:2983 +0x75
  github.com/pingcap/tidb/session.createSession()
      /home/genius/project/src/github.com/pingcap/tidb/session/session.go:2979 +0x84
  github.com/pingcap/tidb/session.createSessions()
      /home/genius/project/src/github.com/pingcap/tidb/session/session.go:2968 +0x6e
  github.com/pingcap/tidb/session.BootstrapSession()
      /home/genius/project/src/github.com/pingcap/tidb/session/session.go:2845 +0x297
  github.com/pingcap/tidb/tests/pessimistictest.createMockStoreAndSetup()
      /home/genius/project/src/github.com/pingcap/tidb/tests/pessimistictest/pessimistic_test.go:154 +0x288
  github.com/pingcap/tidb/tests/pessimistictest.TestInnodbLockWaitTimeout()
      /home/genius/project/src/github.com/pingcap/tidb/tests/pessimistictest/pessimistic_test.go:934 +0x51
  testing.tRunner()
      /home/genius/project/go/src/testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      /home/genius/project/go/src/testing/testing.go:1486 +0x47

Goroutine 105 (running) created at:
  testing.(*T).Run()
      /home/genius/project/go/src/testing/testing.go:1486 +0x724
  testing.runTests.func1()
      /home/genius/project/go/src/testing/testing.go:1839 +0x99
  testing.tRunner()
      /home/genius/project/go/src/testing/testing.go:1439 +0x213
  testing.runTests()
      /home/genius/project/go/src/testing/testing.go:1837 +0x7e4
  testing.(*M).Run()
      /home/genius/project/go/src/testing/testing.go:1719 +0xa71
  go.uber.org/goleak.VerifyTestMain()
      /home/genius/go/pkg/mod/go.uber.org/goleak@v1.1.12/testmain.go:53 +0x59
  github.com/pingcap/tidb/tests/pessimistictest.TestMain()
      /home/genius/project/src/github.com/pingcap/tidb/tests/pessimistictest/pessimistic_test.go:85 +0xc04
  main.main()
      _testmain.go:165 +0x317
==================

4. What is your TiDB version? (Required)

master 2f86eac3cfef6bbefcdafc9220616feca030c9d5

tiancaiamao commented 2 years ago

Introduced by https://github.com/pingcap/tidb/pull/34353