Skip to content

Commit

Permalink
mcs: add timeout when call alloc of api server (tikv#7254)
Browse files Browse the repository at this point in the history
close tikv#7207

Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 authored Oct 26, 2023
1 parent 9f19361 commit 459671f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ type Cluster struct {
running atomic.Bool
}

const regionLabelGCInterval = time.Hour
const (
regionLabelGCInterval = time.Hour
requestTimeout = 3 * time.Second
)

// NewCluster creates a new cluster.
func NewCluster(parentCtx context.Context, persistConfig *config.PersistConfig, storage storage.Storage, basicCluster *core.BasicCluster, hbStreams *hbstream.HeartbeatStreams, clusterID uint64, checkMembershipCh chan struct{}) (*Cluster, error) {
Expand Down Expand Up @@ -199,7 +202,9 @@ func (c *Cluster) AllocID() (uint64, error) {
if err != nil {
return 0, err
}
resp, err := client.AllocID(c.ctx, &pdpb.AllocIDRequest{Header: &pdpb.RequestHeader{ClusterId: c.clusterID}})
ctx, cancel := context.WithTimeout(c.ctx, requestTimeout)
defer cancel()
resp, err := client.AllocID(ctx, &pdpb.AllocIDRequest{Header: &pdpb.RequestHeader{ClusterId: c.clusterID}})
if err != nil {
c.checkMembershipCh <- struct{}{}
return 0, err
Expand Down

0 comments on commit 459671f

Please sign in to comment.