X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=schema.sql;h=5017d9bf530461c01a040fe56973674ba3835605;hb=248b2455853ed082bf3b032fea4cb6b557a145ae;hp=d225ec1f1c0cc0be002fc31ca9a74bf8b6c1c9a2;hpb=6a181a1eb21ac5f9f4f742281b6de841dac9a3c8;p=cumulus.git diff --git a/schema.sql b/schema.sql index d225ec1..5017d9b 100644 --- a/schema.sql +++ b/schema.sql @@ -36,3 +36,21 @@ create table snapshot_contents ( ); 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 as benefit from + (select segmentid, + cast(used as real) / size as u, julianday('now') - mtime as age + from segment_info) +where benefit > 0;