Commit Graph

21 Commits

Author SHA1 Message Date
laforetbrut
59bd884263 perf: zero JDBC on server thread + HikariCP + parallel shutdown + audit fixes
- Migrate connection pool from manual LinkedBlockingQueue to HikariCP
  (eliminates isValid() ping on every query visible in Spark profiler)
- Move ALL DB writes off server thread: logout uses snapshot+async+latch,
  shutdown uses snapshot+CompletableFuture.allOf for parallel saves
- Pre-read curios/accessories/cosmeticarmor/attachments on background
  thread during login (4-7 fewer DB queries on main thread per login)
- Auto-save interval increased to 5 minutes
- Fix pool shutdown ordering: shutdownPool() now runs AFTER all shutdown
  saves complete (previously could fire before, silently losing all data)
- Fix connection leak in executeQuery/executePreparedQuery when
  prepareStatement throws (leaked connections exhaust HikariCP pool)
- Fix duplication bug: saveStorageContents guard used nbt.size()<=1 which
  blocked legitimately emptied backpacks from saving to DB
- Fix stale SaveToFile overwriting logout: check playerLocks.containsKey
  before writing to prevent stale background task from regressing data
- Remove LIMIT 1000 on startup online=0 reset (could leave players stuck)
- Add executorService.shutdown() on server stop to prevent JVM hang
- Add apply methods (applyCuriosFromData, applyAccessoriesFromData, etc.)
  to separate entity writes from DB reads for thread-safe restore
- Add UUID collectors (collectBackpackUuids, collectSSUuids) and
  background save methods for snapshot+async logout/shutdown pattern
2026-03-29 18:58:27 +02:00
laforetbrut
d60b8eb01e Add connection pool - fix 10% server thread usage from MySQL connects
Spark showed PlayerSync consuming 10.16% of the server thread, almost
entirely from DriverManager.getConnection() (TCP handshake + MySQL auth
+ USE db) called for EVERY single query. With auto-save every 60s,
each player generated ~6 new connections per save cycle on main thread.

FIX: Simple connection pool (LinkedBlockingQueue, 5 connections).
- Connections are reused instead of opened/closed per query
- isValid(2) check before reuse to detect dead connections
- returnConnection() puts connections back in pool instead of closing
- QueryResult.close() also returns to pool
- autoReconnect=true in JDBC URL for resilience
- shutdownPool() for clean server stop
- Non-database connections (startup DDL) bypass the pool

Expected improvement: ~90% reduction in MySQL overhead on server thread.

Vyrriox
2026-03-26 21:13:17 +01:00
laforetbrut
484f1a8c05 Final audit: fix ghost-online, SQL injection, resource leak, NPE
CRITICAL-1/2: Remove duplicate online=1 writes from doPlayerJoin.
The synchronous onPlayerLoggedInKickCheck already sets online=1.
The background thread writes raced with logout's online=0, permanently
locking players as "online" after crash-disconnect during join.

HIGH-1: Startup SQL uses PreparedStatement for server_id (was string concat).
HIGH-2: update() method now uses try-with-resources for PreparedStatement.
HIGH-3: NPE guard in RS2 data file logging when getRS2DataFile returns null.

Vyrriox
2026-03-26 18:33:00 +01:00
laforetbrut
03b57c3e6b Fix critical sync bugs, security, and add Sophisticated Storage support
- Fix advancements disappearing: use PreparedStatements for all SQL with
  user data (advancement JSON contains chars that broke string-concat SQL),
  add null safety for advancement file
- Fix multi-server kick: run doPlayerConnect synchronously instead of async
  (players could join before the duplicate check completed)
- Fix Curios disappearing: clear slots AFTER validating data exists (not
  before), use CuriosCache for dead players on logout instead of empty API
- Fix Sophisticated Storage items: add storeSophisticatedStorageItems() and
  restoreSophisticatedStorageItems() to sync packed barrels/shulkers/chests
- Anti-duplication: clear all inventories before restoring from DB on join
- Fix tick counter: remove LevelTickEvent (fired per dimension = 3x too
  fast), merge heartbeat into ServerTickEvent
- Fix connection leaks: use try-with-resources for all QueryResult
- Fix logout order: save data BEFORE marking player offline
- Skip auto-save for dead/unsynced players to prevent saving empty data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:04:00 +01:00
mlus
201e63a322 Fix SQL syntax by adding backticks around database and table names 2026-02-24 00:11:06 +08:00
mlus
29da0f28ad recently commit port 2025-11-28 21:00:25 +08:00
EoD
a510b091db add trace logs for all SQL queries
Can be enabled by starting minecraft with
-Dforge.logging.console.level=trace
2025-04-25 20:40:16 +00:00
paulm
439c7ee5bb Addeed Sophisticated Backpack Mod compatibility 2025-03-20 05:26:15 +01:00
mlus
bb45488186 fix #22 2024-09-24 21:46:12 +08:00
mlus
053758e6cc And for update 2024-08-04 17:51:07 +08:00
mlus
bd4694e44b DataBase Fixed 2024-08-04 17:46:38 +08:00
mlus
50e146d7fe Chat Sync performance enhancement 2024-08-04 14:20:25 +08:00
mlus
b3352fde51 1.3.0 update 2024-02-11 17:34:19 +08:00
mlus-Asuka
d32ae52537 update 1.2.1 2023-09-29 16:50:26 +08:00
mlus-Asuka
45e13f1199 1.2.0 release 2023-08-09 16:08:23 +08:00
mlus-Asuka
5ef817a9b7 Use HikariPool instead of original driver.Merge Fork from KK1ve. 2023-08-03 22:05:43 +08:00
mlus-Asuka
30b1690a73 fix chat and effects bugs. 2023-02-16 14:26:24 +08:00
mlus-Asuka
89e74813e2 Add chat message sync 2022-12-21 19:42:56 +08:00
mlus-Asuka
7dc5f0151b fix bug 2022-12-09 22:47:56 +08:00
mlus-Asuka
4d3d8afe3d add curios support 2022-12-08 23:02:50 +08:00
mlus-Asuka
ef153d26c3 Initial commit 2022-12-08 16:59:20 +08:00