Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] skip evict leader for v7.5.1 #8614

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
63eb0cb
placement: add rule/group count metrics (#7232) (#7243)
ti-chi-bot Oct 25, 2023
8b64ecf
rule_checker: fix the issue of not being able to achieve the better R…
ti-chi-bot Oct 25, 2023
7b3611a
*: check whether region is nil (#7263) (#7267)
ti-chi-bot Oct 26, 2023
a54621a
api: fix cannot dump trace (#7255) (#7265)
ti-chi-bot Oct 26, 2023
595d5b0
dashboard: update hotfix version (#7303) (#7307)
ti-chi-bot Nov 2, 2023
710ffcd
replication mode: fix wrong available store list (#7222) (#7328)
ti-chi-bot Nov 8, 2023
da1e92d
core: batch get region size (#7252) (#7332)
ti-chi-bot Nov 8, 2023
a22710c
checker: reduces the probability of deleting normal peers when the st…
lhy1024 Nov 8, 2023
7c65b8d
chore(dashboard): update tidb dashboard verstion to v2023.11.08.1 (#7…
ti-chi-bot Nov 9, 2023
d09a4f5
mcs/resourcemanager: delete expire tokenSlot (#7344) (#7350)
ti-chi-bot Nov 10, 2023
d0a17ca
etcdutil, leadership: avoid redundant created watch channel (#7352) (…
ti-chi-bot Nov 10, 2023
ef6ba85
resourcemanager: return resource-group priority in OnRequestWait (#73…
ti-chi-bot Nov 16, 2023
a5b9d66
go.mod: upgrade gin version from v1.8.1 to v1.9.1 (#7451) (#7514)
ti-chi-bot Dec 11, 2023
3d7f65e
resource_control: improve trace logs, ctl and metrics (#7510) (#7524)
ti-chi-bot Dec 12, 2023
d2074a9
resource_control: fix data race in controller (#7520) (#7526)
ti-chi-bot Dec 13, 2023
c9c9979
errs: remove redundant `FastGenWithCause` in `ZapError` (#7497) (#7545)
ti-chi-bot Dec 22, 2023
8ea0f6f
client: update the leader even if the connection creation fails (#744…
ti-chi-bot Dec 25, 2023
7ce5860
resource_mananger: deep clone resource group (#7623) (#7625)
ti-chi-bot Jan 2, 2024
511b094
resource_control: unify label name to group_name (#7547) (#7656)
ti-chi-bot Jan 3, 2024
a276843
resource_group: don't accumulate tokens when burstlimit less than 0 (…
ti-chi-bot Jan 4, 2024
0794b5e
memory: support cgroup with systemd (#7627) (#7666)
ti-chi-bot Jan 10, 2024
25071dd
scheduler: add aduit log for scheduler config API and add resp msg fo…
ti-chi-bot Jan 16, 2024
1be15d7
check: remove orphan peer only when the peers is greater than the rul…
ti-chi-bot Feb 1, 2024
6978558
client: return total wait duration in resource interceptor OnRequestW…
ti-chi-bot Feb 2, 2024
ae19047
member: avoid frequent campaign times (#7301) (#7790)
ti-chi-bot Feb 2, 2024
85e1a27
*: cherry-pick the etcd client health checker improvements (#7793)
JmPotato Feb 4, 2024
318a3fd
mcs: fix metrics cleanup (#7652) (#7659)
ti-chi-bot Feb 5, 2024
83f290a
*: fix context usage when watch etcd (#7806) (#7811)
ti-chi-bot Feb 7, 2024
decd310
schedule: fix panic when switching placement rules (#7415) (#7425)
ti-chi-bot Feb 7, 2024
ae9db49
api: fix panic when region doesn't have a leader (#7629) (#7650)
ti-chi-bot Feb 9, 2024
b8feb2b
prepare_check: remove redundant check (#7217) (#7818)
ti-chi-bot Feb 10, 2024
3488a65
*: fix region stats check (#7748) (#7812)
ti-chi-bot Feb 10, 2024
7294ff9
chore(dashboard): update TiDB Dashboard to v7.5.1-43fe8dac [release-7…
baurine Feb 20, 2024
d71a1a3
core: fix datarace in MergeLabels (#7537) (#7830)
ti-chi-bot Feb 20, 2024
463297b
scheduler: skip evict-leader-scheduler when setting schedule deny lab…
okJiang Jun 24, 2024
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
Prev Previous commit
Next Next commit
resource_mananger: deep clone resource group (#7623) (#7625)
close #7206

resource_mananger: deep clone resource group

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: nolouch <nolouch@gmail.com>

Co-authored-by: ShuNing <nolouch@gmail.com>
Co-authored-by: nolouch <nolouch@gmail.com>
  • Loading branch information
ti-chi-bot and nolouch authored Jan 2, 2024
commit 7ce5860ab342205c79ab880774558de3ec7fb996
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/kms v1.20.8
github.com/aws/aws-sdk-go-v2/service/sts v1.18.7
github.com/axw/gocov v1.0.0
github.com/brianvoe/gofakeit/v6 v6.26.3
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/coreos/go-semver v0.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch h1:KLE/YeX+9FNaGVW5MtImRVPhjDpfpgJhvkuYWBmOYbo=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8=
github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down
4 changes: 2 additions & 2 deletions pkg/mcs/resourcemanager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (m *Manager) GetResourceGroup(name string) *ResourceGroup {
m.RLock()
defer m.RUnlock()
if group, ok := m.groups[name]; ok {
return group.Copy()
return group.Clone()
}
return nil
}
Expand All @@ -302,7 +302,7 @@ func (m *Manager) GetResourceGroupList() []*ResourceGroup {
m.RLock()
res := make([]*ResourceGroup, 0, len(m.groups))
for _, group := range m.groups {
res = append(res, group.Copy())
res = append(res, group.Clone())
}
m.RUnlock()
sort.Slice(res, func(i, j int) bool {
Expand Down
41 changes: 30 additions & 11 deletions pkg/mcs/resourcemanager/server/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"time"

"github.com/gogo/protobuf/proto"
"github.com/pingcap/errors"
rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/pingcap/log"
Expand All @@ -44,6 +45,20 @@ type RequestUnitSettings struct {
RU *GroupTokenBucket `json:"r_u,omitempty"`
}

// Clone returns a deep copy of the RequestUnitSettings.
func (rus *RequestUnitSettings) Clone() *RequestUnitSettings {
if rus == nil {
return nil
}
var ru *GroupTokenBucket
if rus.RU != nil {
ru = rus.RU.Clone()
}
return &RequestUnitSettings{
RU: ru,
}
}

// NewRequestUnitSettings creates a new RequestUnitSettings with the given token bucket.
func NewRequestUnitSettings(tokenBucket *rmpb.TokenBucket) *RequestUnitSettings {
return &RequestUnitSettings{
Expand All @@ -60,21 +75,25 @@ func (rg *ResourceGroup) String() string {
return string(res)
}

// Copy copies the resource group.
func (rg *ResourceGroup) Copy() *ResourceGroup {
// TODO: use a better way to copy
// Clone copies the resource group.
func (rg *ResourceGroup) Clone() *ResourceGroup {
rg.RLock()
defer rg.RUnlock()
res, err := json.Marshal(rg)
if err != nil {
panic(err)
newRG := &ResourceGroup{
Name: rg.Name,
Mode: rg.Mode,
Priority: rg.Priority,
RUSettings: rg.RUSettings.Clone(),
}
var newRG ResourceGroup
err = json.Unmarshal(res, &newRG)
if err != nil {
panic(err)
if rg.Runaway != nil {
newRG.Runaway = proto.Clone(rg.Runaway).(*rmpb.RunawaySettings)
}
return &newRG

if rg.Background != nil {
newRG.Background = proto.Clone(rg.Background).(*rmpb.BackgroundSettings)
}

return newRG
}

func (rg *ResourceGroup) getRUToken() float64 {
Expand Down
40 changes: 39 additions & 1 deletion pkg/mcs/resourcemanager/server/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package server

import (
"encoding/json"
"reflect"
"testing"

"github.com/brianvoe/gofakeit/v6"
rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/stretchr/testify/require"
)
Expand All @@ -29,8 +31,44 @@ func TestPatchResourceGroup(t *testing.T) {
re.NoError(err)
err = rg.PatchSettings(patch)
re.NoError(err)
res, err := json.Marshal(rg.Copy())
res, err := json.Marshal(rg.Clone())
re.NoError(err)
re.Equal(ca.expectJSONString, string(res))
}
}

func resetSizeCache(obj interface{}) {
resetSizeCacheRecursive(reflect.ValueOf(obj))
}

func resetSizeCacheRecursive(value reflect.Value) {
if value.Kind() == reflect.Ptr {
value = value.Elem()
}

if value.Kind() != reflect.Struct {
return
}

for i := 0; i < value.NumField(); i++ {
fieldValue := value.Field(i)
fieldType := value.Type().Field(i)

if fieldType.Name == "XXX_sizecache" && fieldType.Type.Kind() == reflect.Int32 {
fieldValue.SetInt(0)
} else {
resetSizeCacheRecursive(fieldValue)
}
}
}

func TestClone(t *testing.T) {
for i := 0; i <= 10; i++ {
var rg ResourceGroup
gofakeit.Struct(&rg)
// hack to reset XXX_sizecache, gofakeit will random set this field but proto clone will not copy this field.
resetSizeCache(&rg)
rgClone := rg.Clone()
require.EqualValues(t, &rg, rgClone)
}
}
26 changes: 23 additions & 3 deletions pkg/mcs/resourcemanager/server/token_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ type GroupTokenBucket struct {
GroupTokenBucketState `json:"state,omitempty"`
}

// Clone returns the deep copy of GroupTokenBucket
func (gtb *GroupTokenBucket) Clone() *GroupTokenBucket {
if gtb == nil {
return nil
}
var settings *rmpb.TokenLimitSettings
if gtb.Settings != nil {
settings = proto.Clone(gtb.Settings).(*rmpb.TokenLimitSettings)
}
stateClone := *gtb.GroupTokenBucketState.Clone()
return &GroupTokenBucket{
Settings: settings,
GroupTokenBucketState: stateClone,
}
}

func (gtb *GroupTokenBucket) setState(state *GroupTokenBucketState) {
gtb.Tokens = state.Tokens
gtb.LastUpdate = state.LastUpdate
Expand Down Expand Up @@ -85,10 +101,14 @@ type GroupTokenBucketState struct {

// Clone returns the copy of GroupTokenBucketState
func (gts *GroupTokenBucketState) Clone() *GroupTokenBucketState {
tokenSlots := make(map[uint64]*TokenSlot)
for id, tokens := range gts.tokenSlots {
tokenSlots[id] = tokens
var tokenSlots map[uint64]*TokenSlot
if gts.tokenSlots != nil {
tokenSlots = make(map[uint64]*TokenSlot)
for id, tokens := range gts.tokenSlots {
tokenSlots[id] = tokens
}
}

var lastUpdate *time.Time
if gts.LastUpdate != nil {
newLastUpdate := *gts.LastUpdate
Expand Down
2 changes: 2 additions & 0 deletions tests/integrations/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch h1:KLE/YeX+9FNaGVW5MtImRVPhjDpfpgJhvkuYWBmOYbo=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8=
github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down
2 changes: 2 additions & 0 deletions tests/integrations/mcs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch h1:KLE/YeX+9FNaGVW5MtImRVPhjDpfpgJhvkuYWBmOYbo=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8=
github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down
2 changes: 2 additions & 0 deletions tests/integrations/tso/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch h1:KLE/YeX+9FNaGVW5MtImRVPhjDpfpgJhvkuYWBmOYbo=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8=
github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down
Loading