DL/I programs through a server¶
Status: draft for 0.1.1, open to review with the core implementation.
Many DL/I programs and network clients work on the same DL/I databases at once: GnuCOBOL
and other batch programs that CALL 'CBLTDLI', programs half moved to Java, Python or Rust,
and agents reading over the network API. A store has one opener at a time
(storage-format.md, "Store lock"), so they all go through one server that holds the
stores, runs the DL/I calls, isolates the programs from each other and commits their units
of work. The programs do not change: liboliviadb_dli sends their calls to the server when
it is told to (section 2), with the same C ABI, so CALL 'CBLTDLI', the Rust, Java and
Python bindings and the C hosts work either way.
1. The server¶
- One DL/I system per store, held by the server for as long as it runs (the store lock). The server's configuration names the stores it serves and, per principal, the PSBs it may schedule (section 4). Several programs are scheduled at once, each in its own unit of work.
- Program isolation as IMS describes it for the program isolation (PI) lock manager (IMS 15 Database Administration, SC27-6784-00, chapter 15, "Locking to provide program isolation", PDF p. 191): the database record is locked when a program first gets position in it (the root, or for HDAM and PHDAM the anchor point); a PCB whose processing option allows updates keeps other programs out of the record until it moves to another record or reaches a commit point; a segment the program inserts, replaces or deletes stays locked until its commit point. A request that conflicts waits; the call is answered when the lock is granted.
- Deadlocks end one program of the cycle. IMS's rules for the program chosen are given for its own regions (Database Administration, chapter 30 "Tuning databases", "Contention for DEDB control interval (CI) resources", PDF p. 676: of two BMPs, the one that went through sync point last); OliviaDB's choice is stated in its documentation and is not a compatibility promise. What the chosen program sees is IMS's: when it has issued INIT STATUS GROUPB, a BC status if it made no changes, or made changes and runs with dynamic backout; otherwise abnormal end U0777 (Application Programming APIs, SC27-6779-00, INIT call, "Enabling deadlock occurrence status codes: INIT STATUS GROUPB", PDF p. 57; Messages and Codes Volume 3, GC27-6791-00, abend 0777, PDF p. 361). Its database changes since its last commit point are backed out and its locks released.
- Lock wait limit (optional, off by default): with
lock_timeoutset, a request that waited that long ends the program abnormally with U3310, as IRLM's LOCKTIME does (Messages and Codes Volume 3, abend 3310, PDF p. 632); its unit of work is backed out. Without it a request waits until it is granted or a deadlock is found, as under program isolation. - Units of work are committed at the program's commit points (SYNC, CHKP, normal end) in
one atomic commit across the stores they touched (
storage-format.md, "Units of work across trees"); ROLB and ROLS back out as the DL/I layer does today. A program whose connection ends before its normal end, or that ends abnormally, is backed out to its last commit point and its locks are released. - Readers see committed data only. The read-only view (
native-protocol.md6.4, route0x07 DLI) reads at a committed version, so it sees each unit of work whole or not at all, never a program's uncommitted changes, and takes no program isolation locks (a version is immutable; readers do not wait for programs and programs do not wait for readers). - The server's death: the stores are recovered at the next start; every unit of work committed before the death is there and none that was not. A program learns the death from its connection's end (section 3.4).
2. Client mode of liboliviadb_dli¶
The library runs DL/I in the host's process (today's mode) unless a server is named:
| setting | meaning |
|---|---|
OLIVIADB_DLI_SERVER |
host:port (the native protocol over TLS, native-protocol.md), or unix:/path (the native protocol on a Unix socket of the server's host, without TLS: the socket's file permissions guard it) |
OLIVIADB_DLI_KEY, OLIVIADB_DLI_KEY_FILE |
the credential (an API key; section 4); the file form keeps it out of the environment of child processes |
OLIVIADB_DLI_CA_FILE, OLIVIADB_DLI_SERVER_NAME |
TLS: a CA file instead of the platform's roots, and the name the server's certificate must carry (default: the host of OLIVIADB_DLI_SERVER) |
OLIVIADB_DLI_STORE |
the store on the server, when it serves several (default: its default store) |
or a host calls oliviadb_connect (section 2.1) with the same settings. Then:
oliviadb_open(dir, sync)returns a system bound to the server;dirandsyncare not used (the store isOLIVIADB_DLI_STORE's, by default the server's own; the server decides durability). Nothing is opened locally, and the local store lock is not taken.- The library takes the server's library (DLI_LIBRARY, section 3) when it connects, and uses its definitions for what the C ABI computes in the host: PCB counts and mask lengths, the lengths of SSAs and I/O areas passed by address only, PCB names of the AIB.
oliviadb_load_library(sys, dir)andoliviadb_definecheck the sources against the server's library: each DBD and PSB ofdir(or the source given tooliviadb_define) must be one the server has, with the same source hash (the definitions live in the server). A difference fails the call (-1) andoliviadb_last_error()names the member. Programs keep their host code unchanged, and a program built against other definitions than the server's does not run against it.oliviadb_scheduleand the other schedule functions schedule the PSB in the server (with the runtime the host names: the server converts nothing; the program's storage format is its own) and return a program whose PCBs, masks and calls behave as in process.CBLTDLI,CEETDLI,ASMTDLI,PLITDLI,AIBTDLI,oliviadb_callandoliviadb_dli_callsend each call to the server (section 3.2) and copy back what it returns: the status, the PCB mask, the I/O area and any other area the call writes. Return values are as in process; a call that ended the program abnormally returns -2 witholiviadb_abend_code(p)(U0777, U3310, ...), as an in-process abnormal end does.oliviadb_terminateis the normal end (commit),oliviadb_abortthe abnormal end (back out),oliviadb_syncandoliviadb_backouta commit point and a backout of a program that goes on,oliviadb_closecloses the connection.- Functions that act on the local engine (randomizer, exit and resolver registration, dataset transfer, layout registration, mapping a database to a directory, unload) fail with -1 and an error that names the function and client mode: the server's configuration holds those.
- A server that cannot be reached, or refuses the credential, fails
oliviadb_open(NULL, the reason inoliviadb_last_error()). The library never falls back to opening the store itself.
2.1 C ABI version 14 (additive)¶
oliviadb_abi_version() returns 14. Every function of version 13 keeps its behaviour when
no server is named.
| function | does |
|---|---|
oliviadb_connect(address, options) |
a system bound to the server at address (as OLIVIADB_DLI_SERVER); options a JSON object with key, key_file, ca_file, server_name, store (NULL: the environment's) |
oliviadb_is_remote(sys) |
1 for a system bound to a server, 0 otherwise |
oliviadb_outcome(sys) |
after OLIVIADB_LOST (section 3.4): 1 when the commit point in flight committed, 0 when it did not |
OLIVIADB_LOST (-5, the value of OLIVIADB_LOCAL_LOST of version 10) is returned by a call
when the connection to the server ended.
3. The DL/I frames of the native protocol¶
A DL/I program runs on a connection of the native protocol (native-protocol.md, sections
1 to 3: HELLO, READY, AUTH, AUTH_OK; TLS on TCP, none on a Unix socket). HELLO's options
carry dli_session, a value the client chooses (16 random bytes in hexadecimal) that names
its programs across reconnections (section 3.4). A connection may run several programs; each
has one call in flight at a time. The frames use the stream id as other requests do: one
request, one answer.
| opcode | direction | body |
|---|---|---|
0x30 DLI_SCHEDULE |
client → server | store: str; psb: str; runtime: u8 (0 EBCDIC, 1 ASCII big-endian binary, 2 ASCII little-endian); options: varint count, (str, str)* (bko, disk_log, as the schedule functions take them) |
0x31 DLI_SCHEDULED |
server → client | program: u32; pcbs: varint count, (kind: u8, mask: lp)* (the I/O PCB first; each PCB's mask as the program starts) |
0x32 DLI_CALL |
client → server | program: u32; pcb: u16 (0 the I/O PCB, i the PSB's PCB i; 0xFFFF INQY through the AIB, below); function: 4 bytes (as the program has it); seq: u64 (a commit point's sequence number, section 3.4; 0 for other calls); mask: lp (the PCB's mask in host storage); areas: varint count, lp* (the I/O area then the SSAs, or a system service call's areas, each with its length) |
0x33 DLI_RESULT |
server → client | rc: i32 (the call's return value as in process: 0, the status characters, -2 abnormal end); abend: lp (the abend code's text, U0777; empty if none); used: varint (bytes of the I/O area the call returned data in: AIBOAUSE); mask: lp; areas: varint count, (index: varint, data: lp)* (the areas the call wrote, by index in the request); updates: varint count, (pcb: u16, status: 2 bytes, segment: str)* (statuses the call set in other PCBs, as INIT and INQY DBQUERY do; segment empty when the name is left as it was); error: str (the text oliviadb_last_error() gives, empty if none) |
0x34 DLI_END |
client → server | program: u32; how: u8 (0 normal end: commit; 1 abnormal end: back out; 2 commit point, the program goes on; 3 back out to the last commit point, the program goes on); seq: u64 (section 3.4) |
0x35 DLI_OUTCOME |
client → server | seq: u64: did the commit point with this sequence number of this dli_session commit |
0x36 DLI_DONE |
server → client | result: u8 (DLI_END: 0 done; DLI_OUTCOME: 1 committed, 0 not) |
0x37 DLI_LIBRARY |
client → server | store: str: the library of that store's DL/I system |
0x38 DLI_MEMBERS |
server → client | members: varint count, (kind: u8 (0 DBD, 1 PSB), name: str, hash: u64, source: lp)*: every member, its source hash and its source |
INQY through the AIB (pcb 0xFFFF): areas are the AIB (its 128-byte fixed part) and, when
the program passed one, the I/O area; the server finds the PCB by the AIB's resource name and
writes the AIB's output fields (AIBRETRN, AIBREASN, AIBOALEN, AIBOAUSE, AIBRSA1, AIBRSA2) as the
in-process library does; the AIB and the I/O area come back as written areas.
Errors (a program number that is not the connection's, a PSB the principal may not schedule, a store the server does not serve, a malformed frame) are answered with ERROR and a problem document, as other requests; protocol errors close the connection as section 8 says.
3.1 Scheduling¶
The server schedules the PSB from its library (section 4) in the store named; the profile rules of the DL/I server apply (a principal's access profile narrows the PSB). The answer carries the masks the host copies into its own PCB storage.
3.2 Calls¶
The server runs the call as the in-process library does, with the program's positions,
locks and unit of work kept in the server. The function code, the I/O area and the SSAs are
passed as the program has them, in its runtime's character set and byte order; the areas
written are returned whole. A call that waits for a lock is answered when it is granted, or
with the deadlock's or the lock wait limit's outcome (section 1). Commit points (SYNC, CHKP)
and ROLB, ROLS, SETS, XRST, LOG and STAT are calls on the I/O PCB like the others; a commit
point's DLI_CALL carries the session's next sequence number in seq (section 3.4) and is
answered after the commit is durable.
3.3 End¶
DLI_END with how 0 commits the unit of work and frees the program; with 1 it backs out;
with 2 it commits and the program goes on (positions reset, as after a SYNC); with 3 it backs
out to the last commit point and the program goes on. A connection that ends ends its programs
abnormally (back out, locks released). A connection with a program scheduled is not closed
for being idle (the program may compute between its calls for as long as it needs).
3.4 When the connection ends¶
A call in flight when the connection ends returns OLIVIADB_LOST (-5): the unit of work
since the last commit point is backed out in the server, and positions and locks are gone.
When the call in flight was a commit point (or a normal end) the client cannot tell whether
it committed: it reconnects with the same dli_session and asks DLI_OUTCOME for that commit
point's sequence number (the server writes the session's sequence number in the same atomic
commit as the unit of work), and oliviadb_outcome gives the answer. The library does not
repeat calls on its own; the program restarts from its last checkpoint (XRST), as after an
abnormal end. The abnormal-end code a program should get when its server is lost is not one
IMS defines for this case; it is reported as OLIVIADB_LOST and the error text.
4. Server configuration¶
The dli section of the server (docs/network-api.md, "DL/I databases") gains:
"dli": {"store": "dli/system", "library": "dli/library", "runtime": "ebcdic",
"programs": {"unix": "/run/oliviadb/dli.sock", "lock_timeout_s": null,
"grants": {"batch-cobol": ["PARTPSB", "PAYPSB"], "parts-api": ["PARTPSB"]}},
"views": {"parts-agent": "dli/PARTVIEW.psb"}}
programs turns the DL/I frames on (on the native listener and, with unix, on that socket);
grants names, per principal, the PSBs it may schedule (a principal not named schedules
none). The read-only view (views) is served beside the programs, at committed versions.
5. Tests the implementation carries¶
- The existing scenarios, unchanged, in client mode: the C ABI tests, the GnuCOBOL programs of the quickstart and the smoke kit, the Rust, Java and Python bindings' scenarios, and the reference replay (its ratchet in client mode too).
- Concurrency, each outcome derived from the rules above: two programs updating different database records proceed; the same record waits until the holder's commit point; a deadlock gives BC (INIT STATUS GROUPB) or U0777 and backs out only the chosen program; the lock wait limit gives U3310; a client killed in the middle of a unit of work is backed out and its locks released; a server killed and restarted keeps exactly the committed units of work, and DLI_OUTCOME answers for the commit point in flight.
- The read-only view during writes: a reader sees a unit of work whole or not at all.
6. Open¶
- Shared memory between the library and a server on the same host (the call slot of
oliviadb serve --local,docs/operations.md) as a faster path than the Unix socket, if measurements show the socket's cost matters. - The abnormal-end code for a lost server (section 3.4).