Place expired and repacked objects into segments based on database.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 23 Aug 2007 18:23:28 +0000 (11:23 -0700)
committerMichael Vrable <mvrable@turin.ucsd.edu>
Thu, 23 Aug 2007 18:23:28 +0000 (11:23 -0700)
The local database can store an integer with each expired object that can
be used to group objects together based on age or other factors.  Update
the lbs snapshot utility to place objects into segments based on this
value.

localdb.cc
localdb.h
scandir.cc

index e946d18..251148b 100644 (file)
@@ -223,14 +223,15 @@ ObjectReference LocalDb::FindObject(const string &checksum, int64_t size)
     return ref;
 }
 
-bool LocalDb::IsOldObject(const string &checksum, int64_t size, double *age)
+bool LocalDb::IsOldObject(const string &checksum, int64_t size, double *age,
+                          int *group)
 {
     int rc;
     sqlite3_stmt *stmt;
     bool found = false;
 
-    stmt = Prepare("select segmentid, object, timestamp from block_index "
-                   "where checksum = ? and size = ?");
+    stmt = Prepare("select segmentid, object, timestamp, expired "
+                   "from block_index where checksum = ? and size = ?");
     sqlite3_bind_text(stmt, 1, checksum.c_str(), checksum.size(),
                       SQLITE_TRANSIENT);
     sqlite3_bind_int64(stmt, 2, size);
@@ -241,6 +242,7 @@ bool LocalDb::IsOldObject(const string &checksum, int64_t size, double *age)
     } else if (rc == SQLITE_ROW) {
         found = true;
         *age = sqlite3_column_double(stmt, 2);
+        *group = sqlite3_column_int(stmt, 3);
     } else {
         fprintf(stderr, "Could not execute SELECT statement!\n");
         ReportError(rc);
index 6d28cd8..bef9286 100644 (file)
--- a/localdb.h
+++ b/localdb.h
@@ -27,7 +27,8 @@ public:
     void StoreObject(const ObjectReference& ref,
                      const std::string &checksum, int64_t size, double age);
     ObjectReference FindObject(const std::string &checksum, int64_t size);
-    bool IsOldObject(const std::string &checksum, int64_t size, double *age);
+    bool IsOldObject(const std::string &checksum, int64_t size, double *age,
+                     int *group);
     bool IsAvailable(const ObjectReference &ref);
     void UseObject(const ObjectReference& ref);
 
index 588a907..e4fe21f 100644 (file)
@@ -200,6 +200,7 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
             // Store a copy of the object if one does not yet exist
             if (ref.get_segment().size() == 0) {
                 LbsObject *o = new LbsObject;
+                int object_group;
 
                 /* We might still have seen this checksum before, if the object
                  * was stored at some time in the past, but we have decided to
@@ -212,8 +213,15 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
                  * Additionally, keep track of the age of the data by looking
                  * up the age of the block which was expired and using that
                  * instead of the current time. */
-                if (db->IsOldObject(block_csum, bytes, &block_age)) {
-                    o->set_group("compacted");
+                if (db->IsOldObject(block_csum, bytes,
+                                    &block_age, &object_group)) {
+                    if (object_group == 0) {
+                        o->set_group("data");
+                    } else {
+                        char group[32];
+                        sprintf(group, "compacted-%d", object_group);
+                        o->set_group(group);
+                    }
                     if (status == NULL)
                         status = "partial";
                 } else {