Skip to content

Commit

Permalink
Fix data race,ref #4857 (#4996)
Browse files Browse the repository at this point in the history
ref #4704, fix #4704, close #4857, ref #4881

Reorder the code logic, and acquire the lock before modifying the cluster to avoid data race.

Signed-off-by: v01dstar <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
v01dstar and ti-chi-bot authored May 20, 2022
1 parent 056ca9d commit aafc77d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/cluster/unsafe_recovery_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,17 +1316,17 @@ func (s *testUnsafeRecoverySuite) TestRemoveFailedStores(c *C) {
func (s *testUnsafeRecoverySuite) TestSplitPaused(c *C) {
_, opt, _ := newTestScheduleConfig()
cluster := newTestRaftCluster(s.ctx, mockid.NewIDAllocator(), opt, storage.NewStorageWithMemoryBackend(), core.NewBasicCluster())
recoveryController := newUnsafeRecoveryController(cluster)
cluster.Lock()
cluster.unsafeRecoveryController = recoveryController
cluster.coordinator = newCoordinator(s.ctx, cluster, hbstream.NewTestHeartbeatStreams(s.ctx, cluster.meta.GetId(), cluster, true))
cluster.Unlock()
cluster.coordinator.run()
stores := newTestStores(2, "5.3.0")
stores[1] = stores[1].Clone(core.SetLastHeartbeatTS(time.Now()))
for _, store := range stores {
c.Assert(cluster.PutStore(store.GetMeta()), IsNil)
}
recoveryController := newUnsafeRecoveryController(cluster)
cluster.Lock()
cluster.unsafeRecoveryController = recoveryController
cluster.Unlock()
failedStores := map[uint64]struct{}{
1: {},
}
Expand Down

0 comments on commit aafc77d

Please sign in to comment.