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,
22 -- Index of all blocks which have been stored in a snapshot, by checksum.
23 create table block_index (
24 blockid integer primary key,
25 segmentid integer not null,
32 create index block_content_index on block_index(checksum);
33 create unique index block_name_index on block_index(segmentid, object);
35 -- Index tracking which blocks are used by which snapshots.
36 create table snapshot_contents (
40 create unique index snapshot_contents_unique
41 on snapshot_contents(blockid, snapshotid);
43 -- Summary statistics for each segment.
44 create view segment_info as select * from
45 (select segmentid, max(timestamp) as mtime,
46 sum(size) as size, count(*) as objects
47 from block_index join segments using (segmentid) group by segmentid)
49 (select segmentid, sum(size) as used, count(*) as objects_used
50 from block_index where blockid in
51 (select blockid from snapshot_contents) group by segmentid);
53 -- Ranking of segments to be cleaned, using a benefit function of
54 -- (fraction free space)*(age of youngest object).
55 create view cleaning_order as select *, (1-u)*age/(u+0.1) as benefit from
57 cast(used as real) / size as u, julianday('now') - mtime as age