From a855c59ca566ee7a55fc3dda56ab70943a85ef32 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Thu, 23 Aug 2007 11:23:28 -0700 Subject: [PATCH] Place expired and repacked objects into segments based on database. 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 | 8 +++++--- localdb.h | 3 ++- scandir.cc | 12 ++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/localdb.cc b/localdb.cc index e946d18..251148b 100644 --- a/localdb.cc +++ b/localdb.cc @@ -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); diff --git a/localdb.h b/localdb.h index 6d28cd8..bef9286 100644 --- 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); diff --git a/scandir.cc b/scandir.cc index 588a907..e4fe21f 100644 --- a/scandir.cc +++ b/scandir.cc @@ -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 { -- 2.20.1