mirror of https://github.com/tikv/client-go.git
txnkv: fix the issue that batch-get error might be ignored (#1733)
Signed-off-by: zyguan <zhongyangguan@gmail.com>
This commit is contained in:
parent
97cad411eb
commit
82ff387182
|
|
@ -39,6 +39,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pingcap/failpoint"
|
||||||
"github.com/pingcap/kvproto/pkg/keyspacepb"
|
"github.com/pingcap/kvproto/pkg/keyspacepb"
|
||||||
"github.com/pingcap/kvproto/pkg/meta_storagepb"
|
"github.com/pingcap/kvproto/pkg/meta_storagepb"
|
||||||
"github.com/pingcap/kvproto/pkg/metapb"
|
"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("a"), m[string([]byte{'a'})])
|
||||||
s.Equal([]byte("c"), m[string([]byte{'c'})])
|
s.Equal([]byte("c"), m[string([]byte{'c'})])
|
||||||
s.NotContains(m, string([]byte{'b'}))
|
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() {
|
func (s *testSplitSuite) TestStaleEpoch() {
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,14 @@ func (s *RegionRequestSender) SendReqAsync(
|
||||||
cb async.Callback[*tikvrpc.ResponseExt],
|
cb async.Callback[*tikvrpc.ResponseExt],
|
||||||
opts ...StoreSelectorOption,
|
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 {
|
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))
|
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)
|
cb.Invoke(nil, err)
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,8 @@ func (s *KVSnapshot) asyncBatchGetByRegions(
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
for completed < len(batches) {
|
for completed < len(batches) {
|
||||||
_, err = runloop.Exec(bo.GetCtx())
|
if _, e := runloop.Exec(bo.GetCtx()); e != nil {
|
||||||
if err != nil {
|
err = errors.WithStack(e)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue