Skip to content

Commit

Permalink
[Bugfix] Fix Replaced Member Zone during Replace operation (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow authored Nov 15, 2023
1 parent 28d9d91 commit 3b0c7cc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- (Feature) License ArangoDeployment Fetcher
- (Feature) K8S Resources Compare Generic
- (Feature) Add support for CRD validation schemas
- (Bugfix) Fix Replaced Member Zone during Replace operation

## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks
Expand Down
51 changes: 41 additions & 10 deletions pkg/apis/deployment/v1/topology_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
)

type TopologyZoneFilter func(g ServerGroup, id string) bool

func TopologyZoneFilterMerge(functions ...TopologyZoneFilter) TopologyZoneFilter {
return func(g ServerGroup, id string) bool {
for _, f := range functions {
if !f(g, id) {
return false
}
}

return true
}
}

type TopologyStatus struct {
ID types.UID `json:"id"`

Expand All @@ -53,25 +67,42 @@ func (t *TopologyStatus) Equal(b *TopologyStatus) bool {
}

func (t *TopologyStatus) GetLeastUsedZone(group ServerGroup) int {
return t.GetLeastUsedZoneWithFilter(group)
}

func (t *TopologyStatus) GetLeastUsedZoneWithFilter(group ServerGroup, filters ...TopologyZoneFilter) int {
if t == nil {
return -1
}

r, m := -1, math.MaxInt64
// If no zones are found
if len(t.Zones) == 0 {
return -1
}

for i, z := range t.Zones {
if n, ok := z.Members[group.AsRoleAbbreviated()]; ok {
if v := len(n); v < m {
r, m = i, v
}
} else {
if v := 0; v < m {
r, m = i, v
counts := make([]int, len(t.Zones))

for id, zone := range t.Zones {
c := 0

for _, member := range zone.Members[group.AsRoleAbbreviated()] {
if TopologyZoneFilterMerge(filters...)(group, member) {
c++
}
}

counts[id] = c
}

max := 0

for id := 1; id < len(counts); id++ {
if counts[id] < counts[max] {
max = id
}
}

return r
return max
}

func (t *TopologyStatus) RegisterTopologyLabel(zone int, label string) bool {
Expand Down
51 changes: 41 additions & 10 deletions pkg/apis/deployment/v2alpha1/topology_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
)

type TopologyZoneFilter func(g ServerGroup, id string) bool

func TopologyZoneFilterMerge(functions ...TopologyZoneFilter) TopologyZoneFilter {
return func(g ServerGroup, id string) bool {
for _, f := range functions {
if !f(g, id) {
return false
}
}

return true
}
}

type TopologyStatus struct {
ID types.UID `json:"id"`

Expand All @@ -53,25 +67,42 @@ func (t *TopologyStatus) Equal(b *TopologyStatus) bool {
}

func (t *TopologyStatus) GetLeastUsedZone(group ServerGroup) int {
return t.GetLeastUsedZoneWithFilter(group)
}

func (t *TopologyStatus) GetLeastUsedZoneWithFilter(group ServerGroup, filters ...TopologyZoneFilter) int {
if t == nil {
return -1
}

r, m := -1, math.MaxInt64
// If no zones are found
if len(t.Zones) == 0 {
return -1
}

for i, z := range t.Zones {
if n, ok := z.Members[group.AsRoleAbbreviated()]; ok {
if v := len(n); v < m {
r, m = i, v
}
} else {
if v := 0; v < m {
r, m = i, v
counts := make([]int, len(t.Zones))

for id, zone := range t.Zones {
c := 0

for _, member := range zone.Members[group.AsRoleAbbreviated()] {
if TopologyZoneFilterMerge(filters...)(group, member) {
c++
}
}

counts[id] = c
}

max := 0

for id := 1; id < len(counts); id++ {
if counts[id] < counts[max] {
max = id
}
}

return r
return max
}

func (t *TopologyStatus) RegisterTopologyLabel(zone int, label string) bool {
Expand Down

0 comments on commit 3b0c7cc

Please sign in to comment.