Skip to content

Commit

Permalink
unify the error definition
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Dec 11, 2024
1 parent 5d62787 commit f1ebf38
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 174 deletions.
130 changes: 130 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ error = '''
unsupported metrics type %v
'''

["PD:cgroup:ErrNoCPUControllerDetected"]
error = '''
no cpu controller detected
'''

["PD:checker:ErrCheckerMergeAgain"]
error = '''
region will be merged again, %s
Expand All @@ -71,6 +76,36 @@ error = '''
checker not found
'''

["PD:checker:ErrNoNewLeader"]
error = '''
no new leader
'''

["PD:checker:ErrNoStoreToAdd"]
error = '''
no store to add peer
'''

["PD:checker:ErrNoStoreToReplace"]
error = '''
no store to replace peer
'''

["PD:checker:ErrPeerCannotBeLeader"]
error = '''
peer cannot be leader
'''

["PD:checker:ErrPeerCannotBeWitness"]
error = '''
peer cannot be witness
'''

["PD:checker:ErrRegionNoLeader"]
error = '''
region no leader
'''

["PD:client:ErrClientCreateTSOStream"]
error = '''
create TSO stream failed, %s
Expand Down Expand Up @@ -491,6 +526,91 @@ error = '''
failed to unmarshal json
'''

["PD:keyspace:ErrExceedMaxEtcdTxnOps"]
error = '''
exceed max etcd txn operations
'''

["PD:keyspace:ErrIllegalOperation"]
error = '''
unknown operation
'''

["PD:keyspace:ErrKeyspaceExists"]
error = '''
keyspace already exists
'''

["PD:keyspace:ErrKeyspaceGroupExists"]
error = '''
keyspace group already exists
'''

["PD:keyspace:ErrKeyspaceGroupNotEnoughReplicas"]
error = '''
not enough replicas in the keyspace group
'''

["PD:keyspace:ErrKeyspaceGroupPrimaryNotFound"]
error = '''
primary of keyspace group does not exist
'''

["PD:keyspace:ErrKeyspaceGroupWithEmptyKeyspace"]
error = '''
keyspace group with empty keyspace
'''

["PD:keyspace:ErrKeyspaceNotFound"]
error = '''
keyspace does not exist
'''

["PD:keyspace:ErrKeyspaceNotInAnyKeyspaceGroup"]
error = '''
keyspace is not in any keyspace group
'''

["PD:keyspace:ErrKeyspaceNotInKeyspaceGroup"]
error = '''
keyspace is not in this keyspace group
'''

["PD:keyspace:ErrModifyDefaultKeyspace"]
error = '''
cannot modify default keyspace's state
'''

["PD:keyspace:ErrModifyDefaultKeyspaceGroup"]
error = '''
default keyspace group cannot be modified
'''

["PD:keyspace:ErrNoAvailableNode"]
error = '''
no available node
'''

["PD:keyspace:ErrNodeNotInKeyspaceGroup"]
error = '''
the tso node is not in this keyspace group
'''

["PD:keyspace:ErrRegionSplitFailed"]
error = '''
region split failed
'''

["PD:keyspace:ErrRegionSplitTimeout"]
error = '''
region split timeout
'''

["PD:keyspace:ErrUnsupportedOperationInKeyspace"]
error = '''
it's a unsupported operation
'''

["PD:leveldb:ErrLevelDBClose"]
error = '''
close leveldb error
Expand Down Expand Up @@ -646,6 +766,11 @@ error = '''
failed to unmarshal proto
'''

["PD:ratelimit:ErrMaxWaitingTasksExceeded"]
error = '''
max waiting tasks exceeded
'''

["PD:region:ErrRegionAbnormalPeer"]
error = '''
region %v has abnormal peer
Expand Down Expand Up @@ -691,6 +816,11 @@ error = '''
invalid group settings, please check the group name, priority and the number of resources
'''

["PD:scatter:ErrEmptyRegion"]
error = '''
empty region
'''

