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.
storage:
type: SQLITE
file: database.db
table-prefix: minioncore_| Key | Default | What it does |
|---|---|---|
storage.type | SQLITE | SQLITE or MYSQL |
storage.file | database.db | The file name inside the plugin folder. Only used for SQLite |
storage.table-prefix | minioncore_ | 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
storage:
type: MYSQL
table-prefix: minioncore_
mysql:
host: localhost
port: 3306
database: minioncore
username: root
password: ""
ssl: false
pool-size: 10
connection-timeout: 10000Restart 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.
| Key | Default | What it does |
|---|---|---|
storage.mysql.host | localhost | The address of the MySQL server |
storage.mysql.port | 3306 | The port it listens on |
storage.mysql.database | minioncore | The database the plugin writes to |
storage.mysql.username | root | The user the plugin connects as |
storage.mysql.password | "" | That user's password |
storage.mysql.ssl | false | Whether the connection uses SSL |
storage.mysql.pool-size | 10 | How many connections the plugin keeps open |
storage.mysql.connection-timeout | 10000 | How 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.
| Moment | What happens |
|---|---|
| Save timer | Every performance.save-interval seconds (60 by default), every minion that changed is written: its level, upgrades, fuel, stored items and statistics |
| Pick up or removal | The 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 unload | When a chunk that holds a minion unloads, every pending change is written |
| Server stop | A 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 giveto 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.
performance:
save-interval: 60What is stored
The plugin creates these tables, each name starting with your table-prefix.
| Table | What it holds |
|---|---|
minions | One 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_storage | The items inside each minion's storage |
minion_stats | Each minion's total actions, items produced, fuel used and time spent working |
minion_trust | The players trusted on each minion |
players | Each player's name and last logout time |
claim_queue | Items waiting for a player to claim them from the main menu |
chunk_tickets | The chunks each chunk loader is keeping loaded, so they are loaded again after a restart |
collector_links | Which minions are paired with which chunk collector, one row per pair |
schema_version | The 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:
- The minion's row is switched from placed to item, but only if it is still marked as placed.
- 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.fileis 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.
| When | What the console shows |
|---|---|
| The first failure | One line with the reason and what it means for players |
| Every 5 minutes while it is still down | One reminder with how many database tasks failed since the last one |
| It works again | The 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.
Related pages
- Configuration for the rest of
config.yml - Offline working for how logout times are used
- Shop and claims for the claim queue