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