1 -- We maintain a local index of data blocks that have been previously stored
2 -- for constructing incremental snapshots.
4 -- The index is stored in an SQLite3 database. This is its schema.
6 -- List of snapshots which have been created.
7 create table snapshots (
8 snapshotid integer primary key,
13 -- List of segments which have been created.
14 create table segments (
15 segmentid integer primary key,
16 segment text unique not null
19 -- Index of all blocks which have been stored in a snapshot, by checksum.
20 create table block_index (
21 blockid integer primary key,
22 segmentid integer not null,
29 create index block_content_index on block_index(checksum);
30 create unique index block_name_index on block_index(segmentid, object);
32 -- Index tracking which blocks are used by which snapshots.
33 create table snapshot_contents (
37 create unique index snapshot_contents_unique
38 on snapshot_contents(blockid, snapshotid);
40 -- Summary statistics for each segment.
41 create view segment_info as select * from
42 (select segmentid, max(timestamp) as mtime,
43 sum(size) as size, count(*) as objects
44 from block_index natural join segments group by segmentid)
46 (select segmentid, sum(size) as used, count(*) as objects_used
47 from block_index where blockid in
48 (select blockid from snapshot_contents) group by segmentid);
50 -- Ranking of segments to be cleaned, using a benefit function of
51 -- (fraction free space)*(age of youngest object).
52 create view cleaning_order as select *, (1-u)*age as benefit from
54 cast(used as real) / size as u, julianday('now') - mtime as age