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,
14 -- List of segments which have been created.
15 create table segments (
16 segmentid integer primary key,
17 segment text unique not null
20 -- Index of all blocks which have been stored in a snapshot, by checksum.
21 create table block_index (
22 blockid integer primary key,
23 segmentid integer not null,
30 create index block_content_index on block_index(checksum);
31 create unique index block_name_index on block_index(segmentid, object);
33 -- Index tracking which blocks are used by which snapshots.
34 create table snapshot_contents (
38 create unique index snapshot_contents_unique
39 on snapshot_contents(blockid, snapshotid);
41 -- Summary statistics for each segment.
42 create view segment_info as select * from
43 (select segmentid, max(timestamp) as mtime,
44 sum(size) as size, count(*) as objects
45 from block_index natural join segments group by segmentid)
47 (select segmentid, sum(size) as used, count(*) as objects_used
48 from block_index where blockid in
49 (select blockid from snapshot_contents) group by segmentid);
51 -- Ranking of segments to be cleaned, using a benefit function of
52 -- (fraction free space)*(age of youngest object).
53 create view cleaning_order as select *, (1-u)*age/(u+0.1) as benefit from
55 cast(used as real) / size as u, julianday('now') - mtime as age