1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

GT-198 Cleanout calculation - picks members with the lowest number of shards (#1261)

This commit is contained in:
jwierzbo 2023-03-06 15:56:57 +01:00 committed by GitHub
parent b939de9457
commit ba4acae4da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 3 deletions

View file

@ -19,6 +19,7 @@
- (Improvement) Change Operator default ReplicasCount to 1
- (Maintenance) Change MD content injection method
- (Maintenance) Generate README Platforms
- (Improvement) Cleanout calculation - picks members with the lowest number of shards
## [1.2.24](https://github.com/arangodb/kube-arangodb/tree/1.2.24) (2023-01-25)
- (Bugfix) Fix deployment creation on ARM64

View file

@ -53,7 +53,7 @@ type MemberStatus struct {
CreatedAt meta.Time `json:"created-at"`
// Conditions specific to this member
Conditions ConditionList `json:"conditions,omitempty"`
// RecentTerminatons holds the times when this member was recently terminated.
// RecentTerminations holds the times when this member was recently terminated.
// First entry is the oldest. (do not add omitempty, since we want to be able to switch from a list to an empty list)
RecentTerminations []meta.Time `json:"recent-terminations"`
// IsInitialized is set after the very first time a pod was created for this member.

View file

@ -53,7 +53,7 @@ type MemberStatus struct {
CreatedAt meta.Time `json:"created-at"`
// Conditions specific to this member
Conditions ConditionList `json:"conditions,omitempty"`
// RecentTerminatons holds the times when this member was recently terminated.
// RecentTerminations holds the times when this member was recently terminated.
// First entry is the oldest. (do not add omitempty, since we want to be able to switch from a list to an empty list)
RecentTerminations []meta.Time `json:"recent-terminations"`
// IsInitialized is set after the very first time a pod was created for this member.

View file

@ -132,6 +132,42 @@ func (s State) CountShards() int {
return count
}
// ShardsByDbServers returns a map of DBServers and the amount of shards they have
func (s State) ShardsByDbServers() map[Server]int {
result := make(map[Server]int)
for _, collections := range s.Current.Collections {
for _, shards := range collections {
for _, shard := range shards {
for _, server := range shard.Servers {
result[server]++
}
}
}
}
return result
}
// GetDBServerWithLowestShards returns the DBServer with the lowest amount of shards
func (s State) GetDBServerWithLowestShards() Server {
var resultServer Server = ""
var resultShards int
for server, shards := range s.ShardsByDbServers() {
// init first server as result
if resultServer == "" {
resultServer = server
resultShards = shards
} else if shards < resultShards {
resultServer = server
resultShards = shards
}
}
return resultServer
}
// PlanServers returns all servers which are part of the plan
func (s State) PlanServers() Servers {
q := map[Server]bool{}

View file

@ -93,7 +93,13 @@ func (r *Reconciler) createScalePlan(status api.DeploymentStatus, members api.Me
Debug("Creating scale-up plan")
} else if len(members) > count {
// Note, we scale down 1 member at a time
if m, err := members.SelectMemberToRemove(getCleanedServer(context), getToBeCleanedServer(context), topologyMissingMemberToRemoveSelector(status.Topology), topologyAwarenessMemberToRemoveSelector(group, status.Topology)); err != nil {
if m, err := members.SelectMemberToRemove(
getCleanedServer(context),
getToBeCleanedServer(context),
topologyMissingMemberToRemoveSelector(status.Topology),
topologyAwarenessMemberToRemoveSelector(group, status.Topology),
getDbServerWithLowestShards(context, group)); err != nil {
r.planLogger.Err(err).Str("role", group.AsRole()).Warn("Failed to select member to remove")
} else {
ready, message := groupReadyForRestart(context, status, m, group)
@ -194,6 +200,18 @@ func getToBeCleanedServer(ctx reconciler.ArangoAgencyGet) api.MemberToRemoveSele
}
}
func getDbServerWithLowestShards(ctx reconciler.ArangoAgencyGet, g api.ServerGroup) api.MemberToRemoveSelector {
return func(m api.MemberStatusList) (string, error) {
if g != api.ServerGroupDBServers {
return "", nil
}
if a, ok := ctx.GetAgencyCache(); ok {
return string(a.GetDBServerWithLowestShards()), nil
}
return "", nil
}
}
func (r *Reconciler) scaleDownCandidate(ctx context.Context, apiObject k8sutil.APIObject,
spec api.DeploymentSpec, status api.DeploymentStatus,
context PlanBuilderContext) api.Plan {