From f893ecfbb31cdee8fa250abf5b5edb2eed69fb49 Mon Sep 17 00:00:00 2001 From: gaoruoshu Date: Thu, 19 Aug 2021 06:59:28 +0000 Subject: [PATCH] Cluster tuning: re-write params in server.yaml --- common/project/projet.go | 2 ++ common/tuning/optimizer.go | 55 ++++++++++++++++++++++++++++++++++++++ common/utils/utils.go | 25 +++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/common/project/projet.go b/common/project/projet.go index 3e48bec..4bc5c90 100644 --- a/common/project/projet.go +++ b/common/project/projet.go @@ -97,6 +97,7 @@ type YamlObj struct { Type string `yaml:"type"` Step float32 `yaml:"step,omitempty"` Items []float32 `yaml:"items"` + Requires string `yaml:"requires"` Options []string `yaml:"options"` Scope []float32 `yaml:"scope,flow"` Dtype string `yaml:"dtype"` @@ -108,6 +109,7 @@ type YamlPrjObj struct { Name string `yaml:"name"` Info YamlObj `yaml:"info"` Relations []*RelationShip `yaml:"relationships"` + Clusters string } type RelationShip struct { diff --git a/common/tuning/optimizer.go b/common/tuning/optimizer.go index 70715ea..20932f3 100644 --- a/common/tuning/optimizer.go +++ b/common/tuning/optimizer.go @@ -72,6 +72,11 @@ type Optimizer struct { PrjId string } +// object set type +type ObjectSet struct { + Objects []*project.YamlPrjObj +} + // InitTuned method for iniit tuning func (o *Optimizer) InitTuned(ch chan *PB.TuningMessage, stopCh chan int) error { o.FeatureFilter = false @@ -622,7 +627,11 @@ func CheckServerPrj(data string, optimizer *Optimizer) error { log.Infof("find Project:%s from %s", prj.Project, yamlPaths[idx]) + objectSet := new(ObjectSet) + objectSet.Objects = append(objectSet.Objects, prj.Object...) prj.Object = CheckObjectReplace(prj.Object) + objectSet.CheckObjectDuplicate() + prj.Object = objectSet.Objects if optimizer.Prj == nil { optimizer.Prj = prj @@ -677,6 +686,52 @@ func ReplaceObject(replace string, param string, objects []*project.YamlPrjObj, return objects } +// Check the address value in atuned.cnf +func (obj *ObjectSet) CheckObjectDuplicate() { + if strings.TrimSpace(config.Connect) == "" { + return + } + ipGroups := strings.Split(strings.TrimSpace(config.Connect), ",") + for ind := 0; ind < len(obj.Objects); ind++ { + if obj.Objects[ind].Clusters != "" { + continue + } + if obj.Objects[ind].Info.Requires == "" { + obj.WriteObject(ind, ipGroups) + } else if obj.Objects[ind].Info.Requires != "" { + reqGroups := utils.DivideToGroups(obj.Objects[ind].Info.Requires, ipGroups) + obj.WriteObject(ind, reqGroups) + } + } +} + +func (obj *ObjectSet) WriteObject(ind int, groups []string) { + if len(groups) == 1 { + obj.Objects[ind].Clusters = groups[0] + return + } + obj.AppendObject(ind, groups) + obj.Objects[ind].Name = obj.Objects[ind].Name + "-0" + obj.Objects[ind].Clusters = groups[0] +} + +// append new params in object +func (obj *ObjectSet) AppendObject(ind int, ipGroups []string) { + for i := 1; i < len(ipGroups); i++ { + if ipGroups[i] == "" { + continue + } + newObj := &project.YamlPrjObj{ + Name: obj.Objects[ind].Name, + Info: obj.Objects[ind].Info, + Relations: obj.Objects[ind].Relations, + } + newObj.Name = newObj.Name + "-" + strconv.Itoa(i) + newObj.Clusters = ipGroups[i] + obj.Objects = append(obj.Objects, newObj) + } +} + // SyncTune: sync tuned node func (o *Optimizer) SyncTunedNode(ch chan *PB.TuningMessage) error { log.Infof("setting params is: %s", string(o.Content)) diff --git a/common/utils/utils.go b/common/utils/utils.go index 6142ebc..e9641a5 100644 --- a/common/utils/utils.go +++ b/common/utils/utils.go @@ -612,3 +612,28 @@ func CheckValueInSlice(value string, strList []string) bool { } return false } + +// Divide requires into groups +func DivideToGroups(strs string, groups []string) []string { + strsArr := strings.Split(strs, ",") + div := make([]string, len(groups)) + for _, val := range strsArr { + for ind, group := range groups { + if strings.Contains(group, val) { + if div[ind] == "" { + div[ind] += val + } else { + div[ind] += " " + val + } + break + } + } + } + divRes := make([]string, 0) + for _, val := range div { + if val != "" { + divRes = append(divRes, val) + } + } + return divRes +} -- Gitee