Professional Documents
Culture Documents
Ota Slides
Ota Slides
Ota Slides
System
Applications OTA Application
target.db
ota.db
state.db
Update in SQL:
a b c ota_control
'one' 1 4 0 If the target table
'three' NULL NULL 1 actually has a column
'two' 5 NULL '.x.' named “ota_control”,
you're out of luck
Overview: Application Code
int apply_ota(){
sqlite3ota *pOta;
int rc;
B-Tree:
SQLite Cache:
ZipVFS
Operating System
Write Amplification
● For a non-trivial schema:
CREATE TABLE t1(a PRIMARY KEY, b, c UNIQUE) WITHOUT ROWID;
CREATE INDEX t1b ON t1(b);
a b c ota_control
4 NULL NULL 1
target.db
Database Applications
target.db-wal
How Resumable Transactions Work
● Target database must be in “rollback mode”
● OTA writes into the *-oal file, which is like a *-
wal file but nobody else knows it's there
● Once the entire update is in the *-oal file, OTA
moves it to *-wal
● Then runs a checkpoint (incrementally – which
regular clients cannot do).
How Resumable Transactions Work
Database Database
Applications Applications
target.db target.db
target.db-oal target.db-wal
Update in SQL:
INSERT INTO t1 VALUES('x', 'y', 'z');
INSERT INTO t1(rowid, a, b, c) VALUES(13, 'a', 'b', 'c');
DELETE FROM t1 WHERE rowid = 5;
ota_rowid a b c ota_control
5 NULL NULL NULL 1
13 'a' 'b' 'c' 0
NULL 'x' 'y' 'z' 0
Details: Virtual Tables
● Virtual tables must have a “rowid” column that
works like a PRIMARY KEY (most do)
● Add the “ota_rowid” column to the data_xxx
table
● Any hidden columns (i.e. languageid columns)
are optional
Target Database Schema:
CREATE VIRTUAL TABLE x1 USING fts4(txt, languageid=lid);
OTA Database Schema:
CREATE TABLE data_x1(ota_rowid, txt, lid, ota_control);
Details: Limitations
● INSERT, UPDATE and DELETE operations only,
● INSERT may not use default values,
● UPDATE and DELETE must identify their target rows by
primary key,
● UPDATE statements may not modify primary key columns,
● No triggers are fired,
● No foreign key constraint handling is performed,
● CHECK constraints are not enforced
● Constraint handling (for UNIQUE and NOT NULL constraints) is
always “OR ROLLBACK”.
And Finally...
● It does large updates to databases:
– With b-tree writes in sorted order to avoid “write
amplfication”, and
– With support for “resumable transactions”