Operations
Storage and indexes
The record log, field indexes, compaction and the data folder.
OmniCore.Database has its own storage engine: an append-only record log, in-memory indexes of ids and perspectives, and disk-based B+ tree indexes on the fields you choose.
The data folder
Everything lives in DataDirectory (/data in Docker):
| File | Contents |
|---|---|
entities.omni | The record log: every write ever made, appended. The source of truth. |
schema.json | Fields, perspectives and relationships. |
security.json | Roles and role assignments. |
indexes/indexes.json, indexes/<field>.idx | The indexed fields, and one B+ tree per field. |
views.json, workflows.json, dashboards.json | Views, workflows and dashboards. |
workflow-runs/<workflow>/ | Each run's record. |
plugins/plugins.json, plugins/<id>/ | Installed plugins and their files. |
resources.json, Resources/<path> | The resource catalogue and the files, including forms and web part packages. |
schema.json and security.json are written atomically (a temporary file, then a rename) on every change.
The record log
Each write appends a record: a length, a CRC-32 and the entity's JSON (or, for a delete, its id). Opening the database replays the log to rebuild the in-memory primary index (id to record) and perspective index (perspective to ids); documents are read from disk when needed.
- Durability: with
DurableWrites(the default), each write is flushed to disk before the server answers. Without it, writes survive a process crash but may be lost in a power cut. - Crash recovery: a record whose CRC doesn't match, or which is cut short, marks the end of the valid log; what
follows is treated as a torn write and removed.
GET /api/statsreports how many bytes were.
Concurrency
Many readers and one writer at a time. Queries find their candidates under a read lock, then load documents one by one, so long reads don't block writers. Only one server can open a data folder: it holds an exclusive lock on the folder while it runs.
Field indexes
Index a field with PUT /api/indexes/{field} (System Admin). Each index is a disk-based, copy-on-write B+ tree of
4 KB pages:
- A change copies the path from the root to the leaf into new pages, then writes a new header. A crash at any moment leaves the previous tree intact.
- Each commit records the log position it reflects. On start-up an index is checked against the log and caught up by replaying later records. An index that's missing, damaged or out of step is rebuilt automatically.
- Text is indexed ignoring case; dates by instant. Json fields can't be indexed.
- Relationship reference fields are indexed automatically.
How queries use them
=,<,>,<=and>=become range scans;&intersects and|unions candidate sets. Every candidate is checked against the full filter, so results are the same with or without an index.- When the first sort key is indexed, results stream from the tree in order and only the requested page is loaded. On 50,000 entities, the first 20-row page sorted by an indexed field took about 5 ms, against about 450 ms without.
- Only the first sort key uses an index, and there are no composite indexes.
~=(contains) never uses an index.
Use Explain to see what a query will do.
Compaction
Updates and deletes leave old records in the log. POST /api/admin/compact writes a new log with only the current
version of each live entity, replaces the old file atomically, and rebuilds every index compactly. It blocks reads and
writes while it runs. GET /api/stats shows the live and garbage bytes, to judge when it's worth it.
Statistics
GET /api/stats (System Admin): the entity count, file and live bytes, garbage, bytes discarded at start-up, entities
per perspective, and for each index its entries, height, pages, size and state.
Backups
Stop the server (or take a consistent snapshot of the volume) and copy the whole data folder. The log, indexes and JSON files belong together; indexes can be rebuilt from the log, but the rest can't.
Using the engine in-process
The engine is a .NET library, and can be used without the HTTP server (with no security applied):
using var db = OmniDatabase.Open("data", new OmniDatabaseOptions { DurableWrites = true });
db.Schema.DefineField(new("firstName", "First Name", FieldType.Text));
db.Schema.DefineField(new("creditLimit", "Credit Limit", FieldType.Decimal));
db.Schema.DefineInterface(InterfaceDefinition.Create("Customer", "Customer",
new("firstName", Required: true), new("creditLimit")));
var ann = db.Insert(new EntityDocument("Customer").Set("firstName", "Ann").Set("creditLimit", 5000m));
db.Modify(ann.Id, d => d["creditLimit"] = 6000m);
db.CreateIndex("creditLimit");