refine error msg (#1338)

* refine error msg

Signed-off-by: crazycs520 <crazycs520@gmail.com>

* refine

Signed-off-by: crazycs520 <crazycs520@gmail.com>

* fix test

Signed-off-by: crazycs520 <crazycs520@gmail.com>

---------

Signed-off-by: crazycs520 <crazycs520@gmail.com>
This commit is contained in:
crazycs 2024-05-13 21:49:13 +08:00 committed by GitHub
parent c82e921992
commit e1ca512cca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -924,8 +924,8 @@ func sendBatchRequest(
case <-timer.C: case <-timer.C:
return nil, errors.WithMessage(context.DeadlineExceeded, "wait sendLoop") return nil, errors.WithMessage(context.DeadlineExceeded, "wait sendLoop")
} }
waitDuration := time.Since(start) waitSendDuration := time.Since(start)
metrics.TiKVBatchWaitDuration.Observe(float64(waitDuration)) metrics.TiKVBatchWaitDuration.Observe(float64(waitSendDuration))
select { select {
case res, ok := <-entry.res: case res, ok := <-entry.res:
@ -944,7 +944,8 @@ func sendBatchRequest(
return nil, errors.New("batchConn closed") return nil, errors.New("batchConn closed")
case <-timer.C: case <-timer.C:
atomic.StoreInt32(&entry.canceled, 1) atomic.StoreInt32(&entry.canceled, 1)
reason := fmt.Sprintf("wait recvLoop timeout,timeout:%s, wait_duration:%s:", timeout, waitDuration) reason := fmt.Sprintf("wait recvLoop timeout, timeout:%s, wait_send_duration:%s, wait_recv_duration:%s",
timeout, util.FormatDuration(waitSendDuration), util.FormatDuration(time.Since(start)-waitSendDuration))
return nil, errors.WithMessage(context.DeadlineExceeded, reason) return nil, errors.WithMessage(context.DeadlineExceeded, reason)
} }
} }

View File

@ -148,7 +148,7 @@ func TestSendWhenReconnect(t *testing.T) {
req := tikvrpc.NewRequest(tikvrpc.CmdEmpty, &tikvpb.BatchCommandsEmptyRequest{}) req := tikvrpc.NewRequest(tikvrpc.CmdEmpty, &tikvpb.BatchCommandsEmptyRequest{})
_, err = rpcClient.SendRequest(context.Background(), addr, req, 5*time.Second) _, err = rpcClient.SendRequest(context.Background(), addr, req, 5*time.Second)
require.Regexp(t, "wait recvLoop timeout,timeout:5s, wait_duration:.* context deadline exceeded", err.Error()) require.Regexp(t, "wait recvLoop timeout, timeout:5s, wait_send_duration:.*, wait_recv_duration:.*: context deadline exceeded", err.Error())
server.Stop() server.Stop()
} }