fix attach api ctx error for unknown requests like StoreSafeTS (#720)

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
This commit is contained in:
iosmanthus 2023-02-28 13:47:31 +08:00 committed by GitHub
parent 596b79404d
commit 11d34cbd8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -101,10 +101,7 @@ func attachAPICtx(c Codec, req *tikvrpc.Request) (*tikvrpc.Request, error) {
r.Req = &mpp
}
err := tikvrpc.AttachContext(&r, ctx)
if err != nil {
return nil, err
}
_ = tikvrpc.AttachContext(&r, ctx)
return &r, nil
}

View File

@ -5,6 +5,7 @@ import (
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/stretchr/testify/assert"
"github.com/tikv/client-go/v2/tikvrpc"
)
func TestParseKeyspaceID(t *testing.T) {
@ -46,3 +47,13 @@ func TestDecodeKey(t *testing.T) {
assert.Empty(t, pfx)
assert.Empty(t, key)
}
func TestEncodeUnknownRequest(t *testing.T) {
req := &tikvrpc.Request{
Type: tikvrpc.CmdStoreSafeTS,
Req: &kvrpcpb.StoreSafeTSRequest{},
}
c := NewCodecV1(ModeTxn)
_, err := c.EncodeRequest(req)
assert.Nil(t, err)
}