@@ -3921,6 +3921,78 @@ func TestConcurrentStoreStats(t *testing.T) {
39213921 wg .Wait ()
39223922}
39233923
3924+ func TestCheckStoresUpCountWithLowSpace (t * testing.T ) {
3925+ re := require .New (t )
3926+ ctx , cancel := context .WithCancel (context .Background ())
3927+ defer cancel ()
3928+
3929+ _ , opt , err := newTestScheduleConfig ()
3930+ re .NoError (err )
3931+ cluster := newTestRaftCluster (ctx , mockid .NewIDAllocator (), opt , storage .NewStorageWithMemoryBackend ())
3932+ cluster .coordinator = schedule .NewCoordinator (ctx , cluster , nil )
3933+ cluster .ruleManager = placement .NewRuleManager (ctx , storage .NewStorageWithMemoryBackend (), cluster , cluster .GetOpts ())
3934+ if opt .IsPlacementRulesEnabled () {
3935+ err := cluster .ruleManager .Initialize (opt .GetMaxReplicas (), opt .GetLocationLabels (), opt .GetIsolationLevel (), false )
3936+ if err != nil {
3937+ panic (err )
3938+ }
3939+ }
3940+
3941+ // Add stores with low space to the cluster.
3942+ storeCount := uint64 (3 )
3943+ for i := uint64 (1 ); i <= storeCount ; i ++ {
3944+ store := & metapb.Store {
3945+ Id : i ,
3946+ Address : fmt .Sprintf ("mock://tikv-%d:%d" , i , i ),
3947+ StatusAddress : fmt .Sprintf ("mock://tikv-%d:%d" , i , i + 1 ),
3948+ Version : "2.0.0" ,
3949+ DeployPath : getTestDeployPath (i ),
3950+ NodeState : metapb .NodeState_Preparing ,
3951+ }
3952+ err = cluster .PutMetaStore (store )
3953+ re .NoError (err )
3954+ req := & pdpb.StoreHeartbeatRequest {}
3955+ resp := & pdpb.StoreHeartbeatResponse {}
3956+ req .Stats = & pdpb.StoreStats {
3957+ StoreId : i ,
3958+ Capacity : 100 * 1024 , // 100 GiB
3959+ Available : 1 * 1024 , // 1 GiB
3960+ RegionCount : 1 ,
3961+ }
3962+ re .NoError (cluster .HandleStoreHeartbeat (req , resp ))
3963+ }
3964+ re .Equal (int (storeCount ), cluster .GetStoreCount ())
3965+
3966+ upStoreCount := 0
3967+ for _ , s := range cluster .GetStores () {
3968+ isUp , _ := cluster .checkStore (s .GetID ())
3969+ if isUp {
3970+ upStoreCount ++
3971+ }
3972+ }
3973+ re .Equal (0 , upStoreCount , "upStoreCount should be 0 when store is low space" )
3974+
3975+ // Add stores to the cluster.
3976+ for i := uint64 (1 ); i <= storeCount ; i ++ {
3977+ req := & pdpb.StoreHeartbeatRequest {}
3978+ resp := & pdpb.StoreHeartbeatResponse {}
3979+ req .Stats = & pdpb.StoreStats {
3980+ StoreId : i ,
3981+ Capacity : 100 * 1024 , // 100 GiB
3982+ Available : 50 * 1024 , // 50 GiB
3983+ RegionCount : 1 ,
3984+ }
3985+ re .NoError (cluster .HandleStoreHeartbeat (req , resp ))
3986+ }
3987+ for _ , s := range cluster .GetStores () {
3988+ isUp , _ := cluster .checkStore (s .GetID ())
3989+ if isUp {
3990+ upStoreCount ++
3991+ }
3992+ }
3993+ re .Equal (int (storeCount ), upStoreCount , "upStoreCount should be 3 when store is not low space" )
3994+ }
3995+
39243996func waitAddLearner (re * require.Assertions , stream mockhbstream.HeartbeatStream , region * core.RegionInfo , storeID uint64 ) * core.RegionInfo {
39253997 var res * pdpb.RegionHeartbeatResponse
39263998 testutil .Eventually (re , func () bool {
0 commit comments