cluster: pre-compute Zone's primary region

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2024-06-03 00:14:53 +00:00
parent cede95e119
commit 982e16581c
3 changed files with 35 additions and 12 deletions
+30
View File
@@ -102,6 +102,7 @@ func (m *Cluster) initRegions(_ *ScanOptions) error {
m.sortRegions()
m.scanRegionID()
m.computeZonesRegion()
return nil
}
@@ -277,6 +278,35 @@ func (m *Cluster) scanRegionID() {
}
}
func (m *Cluster) computeZonesRegion() {
fn := func(r *Region, z *Zone) {
if z.region != nil {
m.error(nil).
WithField("zone", z.Name).
WithField("region", []string{
z.region.Name,
r.Name,
}).
Print("zone in two regions")
} else {
z.region = r
}
}
m.ForEachRegion(func(r *Region) bool {
var term bool
if r.IsPrimary() {
r.ForEachZone(func(z *Zone) bool {
fn(r, z)
return term
})
}
return term
})
}
func (m *Cluster) getRegion(name string) (*Region, bool) {
for i := range m.Regions {
r := &m.Regions[i]