txnkv: fix the issue that batch-get error might be ignored (#1733)

Signed-off-by: zyguan <zhongyangguan@gmail.com>
This commit is contained in:
zyguan 2025-08-25 18:24:00 +08:00 committed by GitHub
parent 97cad411eb
commit 82ff387182
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View File

@ -39,6 +39,7 @@ import (
"sync"
"testing"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/keyspacepb"
"github.com/pingcap/kvproto/pkg/meta_storagepb"
"github.com/pingcap/kvproto/pkg/metapb"
@ -172,6 +173,13 @@ func (s *testSplitSuite) TestBatchGetUsingAsyncAPI() {
s.Equal([]byte("a"), m[string([]byte{'a'})])
s.Equal([]byte("c"), m[string([]byte{'c'})])
s.NotContains(m, string([]byte{'b'}))
// inject an error on sending request.
failpoint.Enable("tikvclient/tikvStoreSendReqResult", `1*return("timeout")`)
defer failpoint.Disable("tikvclient/tikvStoreSendReqResult")
txn = s.begin()
_, err = txn.GetSnapshot().BatchGet(context.TODO(), [][]byte{{'a'}, {'b'}, {'c'}})
s.Error(err)
}
func (s *testSplitSuite) TestStaleEpoch() {

View File

@ -470,6 +470,14 @@ func (s *RegionRequestSender) SendReqAsync(
cb async.Callback[*tikvrpc.ResponseExt],
opts ...StoreSelectorOption,
) {
if resp, err := failpointSendReqResult(req, tikvrpc.TiKV); err != nil || resp != nil {
var re *tikvrpc.ResponseExt
if resp != nil {
re = &tikvrpc.ResponseExt{Response: *resp}
}
cb.Invoke(re, err)
return
}
if err := s.validateReadTS(bo.GetCtx(), req); err != nil {
logutil.Logger(bo.GetCtx()).Error("validate read ts failed for request", zap.Stringer("reqType", req.Type), zap.Stringer("req", req.Req.(fmt.Stringer)), zap.Stringer("context", &req.Context), zap.Stack("stack"), zap.Error(err))
cb.Invoke(nil, err)

View File

@ -75,8 +75,8 @@ func (s *KVSnapshot) asyncBatchGetByRegions(
}))
}
for completed < len(batches) {
_, err = runloop.Exec(bo.GetCtx())
if err != nil {
if _, e := runloop.Exec(bo.GetCtx()); e != nil {
err = errors.WithStack(e)
break
}
}