Databases

All three servers use MariaDB via Spring Data JPA/Hibernate, each with its own database and its own compose.yaml. No server reads another one’s database:

ServerDatabaseSchemaHolds
zone-serverbestia_zone (port 3306)no migrations, ddl-auto: updatethe world, masters, bestias, items, everything in play
login-serverbestia_login (port 3307)Flyway migrations, ddl-auto: validateaccounts, passkeys, refresh tokens, bans
api-serverbestia_api (port 3308)Flyway migrations, ddl-auto: validatepush subscriptions and notification preferences

The zone and the login-server each define their own Account entity. They are linked only by the id: the zone’s account row takes the id the login token carries, and AccountProvisioningService creates it on the first connect. There is no shared entity class and no shared table.

The zone’s tests run on in-memory H2. The login-server’s and the api-server’s tests start a MariaDB through Testcontainers, so they need Docker.

How the zone writes

Nothing on the tick thread talks to the database. A system or handler takes a snapshot of an entity (plain values, no live components) and hands it to EntityWriteBehind, which writes it on the DB executor (AsyncJobExecutor). Every write about one owner uses the same key: a master’s id, or one shared key for the generic entity rows. So the writes for one owner land in the order they were taken, and a delete never overtakes an earlier write.

  • A master is written on every exp gain, on every status or skill point spend, on logout (the PersistAndRemove component), and by the periodic save. Selecting a master first waits for its pending writes, so a quick relog reads what the logout wrote.
  • While a master is online its components are the authority, and MasterEntityPersister is the only writer of its level, exp, points, effort values and learned skill levels. A spend changes the components on the tick and is saved like any other change: the points and the skill levels they bought land in one transaction, so a crash loses both or neither.
  • Party and inventory changes still write the master row directly, under a row lock. Master uses @DynamicUpdate, so such a write sets only the columns it changed and cannot put back a level the persister just saved. A party change locks the party row first; the party component on each member changes only after the commit, and a member who logs in gets it back from the row.
  • A guild lives in its own rows (guild, guild_rank, guild_member) and never writes the master row. Every guild change locks the guild row first. The EXP its tax raises is gathered in memory on the tick and written once per guild.exp-flush-seconds (30 s), one transaction per guild, so a crash loses at most that much.
  • Party rosters and guild state go out from the DB executor too, on one key per party or guild, so a roster built just before a kick can never reach the kicked member after the kick did.
  • The periodic save (EntityPersistenceSystem) runs on the tick. It saves each Persistent entity once per persistence.interval-ms (90 s by default) and spreads them over that time, a slice every second. An entity whose snapshot equals the last one queued is skipped. A failed write is retried by the next save. A blob row is updated in place, and Hibernate batches the updates.
  • A failed DB job is logged with its owner key and counted (zone_db_jobs_failed_total). An item grant goes to the live inventory first, so its write is tried again when it lost a lock race; each such failure rolls back, so a second try cannot grant twice.
  • On shutdown, PersistOnShutdown stops the tick, saves what changed, flushes the economy ledger, the terrain edits and the ground wear and blood levels, and gives the DB executor up to 30 s to finish.
  • Terrain edits: every edited chunk is one chunk_edit row. ChunkEditJournal writes the chunks edited since its last write every 10 s, keyed by chunk; see World Generation.
  • Wild den packs are not saved: a den makes a fresh pack when a player comes near.
  • A drop removes the item in the database first; only then does it leave the live inventory and appear on the ground. A drop can lose an item but never copy one.
  • Handing an item between a master and its own bestias (TransferItemHandler) takes it out of the giver’s live inventory on the tick that checks the move. Nothing else can reach it after that. The database move follows as one transaction on the master’s job key, which locks both container rows: the master first, then the bestias by id. The item is given back only if that transaction rolls back. If the database finds the giver no longer holds the item, the live bag showed more than it had, and the item stays gone.
  • Static content (items, species, loot tables, commodities) is read into in-memory catalogues once at boot (CatalogueWarmUpBootRunner), so the tick never needs a lookup.
  • TickSqlGuard, a Hibernate statement inspector, reports any SQL that still runs on the tick thread (zone.sql-on-tick: log). It sees lazy loads behind a service call too.

Last updated 04 Dec 2026, 01:08 +0100 . history