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

resource_manager: persist settings with settings prefix #5826

Merged
merged 5 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,5 @@ require (
// kvproto at the same time. You can run `go mod tidy` to make it replaced with go-mod style specification.
// After the PR to kvproto is merged, remember to comment this out and run `go mod tidy`.
// replace github.com/pingcap/kvproto => github.com/$YourPrivateRepo $YourPrivateBranch

replace github.com/pingcap/kvproto => github.com/nolouch/kvproto v0.0.0-20230104035728-9dcd8bcfcf2b
9 changes: 2 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQF
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v0.0.0-20180717141946-636bf0302bc9/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand All @@ -185,7 +184,6 @@ github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4er
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v0.0.0-20180814211427-aa810b61a9c7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -332,6 +330,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nolouch/kvproto v0.0.0-20230104035728-9dcd8bcfcf2b h1:2si08qfbhPfz6ZxKmt1tNmp2FDQgh5xTJPELL/Jj0+k=
github.com/nolouch/kvproto v0.0.0-20230104035728-9dcd8bcfcf2b/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM=
github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60=
Expand Down Expand Up @@ -364,9 +364,6 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c h1:xpW9bvK+HuuTm
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce h1:Y1kCxlCtlPTMtVcOkjUcuQKh+YrluSo7+7YMCQSzy30=
github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce/go.mod h1:w4PEZ5y16LeofeeGwdgZB4ddv9bLyDuIX+ljstgKZyk=
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26 h1:Tw4afZ2Tyr8iT8Oln6/szMjh5IDs+GtlnLsDo/Y2HEE=
github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
Expand Down Expand Up @@ -692,11 +689,9 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c h1:hrpEMCZ2O7DR5gC1n2AJGVhrwiEjOi35+jxtIuZpTMo=
google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
google.golang.org/grpc v0.0.0-20180607172857-7a6a684ca69e/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
Expand Down
6 changes: 3 additions & 3 deletions pkg/mcs/resource_manager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m *Manager) AddResourceGroup(group *ResourceGroup) error {
return err
}
m.Lock()
if err := m.storage().SaveResourceGroup(group.Name, group); err != nil {
if err := group.persistSettings(m.storage()); err != nil {
return err
}
m.groups[group.Name] = group
Expand All @@ -87,11 +87,11 @@ func (m *Manager) ModifyResourceGroup(group *rmpb.ResourceGroup) error {
return errors.New("not exists the group")
}
newGroup := curGroup.Copy()
err := newGroup.PatchSettings(group.GetSettings())
err := newGroup.PatchSettings(group)
if err != nil {
return err
}
if m.storage().SaveResourceGroup(group.Name, newGroup); err != nil {
if err := newGroup.persistSettings(m.storage()); err != nil {
return err
}
m.groups[group.Name] = newGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ package server

import (
"encoding/json"
"path"
"sync"

"github.com/pingcap/errors"
rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/pingcap/log"
"github.com/tikv/pd/server/storage"
"go.uber.org/zap"
)

const (
// ResourceGroupPathPrefix is the prefix of the resource group path to store group settings.
GroupSettingsPathPrefix = "/settings"
nolouch marked this conversation as resolved.
Show resolved Hide resolved
)

// ResourceGroup is the definition of a resource group, for REST API.
type ResourceGroup struct {
sync.RWMutex
Expand Down Expand Up @@ -106,26 +113,26 @@ func (rg *ResourceGroup) CheckAndInit() error {
// PatchSettings patches the resource group settings.
// Only used to patch the resource group when updating.
// Note: the tokens is the delta value to patch.
func (rg *ResourceGroup) PatchSettings(groupSettings *rmpb.GroupSettings) error {
func (rg *ResourceGroup) PatchSettings(metaGroup *rmpb.ResourceGroup) error {
rg.Lock()
defer rg.Unlock()
if groupSettings.GetMode() != rg.Mode {
if metaGroup.GetMode() != rg.Mode {
return errors.New("only support reconfigure in same mode, maybe you should delete and create a new one")
}
switch rg.Mode {
case rmpb.GroupMode_RUMode:
if groupSettings.GetRUSettings() == nil {
if metaGroup.GetRUSettings() == nil {
return errors.New("invalid resource group settings, RU mode should set RU settings")
}
rg.RUSettings.RRU.patch(groupSettings.GetRUSettings().GetRRU())
rg.RUSettings.WRU.patch(groupSettings.GetRUSettings().GetWRU())
rg.RUSettings.RRU.patch(metaGroup.GetRUSettings().GetRRU())
rg.RUSettings.WRU.patch(metaGroup.GetRUSettings().GetWRU())
case rmpb.GroupMode_NativeMode:
if groupSettings.GetResourceSettings() == nil {
if metaGroup.GetResourceSettings() == nil {
return errors.New("invalid resource group settings, native mode should set resource settings")
}
rg.ResourceSettings.CPU.patch(groupSettings.GetResourceSettings().GetCpu())
rg.ResourceSettings.IOReadBandwidth.patch(groupSettings.GetResourceSettings().GetIoRead())
rg.ResourceSettings.IOWriteBandwidth.patch(groupSettings.GetResourceSettings().GetIoWrite())
rg.ResourceSettings.CPU.patch(metaGroup.GetResourceSettings().GetCpu())
rg.ResourceSettings.IOReadBandwidth.patch(metaGroup.GetResourceSettings().GetIoRead())
rg.ResourceSettings.IOWriteBandwidth.patch(metaGroup.GetResourceSettings().GetIoWrite())
}
log.Info("patch resource group settings", zap.String("name", rg.Name), zap.String("settings", rg.String()))
return nil
Expand All @@ -140,11 +147,11 @@ func FromProtoResourceGroup(group *rmpb.ResourceGroup) *ResourceGroup {

rg := &ResourceGroup{
Name: group.Name,
Mode: group.Settings.Mode,
Mode: group.Mode,
}
switch group.GetSettings().GetMode() {
switch group.GetMode() {
case rmpb.GroupMode_RUMode:
if settings := group.GetSettings().GetRUSettings(); settings != nil {
if settings := group.GetRUSettings(); settings != nil {
ruSettings = &RequestUnitSettings{
RRU: GroupTokenBucket{
TokenBucket: settings.GetRRU(),
Expand All @@ -156,7 +163,7 @@ func FromProtoResourceGroup(group *rmpb.ResourceGroup) *ResourceGroup {
rg.RUSettings = ruSettings
}
case rmpb.GroupMode_NativeMode:
if settings := group.GetSettings().GetResourceSettings(); settings != nil {
if settings := group.GetResourceSettings(); settings != nil {
resourceSettings = &NativeResourceSettings{
CPU: GroupTokenBucket{
TokenBucket: settings.GetCpu(),
Expand All @@ -182,28 +189,33 @@ func (rg *ResourceGroup) IntoProtoResourceGroup() *rmpb.ResourceGroup {
case rmpb.GroupMode_RUMode: // RU mode
group := &rmpb.ResourceGroup{
Name: rg.Name,
Settings: &rmpb.GroupSettings{
Mode: rmpb.GroupMode_RUMode,
RUSettings: &rmpb.GroupRequestUnitSettings{
RRU: rg.RUSettings.RRU.TokenBucket,
WRU: rg.RUSettings.WRU.TokenBucket,
},
Mode: rmpb.GroupMode_RUMode,
RUSettings: &rmpb.GroupRequestUnitSettings{
RRU: rg.RUSettings.RRU.TokenBucket,
WRU: rg.RUSettings.WRU.TokenBucket,
},
}
return group
case rmpb.GroupMode_NativeMode: // Native mode
group := &rmpb.ResourceGroup{
Name: rg.Name,
Settings: &rmpb.GroupSettings{
Mode: rmpb.GroupMode_NativeMode,
ResourceSettings: &rmpb.GroupResourceSettings{
Cpu: rg.ResourceSettings.CPU.TokenBucket,
IoRead: rg.ResourceSettings.IOReadBandwidth.TokenBucket,
IoWrite: rg.ResourceSettings.IOWriteBandwidth.TokenBucket,
},
Mode: rmpb.GroupMode_NativeMode,
ResourceSettings: &rmpb.GroupResourceSettings{
Cpu: rg.ResourceSettings.CPU.TokenBucket,
IoRead: rg.ResourceSettings.IOReadBandwidth.TokenBucket,
IoWrite: rg.ResourceSettings.IOWriteBandwidth.TokenBucket,
},
}
return group
}
return nil
}

// persistSettings persists the resource group settings.
// TODO: persist the state of the group separately.
func (rg *ResourceGroup) persistSettings(storage storage.Storage) error {
rg.RLock()
defer rg.RUnlock()
metaGroup := rg.IntoProtoResourceGroup()
nolouch marked this conversation as resolved.
Show resolved Hide resolved
return storage.SaveResourceGroup(path.Join(GroupSettingsPathPrefix, rg.Name), metaGroup)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ func TestPatchResourceGroup(t *testing.T) {
patchJSONString string
expectJSONString string
}{
{`{"mode":0, "r_u_settings": {"r_r_u":{"settings":{"fillrate": 200000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"wru":{"initialized":false}}}`},
{`{"mode":0, "r_u_settings": {"w_r_u":{"settings":{"fillrate": 200000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"initialized":false},"wru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`},
{`{"mode":0, "r_u_settings": {"w_r_u":{"settings":{"fillrate": 200000, "burst": 100000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"initialized":false},"wru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`},
{`{"mode":0, "r_u_settings": {"r_r_u":{"settings":{"fillrate": 200000, "burst": 100000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"wru":{"initialized":false}}}`},
{`{"mode":0, "r_u_settings": {"r_r_u":{"settings":{"fillrate": 200000, "burst": 100000}}, "w_r_u":{"settings":{"fillrate": 200000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"wru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`},
{`{"name":"test", "mode":0, "r_u_settings": {"r_r_u":{"settings":{"fill_rate": 200000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false},"wru":{"initialized":false}}}`},
{`{"name":"test", "mode":0, "r_u_settings": {"w_r_u":{"settings":{"fill_rate": 200000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"initialized":false},"wru":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false}}}`},
{`{"name":"test", "mode":0, "r_u_settings": {"w_r_u":{"settings":{"fill_rate": 200000, "burst": 100000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"initialized":false},"wru":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false}}}`},
{`{"name":"test", "mode":0, "r_u_settings": {"r_r_u":{"settings":{"fill_rate": 200000, "burst": 100000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false},"wru":{"initialized":false}}}`},
{`{"name":"test", "mode":0, "r_u_settings": {"r_r_u":{"settings":{"fill_rate": 200000, "burst": 100000}}, "w_r_u":{"settings":{"fill_rate": 200000}}}}`,
`{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false},"wru":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false}}}`},
}

for _, ca := range testCaseRU {
rg := rg1.Copy()
patch := &rmpb.GroupSettings{}
patch := &rmpb.ResourceGroup{}
err := json.Unmarshal([]byte(ca.patchJSONString), patch)
re.NoError(err)
err = rg.PatchSettings(patch)
Expand All @@ -48,17 +48,17 @@ func TestPatchResourceGroup(t *testing.T) {
patchJSONString string
expectJSONString string
}{
{`{"mode":1, "resource_settings": {"cpu":{"settings":{"fillrate": 200000}}}}`,
`{"name":"test","mode":1,"resource_settings":{"cpu":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"initialized":false}}}`},
{`{"mode":1, "resource_settings": {"io_read":{"settings":{"fillrate": 200000}}}}`,
`{"name":"test","mode":1,"resource_settings":{"cpu":{"initialized":false},"io_read_bandwidth":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"io_write_bandwidth":{"initialized":false}}}`},
{`{"mode":1, "resource_settings": {"io_write":{"settings":{"fillrate": 200000}}}}`,
`{"name":"test","mode":1,"resource_settings":{"cpu":{"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`},
{`{"name":"test", "mode":1, "resource_settings": {"cpu":{"settings":{"fill_rate": 200000}}}}`,
`{"name":"test","mode":1,"resource_settings":{"cpu":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"initialized":false}}}`},
{`{"name":"test", "mode":1, "resource_settings": {"io_read":{"settings":{"fill_rate": 200000}}}}`,
`{"name":"test","mode":1,"resource_settings":{"cpu":{"initialized":false},"io_read_bandwidth":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false},"io_write_bandwidth":{"initialized":false}}}`},
{`{"name":"test", "mode":1, "resource_settings": {"io_write":{"settings":{"fill_rate": 200000}}}}`,
`{"name":"test","mode":1,"resource_settings":{"cpu":{"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"token_bucket":{"settings":{"fill_rate":200000}},"initialized":false}}}`},
}

for _, ca := range testCaseResource {
rg := rg2.Copy()
patch := &rmpb.GroupSettings{}
patch := &rmpb.ResourceGroup{}
err := json.Unmarshal([]byte(ca.patchJSONString), patch)
re.NoError(err)
err = rg.PatchSettings(patch)
Expand Down
4 changes: 2 additions & 2 deletions pkg/mcs/resource_manager/server/token_bukets.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (t *GroupTokenBucket) patch(settings *rmpb.TokenBucket) {
// Update updates the token bucket.
func (t *GroupTokenBucket) Update(now time.Time) {
if !t.Initialized {
t.Settings.Fillrate = defaultRefillRate
t.Settings.FillRate = defaultRefillRate
t.Tokens = defaultInitialTokens
t.LastUpdate = &now
t.Initialized = true
Expand All @@ -63,7 +63,7 @@ func (t *GroupTokenBucket) Update(now time.Time) {

delta := now.Sub(*t.LastUpdate)
if delta > 0 {
t.Tokens += float64(t.Settings.Fillrate) * delta.Seconds()
t.Tokens += float64(t.Settings.FillRate) * delta.Seconds()
t.LastUpdate = &now
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/storage/endpoint/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ package endpoint
// ResourceGroupStorage defines the storage operations on the rule.
type ResourceGroupStorage interface {
LoadResourceGroups(f func(k, v string)) error
SaveResourceGroup(groupName string, groupPayload interface{}) error
DeleteResourceGroup(groupName string) error
SaveResourceGroup(prefix string, groupPayload interface{}) error
DeleteResourceGroup(prefix string) error
}

var _ ResourceGroupStorage = (*StorageEndpoint)(nil)

// SaveResourceGroup stores a resource group to storage.
func (se *StorageEndpoint) SaveResourceGroup(groupName string, payload interface{}) error {
return se.saveJSON(resourceGroupPath, groupName, payload)
func (se *StorageEndpoint) SaveResourceGroup(prefix string, payload interface{}) error {
return se.saveJSON(resourceGroupPath, prefix, payload)
}

// DeleteResourceGroup removes a resource group from storage.
func (se *StorageEndpoint) DeleteResourceGroup(groupName string) error {
return se.Remove(resourceGroupKeyPath(groupName))
func (se *StorageEndpoint) DeleteResourceGroup(prefix string) error {
return se.Remove(resourceGroupKeyPath(prefix))
}

// LoadResourceGroups loads all resource groups from storage.
Expand Down
Loading