Skip to content

Fix the coordinator selection to try harder and pick more nodes in ea… #2

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

Open
wants to merge 1 commit into
base: backup-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 28 additions & 2 deletions controllers/generate_initial_cluster_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,34 @@ func (g generateInitialClusterFile) reconcile(ctx context.Context, r *Foundation
coordinators, err := locality.ChooseDistributedProcesses(cluster, processLocality, count, locality.ProcessSelectionConstraint{
HardLimits: locality.GetHardLimits(cluster),
})
if err != nil {
return &requeue{curError: err}
logger.Info("Current coordinators", "coordinators", coordinators, "error", err)
if len(coordinators) != count {
// Try one more time to get more coordinators
// Let's do a map with the ID of the coordinators
coordinatorsIDMap := make(map[string]bool, len(coordinators))
for _, coordinator := range coordinators {
coordinatorsIDMap[coordinator.ID] = true
}
// Filter out the coordinators already found from the candidates list
filteredCandidates := make([]locality.Info, 0, len(processLocality))
for _, candidate := range processLocality {
if _, exists := coordinatorsIDMap[candidate.ID]; !exists {
filteredCandidates = append(filteredCandidates, candidate)
}
}
newcoordinators, err := locality.ChooseDistributedProcesses(cluster, filteredCandidates, count-len(coordinators), locality.ProcessSelectionConstraint{
HardLimits: locality.GetHardLimits(cluster),
})
// append the new coordinators to the existing coordinators
logger.Info("Current coordinators", "coordinators", coordinators, "additional coordinators", newcoordinators, "error", err)
if err != nil {
return &requeue{curError: err}
}
coordinators = append(coordinators, newcoordinators...)
} else {
if err != nil {
return &requeue{curError: err}
}
}

for _, currentLocality := range coordinators {
Expand Down
27 changes: 25 additions & 2 deletions internal/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,31 @@ func selectCoordinatorsLocalities(logger logr.Logger, cluster *fdbv1beta2.Founda
})

logger.Info("Current coordinators", "coordinators", coordinators, "error", err)
if err != nil {
return nil, err
if len(coordinators) != coordinatorCount {
// Try one more time to get more coordinators
coordinatorsIDMap := make(map[string]bool, len(coordinators))
for _, coordinator := range coordinators {
coordinatorsIDMap[coordinator.ID] = true
}
filteredCandidates := make([]locality.Info, 0, len(candidates))
for _, candidate := range candidates {
if _, exists := coordinatorsIDMap[candidate.ID]; !exists {
filteredCandidates = append(filteredCandidates, candidate)
}
}
newcoordinators, err := locality.ChooseDistributedProcesses(cluster, filteredCandidates, coordinatorCount-len(coordinators), locality.ProcessSelectionConstraint{
HardLimits: locality.GetHardLimits(cluster),
})
// append the new coordinators to the existing coordinators
logger.Info("Current coordinators", "coordinators", coordinators, "additional coordinators", newcoordinators, "error", err)
if err != nil {
return nil, err
}
coordinators = append(coordinators, newcoordinators...)
} else {
if err != nil {
return nil, err
}
}

coordinatorStatus := make(map[string]bool, len(status.Client.Coordinators.Coordinators))
Expand Down