Private
Public Access
1
0

Revise room-to-pod assignment logic with hash-based distribution for improved load balancing and better replica handling.
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m31s

This commit is contained in:
Sebastian Unterschütz
2026-01-04 17:41:46 +01:00
parent 400a7e752b
commit 4b3466a1b0

View File

@@ -275,34 +275,30 @@ func isResponsibleForRoom(roomID string) bool {
return true
}
// Hash-basierte Zuweisung: RoomID → Pod
// Einfacher Ansatz: erster Buchstabe von RoomID
// A-M → Pod 0, N-Z → Pod 1
if len(roomID) == 0 {
return true
}
firstChar := roomID[0]
// Für 2 Replicas: A-M und N-Z splitten
if totalReplicas == "2" {
// Pod Namen sind meist: escape-game-0, escape-game-1, etc.
if firstChar <= 'M' || firstChar <= 'm' {
return serverID[len(serverID)-1] == '0' || !hasDigitSuffix()
}
return serverID[len(serverID)-1] == '1' || hasDigitSuffix()
// Hash-basierte Zuweisung: RoomID → Pod
// Verwende einfachen Hash für bessere Verteilung
hash := 0
for _, c := range roomID {
hash = (hash*31 + int(c)) % 2
}
// Fallback: immer zuständig
return true
}
func hasDigitSuffix() bool {
if len(serverID) == 0 {
return false
}
// Bestimme Pod-Nummer aus ServerID
podNumber := 0
if len(serverID) > 0 {
lastChar := serverID[len(serverID)-1]
return lastChar >= '0' && lastChar <= '9'
if lastChar >= '0' && lastChar <= '9' {
podNumber = int(lastChar - '0')
}
}
responsible := (hash % 2) == (podNumber % 2)
log.Printf("🎯 Room '%s' → Hash=%d, Pod=%d (%s) → Responsible=%v", roomID, hash, podNumber, serverID, responsible)
return responsible
}
func loadServerAssets(w *game.World) {