Skip to content

Commit

Permalink
*: handle region error for GetMvccByEncodedKey API (#47811) (#47820)
Browse files Browse the repository at this point in the history
close #47807
  • Loading branch information
ti-chi-bot authored Nov 10, 2023
1 parent 8c0f360 commit 76fab0e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ go_test(
"//pkg/expression/aggregation",
"//pkg/infoschema",
"//pkg/kv",
"//pkg/meta",
"//pkg/meta/autoid",
"//pkg/metrics",
"//pkg/parser",
Expand Down
30 changes: 30 additions & 0 deletions pkg/executor/executor_failpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/ddl"
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/parser/terror"
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/store/copr"
"github.com/pingcap/tidb/pkg/store/helper"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/util/dbterror/exeerrors"
"github.com/pingcap/tidb/pkg/util/deadlockhistory"
Expand Down Expand Up @@ -622,3 +624,31 @@ func TestTiKVClientReadTimeout(t *testing.T) {
explain = fmt.Sprintf("%v", rows[0])
require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 2.*", explain)
}

func TestGetMvccByEncodedKeyRegionError(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
h := helper.NewHelper(store.(helper.Storage))
txn, err := store.Begin()
require.NoError(t, err)
m := meta.NewMeta(txn)
schemaVersion := tk.Session().GetDomainInfoSchema().SchemaMetaVersion()
key := m.EncodeSchemaDiffKey(schemaVersion)

resp, err := h.GetMvccByEncodedKey(key)
require.NoError(t, err)
require.NotNil(t, resp.Info)
require.Equal(t, 1, len(resp.Info.Writes))
require.Less(t, uint64(0), resp.Info.Writes[0].CommitTs)
commitTs := resp.Info.Writes[0].CommitTs

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/store/mockstore/unistore/epochNotMatch", "2*return(true)"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/mockstore/unistore/epochNotMatch"))
}()
resp, err = h.GetMvccByEncodedKey(key)
require.NoError(t, err)
require.NotNil(t, resp.Info)
require.Equal(t, 1, len(resp.Info.Writes))
require.Equal(t, commitTs, resp.Info.Writes[0].CommitTs)
}
5 changes: 5 additions & 0 deletions pkg/store/mockstore/unistore/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (c *RPCClient) SendRequest(ctx context.Context, addr string, req *tikvrpc.R
failpoint.Return(tikvrpc.GenRegionErrorResp(req, &errorpb.Error{ServerIsBusy: &errorpb.ServerIsBusy{}}))
}
})
failpoint.Inject("epochNotMatch", func(val failpoint.Value) {
if val.(bool) {
failpoint.Return(tikvrpc.GenRegionErrorResp(req, &errorpb.Error{EpochNotMatch: &errorpb.EpochNotMatch{}}))
}
})

failpoint.Inject("unistoreRPCClientSendHook", func(val failpoint.Value) {
if fn := UnistoreRPCClientSendHook.Load(); val.(bool) && fn != nil {
Expand Down

0 comments on commit 76fab0e

Please sign in to comment.