From 0d4e66ee8d6c1008f247a693f371fe2eb4b23fa8 Mon Sep 17 00:00:00 2001 From: Shirly Date: Thu, 6 May 2021 12:09:52 +0800 Subject: [PATCH] store/tikv: make tikv.ErrTiKV* as normal errors instead of dberror (#24396) --- store/driver/txn/error.go | 16 ++++++++++++++-- store/tikv/error/errcode.go | 6 ++---- store/tikv/error/error.go | 17 ++++++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/store/driver/txn/error.go b/store/driver/txn/error.go index bd1ecc2c9a..10e08aaf35 100644 --- a/store/driver/txn/error.go +++ b/store/driver/txn/error.go @@ -39,8 +39,12 @@ import ( // tikv error instance var ( // ErrTiKVServerTimeout is the error when tikv server is timeout. - ErrTiKVServerTimeout = dbterror.ClassTiKV.NewStd(errno.ErrTiKVServerTimeout) - ErrResolveLockTimeout = dbterror.ClassTiKV.NewStd(errno.ErrResolveLockTimeout) + ErrTiKVServerTimeout = dbterror.ClassTiKV.NewStd(errno.ErrTiKVServerTimeout) + // ErrTiKVStaleCommand is the error that the command is stale in tikv. + ErrTiKVStaleCommand = dbterror.ClassTiKV.NewStd(errno.ErrTiKVStaleCommand) + // ErrTiKVMaxTimestampNotSynced is the error that tikv's max timestamp is not synced. + ErrTiKVMaxTimestampNotSynced = dbterror.ClassTiKV.NewStd(errno.ErrTiKVMaxTimestampNotSynced) + ErrResolveLockTimeout = dbterror.ClassTiKV.NewStd(errno.ErrResolveLockTimeout) ) func genKeyExistsError(name string, value string, err error) error { @@ -189,6 +193,14 @@ func toTiDBErr(err error) error { return ErrTiKVServerTimeout } + if errors.ErrorEqual(err, tikverr.ErrTiKVStaleCommand) { + return ErrTiKVStaleCommand + } + + if errors.ErrorEqual(err, tikverr.ErrTiKVMaxTimestampNotSynced) { + return ErrTiKVMaxTimestampNotSynced + } + if errors.ErrorEqual(err, tikverr.ErrResolveLockTimeout) { return ErrResolveLockTimeout } diff --git a/store/tikv/error/errcode.go b/store/tikv/error/errcode.go index 192d2163b3..1c6c77eb2c 100644 --- a/store/tikv/error/errcode.go +++ b/store/tikv/error/errcode.go @@ -32,8 +32,6 @@ const ( CodeTiKVStoreLimit = 9008 - CodeTiKVStaleCommand = 9010 - CodeTiKVMaxTimestampNotSynced = 9011 - CodeTiFlashServerTimeout = 9012 - CodeTiFlashServerBusy = 9013 + CodeTiFlashServerTimeout = 9012 + CodeTiFlashServerBusy = 9013 ) diff --git a/store/tikv/error/error.go b/store/tikv/error/error.go index f623c9f0f7..57efa7c82b 100644 --- a/store/tikv/error/error.go +++ b/store/tikv/error/error.go @@ -35,6 +35,10 @@ var ( ErrInvalidTxn = errors.New("invalid transaction") // ErrTiKVServerTimeout is the error when tikv server is timeout. ErrTiKVServerTimeout = errors.New("tikv server timeout") + // ErrTiKVStaleCommand is the error that the command is stale in tikv. + ErrTiKVStaleCommand = errors.New("tikv stale command") + // ErrTiKVMaxTimestampNotSynced is the error that tikv's max timestamp is not synced. + ErrTiKVMaxTimestampNotSynced = errors.New("tikv max timestamp not synced") // ErrResolveLockTimeout is the error that resolve lock timeout. ErrResolveLockTimeout = errors.New("resolve lock timeout") ) @@ -44,13 +48,12 @@ const MismatchClusterID = "mismatch cluster id" // error instances. var ( - ErrTiFlashServerTimeout = dbterror.ClassTiKV.NewStd(CodeTiFlashServerTimeout) - ErrPDServerTimeout = dbterror.ClassTiKV.NewStd(CodePDServerTimeout) - ErrRegionUnavailable = dbterror.ClassTiKV.NewStd(CodeRegionUnavailable) - ErrTiKVServerBusy = dbterror.ClassTiKV.NewStd(CodeTiKVServerBusy) - ErrTiFlashServerBusy = dbterror.ClassTiKV.NewStd(CodeTiFlashServerBusy) - ErrTiKVStaleCommand = dbterror.ClassTiKV.NewStd(CodeTiKVStaleCommand) - ErrTiKVMaxTimestampNotSynced = dbterror.ClassTiKV.NewStd(CodeTiKVMaxTimestampNotSynced) + ErrTiFlashServerTimeout = dbterror.ClassTiKV.NewStd(CodeTiFlashServerTimeout) + ErrPDServerTimeout = dbterror.ClassTiKV.NewStd(CodePDServerTimeout) + ErrRegionUnavailable = dbterror.ClassTiKV.NewStd(CodeRegionUnavailable) + ErrTiKVServerBusy = dbterror.ClassTiKV.NewStd(CodeTiKVServerBusy) + ErrTiFlashServerBusy = dbterror.ClassTiKV.NewStd(CodeTiFlashServerBusy) + ErrGCTooEarly = dbterror.ClassTiKV.NewStd(CodeGCTooEarly) ErrQueryInterrupted = dbterror.ClassTiKV.NewStd(CodeQueryInterrupted) ErrLockAcquireFailAndNoWaitSet = dbterror.ClassTiKV.NewStd(CodeLockAcquireFailAndNoWaitSet)