Skip to content

Commit a1380cb

Browse files
committed
fix panic of store not found
Signed-off-by: Ryan Leung <rleungx@gmail.com>
1 parent 0b32e6e commit a1380cb

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

pkg/mcs/scheduling/server/grpc_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func (s *Service) RegionBuckets(stream schedulingpb.Scheduling_RegionBucketsServ
207207
// 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.
208208
// So we should not return error here.
209209
log.Warn("the store of the bucket in region is not found ", zap.Uint64("region-id", buckets.GetRegionId()))
210+
continue
210211
}
211212

212213
storeAddress := store.GetAddress()

tests/integrations/mcs/scheduling/server_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"net/http"
2121
"reflect"
22+
"strings"
2223
"sync"
2324
"testing"
2425
"time"
@@ -27,10 +28,13 @@ import (
2728
"github.com/stretchr/testify/require"
2829
"github.com/stretchr/testify/suite"
2930
"go.uber.org/goleak"
31+
"google.golang.org/grpc"
32+
"google.golang.org/grpc/credentials/insecure"
3033

3134
"github.com/pingcap/failpoint"
3235
"github.com/pingcap/kvproto/pkg/metapb"
3336
"github.com/pingcap/kvproto/pkg/pdpb"
37+
"github.com/pingcap/kvproto/pkg/schedulingpb"
3438

3539
"github.com/tikv/pd/pkg/core/storelimit"
3640
"github.com/tikv/pd/pkg/mcs/utils/constant"
@@ -1500,3 +1504,55 @@ func (suite *serverTestSuite) TestForwardSplitRegion() {
15001504
re.Equal([]uint64{101}, splitResp.GetRegionsId())
15011505
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker", `return(true)`))
15021506
}
1507+
1508+
func (suite *serverTestSuite) TestRegionBucketsStoreNotFound() {
1509+
re := suite.Require()
1510+
tc, err := tests.NewTestSchedulingCluster(suite.ctx, 1, suite.cluster)
1511+
re.NoError(err)
1512+
defer tc.Destroy()
1513+
tc.WaitForPrimaryServing(re)
1514+
1515+
addr := strings.TrimPrefix(tc.GetPrimaryServer().GetAddr(), "http://")
1516+
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
1517+
re.NoError(err)
1518+
defer conn.Close()
1519+
1520+
schedulingClient := schedulingpb.NewSchedulingClient(conn)
1521+
stream, err := schedulingClient.RegionBuckets(suite.ctx)
1522+
re.NoError(err)
1523+
defer stream.CloseSend()
1524+
1525+
// Create buckets for a region that doesn't exist in the cluster
1526+
// This will trigger the store == nil condition because GetLeaderStoreByRegionID returns nil
1527+
buckets := &metapb.Buckets{
1528+
RegionId: 999, // Non-existent region ID
1529+
Version: 1,
1530+
Keys: [][]byte{[]byte("key1"), []byte("key2")},
1531+
PeriodInMs: 1000,
1532+
}
1533+
1534+
bucketsReq := &schedulingpb.RegionBucketsRequest{
1535+
Header: &schedulingpb.RequestHeader{ClusterId: suite.pdLeader.GetClusterID()},
1536+
Buckets: buckets,
1537+
}
1538+
1539+
// This should not return an error - the server will log a warning and continue
1540+
err = stream.Send(bucketsReq)
1541+
re.NoError(err)
1542+
1543+
// Send another valid request to ensure the stream is still working after the store == nil case
1544+
validBuckets := &metapb.Buckets{
1545+
RegionId: 1000, // Another non-existent region
1546+
Version: 1,
1547+
Keys: [][]byte{[]byte("key3"), []byte("key4")},
1548+
PeriodInMs: 1000,
1549+
}
1550+
1551+
validReq := &schedulingpb.RegionBucketsRequest{
1552+
Header: &schedulingpb.RequestHeader{ClusterId: suite.pdLeader.GetClusterID()},
1553+
Buckets: validBuckets,
1554+
}
1555+
1556+
err = stream.Send(validReq)
1557+
re.NoError(err)
1558+
}

0 commit comments

Comments
 (0)