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
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m31s
This commit is contained in:
@@ -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]
|
||||
// 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
|
||||
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()
|
||||
// Bestimme Pod-Nummer aus ServerID
|
||||
podNumber := 0
|
||||
if len(serverID) > 0 {
|
||||
lastChar := serverID[len(serverID)-1]
|
||||
if lastChar >= '0' && lastChar <= '9' {
|
||||
podNumber = int(lastChar - '0')
|
||||
}
|
||||
return serverID[len(serverID)-1] == '1' || hasDigitSuffix()
|
||||
}
|
||||
|
||||
// Fallback: immer zuständig
|
||||
return true
|
||||
}
|
||||
responsible := (hash % 2) == (podNumber % 2)
|
||||
log.Printf("🎯 Room '%s' → Hash=%d, Pod=%d (%s) → Responsible=%v", roomID, hash, podNumber, serverID, responsible)
|
||||
|
||||
func hasDigitSuffix() bool {
|
||||
if len(serverID) == 0 {
|
||||
return false
|
||||
}
|
||||
lastChar := serverID[len(serverID)-1]
|
||||
return lastChar >= '0' && lastChar <= '9'
|
||||
return responsible
|
||||
}
|
||||
|
||||
func loadServerAssets(w *game.World) {
|
||||
|
||||
Reference in New Issue
Block a user