Schemas, access profiles and the layout registry (DRAFT)¶
Status: draft, 2026-12-01. Implemented (2026-12-01): the layout (4.1:
oliviadb_core::layout, canonical JSON, SHA-256 identity without source), the registry for
DL/I databases (4.2: oliviadb_dli::registry, in the catalog of the database's store; local
numbers, sources as metadata, versioned defaults, program bindings; registration refused
on a node that may not register), the writer layout id (4.3: oliviadb_core::meta, set for
Java writes by spring-data-oliviadb, for DL/I writes from the semantic catalog's binding or
the default), decoding by the writer's layout in the JSON export and in the agent layer's
reads as of a version, format-2 keys with the native typed-node API (spec/path-keys.md), the replication of
the registry over HA (4.7), and unload format 2 carrying layouts (4.6); the IR and its
canonical JSON with the JSON Schema spec/schema/oliviadb-schema.schema.json (3), the language
with its formatter (7, example spec/schema/examples/bank.olv), import of DBDGEN, PSBGEN
and agent PSBs with the round-trip test (5, 8), evolution plans and
deployment (4.5), profile checks (6.1) and enforcement in the network API (6), all in the
open crate oliviadb-schema and, for the importers, in oliviadb-dli and oliviadb-agent; the change
stream of the IMS replica decoded by writer layout and masked per consumer profile
(docs/network-api.md, "Change stream"); aggregates of the schema language served natively
by the network API under profiles, with their layouts (4.1, "Layouts of the schema
language"), writes as optimistic transactions within the profile's transaction scope, and
their change stream decoded by writer layout (docs/network-api.md, "Native aggregates");
typed clients generated from a profile, Rust and TypeScript (oliviadb schema client,
docs/network-api.md, "Generated clients"). Not yet: clients in Java and Python, SQL
views and OpenAPI from profiles, oliviadb profile suggest. Names, fields and encodings may still change.
The language and its JSON Schema are open (Apache-2.0, like the rest of spec/). The
importers of IMS definitions (DBDGEN and PSBGEN source) stay in the enterprise layer.
1. Why¶
A hierarchical database knows two things in advance, and OliviaDB keeps both:
- What the data is: the aggregate (a tree of node types, their keys, their fields, how they are placed). In IMS this is the DBD, together with the COBOL copybooks that give the segments' fields.
- How each program may use it: which node types and fields it sees, what it may do, by which paths. In IMS this is the PSB (PCB, SENSEG, SENFLD, PROCOPT, PROCSEQ).
OliviaDB is schema-first and contract-first. This document gives both a modern form that lives in git, is checked in CI and generates clients, and maps one to one onto the IMS forms that migrated applications already have.
The record structure is a layout, wherever it comes from. In COBOL the copybook defines
the bytes of a segment; in Java the class does (oliviadb-dli-mapping records, and later the
spring-data-oliviadb entities); in a new application the aggregate declaration does. OliviaDB
treats all three the same way: as immutable, versioned layouts kept in a registry inside
the database, and every stored version of a node records the layout it was written with.
2. Terms and their IMS equivalents¶
Documentation of OliviaDB always shows the IMS equivalent next to the new term.
| OliviaDB term | IMS equivalent | Notes |
|---|---|---|
aggregate |
DBD (physical database) | one tree of node types; the root type's key identifies a database record |
child (node type) |
SEGM with PARENT= | |
| key parts | FIELD with SEQ (U or M) | format 1 (raw bytes) for imported DBDs, format 2 (typed, spec/path-keys.md) for declared aggregates |
unique / duplicates / ordered |
SEQ,U / SEQ,M / no SEQ field with RULES=(,FIRST|LAST|HERE) | oliviadb_core::schema::Twins |
field numbers (1 name: ...) |
none (START= offsets in the DBD, copybook positions) | stable ids, like protobuf tags |
variant on |
REDEFINES in a copybook | the discriminator is declared, not guessed |
enum with labels |
88-level condition names | |
ref ... on delete |
logical child, insert/replace/delete rules P, L, V | |
placement hash |
HDAM/PHDAM randomizing module | |
partition by range |
HALDB partitions | |
index ... [async] |
LCHILD/XDFLD (secondary index) | in the same unit of work, or asynchronous with a freshness mark |
profile |
PSB | bound to an identity (service, agent), not to a load module name |
path grants (get, list, range, update, insert, delete) |
PCB + SENSEG + PROCOPT (G, I, R, D, A, K) | granted per access path, not per segment type |
fields(...), except |
SENFLD | |
lookup index -> Aggregate |
PROCSEQ | |
rows, mask, pii |
OliviaDB's agent PSB statements ROWS, MASK, PDATA | no IMS equivalent |
| layout | copybook record (or Java class) bound to a segment | kept in the registry, versioned |
3. The intermediate representation (IR)¶
One IR holds aggregates, profiles and layouts. Every input (the .olv language, DBDGEN,
PSBGEN, the agent PSB, copybooks through the semantic catalog, Java classes) produces it;
every consumer (the engine's oliviadb_core::schema::Schema, the DL/I layer, policies,
generated clients, SQL views, CDC, export) reads it. Its canonical form is JSON with sorted
object keys and no insignificant whitespace; the JSON Schema will be
spec/schema/oliviadb-schema.schema.json.
Schema { name, version:int, aggregates:[Aggregate], indexes:[Index],
profiles:[Profile] }
Aggregate { name, root:NodeType, placement?, partition?, residency?, history?,
subject?, ims?:{dbd, access} }
NodeType { name, key_format:1|2, key:[KeyPart], twins:"unique"|"duplicate"|"ordered",
fields:[Field], variants:[Variant], children:[NodeType],
refs:[Ref], tier?, code?:int, listing_index?:{include?:[name]},
ims?:{segm, bytes, rules} }
KeyPart { name, type:Type, desc:bool } ; format 1: one part of type bytes(n)
Field { number:int, name, type:Type, pii?:class, label?, description? }
Variant { discriminator:field-number, cases:[{values:[...], fields:[Field]}] }
Ref { name, target:path, on_delete:"restrict"|"cascade"|"keep",
ims?:{rules:"P"|"L"|"V" x3, pair?} }
Index { name, on:path, parts:[KeyPart], unique:bool, mode:"sync"|"async",
ims?:{lchild, xdfld, procseq_dbd} }
Profile { name, principal:{kind:"service"|"agent"|"program", id}, identities?,
mode:"enforce"|"observe", consistency:{level:"strong"|"follower",
max_lag_ms?, as_of?}, txn_scope:"aggregate"|"cross", rows:[Rows],
masks:[Mask], pii_masked:[aggregate|"*"], grants:[Grant], purpose?,
quota?:{calls, per:"s"|"min"|"h"}, ims?:{lang, cmpat, pcb} }
Grant { verb:"get"|"list"|"range"|"update"|"insert"|"delete"|"lookup"|"search"
|"watch", path, fields?:[...], except?:[...], by?, limit?,
target?, budget?, scan?, propose? }
The JSON Schema (spec/schema/oliviadb-schema.schema.json) is the exact form; absent options,
empty lists and false flags are left out of the canonical text, so a schema has exactly one.
Layouts are not part of the schema document: they live in the registry (4), which names
the node types they describe.
Type is one of string(n[, collation]), bytes(n), int8..int64, uint8..uint64,
decimal(p,s), date, timestamp, bool, float64, enum{...}, text (variable
length), ref. The logical type says what a value is; the physical encoding (zoned,
packed, binary big- or little-endian, EBCDIC code page, fixed offset) belongs to a layout
(section 4), because the same logical field is stored differently by a COBOL program and
by a new service.
code is assigned on the first deployment and then never changes: it is the node type's
format-1/format-2 component code. A new type takes a free code between its neighbours
(the gaps of spec/path-keys.md); this is the online addition of a segment type.
Anything an IMS definition holds that the IR has no field for is kept in the ims
extension objects, verbatim, so that an imported definition exports back unchanged.
4. Layouts and the registry¶
4.1 Layout¶
A layout is the byte-level description of one node type's data:
Layout { node_type, length | {min,max}, fields:[{number, name, offset, length,
encoding, scale?, signed?, occurs?}], variants:[{discriminator, values,
fields}], source:{kind:"copybook"|"java"|"dsl"|"dbd", name, digest} }
source says where the layout came from; it is not part of the layout's identity
(section 4.2): the canonical JSON that is hashed holds everything above except source,
so renaming a copybook or a Java class keeps the layout's id, and two sources that
describe the same bytes are one layout.
encoding is one of char(ccsid), zoned, packed, binary-be, binary-le,
float-hex, float-ieee, bytes. Field sizes of copybook layouts are computed as the
semantic catalog does it (docs/semantic-catalog.md, from the Enterprise COBOL Language
Reference, "PICTURE clause" and "USAGE clause").
Layouts of the schema language¶
A node type declared in the language gets one layout (source.kind = "dsl", built by
oliviadb_schema::codec), its fields in field-number order at fixed offsets, then one area per
variant on as long as its longest case (the fields of the case the discriminator
selects, zeros otherwise), then a tail of the text fields:
| type | encoding | bytes |
|---|---|---|
string(n) |
char(1208) (UTF-8), padded with spaces |
n |
bytes(n) |
bytes |
n |
intN, uintN |
binary-be (signed: false for uint) |
N/8 |
decimal(p,s) |
packed, sign nibble C or D, scale s |
p/2 + 1 |
date |
binary-be, days since 1970-01-01 |
4 |
timestamp |
binary-be, microseconds since 1970-01-01T00:00:00Z |
8 |
bool |
binary-be, 0 or 1 |
1 |
float64 |
float-ieee, big-endian |
8 |
enum |
char(1208) of the stored value, padded |
the longest stored value |
text |
in tail: a varint length and the UTF-8 bytes |
variable |
ref |
in tail: a varint length and the target's path (UTF-8) |
variable |
Every field of such a layout carries its logical type as "type" (the type's canonical
JSON), and the tail fields are listed under "tail" (number, name, encoding,
type); both are part of the canonical JSON and so of the identity. length is the fixed
part (it may be 0). A ref field is in the tail too, holding its target's path text
(docs/network-api.md, "References"). text and ref fields of a variant case are tail
fields with the case's discriminator and values, present only when the case is
selected. A field a newer layout adds reads, in versions written before, as its type's
default (oliviadb_schema::codec::default_value).
4.2 Registry¶
- Immutable and content-addressed. A layout's identity is the SHA-256 of its
canonical JSON without
source. Registering the same layout twice gives the same entry. A layout is never changed; a new version is a new layout withsupersedespointing at the old one. - Sources are metadata. The registry keeps, per layout, the set of sources that
registered it (
kind,name,digest): several sources (a copybook and the Java class generated from it, two classes with the same fields) may map to one layout. Adding a source to an existing layout changes neither its id nor its local number. - Inside the database. The registry is a tree in the store's catalog namespace (with
the database catalog of
oliviadb-dli), so it is backed up, replicated, versioned and read "as of" like any data. Catalog keys:L/d/<digest>(number and canonical JSON),L/n/<number>,L/next,L/s/<digest><source JSON>,L/def/<DBD> 0x00 <segment>,L/bind/<program> 0x00 <DBD> 0x00 <segment>. - Registration on a standby. A standby refuses registration: on an HA node the
registry is a replicated class (4.7) written only by the primary; a node without HA can
be told to refuse (
Registration::Refused, C ABIoliviadb_set_layout_registration(sys, 0)). It writes with the layouts it has. - Local number. Each registered layout also gets a small number, assigned in registration order per store, starting at 1. Stored versions use the number (section 4.3); the registry maps it to the digest. 0 means "no layout recorded".
- Validity. The registry records, per node type, which layout is the default from
which version on (
default_from: hlc). A read as of versionvuses the default valid atvwhere a version carries no layout of its own.
4.3 Writer layout id¶
Every stored version of a node carries the local number of the layout its writer used, and optionally the REDEFINES variant the writer knew:
stored value = meta segment-bytes
meta = flags:varint [layout:varint] [variant:varint]
flags : bit 0 layout present, bit 1 variant present, other bits reserved (0)
- The meta prefix is outside the segment bytes: the DL/I layer strips it before the data reaches an I/O area, and adds it on ISRT/REPL. A DL/I program sees exactly the bytes it wrote; unload in IMS formats writes exactly the segment bytes.
- Where it lives: the meta prefix is part of the stored value, so the write-ahead log,
tables, replication batches and resynchronisation carry it without a format change of
their own. A store records in its catalog that its values carry meta (a store created
before this format has none; conversion is a rewrite by compaction). Implemented: a
DL/I database store created from now on is marked in the catalog (
meta:<store>) and keeps headers; an older one keeps its format. The alternative, a field in the table entry next to the version (ts), would need a new table, log and replication format for the same information; it is kept in reserve if the prefix shows a measurable cost. - Who sets it:
| writer | layout | variant |
|---|---|---|
| native API, DSL clients | the aggregate's layout of the schema version in use | written explicitly by the client |
Java (oliviadb-dli-mapping, spring-data-oliviadb) |
the class's layout (registered at startup from the class, or generated by oliviadb-codegen from the catalog) |
from the @When case the object is |
| DL/I call from a migrated program (CBLTDLI, AIBTDLI, C ABI) | the copybook layout bound to (program, segment) in the semantic catalog, when known; else the node type's default | not recorded (the catalog's discriminator rule decides at read time) |
| replica applier (IMS log, unload) | the binding of the program named in the log record when known; else the default | not recorded |
- Readers that decode (CDC, JSON export, the SQL projection, agent views): each version is decoded by its writer layout; a version without one by the default valid at its version. As-of reads therefore decode history in the layout that was valid then. Readers that do not decode (DL/I) ignore the meta.
4.4 Cost¶
- Bytes per version.
flagsis one byte; a layout number below 128 is one more byte, below 16 384 two. Typically 2 bytes per version (3 with a variant). On the benchmark database ofdocs/status.md(segments of 40 to 60 bytes) this is 3-5 % of the stored value and less of the stored entry (key and version included); on entries of ~150 bytes it is ~1.3 %. A store may set "layout implied" for a node type whose every version uses the default: thenflagsis 0 and the cost is 1 byte. Whether a table-level dictionary (one layout number per block when all entries share it) is worth a storage format change is open; measure first. - CPU. Decoders are compiled once per layout (a field list with offsets and converters) and cached by local number in a bounded map per node; the number of layouts is small (a few per segment type: copybook versions and classes), so the cache hit rate is effectively 100 % after warm-up. DL/I calls pay only the strip/add of the prefix (one varint read; no decode).
4.5 Schema evolution checks¶
oliviadb schema plan --against <store> compares a candidate schema with the registry and the
profiles (an analogue of protobuf's buf breaking):
- Refused (breaking): a key part's type, order, direction or collation changes; a field number is reused with another type; a field that a profile grants is removed; a fixed layout gets shorter; a discriminator changes its field or a value moves to another variant; a node type changes its parent or code.
- Allowed: a new field with a new number (a default for old versions); a new node type
in a code gap; a new layout for an existing node type (old versions keep theirs); a new
index (built online,
syncorasync); a new profile; widening anenum. - The plan lists the indexes that will be built, the profiles affected and the layouts added.
4.6 Unload, reload and IMS formats¶
- IMS formats (HD Reorganization Unload, HISAM and SHISAM data sets, DEDB unloaded
segment records, DL/I programs, GSAM; readers in
docs/operations.md) hold segment bytes only: exporting to them drops the writer layout ids. Reloading data in an IMS format sets them by the rule for DL/I writers (binding when known, else default); the reload reports how many versions got a bound layout and how many the default. - OliviaDB's unload format (
spec/unload-format.md) gets an optional version 2: a layout table (digest, canonical JSON) after the header and a layout index per record, so an OliviaDB-to-OliviaDB unload and reload keeps the ids (renumbered into the target's registry by digest). - JSON export (an aggregate as one JSON document, field names from the layout, keys decoded where the collation is reversible) carries the layout digest per node; JSON import needs a schema and refuses fields the layout does not have.
4.7 Replication¶
- The registry tree is a replicated class (as the agent memory's key store is in phase 1,
docs/ha.md): it is shipped from the primary to the standby with the durable class's guarantees. Implemented:Class::Layoutsofoliviadb-ha; registration is admitted only on the primary and acknowledged once the standby holds it; a promoted standby is a primary and registers through the same class. - Invariant: a layout is committed no later than the first version that refers to it (in the same commit batch or an earlier one). A reader that meets an unknown local number has found a bug and fails loudly.
- Layer-1 data of the IMS replica is not shipped: each node applies the IMS change stream
itself (
docs/ha.md). Its local numbers therefore must agree on both nodes. Rule: only the primary registers layouts; the standby's applier waits until the registry it received holds the digest it needs, and uses that number. On promotion the new primary registers, through the replicated class, to its own standby. - Resynchronisation ships every version of every key with its meta prefix; the registry is resynchronised first.
4.8 Listing indexes¶
A listing of one type under one parent (the customers of an aggregate, the accounts of a
customer) reads the children in key order. Nodes are stored in pre-order
(spec/path-keys.md), so between two children lies the first one's subtree, and the listing
seeks past each child's subtree. A type that is listed more than it is read whole can declare
a listing index: a second copy of its nodes' keys, in the same order, with no subtrees in
between, and optionally the fields a listing shows. It is what a table with a covering index
gives a relational database (PostgreSQL: an index with INCLUDE columns), chosen by the
schema's author per type.
child Account [number: string(20)] unique {
listing index include (currency, balance)
...
}
aggregate Customer {
key id: string(12)
listing index include (name, branch)
...
}
Entries. One entry per node of the type, its key the node's key path (the parent's
components and the node's own component, spec/path-keys.md) under the index's own prefix,
so the entries of one parent's children are one key range in the children's key order. The
entry's value is empty without include. With include it is the node's stored value (its
version header, writer layout and data) with every field outside the list cleared as a
masked field is (fixed fields filled with zero bytes, variable fields empty): the entry is
decoded by the node's own writer layout.
Writes. An entry is written in the same commit as the insert of its node and deleted in
the same commit as the delete of the node or of a subtree holding it, so it is in the same
write-ahead log record. An update of the node writes the entry again only when a field in the
include list changes; an index without include is written on inserts and deletes only.
Each entry costs one key (the node's key with the index prefix) and, with include, the
included fields' bytes.
Reads. A listing of the type (GET of the type, the native protocol's GET, a profile's
list or range grant) reads the index instead of the nodes when every field the caller's
profile shows of the type, and every field its rows rules and masks of the type read, is in
the include list. The answer is the one the listing over the nodes gives: the same nodes,
in the same order, at the same version, each shown, hidden or masked by the same rules, with
limit, after, prefix and to as before. A listing that needs a field outside the list
reads the nodes as before. An index without include serves no listing on its own: its
entries name the children, and their fields are read from the nodes.
Changes to the declaration. Adding a listing index to a type, or a field to its
include list, is a schema change (4.5) that builds the entries online before the index is
read; removing one deletes its entries. The server's check report (GET /v1/admin/check) gives,
for each listing index marked complete, the number of entries missing, in excess or different
from the nodes.
5. Import¶
| input | gives | where |
|---|---|---|
| DBDGEN source | aggregates (key format 1), default layouts from FIELD statements, indexes from LCHILD/XDFLD, refs from logical relationships with their P/L/V rules, ims extensions |
enterprise (oliviadb-dli) |
| PSBGEN source | profiles of principal.kind = "program": one grant set per PCB from SENSEG and PROCOPT, fields from SENFLD, lookup from PROCSEQ |
enterprise |
| agent PSB (PSBGEN + ROWS, MASK, PDATA) | profiles of kind = "agent" with rows, masks, pii |
enterprise (oliviadb-agent) |
| semantic catalog (copybooks bound to segments) | layouts with source.kind = "copybook" and the program-to-layout bindings used for DL/I writes |
enterprise (oliviadb-agent) |
Java classes (@Segment, spring-data-oliviadb entities) |
layouts with source.kind = "java" |
enterprise Java libraries |
.olv source |
everything | open |
oliviadb schema export prints a store's schema as .olv text: a migrated IMS database is
shown in the new form, and the customer can evolve it there while DL/I programs go on.
6. Enforcement¶
- A call by a path that the caller's profile does not declare is refused in
production. A profile in
mode: "observe"(staging) lets the call through and logs it with the path, the profile and the purpose;oliviadb profile suggest(later) turns such a log into a minimal profile. - DL/I programs keep their PSB semantics unchanged: an imported PSB is a profile whose grants reproduce PROCOPT and SENSEG exactly; the status codes are those of DL/I.
- Enforcement starts in
oliviadb-server, where the agent policies are already applied.
In the DL/I call path (oliviadb serve --schema, docs/operations.md, "Programs under access
profiles") a program's profile narrows its PSB: a segment the profile grants nothing of is
not sensitive, an option taken from every segment of a PCB leaves its PROCOPT, I, R or D
taken from some segments only leaves their SENSEG PROCOPT, and the
program runs under the narrowed PSB, so its calls get the status codes a PSB without them
gives (AC, AM, the GN that passes over a segment). A profile cannot widen its PSB; what a
PSB cannot express is refused when the server starts. Observe mode runs the whole PSB and
records the calls the profile would have refused.
Implemented in the network API (oliviadb-server, oliviadb-agent-server): the configuration names
a schema ("schema") and an environment ("environment": "production" or "staging").
Each caller is under the profile declared for its principal (or naming it in an
identity). On every operational-data call (path reads and listings, search, watches):
- the path must be granted:
getfor a node (orget .../**for anything under one),listorrangefor a listing (within the grant'slimit),searchfor a search (within its tokenbudget),watchfor a watch (and what is under the watched path); otherwise 403.fields(...)keeps only the named fields of what the grant serves;except Type/Path.fieldtakes a field out of every grant of the profile that reaches that type, whichever grant serves the call (deny wins: a field one grant hides is not shown by a listing, a watch or a change stream under another); - the consistency must be what the node can give:
strongonly on the leader,follower max_lag donly while the follower knows it is less thandbehind (otherwise 503, retryable);as_ofreads only when the profile saysas_of allowed(otherwise 403). The IMS replica's agent server is a follower:strongis refused there,follower max_lagis served while the replica's measured lag (docs/agent-data.md, "Lag") is within it; - the
quotais counted per profile (429, retryable).
A profile in observe mode lets the call through and writes a record ("observe": true,
profile, purpose, principal, path, the reason it would have been refused) to the audit log.
A production server refuses to start with a profile in observe mode and gives a caller
without a profile no data; a staging server lets such a caller through and records each
call. Memory calls are outside profiles. txn scope: under the default scope a
transaction writes one aggregate record (Guard::txn); cross is refused for services
and agents until transactions across aggregates exist, and is what an imported PSB says
(a DL/I sync point commits every record the program changed). Native aggregates
(docs/network-api.md, "Native aggregates") are written through the network API in
transactions whose records the scope bounds (403 for a transaction across records under
txn scope aggregate); writes need insert (a grant ending with the type covers any key
of it), update (its fields(...) bound the fields changed, except fields cannot be
changed) or delete grants, and rows refuse a write that would leave a node the
profile does not admit.
6.1 Profile check¶
oliviadb profile check FILE [--profile NAME] gives every grant its plan: key (every key on
the path named), key prefix (a listing or subtree under named keys; a range by the
first key part), index <name> (a range by the first field of an index on the type, a
lookup), key order, first n (the aggregate's records with a limit), text index
(search), change stream (watch). A path that would read a whole aggregate or type
(a * key, every record without a limit, a range by another field) fails the check
unless the grant says scan. Exit code 2 when one fails.
7. The language¶
The full example is spec/schema/examples/bank.olv. Text is UTF-8; // starts a comment
to the end of the line; names are letters, digits and _ # @ $ - (not first), or any text
in backquotes. Keywords are lowercase and only special where the grammar expects them.
database and psb are accepted for aggregate and profile.
file = [ "schema" name "version" int ] { aggregate | index | profile }
aggregate = "aggregate" name [ "root" name ] "{" { aggstmt | nodestmt } "}"
aggstmt = "key" keypart { "," keypart } [ "duplicate" ] [ "format" ("1"|"2") ]
| "ordered" // an unkeyed root
| "placement" "hash" "(" names ")" "buckets" int
| "partition" "by" "range" "(" names ")"
| "residency" name | "history" duration | "subject" name
| "ims" "aggregate" json
nodestmt = field | variant | child | ref | "tier" name "after" duration
| "code" int | "ims" json
| "listing" "index" [ "include" "(" names ")" ]
field = int name ":" type { "pii" [ "(" name ")" ] | string | "description" string
| "ims" json }
keypart = name ":" type [ "desc" ]
type = "string(" int [ "," collation ] ")" | "bytes(" int ")" | int8..int64
| uint8..uint64 | "decimal(" int [ "," int ] ")" | "date" | "timestamp"
| "bool" | "float64" | "text"
| "enum" "{" name "=" string [ string ] { "," ... } "}"
| "ref" refpath [ "on" "delete" ("restrict"|"cascade"|"keep") ]
variant = "variant" "on" name "{" { case { "," case } "{" { field } "}" } "}"
case = name /* an enum member */ | string /* a stored value */
child = "child" name [ "[" keypart { "," keypart } "]" ]
[ "unique" | "duplicate" | "ordered" ] [ "format" ("1"|"2") ]
"{" { nodestmt } "}"
ref = "ref" name "->" refpath [ "on" "delete" word ] [ "ims" json ]
index = "index" name "on" typepath "(" name [ "desc" ] { "," ... } ")"
[ "unique" ] [ "async" ] [ "ims" json ]
profile = "profile" name "for" ("service"|"agent"|"program") string "{" { pstmt } "}"
pstmt = "identity" name name string | "mode" ("enforce"|"observe")
| "consistency" ( "strong" | "follower" [ "max_lag" duration ] )
[ "," "as_of" "allowed" ]
| "txn" "scope" ("aggregate"|"cross") | "purpose" string
| "rows" typepath ( "all" | "where" name ("="|"!="|"in") values )
| "mask" typepath "." name ( "redact" | "token" | "partial(" int ")" )
| "pii" "masked" [ "on" names ]
| "quota" int "calls" "/" ("s"|"min"|"h") | "ims" json
| [ "propose" ] verb grantpath { "fields(" names ")" | "except" fieldref { "," fieldref }
| "by" name | "limit" int
| "budget" int "tokens" | "scan" }
| "lookup" name "->" name
grantpath = name { "/" ( "{" name "}" | "*" | name ) } [ "/**" ]
values = value | "(" value { "," value } ")" value = string | "$user." name
duration = int ( "ms" | "s" | "min" | "h" | "d" | "w" | "y" )
Defaults: a root key is unique; a keyed child without unique has duplicates; an
unkeyed type is ordered; key format 2 unless format 1 (raw bytes, the DL/I format:
one part of type bytes(n)); consistency strong; txn scope aggregate; mode
enforce. A grant path alternates keys and types after the aggregate (the root's key
first): Customer/{id}/Account lists a customer's accounts, Customer/{id}/Account/{n}
names one. The ims members carry an imported definition's own attributes as JSON.
Errors name the line and column: syntax errors where the text stops making sense, the
checks (names resolve, field numbers unique, keys well formed, grants name real paths and
fields) at the declaration they are about. The formatter (oliviadb schema fmt) writes one
layout; parsing its output gives the same IR.
8. Round-trip test¶
The importer is correct only if nothing is lost or invented on the way. The round trip is
tested on a corpus of definitions that is not published with the specification (63 DBDs and
37 PSBs in 19 libraries); item 3 compares the Dbd and Psb values, not regenerated DBDGEN
text:
- For every DBD and PSB of the corpus: DBDGEN/PSBGEN → IR →
.olvtext → IR gives the same canonical JSON. - DBDGEN → IR →
oliviadb_core::schema::Schemaequals the schema the current importer builds (codes, bucket and key lengths, twin rules), and a database loaded under either has identical keys. - IR → DBDGEN-shaped text → the current DBD parser gives the same
Dbd. - Call scripts run on stores whose schemas were built through the IR print, step by step,
the same lines as on definitions read from the sources.
System::load_library_through_irimports a library into the IR, writes it as.olvtext, reads it back and defines the databases and programs from that (System::define_schema:to_dbd,to_psb, each store's tree schema fromcore_schemaof its aggregate).
9. Open¶
- Names:
aggregate/profile(decided) are shown with DBD/PSB everywhere; the language and the CLI acceptdatabase/psbas synonyms. - A table-level layout dictionary (section 4.4).
- Layout of OCCURS DEPENDING ON and variable-length segments with several layouts.
- Profiles for cross-aggregate transactions (
txn scope cross) before phase 2's two-phase commit exists: refused for services and agents. - Generating DBDGEN and PSBGEN text from the IR (round trip item 3 compares the parsed values instead).
- In the DL/I call path:
get/listtaken from some segments of a PCB only, field sensitivity narrower than the SENFLDs, profiles that would remove a PCB, and rows or masks for programs are refused at start. - Cedar or another policy language as an alternative input for complex
rowspredicates. - Native aggregates (
docs/network-api.md):refstatements without a field,placement/partition/residency/tieracted on (one node keeps key order), the uniqueness of anasync uniqueindex (not checked), a persistent text index forsearch,range ... bybounds other than a key prefix, history kept per aggregate (the tree keeps the longest window for all). - Generated clients: Java and Python; typed multi-write transactions (
/v1/txn) and server-sent change events (the client pollswatchbatches); a method per node type under aget .../**grant (only the tree is generated).