Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch committed Jan 3, 2024
1 parent 6d0a697 commit 705d510
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 86 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
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
12 changes: 2 additions & 10 deletions pkg/mcs/resource_manager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,7 @@ func (m *Manager) GetResourceGroup(name string) *ResourceGroup {
m.RLock()
defer m.RUnlock()
if group, ok := m.groups[name]; ok {
<<<<<<< HEAD:pkg/mcs/resource_manager/server/manager.go
return group.Copy()
=======
return group.Clone(withStats)
>>>>>>> ed9685a79 (resource_mananger: deep clone resource group (#7623)):pkg/mcs/resourcemanager/server/manager.go
return group.Clone()
}
return nil
}
Expand All @@ -302,11 +298,7 @@ func (m *Manager) GetResourceGroupList() []*ResourceGroup {
m.RLock()
res := make([]*ResourceGroup, 0, len(m.groups))
for _, group := range m.groups {
<<<<<<< HEAD:pkg/mcs/resource_manager/server/manager.go
res = append(res, group.Copy())
=======
res = append(res, group.Clone(withStats))
>>>>>>> ed9685a79 (resource_mananger: deep clone resource group (#7623)):pkg/mcs/resourcemanager/server/manager.go
res = append(res, group.Clone())
}
m.RUnlock()
sort.Slice(res, func(i, j int) bool {
Expand Down
25 changes: 1 addition & 24 deletions pkg/mcs/resource_manager/server/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sync"
"time"

"github.com/gogo/protobuf/proto"
"github.com/pingcap/errors"
rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/pingcap/log"
Expand Down Expand Up @@ -73,14 +72,8 @@ func (rg *ResourceGroup) String() string {
return string(res)
}

<<<<<<< HEAD:pkg/mcs/resource_manager/server/resource_group.go
// 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(withStats bool) *ResourceGroup {
>>>>>>> ed9685a79 (resource_mananger: deep clone resource group (#7623)):pkg/mcs/resourcemanager/server/resource_group.go
func (rg *ResourceGroup) Clone() *ResourceGroup {
rg.RLock()
defer rg.RUnlock()
newRG := &ResourceGroup{
Expand All @@ -89,23 +82,7 @@ func (rg *ResourceGroup) Clone(withStats bool) *ResourceGroup {
Priority: rg.Priority,
RUSettings: rg.RUSettings.Clone(),
}
if rg.Runaway != nil {
newRG.Runaway = proto.Clone(rg.Runaway).(*rmpb.RunawaySettings)
}
<<<<<<< HEAD:pkg/mcs/resource_manager/server/resource_group.go
return &newRG
=======

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

if withStats && rg.RUConsumption != nil {
newRG.RUConsumption = proto.Clone(rg.RUConsumption).(*rmpb.Consumption)
}

return newRG
>>>>>>> ed9685a79 (resource_mananger: deep clone resource group (#7623)):pkg/mcs/resourcemanager/server/resource_group.go
}

func (rg *ResourceGroup) getRUToken() float64 {
Expand Down
44 changes: 1 addition & 43 deletions pkg/mcs/resource_manager/server/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ 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 @@ -31,48 +29,8 @@ func TestPatchResourceGroup(t *testing.T) {
re.NoError(err)
err = rg.PatchSettings(patch)
re.NoError(err)
<<<<<<< HEAD:pkg/mcs/resource_manager/server/resource_group_test.go
res, err := json.Marshal(rg.Copy())
=======
res, err := json.Marshal(rg.Clone(false))
>>>>>>> ed9685a79 (resource_mananger: deep clone resource group (#7623)):pkg/mcs/resourcemanager/server/resource_group_test.go
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(true)
require.EqualValues(t, &rg, rgClone)
}
}
2 changes: 0 additions & 2 deletions tests/integrations/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
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: 0 additions & 2 deletions tests/integrations/mcs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
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: 0 additions & 2 deletions tests/integrations/tso/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
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

0 comments on commit 705d510

Please sign in to comment.