oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1-- Schema version 1 of the hosted controller store. Controller times (columns
2-- ending _t) are integer nanoseconds of controller time. Wall times (columns
3-- ending _unix_ns) are Unix nanoseconds. Migrations are additive: a later
4-- version adds a new file and never edits this one.
5
6-- One row per attempt, created as the launch intent before any provider call.
7CREATE TABLE jobs (
8 attempt_id TEXT PRIMARY KEY,
9 launch_id TEXT NOT NULL UNIQUE,
10 vm_ref TEXT UNIQUE, -- absent until the provider answers
11 task_id TEXT NOT NULL,
12 account_id TEXT NOT NULL,
13 actor_key TEXT NOT NULL, -- the verified key that asked for the launch
14 purpose TEXT NOT NULL,
15 replaces_attempt TEXT, -- absent unless this attempt replaces another
16 spec_json TEXT NOT NULL,
17 spec_sha256 TEXT NOT NULL,
18 provider_fingerprint TEXT NOT NULL DEFAULT '', -- the provider settings the spec launches with (Config.ProviderFingerprint)
19 state TEXT NOT NULL,
20 launched_t INTEGER NOT NULL,
21 deadline_t INTEGER NOT NULL,
22 drain_t INTEGER NOT NULL,
23 stop_t INTEGER NOT NULL,
24 epoch INTEGER NOT NULL DEFAULT 0,
25 pause_generation INTEGER NOT NULL DEFAULT 0,
26 pause_started_t INTEGER, -- absent unless a pause is open
27 pause_quiescent INTEGER NOT NULL DEFAULT 0 CHECK (pause_quiescent IN (0, 1)),
28 pause_cancelled INTEGER NOT NULL DEFAULT 0 CHECK (pause_cancelled IN (0, 1)),
29 stop_requested_t INTEGER, -- absent until a stop is asked for
30 stop_reason TEXT,
31 stop_proof_json TEXT, -- absent until a stop is proven
32 notfound_since_t INTEGER, -- first not-found from Get since the VM was last seen live; absent otherwise
33 last_dispatch_t INTEGER, -- when the last provider launch call for this attempt was about to be made
34 drain_marked_t INTEGER, -- when the reaper found the job past drain_t; absent until then
35 revision INTEGER NOT NULL DEFAULT 0
36);
37
38CREATE INDEX jobs_state ON jobs(state);
39
40-- The launch spec is what the provider was asked for, with the provider
41-- settings it launches under; it never changes.
42CREATE TRIGGER jobs_spec_immutable
43BEFORE UPDATE OF spec_json, spec_sha256, provider_fingerprint ON jobs
44WHEN NEW.spec_json IS NOT OLD.spec_json OR NEW.spec_sha256 IS NOT OLD.spec_sha256
45 OR NEW.provider_fingerprint IS NOT OLD.provider_fingerprint
46BEGIN
47 SELECT RAISE(ABORT, 'spec is immutable');
48END;
49
50-- Jobs rows are never deleted: a deleted row would lose its spec and its
51-- resume history. The store turns on recursive_triggers, so the implicit
52-- delete of INSERT OR REPLACE fires this trigger too.
53CREATE TRIGGER jobs_never_deleted
54BEFORE DELETE ON jobs
55BEGIN
56 SELECT RAISE(ABORT, 'jobs are never deleted');
57END;
58
59-- Resume operations, kept for the attempt's lifetime so a retried operation
60-- ID returns its original epoch.
61CREATE TABLE resume_ops (
62 attempt_id TEXT NOT NULL REFERENCES jobs(attempt_id),
63 operation_id TEXT NOT NULL,
64 status TEXT NOT NULL CHECK (status IN ('pending', 'done', 'failed')),
65 prepared_epoch INTEGER NOT NULL,
66 result_epoch INTEGER, -- absent until done
67 prepared_t INTEGER NOT NULL,
68 completed_t INTEGER, -- absent until done or failed
69 PRIMARY KEY (attempt_id, operation_id)
70);
71
72-- At most one pending resume per attempt.
73CREATE UNIQUE INDEX resume_ops_one_pending ON resume_ops(attempt_id) WHERE status = 'pending';
74
75-- VMs the provider lists that match no job, with when the controller first
76-- saw each.
77CREATE TABLE unmatched_vms (
78 vm_ref TEXT PRIMARY KEY,
79 first_seen_t INTEGER NOT NULL
80);
81
82-- Request nonces held until they expire, so a replay is refused.
83CREATE TABLE nonces (
84 key_id TEXT NOT NULL,
85 nonce TEXT NOT NULL,
86 until_unix_ns INTEGER NOT NULL,
87 PRIMARY KEY (key_id, nonce)
88);
89
90CREATE INDEX nonces_until ON nonces(until_unix_ns);
91
92-- The latest expiry among pruned nonces: one row. A nonce valid only up to
93-- this time may already have been forgotten, so Remember denies it.
94CREATE TABLE nonce_pruned (
95 id INTEGER PRIMARY KEY CHECK (id = 1),
96 through_unix_ns INTEGER NOT NULL
97);
98
99-- Every decision the controller takes. Never holds credentials.
100CREATE TABLE audit (
101 id INTEGER PRIMARY KEY AUTOINCREMENT,
102 actor_key TEXT NOT NULL, -- empty for the controller itself
103 account_id TEXT NOT NULL,
104 task_id TEXT NOT NULL,
105 attempt_id TEXT NOT NULL,
106 action TEXT NOT NULL CHECK (action <> ''),
107 reason TEXT NOT NULL,
108 at_t INTEGER NOT NULL
109);
110
111-- The last controller-time checkpoint: one row.
112CREATE TABLE clock (
113 id INTEGER PRIMARY KEY CHECK (id = 1),
114 t_ns INTEGER NOT NULL CHECK (t_ns >= 0),
115 wall_unix_ns INTEGER NOT NULL
116);
117
118-- The provider namespace (for AWS, account and region) the VM references in
119-- this database belong to: one row, written by the first controller and
120-- never changed. A controller set up for another namespace refuses to start.
121CREATE TABLE provider_binding (
122 id INTEGER PRIMARY KEY CHECK (id = 1),
123 namespace TEXT NOT NULL CHECK (namespace <> '')
124);
125
126CREATE TRIGGER provider_binding_fixed
127BEFORE UPDATE ON provider_binding
128BEGIN
129 SELECT RAISE(ABORT, 'provider binding is fixed');
130END;
131
132-- Alerts raised where no Alerter exists yet (Open), kept until delivered.
133-- Delivery is at least once; the id is the alert's stable event ID.
134CREATE TABLE alert_outbox (
135 id INTEGER PRIMARY KEY AUTOINCREMENT,
136 kind TEXT NOT NULL,
137 detail TEXT NOT NULL,
138 at_t INTEGER NOT NULL,
139 delivered INTEGER NOT NULL DEFAULT 0 CHECK (delivered IN (0, 1))
140);
141