Skip to content
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

Prefer processes in coordinator selection for multi-region clusters #2045

Merged
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
53 changes: 53 additions & 0 deletions api/v1beta2/foundationdb_database_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/json"
"fmt"
"html/template"
"math"
"reflect"
"sort"
"strconv"
Expand Down Expand Up @@ -562,6 +563,58 @@ func (configuration DatabaseConfiguration) GetNextConfigurationChange(finalConfi
return finalConfiguration
}

// GetPrimaryDCID will return the DC ID of the primary data center. The primary data center is the one with the highest
// priority in the region configuration.
// See: https://github.com/apple/foundationdb/wiki/Multi-Region-Replication#concepts
func (configuration DatabaseConfiguration) GetPrimaryDCID() string {
var candidate string
priority := math.MinInt

for _, region := range configuration.Regions {
for _, dataCenter := range region.DataCenters {
if dataCenter.Satellite != 0 {
continue
}

if dataCenter.Priority > priority {
candidate = dataCenter.ID
priority = dataCenter.Priority
}
}
}

return candidate
}

// GetMainDCsAndSatellites will return a set of main dcs and a set of satellites. If a dc is a main dc and a satellite
// it will only be counted as a main dc.
func (configuration DatabaseConfiguration) GetMainDCsAndSatellites() (map[string]None, map[string]None) {
mainDCs := map[string]None{}
satellites := map[string]None{}

for _, region := range configuration.Regions {
for _, dataCenter := range region.DataCenters {
if dataCenter.Satellite == 0 {
mainDCs[dataCenter.ID] = None{}
// If the dc ID is present as satellite we will remove it.
johscheuer marked this conversation as resolved.
Show resolved Hide resolved
delete(satellites, dataCenter.ID)

// satellites
continue
}

// If the dc ID is already present in the main dcs, we will not count this as a satellite.
if _, ok := mainDCs[dataCenter.ID]; ok {
continue
}

satellites[dataCenter.ID] = None{}
}
}

return mainDCs, satellites
}

func (configuration DatabaseConfiguration) getRegionPriorities() map[string]int {
priorities := make(map[string]int, len(configuration.Regions))

Expand Down
3 changes: 2 additions & 1 deletion controllers/change_coordinators.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ func selectCoordinators(logger logr.Logger, cluster *fdbv1beta2.FoundationDBClus
}

coordinators, err := locality.ChooseDistributedProcesses(cluster, candidates, coordinatorCount, locality.ProcessSelectionConstraint{
HardLimits: locality.GetHardLimits(cluster),
HardLimits: locality.GetHardLimits(cluster),
SelectingCoordinators: true,
})

logger.Info("Current coordinators", "coordinators", coordinators, "error", err)
Expand Down
Loading
Loading