MinionCore logoMinionCore

Storage

Where MinionCore keeps its data, when it saves, and how to move from SQLite to MySQL.

MinionCore saves every minion, its stored items, its trust list and its statistics in a database, so everything is still there after a restart. Out of the box it uses a single SQLite file and needs no setup. Networks and larger servers can point it at MySQL instead.

SQLite, the default

With the shipped config the plugin creates plugins/MinionCore/database.db on first start and uses it from then on. There is nothing to install and nothing to fill in.

config.yml
storage:
  type: SQLITE
  file: database.db
  table-prefix: minioncore_
KeyDefaultWhat it does
storage.typeSQLITESQLITE or MYSQL
storage.filedatabase.dbThe file name inside the plugin folder. Only used for SQLite
storage.table-prefixminioncore_Put in front of every table name

SQLite keeps two helper files next to the database while the server runs, database.db-wal and database.db-shm. To back up, stop the server and copy all three together.

Switching to MySQL

Use MySQL when you already run a database server, or want the data somewhere other than the server's own disk.

Create a database and user

Create an empty database, for example minioncore, and a user that can create tables and indexes in it. The plugin builds its own tables on first start.

Fill in config.yml

config.yml
storage:
  type: MYSQL
  table-prefix: minioncore_
  mysql:
    host: localhost
    port: 3306
    database: minioncore
    username: root
    password: ""
    ssl: false
    pool-size: 10
    connection-timeout: 10000

Restart the server

Storage is only set up when the server starts. /minion reload does not switch databases. After the restart the console shows Storage is ready using MYSQL.

KeyDefaultWhat it does
storage.mysql.hostlocalhostThe address of the MySQL server
storage.mysql.port3306The port it listens on
storage.mysql.databaseminioncoreThe database the plugin writes to
storage.mysql.usernamerootThe user the plugin connects as
storage.mysql.password""That user's password
storage.mysql.sslfalseWhether the connection uses SSL
storage.mysql.pool-size10How many connections the plugin keeps open
storage.mysql.connection-timeout10000How long to wait for a free connection before giving up, in milliseconds

Switching type does not copy anything across. The new database starts empty, and the old data stays where it was. Switch before players place minions, or be ready to start fresh.

If the database cannot be reached at startup, the console prints the reason and MinionCore switches itself off rather than run without saving. Check the host, port, user and password, then restart. See When the database has a problem.

The table-prefix lets several plugins or several servers keep their own tables apart inside one database. Give each one its own prefix.

When data is saved

Changes are kept in memory while minions work, then written in batches on a background thread so the server does not pause for the database.

MomentWhat happens
Save timerEvery performance.save-interval seconds (60 by default), every minion that changed is written: its level, upgrades, fuel, stored items and statistics
Pick up or removalThe minion is written straight away in one database transaction before its item is handed over, including removal by an admin. See Picking up is all or nothing
Chunk unloadWhen a chunk that holds a minion unloads, every pending change is written
Server stopA last save runs, then the plugin waits up to 15 seconds for writes to finish before closing the database

Some things skip the timer and are written the moment they happen:

  • placing a minion
  • adding or removing a trusted player
  • changing a filter
  • items put in the claim queue, for example from /minion give to an offline player
  • a player's logout time, used for offline working

A lower save-interval means less work lost if the server crashes, at the cost of more database writes. If a save fails, the same changes are kept in memory and tried again on the next save.

config.yml
performance:
  save-interval: 60

What is stored

The plugin creates these tables, each name starting with your table-prefix.

TableWhat it holds
minionsOne row per minion: its type, owner, whether it is placed or an item, world and position, the way it faces (yaw), level, upgrades, stored fuel, paused state, filter, creation time, last action time, stored experience, and a settings column for per minion options such as a collector's mode, a broken down flag and a lumberjack's stored saplings
minion_storageThe items inside each minion's storage
minion_statsEach minion's total actions, items produced, fuel used and time spent working
minion_trustThe players trusted on each minion
playersEach player's name and last logout time
claim_queueItems waiting for a player to claim them from the main menu
chunk_ticketsThe chunks each chunk loader is keeping loaded, so they are loaded again after a restart
collector_linksWhich minions are paired with which chunk collector, one row per pair
schema_versionThe table layout version, so later updates can change tables safely

The table layout is at version 2 in 1.0.0-2. A database from 1.0.0-1 is updated on the first start: the yaw and settings columns are added to minions and the collector_links table is created. Nothing already stored is changed.

1.0.0-3 changes no tables. The per minion block filter is kept in the settings column, like the collector mode and the sapling store.

A minion that has been picked up keeps its row. The item in the player's hand carries the minion's id, so its level and upgrades come back when it is placed again. Its fuel comes back too, unless pickup.keep-fuel-on-pickup is false.

Picking up is all or nothing

When a minion is picked up, by shift right click, /minion remove, the menu or an admin, the database is updated in a single transaction:

  1. The minion's row is switched from placed to item, but only if it is still marked as placed.
  2. The row, its now empty storage and its statistics are written.

Only when all of that succeeds is the minion taken out of the world and its item and stored items handed over. If anything fails, nothing is changed: the minion stays where it is with every item still inside, keeps working, and the player gets pickup.failed. Nothing is lost or handed out twice.

Minions that are still loading

A placed minion reads its stored items and statistics from the database when its chunk loads. Until that has finished, and while a pick up is being saved, the minion refuses to be used. Right clicking it, opening its menus, picking it up or pairing it sends general.minion-busy. If the read fails, it is tried again 30 seconds later.

Items keep everything

Items in a minion's storage and in the claim queue are saved whole. Custom names, lore, enchantments, custom model data and other custom data from other plugins all survive a restart, so a named or custom item comes back exactly as it went in.

When the database has a problem

At startup

Before opening a SQLite database, MinionCore checks the file. MinionCore switches itself off with one line in the console that names the file and says what to do when:

  • the path in storage.file is a folder instead of a file,
  • the file cannot be read,
  • the file is not a SQLite database, for example because a file manager opened and saved it as text, or it was copied or restored while the server was running.

For a file that is not a database, the line tells you to stop the server, move the file out of the plugin folder, and put back a backup or start without it. An empty file is fine and is set up as a new database. A MySQL server that cannot be reached, or a SQLite file that is locked, read only or damaged, also switches the plugin off with a one line reason.

While the server runs

If the database stops working while players are online, for example the MySQL server goes down or the disk fills up, MinionCore does not flood the console.

WhenWhat the console shows
The first failureOne line with the reason and what it means for players
Every 5 minutes while it is still downOne reminder with how many database tasks failed since the last one
It works againThe database is working again. Changes kept in memory are saved on the next save.

While it is down, minions keep working and keep their items in memory. Placing and picking up do not go through, so no minion and no item is lost, and saving is tried again on every save. An error that is not a connection or file problem is logged in full, once for each failed task.

On this page