change slots when annotations change (#914)

when the annotations change, we need to get a different slot key to launch new
containers with these annotations and let the old containers die off unused.

I started on a test for this, but changing all combinations of each field in
isolation to change is not very fun without reflection, and there's still a
subset of fields we're managing, so it put us in about the same spot as we are
now.
This commit is contained in:
Reed Allman
2018-04-03 11:21:56 -07:00
committed by GitHub
parent 1b0a9e2276
commit 3a2550d042

View File

@@ -326,6 +326,25 @@ func getSlotQueueKey(call *call) string {
hash.Write(unsafeBytes("\x00")) hash.Write(unsafeBytes("\x00"))
} }
// we need to additionally delimit config and annotations to eliminate overlap bug
hash.Write(unsafeBytes("\x00"))
keys = keys[:0] // clear keys
for k := range call.Annotations {
i := sort.SearchStrings(keys, k)
keys = append(keys, "")
copy(keys[i+1:], keys[i:])
keys[i] = k
}
for _, k := range keys {
hash.Write(unsafeBytes(k))
hash.Write(unsafeBytes("\x00"))
v, _ := call.Annotations.Get(k)
hash.Write(v)
hash.Write(unsafeBytes("\x00"))
}
var buf [sha1.Size]byte var buf [sha1.Size]byte
hash.Sum(buf[:0]) hash.Sum(buf[:0])
return string(buf[:]) return string(buf[:])