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,
15 -- List of segments which have been created.
16 create table segments (
17 segmentid integer primary key,
18 segment text unique not null,
23 expire_time integer -- snapshotid of latest snapshot when expired
26 -- Index of all blocks which have been stored, by checksum.
27 create table block_index (
28 blockid integer primary key,
29 segmentid integer not null,
36 create index block_content_index on block_index(checksum);
37 create unique index block_name_index on block_index(segmentid, object);
39 -- Checksums for the decomposition of blocks into even smaller chunks
40 -- (variable-sized, but generally ~4 kB, and maximum 64 kB). Chunk boundaries
41 -- are determined based on the contents using Rabin fingerprints. These
42 -- checksums can be used for computing sub-file incrementals.
44 -- Each block stored in block_index may have an entry in the
45 -- subblock_signatures table. The signatures field is a binary blob consisting
46 -- of a packed sequence of (chunk length [16-bit unsigned, big-endian],
47 -- checksum [20 bytes if SHA-1]) tuples that should cover the entire block.
49 -- algorithm specifies the method used for computing break points as well as
50 -- the hash function used, so that signatures can be discarded if the algorithm
51 -- changes. The current algorithm used is 'lbfs-4096/sha1', which specifies a
52 -- target 4 kB block size with parameters set to match LBFS, and SHA-1 as the
54 create table subblock_signatures (
55 blockid integer primary key,
56 algorithm text not null,
57 signatures blob not null
60 -- Summary of segment utilization for each snapshots.
61 create table segments_used (
62 snapshotid integer not null,
63 segmentid integer not null,
66 create unique index segments_used_index
67 on segments_used(snapshotid, segmentid);
69 -- Overall estimate of segment utilization, for all snapshots combined.
70 create view segment_info as
71 select segmentid, mtime, size, expire_time,
72 cast(size * utilization as integer) as used, utilization
74 (select segmentid, max(utilization) as utilization
75 from segments_used group by segmentid)