X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=schema.sql;h=3cf175b3d12dfb28f3e7cc75e5c92113ae1039ad;hb=cc2d3611ed50f5965a9138ffaf3262417993c4f8;hp=a37b5015a57f8e2e63a6ba0a866eabf5d8f0fc8d;hpb=a4cf5f4d8df46fa00992a210d587cd824cedcb08;p=cumulus.git diff --git a/schema.sql b/schema.sql index a37b501..3cf175b 100644 --- a/schema.sql +++ b/schema.sql @@ -8,7 +8,8 @@ create table snapshots ( snapshotid integer primary key, name text not null, scheme text, - timestamp real + timestamp real, + intent real ); -- List of segments which have been created. @@ -16,10 +17,12 @@ create table segments ( segmentid integer primary key, segment text unique not null, path text, - checksum text + checksum text, + mtime real, + size integer ); --- Index of all blocks which have been stored in a snapshot, by checksum. +-- Index of all blocks which have been stored, by checksum. create table block_index ( blockid integer primary key, segmentid integer not null, @@ -32,28 +35,18 @@ create table block_index ( create index block_content_index on block_index(checksum); create unique index block_name_index on block_index(segmentid, object); --- Index tracking which blocks are used by which snapshots. -create table snapshot_contents ( - blockid integer, - snapshotid integer +-- Summary of segment utilization for each snapshots. +create table segments_used ( + snapshotid integer not null, + segmentid integer not null, + utilization real ); -create unique index snapshot_contents_unique - on snapshot_contents(blockid, snapshotid); - --- Summary statistics for each segment. -create view segment_info as select * from - (select segmentid, max(timestamp) as mtime, - sum(size) as size, count(*) as objects - from block_index natural join segments group by segmentid) -natural join - (select segmentid, sum(size) as used, count(*) as objects_used - from block_index where blockid in - (select blockid from snapshot_contents) group by segmentid); --- Ranking of segments to be cleaned, using a benefit function of --- (fraction free space)*(age of youngest object). -create view cleaning_order as select *, (1-u)*age/(u+0.1) as benefit from - (select segmentid, - cast(used as real) / size as u, julianday('now') - mtime as age - from segment_info) -where benefit > 0; +-- Overall estimate of segment utilization, for all snapshots combined. +create view segment_info as +select segmentid, mtime, size, cast(size * utilization as integer) as used, + utilization +from segments join + (select segmentid, max(utilization) as utilization + from segments_used group by segmentid) +using (segmentid);