Live
Ordered plugin data on MySQL
A small data layer that moved plugin storage onto MySQL and guarantees each plugin’s reads and writes happen in the order they were made.
- Role
- Design and implementation
- Stack
- Lua (GLua), MySQL
- Context
- Shared infrastructure for every plugin on Diverge Networks
- Status
- Live
The problem
Plugins save and load their data asynchronously. When a plugin wrote something and read it back soon after, the read could come back before the write had finished, returning stale data.
The design
- Each plugin gets its own queue, and its database operations run strictly one at a time, in order. A read can never overtake the write before it.
- Every call returns a promise that settles when that particular operation is done.
- The queue moves on after both successes and failures, so one bad query can never stall a plugin.
- Values are cached, so reads only hit the database when asked to refresh.
- Stored data is decoded inside a protected call, so corrupt data is rejected cleanly instead of crashing the caller.
Code excerpt coming soon
The per-plugin queue, about 70 lines: enqueue, run the next operation, and advance on success or failure.
assets/excerpts/plugin-data-queue.lua