Skip to content

Commit

Permalink
Merge branch 'master' into move-cb
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Dec 18, 2024
2 parents 0c4df00 + 221877d commit b935908
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 185 deletions.
155 changes: 155 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,116 @@ 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:ErrKeyspaceGroupInMerging"]
error = '''
keyspace group %v is in merging state
'''

["PD:keyspace:ErrKeyspaceGroupInSplit"]
error = '''
keyspace group %v is in split state
'''

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

["PD:keyspace:ErrKeyspaceGroupNotExists"]
error = '''
keyspace group %v does not exist
'''

["PD:keyspace:ErrKeyspaceGroupNotInMerging"]
error = '''
keyspace group %v is not in merging state
'''

["PD:keyspace:ErrKeyspaceGroupNotInSplit"]
error = '''
keyspace group %v is not in split state
'''

["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 +791,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 +841,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
6 changes: 3 additions & 3 deletions pkg/cgroup/cgroup_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"path/filepath"

"github.com/pingcap/errors"
)

var errNoCPUControllerDetected = errors.New("no cpu controller detected")
"github.com/tikv/pd/pkg/errs"
)

// Helper function for getCgroupCPU. Root is always "/", except in tests.
func getCgroupCPUHelper(root string) (CPUUsage, error) {
Expand All @@ -32,7 +32,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
4 changes: 3 additions & 1 deletion pkg/cgroup/cgroup_cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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 +84,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
75 changes: 73 additions & 2 deletions pkg/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,69 @@ 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"))
// ErrKeyspaceGroupNotExists is used to indicate target keyspace group does not exist.
ErrKeyspaceGroupNotExists = errors.Normalize("keyspace group %v does not exist", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotExists"))
// ErrKeyspaceGroupInSplit is used to indicate target keyspace group is in split state.
ErrKeyspaceGroupInSplit = errors.Normalize("keyspace group %v is in split state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupInSplit"))
// ErrKeyspaceGroupNotInSplit is used to indicate target keyspace group is not in split state.
ErrKeyspaceGroupNotInSplit = errors.Normalize("keyspace group %v is not in split state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotInSplit"))
// ErrKeyspaceGroupInMerging is used to indicate target keyspace group is in merging state.
ErrKeyspaceGroupInMerging = errors.Normalize("keyspace group %v is in merging state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupInMerging"))
// ErrKeyspaceGroupNotInMerging is used to indicate target keyspace group is not in merging state.
ErrKeyspaceGroupNotInMerging = errors.Normalize("keyspace group %v is not in merging state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotInMerging"))
// errKeyspaceGroupNotInMerging is used to indicate target keyspace group is not in merging state.
)

// diagnostic errors
Expand Down Expand Up @@ -228,6 +289,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 @@ -25,6 +25,7 @@ import (
"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 @@ -101,7 +102,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 b935908

Please sign in to comment.