Add comments & misc review fixes

Lots of comments describing the heuristics, how it fits together and the
limitations.

In particular, we can't guarantee correct volume placement if the set of
zones is changing between allocating volumes.
This commit is contained in:
Justin Santa Barbara
2016-06-21 15:22:16 -04:00
parent 9c2566572d
commit dd94997619
4 changed files with 34 additions and 3 deletions

View File

@@ -194,6 +194,10 @@ func GenerateVolumeName(clusterName, pvName string, maxLength int) string {
}
// ChooseZone implements our heuristics for choosing a zone for volume creation based on the volume name
// Volumes are generally round-robin-ed across all active zones, using the hash of the PVC Name.
// However, if the PVCName ends with `-<integer>`, we will hash the prefix, and then add the integer to the hash.
// This means that a PetSet's volumes (`claimname-petsetname-id`) will spread across available zones,
// assuming the id values are consecutive.
func ChooseZoneForVolume(zones sets.String, pvcName string) string {
// We create the volume in a zone determined by the name
// Eventually the scheduler will coordinate placement into an available zone
@@ -202,7 +206,7 @@ func ChooseZoneForVolume(zones sets.String, pvcName string) string {
if pvcName == "" {
// We should always be called with a name; this shouldn't happen
glog.Warningf("No Name defined during volume create; choosing random zone")
glog.Warningf("No name defined during volume create; choosing random zone")
hash = rand.Uint32()
} else {
@@ -230,6 +234,14 @@ func ChooseZoneForVolume(zones sets.String, pvcName string) string {
hash = h.Sum32()
}
// Zones.List returns zones in a consistent order (sorted)
// We do have a potential failure case where volumes will not be properly spread,
// if the set of zones changes during PetSet volume creation. However, this is
// probably relatively unlikely because we expect the set of zones to be essentially
// static for clusters.
// Hopefully we can address this problem if/when we do full scheduler integration of
// PVC placement (which could also e.g. avoid putting volumes in overloaded or
// unhealthy zones)
zoneSlice := zones.List()
zone := zoneSlice[(hash+index)%uint32(len(zoneSlice))]