["PD:schedule:ErrCreateOperator"]
error = '''
unable to create operator, %s
Expand Down
5 changes: 2 additions & 3 deletions pkg/cgroup/cgroup_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
"path/filepath"

"github.com/pingcap/errors"
"github.com/tikv/pd/pkg/errs"
)

var errNoCPUControllerDetected = errors.New("no cpu controller detected")

// Helper function for getCgroupCPU. Root is always "/", except in tests.
func getCgroupCPUHelper(root string) (CPUUsage, error) {
path, err := detectControlPath(filepath.Join(root, procPathCGroup), "cpu,cpuacct")
Expand All @@ -32,7 +31,7 @@ func getCgroupCPUHelper(root string) (CPUUsage, error) {

// No CPU controller detected
if path == "" {
return CPUUsage{}, errNoCPUControllerDetected
return CPUUsage{}, errs.ErrNoCPUControllerDetected
}

mount, ver, err := getCgroupDetails(filepath.Join(root, procPathMountInfo), path, "cpu,cpuacct")
Expand Down
3 changes: 2 additions & 1 deletion pkg/cgroup/cgroup_cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tikv/pd/pkg/errs"
)

func checkKernelVersionNewerThan(re *require.Assertions, t *testing.T, major, minor int) bool {
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestGetCgroupCPU(t *testing.T) {
}()
}
cpu, err := GetCgroupCPU()
if err == errNoCPUControllerDetected {
if err == errs.ErrNoCPUControllerDetected {
// for more information, please refer https://github.com/pingcap/tidb/pull/41347
if checkKernelVersionNewerThan(re, t, 4, 7) {
re.NoError(err, "linux version > v4.7 and err still happens")
Expand Down
64 changes: 62 additions & 2 deletions pkg/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,58 @@ var (

// checker errors
var (
ErrCheckerNotFound = errors.Normalize("checker not found", errors.RFCCodeText("PD:checker:ErrCheckerNotFound"))
ErrCheckerMergeAgain = errors.Normalize("region will be merged again, %s", errors.RFCCodeText("PD:checker:ErrCheckerMergeAgain"))
ErrCheckerNotFound = errors.Normalize("checker not found", errors.RFCCodeText("PD:checker:ErrCheckerNotFound"))
ErrCheckerMergeAgain = errors.Normalize("region will be merged again, %s", errors.RFCCodeText("PD:checker:ErrCheckerMergeAgain"))
ErrNoStoreToAdd = errors.Normalize("no store to add peer", errors.RFCCodeText("PD:checker:ErrNoStoreToAdd"))
ErrNoStoreToReplace = errors.Normalize("no store to replace peer", errors.RFCCodeText("PD:checker:ErrNoStoreToReplace"))
ErrPeerCannotBeLeader = errors.Normalize("peer cannot be leader", errors.RFCCodeText("PD:checker:ErrPeerCannotBeLeader"))
ErrPeerCannotBeWitness = errors.Normalize("peer cannot be witness", errors.RFCCodeText("PD:checker:ErrPeerCannotBeWitness"))
ErrNoNewLeader = errors.Normalize("no new leader", errors.RFCCodeText("PD:checker:ErrNoNewLeader"))
ErrRegionNoLeader = errors.Normalize("region no leader", errors.RFCCodeText("PD:checker:ErrRegionNoLeader"))
)

// scatter errors
var (
ErrEmptyRegion = errors.Normalize("empty region", errors.RFCCodeText("PD:scatter:ErrEmptyRegion"))
)

// keyspace errors
var (
// ErrKeyspaceNotFound is used to indicate target keyspace does not exist.
ErrKeyspaceNotFound = errors.Normalize("keyspace does not exist", errors.RFCCodeText("PD:keyspace:ErrKeyspaceNotFound"))
// ErrRegionSplitTimeout indices to split region timeout
ErrRegionSplitTimeout = errors.Normalize("region split timeout", errors.RFCCodeText("PD:keyspace:ErrRegionSplitTimeout"))
// ErrRegionSplitFailed indices to split region failed
ErrRegionSplitFailed = errors.Normalize("region split failed", errors.RFCCodeText("PD:keyspace:ErrRegionSplitFailed"))
// ErrKeyspaceExists indicates target keyspace already exists.
// It's used when creating a new keyspace.
ErrKeyspaceExists = errors.Normalize("keyspace already exists", errors.RFCCodeText("PD:keyspace:ErrKeyspaceExists"))
// ErrKeyspaceGroupExists indicates target keyspace group already exists.
ErrKeyspaceGroupExists = errors.Normalize("keyspace group already exists", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupExists"))
// ErrKeyspaceNotInKeyspaceGroup is used to indicate target keyspace is not in this keyspace group.
ErrKeyspaceNotInKeyspaceGroup = errors.Normalize("keyspace is not in this keyspace group", errors.RFCCodeText("PD:keyspace:ErrKeyspaceNotInKeyspaceGroup"))
// ErrKeyspaceNotInAnyKeyspaceGroup is used to indicate target keyspace is not in any keyspace group.
ErrKeyspaceNotInAnyKeyspaceGroup = errors.Normalize("keyspace is not in any keyspace group", errors.RFCCodeText("PD:keyspace:ErrKeyspaceNotInAnyKeyspaceGroup"))
// ErrNodeNotInKeyspaceGroup is used to indicate the tso node is not in this keyspace group.
ErrNodeNotInKeyspaceGroup = errors.Normalize("the tso node is not in this keyspace group", errors.RFCCodeText("PD:keyspace:ErrNodeNotInKeyspaceGroup"))
// ErrKeyspaceGroupNotEnoughReplicas is used to indicate not enough replicas in the keyspace group.
ErrKeyspaceGroupNotEnoughReplicas = errors.Normalize("not enough replicas in the keyspace group", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotEnoughReplicas"))
// ErrKeyspaceGroupWithEmptyKeyspace is used to indicate keyspace group with empty keyspace.
ErrKeyspaceGroupWithEmptyKeyspace = errors.Normalize("keyspace group with empty keyspace", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupWithEmptyKeyspace"))
// ErrModifyDefaultKeyspaceGroup is used to indicate that default keyspace group cannot be modified.
ErrModifyDefaultKeyspaceGroup = errors.Normalize("default keyspace group cannot be modified", errors.RFCCodeText("PD:keyspace:ErrModifyDefaultKeyspaceGroup"))
// ErrNoAvailableNode is used to indicate no available node in the keyspace group.
ErrNoAvailableNode = errors.Normalize("no available node", errors.RFCCodeText("PD:keyspace:ErrNoAvailableNode"))
// ErrExceedMaxEtcdTxnOps is used to indicate the number of etcd txn operations exceeds the limit.
ErrExceedMaxEtcdTxnOps = errors.Normalize("exceed max etcd txn operations", errors.RFCCodeText("PD:keyspace:ErrExceedMaxEtcdTxnOps"))
// ErrModifyDefaultKeyspace is used to indicate that default keyspace cannot be modified.
ErrModifyDefaultKeyspace = errors.Normalize("cannot modify default keyspace's state", errors.RFCCodeText("PD:keyspace:ErrModifyDefaultKeyspace"))
// ErrIllegalOperation is used to indicate this is an illegal operation.
ErrIllegalOperation = errors.Normalize("unknown operation", errors.RFCCodeText("PD:keyspace:ErrIllegalOperation"))
// ErrUnsupportedOperationInKeyspace is used to indicate this is an unsupported operation.
ErrUnsupportedOperationInKeyspace = errors.Normalize("it's a unsupported operation", errors.RFCCodeText("PD:keyspace:ErrUnsupportedOperationInKeyspace"))
// ErrKeyspaceGroupPrimaryNotFound is used to indicate primary of target keyspace group does not exist.
ErrKeyspaceGroupPrimaryNotFound = errors.Normalize("primary of keyspace group does not exist", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupPrimaryNotFound"))
)

// diagnostic errors
Expand Down Expand Up @@ -229,6 +279,16 @@ var (
ErrBytesToUint64 = errors.Normalize("invalid data, must 8 bytes, but %d", errors.RFCCodeText("PD:typeutil:ErrBytesToUint64"))
)

// cgroup errors
var (
ErrNoCPUControllerDetected = errors.Normalize("no cpu controller detected", errors.RFCCodeText("PD:cgroup:ErrNoCPUControllerDetected"))
)

// ratelimit errors
var (
ErrMaxWaitingTasksExceeded = errors.Normalize("max waiting tasks exceeded", errors.RFCCodeText("PD:ratelimit:ErrMaxWaitingTasksExceeded"))
)

// The third-party project error.
// url errors
var (
Expand Down
3 changes: 2 additions & 1 deletion pkg/gc/safepoint_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/keyspacepb"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/keyspace"
"github.com/tikv/pd/pkg/slice"
"github.com/tikv/pd/pkg/storage/endpoint"
Expand Down Expand Up @@ -99,7 +100,7 @@ func (manager *SafePointV2Manager) checkKeyspace(keyspaceID uint32, updateReques
}
// If a keyspace does not exist, then loading its gc safe point is prohibited.
if meta == nil {
return keyspace.ErrKeyspaceNotFound
return errs.ErrKeyspaceNotFound
}
// If keyspace's state does not permit updating safe point, we return error.
if updateRequest && !slice.Contains(allowUpdateSafePoint, meta.GetState()) {
Expand Down
Loading

0 comments on commit f1ebf38

Please sign in to comment.