Fix SurfPlayerSyncTask for multiproxy: scope stale eviction to current proxy only and sync current server#35
Conversation
Co-authored-by: TheBjoRedCraft <143264463+TheBjoRedCraft@users.noreply.github.com>
|
@copilot this wont work. There is multiproxy support. |
…for current proxy Co-authored-by: TheBjoRedCraft <143264463+TheBjoRedCraft@users.noreply.github.com>
Fixed in 1fdde55. Instead of |
|
@copilot update the players current server to the server from the velocity player |
Co-authored-by: TheBjoRedCraft <143264463+TheBjoRedCraft@users.noreply.github.com>
Done in 5068f84. During the sync tick, each Velocity |
There was a problem hiding this comment.
Pull request overview
Adds a periodic Velocity-side player cache synchronization intended for multiproxy setups, avoiding global Redis player-cache wipes while keeping per-proxy entries fresh and updating players’ currentServer.
Changes:
- Introduces
SurfPlayerSyncTaskthat invalidates stale cached players only forSurfProxyServer.current()and upserts live players with an updatedcurrentServer. - Starts/stops the sync task during Velocity proxy initialize/shutdown.
- Adjusts server lookup operators:
CommonSurfServer[name]now usesgetCommonServerByName, andSurfServer[name]is added for backend-only lookups.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| surf-core-velocity/src/main/kotlin/dev/slne/surf/core/velocity/task/SurfPlayerSyncTask.kt | New scheduled task to invalidate stale per-proxy player cache entries and update currentServer. |
| surf-core-velocity/src/main/kotlin/dev/slne/surf/core/velocity/VelocityMain.kt | Wires the new sync task into proxy lifecycle. |
| surf-core-api/surf-core-api-common/src/main/kotlin/dev/slne/surf/core/api/common/server/SurfServer.kt | Adds operator fun get(name) for backend server lookup. |
| surf-core-api/surf-core-api-common/src/main/kotlin/dev/slne/surf/core/api/common/server/CommonSurfServer.kt | Changes operator fun get(name) to return proxy-or-backend via getCommonServerByName. |
| gradle.properties | Bumps snapshot version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| companion object { | ||
| operator fun get(name: String) = surfCoreApi.getServerByName(name) | ||
| operator fun get(name: String) = surfCoreApi.getCommonServerByName(name) |
There was a problem hiding this comment.
Changing CommonSurfServer[name] to call getCommonServerByName widens the operator’s return type from SurfServer? to CommonSurfServer?. There are existing call sites that relied on the old type inference (e.g. surf-core-velocity/.../ConnectionListener.kt uses CommonSurfServer[toServer] and passes it into SurfPlayer.copy(currentServer = ...), where currentServer is a SurfServer?). After this change that code will no longer type-check. Consider updating those call sites to use SurfServer[name] when a backend server is required, or otherwise explicitly narrow/cast the result before assigning to currentServer.
| operator fun get(name: String) = surfCoreApi.getCommonServerByName(name) | |
| operator fun get(name: String): SurfServer? = | |
| surfCoreApi.getCommonServerByName(name) as? SurfServer |
| val onlineUuids = onlinePlayers.map { it.uuid } | ||
|
|
||
| SurfProxyServer.current().getPlayers() | ||
| .filter { it.uuid !in onlineUuids } | ||
| .forEach { surfPlayerService.invalidatePlayer(it.uuid) } |
There was a problem hiding this comment.
onlineUuids is built as a List and then used for membership checks inside a filter (uuid !in onlineUuids). This makes the stale-eviction step O(n*m) due to linear contains checks. Convert onlineUuids to a HashSet (e.g. via toHashSet()) before filtering to keep lookups O(1).
|
@copilot wenn der spieler nicht in der online list ist, aber auf dem proxy online wird nix gemacht, zuerst soll geguckt werden ob er irgendwo anders on ist, wenn ja soll der genommen werden, wenn nicht soll der asus der db geladen oder erstellt werden wie beim join |
Co-authored-by: TheBjoRedCraft <143264463+TheBjoRedCraft@users.noreply.github.com>
Done in edd6f3f. When a Velocity player is online but not found in the cache ( |
clearPlayers()wiped the entire shared RedisSyncMap, destroying cached player entries belonging to sibling proxy instances in a multiproxy setup.Changes
SurfPlayerSyncTaskclearPlayers()with targeted per-proxy invalidationSurfProxyServer.current().getPlayers()to scope lookups to only this proxy's cached entriesallPlayers) →invalidatePlayer()currentServeris updated from the Velocity player's actual connected server viavelocityPlayer.currentServer.getOrNull()?.serverInfo?.name, thencachePlayer()persists the updated entry (upsert/override, no data loss)findPlayerByUuidreturns null), the sync falls back togetOrLoadOrCreatePlayerByUuid()(same as the join handler) and setscurrentProxy = SurfProxyServer.current()on the loaded/created player before cachingonlineUuidsusestoHashSet()for O(1) membership checks during stale-eviction💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.