Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential bad case for tryIdleReplica #1091

Open
zyguan opened this issue Dec 25, 2023 · 0 comments
Open

Potential bad case for tryIdleReplica #1091

zyguan opened this issue Dec 25, 2023 · 0 comments

Comments

@zyguan
Copy link
Contributor

zyguan commented Dec 25, 2023

Here is the case, if the leader is always busy and the followers are busy for a few times, tryIdleReplica will keep trying busy leader until backoff timeout.

func (s *testRegionRequestToThreeStoresSuite) TestDebugLeaderReadBusyThreshold() {
	// load region into cache
	key := []byte("key")
	loc, err := s.cache.LocateKey(s.bo, key)
	s.Require().NoError(err)

	// load region and leader store
	region := s.cache.GetCachedRegionWithRLock(loc.Region)
	leader, _, _, _ := region.WorkStorePeer(region.getStore())

	// make leader read request
	req := tikvrpc.NewReplicaReadRequest(tikvrpc.CmdGet, &kvrpcpb.GetRequest{Key: key}, kv.ReplicaReadLeader, nil)
	req.ReadReplicaScope = oracle.GlobalTxnScope
	req.TxnScope = oracle.GlobalTxnScope
	req.BusyThresholdMs = 100

	// setup mock client: 1) leader always returns server busy; 2) followers return server busy twice.
	followerBusyCount := 2
	s.regionRequestSender.client = &fnClient{fn: func(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (response *tikvrpc.Response, err error) {
		if addr == leader.addr || followerBusyCount > 0 {
			logutil.BgLogger().Sugar().Infof(">>> rpc to %s is busy", addr)
			if addr != leader.addr {
				followerBusyCount--
			}
			return &tikvrpc.Response{Resp: &kvrpcpb.GetResponse{RegionError: &errorpb.Error{ServerIsBusy: &errorpb.ServerIsBusy{Reason: "mock busy", EstimatedWaitMs: 60000}}}}, nil
		}
		logutil.BgLogger().Sugar().Infof(">>> rpc to %s", addr)
		return &tikvrpc.Response{Resp: &kvrpcpb.GetResponse{Value: []byte(addr)}}, nil
	}}

	bo := retry.NewBackoffer(context.Background(), -1)
	logutil.BgLogger().Sugar().Info(s.regionRequestSender.SendReqCtx(bo, req, loc.Region, time.Second, tikvrpc.TiKV))
}

2023-12-25_225257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant