From: Michael Vrable Date: Wed, 12 Dec 2007 01:49:44 +0000 (-0800) Subject: Add "intent" field to a snapshot. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=cc2d3611ed50f5965a9138ffaf3262417993c4f8;p=cumulus.git Add "intent" field to a snapshot. This field is intended to indicate how long the backup might be kept or what backup schedule the given snapshot is part of--for example 1 for a daily backup, 7 for a weekly backup. This might be used when performing segment cleaning or deleting old snapshots, but for now the information is just stored in the local database. --- diff --git a/contrib/upgrade0.6-localdb.sql b/contrib/upgrade0.6-localdb.sql index dbf7789..d1449ac 100644 --- a/contrib/upgrade0.6-localdb.sql +++ b/contrib/upgrade0.6-localdb.sql @@ -7,7 +7,8 @@ -- Database schema changes: the size and mtime columns were added to the -- segments table, and the segments_used table was added. Rather than upgrade -- the segments table in-place, we create a new table and then rename it over --- the old segments table. +-- the old segments table. The intent column was also added to the snapshots +-- table. create table segments_new ( segmentid integer primary key, segment text unique not null, @@ -23,6 +24,12 @@ create table segments_used ( utilization real ); +alter table snapshots add column intent real; + +-- Initialize the intent column; set all old snapshots to have intent 1 +-- (intended to be a daily snapshot). +update snapshots set intent = 1; + -- Compute the size of each of the segments, if possible, based on our -- knowledge of the objects stored in them. insert into segments_new diff --git a/localdb.cc b/localdb.cc index 1509b61..004391b 100644 --- a/localdb.cc +++ b/localdb.cc @@ -46,7 +46,7 @@ void LocalDb::ReportError(int rc) } void LocalDb::Open(const char *path, const char *snapshot_name, - const char *snapshot_scheme) + const char *snapshot_scheme, double intent) { int rc; @@ -69,8 +69,8 @@ void LocalDb::Open(const char *path, const char *snapshot_name, /* Insert this snapshot into the database, and determine the integer key * which will be used to identify it. */ sqlite3_stmt *stmt = Prepare("insert into " - "snapshots(name, scheme, timestamp) " - "values (?, ?, julianday('now'))"); + "snapshots(name, scheme, timestamp, intent) " + "values (?, ?, julianday('now'), ?)"); sqlite3_bind_text(stmt, 1, snapshot_name, strlen(snapshot_name), SQLITE_TRANSIENT); if (snapshot_scheme == NULL) @@ -78,6 +78,7 @@ void LocalDb::Open(const char *path, const char *snapshot_name, else sqlite3_bind_text(stmt, 2, snapshot_scheme, strlen(snapshot_scheme), SQLITE_TRANSIENT); + sqlite3_bind_double(stmt, 3, intent); rc = sqlite3_step(stmt); if (rc != SQLITE_DONE) { diff --git a/localdb.h b/localdb.h index bef9286..69fb330 100644 --- a/localdb.h +++ b/localdb.h @@ -22,7 +22,7 @@ class LocalDb { public: void Open(const char *path, const char *snapshot_name, - const char *snapshot_scheme); + const char *snapshot_scheme, double intent); void Close(); void StoreObject(const ObjectReference& ref, const std::string &checksum, int64_t size, double age); diff --git a/scandir.cc b/scandir.cc index cf66ea6..f653f43 100644 --- a/scandir.cc +++ b/scandir.cc @@ -57,6 +57,11 @@ LocalDb *db; /* Keep track of all segments which are needed to reconstruct the snapshot. */ std::set segment_list; +/* Snapshot intent: 1=daily, 7=weekly, etc. This is not used directly, but is + * stored in the local database and can help guide segment cleaning and + * snapshot expiration policies. */ +double snapshot_intent = 1.0; + /* Selection of files to include/exclude in the snapshot. */ std::list includes; // Paths in which files should be saved std::list excludes; // Paths which will not be saved @@ -557,7 +562,9 @@ void usage(const char *program) " (defaults to \".bz2\")\n" " --signature-filter=COMMAND\n" " program though which to filter descriptor\n" - " --scheme=NAME optional name for this snapshot\n", + " --scheme=NAME optional name for this snapshot\n" + " --intent=FLOAT intended backup type: 1=daily, 7=weekly, ...\n" + " (defaults to \"1\")\n", lbs_version, program ); } @@ -578,6 +585,7 @@ int main(int argc, char *argv[]) {"dest", 1, 0, 0}, // 4 {"scheme", 1, 0, 0}, // 5 {"signature-filter", 1, 0, 0}, // 6 + {"intent", 1, 0, 0}, // 7 {NULL, 0, 0, 0}, }; @@ -613,6 +621,11 @@ int main(int argc, char *argv[]) case 6: // --signature-filter signature_filter = optarg; break; + case 7: // --intent + snapshot_intent = atof(optarg); + if (snapshot_intent <= 0) + snapshot_intent = 1; + break; default: fprintf(stderr, "Unhandled long option!\n"); return 1; @@ -683,7 +696,8 @@ int main(int argc, char *argv[]) string database_path = localdb_dir + "/localdb.sqlite"; db = new LocalDb; db->Open(database_path.c_str(), desc_buf, - backup_scheme.size() ? backup_scheme.c_str() : NULL); + backup_scheme.size() ? backup_scheme.c_str() : NULL, + snapshot_intent); tss = new TarSegmentStore(backup_dest, db); diff --git a/schema.sql b/schema.sql index e0f16a6..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.