Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/mcs/scheduling/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (s *Service) RegionBuckets(stream schedulingpb.Scheduling_RegionBucketsServ
// As TiKV report buckets just after the region heartbeat, for new created region, PD may receive buckets report before the first region heartbeat is handled.
// So we should not return error here.
log.Warn("the store of the bucket in region is not found ", zap.Uint64("region-id", buckets.GetRegionId()))
continue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The address can be nil if the store is nil

Copy link
Copy Markdown
Member Author

@rleungx rleungx Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it won't get the address if it is nil.

}

storeAddress := store.GetAddress()
Expand Down
56 changes: 56 additions & 0 deletions tests/integrations/mcs/scheduling/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"fmt"
"net/http"
"reflect"
"strings"
"sync"
"testing"
"time"
Expand All @@ -27,10 +28,13 @@
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/goleak"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/kvproto/pkg/schedulingpb"

"github.com/tikv/pd/pkg/core/storelimit"
"github.com/tikv/pd/pkg/mcs/utils/constant"
Expand Down Expand Up @@ -1500,3 +1504,55 @@
re.Equal([]uint64{101}, splitResp.GetRegionsId())
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker", `return(true)`))
}

func (suite *serverTestSuite) TestRegionBucketsStoreNotFound() {
re := suite.Require()
tc, err := tests.NewTestSchedulingCluster(suite.ctx, 1, suite.cluster)
re.NoError(err)
defer tc.Destroy()
tc.WaitForPrimaryServing(re)

addr := strings.TrimPrefix(tc.GetPrimaryServer().GetAddr(), "http://")
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
re.NoError(err)
defer conn.Close()

schedulingClient := schedulingpb.NewSchedulingClient(conn)
stream, err := schedulingClient.RegionBuckets(suite.ctx)
re.NoError(err)
defer stream.CloseSend()

Check failure on line 1523 in tests/integrations/mcs/scheduling/server_test.go

View workflow job for this annotation

GitHub Actions / statics

Error return value of `stream.CloseSend` is not checked (errcheck)

// Create buckets for a region that doesn't exist in the cluster
// This will trigger the store == nil condition because GetLeaderStoreByRegionID returns nil
buckets := &metapb.Buckets{
RegionId: 999, // Non-existent region ID
Version: 1,
Keys: [][]byte{[]byte("key1"), []byte("key2")},
PeriodInMs: 1000,
}

bucketsReq := &schedulingpb.RegionBucketsRequest{
Header: &schedulingpb.RequestHeader{ClusterId: suite.pdLeader.GetClusterID()},
Buckets: buckets,
}

// This should not return an error - the server will log a warning and continue
err = stream.Send(bucketsReq)
re.NoError(err)

// Send another valid request to ensure the stream is still working after the store == nil case
validBuckets := &metapb.Buckets{
RegionId: 1000, // Another non-existent region
Version: 1,
Keys: [][]byte{[]byte("key3"), []byte("key4")},
PeriodInMs: 1000,
}

validReq := &schedulingpb.RegionBucketsRequest{
Header: &schedulingpb.RequestHeader{ClusterId: suite.pdLeader.GetClusterID()},
Buckets: validBuckets,
}

err = stream.Send(validReq)
re.NoError(err)
}
Loading