Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pkg/schedule/affinity/affinity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, testutil.LeakOptions...)
}

//nolint:unused
func getGroupForTest(re *require.Assertions, m *Manager, id string) *runtimeGroupInfo {
m.RLock()
defer m.RUnlock()
Expand All @@ -45,7 +44,6 @@ func getGroupForTest(re *require.Assertions, m *Manager, id string) *runtimeGrou
return &newGroup
}

//nolint:unused
func createGroupForTest(re *require.Assertions, m *Manager, id string, rangeCount int) []keyutil.KeyRange {
gkr := GroupKeyRanges{
KeyRanges: make([]keyutil.KeyRange, rangeCount),
Expand All @@ -61,7 +59,6 @@ func createGroupForTest(re *require.Assertions, m *Manager, id string, rangeCoun
return gkr.KeyRanges
}

//nolint:unused
func testCacheStale(re *require.Assertions, m *Manager, region *core.RegionInfo) {
cache, group := m.getCache(region)
if cache != nil && group != nil {
Expand All @@ -71,8 +68,6 @@ func testCacheStale(re *require.Assertions, m *Manager, region *core.RegionInfo)

// generateRegionForTest generates a test Region from the given information,
// where voterStoreIDs[0] is used as the leaderStoreID.
//
//nolint:unparam
func generateRegionForTest(id uint64, voterStoreIDs []uint64, keyRange keyutil.KeyRange) *core.RegionInfo {
peers := make([]*metapb.Peer, len(voterStoreIDs))
for i, storeID := range voterStoreIDs {
Expand Down
67 changes: 4 additions & 63 deletions pkg/schedule/affinity/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,66 +65,6 @@ func (a groupAvailability) String() string {
}
}

// storeCondition is an enum for store conditions. Valid values are the store-prefixed enum constants,
// which are split into three groups separated by degradedBoundary.
type storeCondition int

const (
storeAvailable storeCondition = iota

// All values greater than storeAvailable and less than degradedBoundary will trigger groupDegraded.
storeEvictLeader
storeDisconnected
storePreparing
storeLowSpace
degradedBoundary

// All values greater than degradedBoundary will trigger groupExpired.
storeDown
storeRemovingOrRemoved
)

func (c storeCondition) String() string {
switch c {
case storeAvailable:
return "available"
case storeEvictLeader:
return "evicted"
case storeDisconnected:
return "disconnected"
case storePreparing:
return "preparing"
case storeLowSpace:
return "low-space"
case storeDown:
return "down"
case storeRemovingOrRemoved:
return "removing-or-removed"
default:
return "unknown"
}
}

func (c storeCondition) groupAvailability() groupAvailability {
switch {
case c == storeAvailable:
return groupAvailable
case c <= degradedBoundary:
return groupDegraded
default:
return groupExpired
}
}

func (c storeCondition) affectsLeaderOnly() bool {
switch c {
case storeEvictLeader:
return true
default:
return false
}
}

// Phase is a status intended for API display
type Phase string

Expand Down Expand Up @@ -306,15 +246,16 @@ func (g *runtimeGroupInfo) SetAvailability(newAvailability groupAvailability) {
g.availability = groupExpired
}
// Update availability
if newAvailability == groupDegraded {
switch newAvailability {
case groupAvailable, groupExpired:
g.availability = newAvailability
case groupDegraded:
// Only set the expiration time when transitioning from groupAvailable to groupDegraded.
// Do nothing if the original availability is already groupDegraded or groupExpired.
if g.availability == groupAvailable {
g.availability = groupDegraded
g.degradedExpiredAt = newDegradedExpiredAtFromNow()
}
} else {
g.availability = newAvailability
}
}

Expand Down
6 changes: 0 additions & 6 deletions pkg/schedule/affinity/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func (m *Manager) initGroupLocked(group *Group) {
}
}

//nolint:unused
func (m *Manager) noGroupsExist(groups []*Group) error {
m.RLock()
defer m.RUnlock()
Expand All @@ -174,7 +173,6 @@ func (m *Manager) noGroupsExist(groups []*Group) error {
return nil
}

//nolint:unused
func (m *Manager) allGroupsExist(groupIDs []string) error {
m.RLock()
defer m.RUnlock()
Expand All @@ -186,7 +184,6 @@ func (m *Manager) allGroupsExist(groupIDs []string) error {
return nil
}

//nolint:unused
func (m *Manager) createGroups(groups []*Group, labelRules []*labeler.LabelRule) {
m.Lock()
defer m.Unlock()
Expand All @@ -202,7 +199,6 @@ func (m *Manager) resetCountLocked(groupInfo *runtimeGroupInfo) {
groupInfo.AffinityVer++
}

//nolint:unused
func (m *Manager) updateGroupPeers(groupID string, leaderStoreID uint64, voterStoreIDs []uint64) (*GroupState, error) {
m.Lock()
defer m.Unlock()
Expand Down Expand Up @@ -276,7 +272,6 @@ func (m *Manager) updateGroupLabelRuleLockedWithCount(groupID string, labelRule
groupInfo.RangeCount = rangeCount
}

//nolint:unused
func (m *Manager) updateGroupLabelRules(labels map[string]*labeler.LabelRule, needClear bool) {
m.Lock()
defer m.Unlock()
Expand All @@ -303,7 +298,6 @@ func (m *Manager) deleteGroupLocked(groupID string) {
delete(m.groups, groupID)
}

//nolint:unused
func (m *Manager) deleteGroups(groupIDs []string) {
m.Lock()
defer m.Unlock()
Expand Down
Loading