@@ -15,6 +15,7 @@ package schedule
1515
1616import (
1717 "container/heap"
18+ "fmt"
1819 "sync"
1920 "time"
2021
@@ -26,6 +27,7 @@ import (
2627 "github.com/pingcap/pd/pkg/mock/mockhbstream"
2728 "github.com/pingcap/pd/pkg/mock/mockoption"
2829 "github.com/pingcap/pd/server/core"
30+ "github.com/pingcap/pd/server/namespace"
2931)
3032
3133var _ = Suite (& testOperatorControllerSuite {})
@@ -203,3 +205,51 @@ func (t *testOperatorControllerSuite) TestPollDispatchRegion(c *C) {
203205 c .Assert (r , IsNil )
204206 c .Assert (next , IsFalse )
205207}
208+
209+ func (t * testOperatorControllerSuite ) TestRemoveTombstone (c * C ) {
210+ var mu sync.RWMutex
211+ cfg := mockoption .NewScheduleOptions ()
212+ cfg .StoreBalanceRate = 1000
213+ cfg .LocationLabels = []string {"zone" , "rack" }
214+ tc := mockcluster .NewCluster (cfg )
215+ rc := NewReplicaChecker (tc , namespace .DefaultClassifier )
216+ oc := NewOperatorController (tc , mockhbstream .NewHeartbeatStream ())
217+
218+ tc .AddLabelsStore (1 , 100 , map [string ]string {"zone" : "zone1" , "rack" : "rack1" })
219+ tc .AddLabelsStore (2 , 100 , map [string ]string {"zone" : "zone1" , "rack" : "rack1" })
220+ tc .AddLabelsStore (3 , 100 , map [string ]string {"zone" : "zone2" , "rack" : "rack1" })
221+ tc .AddLabelsStore (4 , 10 , map [string ]string {"zone" : "zone3" , "rack" : "rack1" })
222+ peers := []* metapb.Peer {
223+ {Id : 4 , StoreId : 1 },
224+ {Id : 5 , StoreId : 2 },
225+ {Id : 6 , StoreId : 3 },
226+ }
227+ regions := make ([]* core.RegionInfo , 100 )
228+ for i := 2 ; i < 20 ; i ++ {
229+ r := core .NewRegionInfo (& metapb.Region {
230+ Id : uint64 (i ),
231+ StartKey : []byte (fmt .Sprintf ("%20d" , i )),
232+ EndKey : []byte (fmt .Sprintf ("%20d" , i + 1 )),
233+ Peers : peers }, peers [0 ], core .SetApproximateSize (50 * (1 << 20 )))
234+ regions [i ] = r
235+ tc .PutRegion (r )
236+ }
237+ var wg sync.WaitGroup
238+ wg .Add (1 )
239+ go func () {
240+ defer wg .Done ()
241+ time .Sleep (100 * time .Millisecond )
242+ mu .Lock ()
243+ defer mu .Unlock ()
244+ oc .RemoveStoreLimit (4 )
245+ }()
246+ for i := 2 ; i < 20 ; i ++ {
247+ time .Sleep (10 * time .Millisecond )
248+ mu .Lock ()
249+ op := rc .Check (regions [i ])
250+ mu .Unlock ()
251+ oc .AddOperator (op )
252+ oc .RemoveOperator (op )
253+ }
254+ wg .Wait ()
255+ }
0 commit comments