diff --git a/error/error.go b/error/error.go index 48650cc4..0a44fbf4 100644 --- a/error/error.go +++ b/error/error.go @@ -41,6 +41,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/pingcap/parser/terror" "github.com/tikv/client-go/v2/internal/logutil" "github.com/tikv/client-go/v2/util" "go.uber.org/zap" @@ -259,3 +260,8 @@ func ExtractKeyErr(keyErr *kvrpcpb.KeyError) error { } return errors.Errorf("unexpected KeyError: %s", keyErr.String()) } + +// IsErrorUndetermined checks if the error is undetermined error. +func IsErrorUndetermined(err error) bool { + return terror.ErrorEqual(err, terror.ErrResultUndetermined) +} diff --git a/integration_tests/2pc_test.go b/integration_tests/2pc_test.go index 20a74ac2..8ce41838 100644 --- a/integration_tests/2pc_test.go +++ b/integration_tests/2pc_test.go @@ -51,7 +51,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/kvrpcpb" - "github.com/pingcap/parser/terror" drivertxn "github.com/pingcap/tidb/store/driver/txn" "github.com/stretchr/testify/suite" "github.com/tikv/client-go/v2/config" @@ -1433,7 +1432,7 @@ func (s *testCommitterSuite) TestFailCommitPrimaryRpcErrors() { s.Nil(err) err = t1.Commit(context.Background()) s.NotNil(err) - s.True(terror.ErrorEqual(err, terror.ErrResultUndetermined), errors.ErrorStack(err)) + s.True(tikverr.IsErrorUndetermined(err), errors.ErrorStack(err)) // We don't need to call "Rollback" after "Commit" fails. err = t1.Rollback() @@ -1454,7 +1453,7 @@ func (s *testCommitterSuite) TestFailCommitPrimaryRegionError() { s.Nil(err) err = t2.Commit(context.Background()) s.NotNil(err) - s.True(terror.ErrorNotEqual(err, terror.ErrResultUndetermined)) + s.False(tikverr.IsErrorUndetermined(err), errors.ErrorStack(err)) } // TestFailCommitPrimaryRPCErrorThenRegionError tests the case when commit first @@ -1470,7 +1469,7 @@ func (s *testCommitterSuite) TestFailCommitPrimaryRPCErrorThenRegionError() { s.Nil(err) err = t1.Commit(context.Background()) s.NotNil(err) - s.True(terror.ErrorEqual(err, terror.ErrResultUndetermined), errors.ErrorStack(err)) + s.True(tikverr.IsErrorUndetermined(err), errors.ErrorStack(err)) } // TestFailCommitPrimaryKeyError tests KeyError is handled properly when @@ -1487,7 +1486,7 @@ func (s *testCommitterSuite) TestFailCommitPrimaryKeyError() { s.Nil(err) err = t3.Commit(context.Background()) s.NotNil(err) - s.True(terror.ErrorNotEqual(err, terror.ErrResultUndetermined)) + s.False(tikverr.IsErrorUndetermined(err)) } // TestFailCommitPrimaryRPCErrorThenKeyError tests KeyError overwrites the undeterminedErr. @@ -1503,7 +1502,7 @@ func (s *testCommitterSuite) TestFailCommitPrimaryRPCErrorThenKeyError() { s.Nil(err) err = t3.Commit(context.Background()) s.NotNil(err) - s.False(terror.ErrorEqual(err, terror.ErrResultUndetermined)) + s.False(tikverr.IsErrorUndetermined(err)) } func (s *testCommitterSuite) TestFailCommitTimeout() { diff --git a/integration_tests/async_commit_fail_test.go b/integration_tests/async_commit_fail_test.go index be335ad7..252abc56 100644 --- a/integration_tests/async_commit_fail_test.go +++ b/integration_tests/async_commit_fail_test.go @@ -43,7 +43,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/kvrpcpb" - "github.com/pingcap/parser/terror" "github.com/stretchr/testify/suite" tikverr "github.com/tikv/client-go/v2/error" "github.com/tikv/client-go/v2/tikv" @@ -87,7 +86,7 @@ func (s *testAsyncCommitFailSuite) TestFailAsyncCommitPrewriteRpcErrors() { ctx := context.WithValue(context.Background(), util.SessionID, uint64(1)) err = t1.Commit(ctx) s.NotNil(err) - s.True(terror.ErrorEqual(err, terror.ErrResultUndetermined), errors.ErrorStack(err)) + s.True(tikverr.IsErrorUndetermined(err), errors.ErrorStack(err)) // We don't need to call "Rollback" after "Commit" fails. err = t1.Rollback()