- hash.process(block_buf, bytes);
-
- // Either find a copy of this block in an already-existing segment, or
- // index it so it can be re-used in the future
- SHA1Checksum block_hash;
- block_hash.process(block_buf, bytes);
- string block_csum = block_hash.checksum_str();
- ObjectReference ref = db->FindObject(block_csum, bytes);
-
- // Store a copy of the object if one does not yet exist
- if (ref.get_segment().size() == 0) {
- LbsObject *o = new LbsObject;
-
- /* We might still have seen this checksum before, if the object was
- * stored at some time in the past, but we have decided to clean
- * the segment the object was originally stored in (FindObject will
- * not return such objects). When rewriting the object contents,
- * put it in a separate group, so that old objects get grouped
- * together. The hope is that these old objects will continue to
- * be used in the future, and we obtain segments which will
- * continue to be well-utilized. */
- if (db->IsOldObject(block_csum, bytes))
- o->set_group("compacted");
- else
- o->set_group("data");
+ hash.process(block_buf, bytes);
+
+ // Either find a copy of this block in an already-existing segment,
+ // or index it so it can be re-used in the future
+ double block_age = 0.0;
+ SHA1Checksum block_hash;
+ block_hash.process(block_buf, bytes);
+ string block_csum = block_hash.checksum_str();
+ ObjectReference ref = db->FindObject(block_csum, bytes);
+
+ // Store a copy of the object if one does not yet exist
+ if (ref.get_segment().size() == 0) {
+ LbsObject *o = new LbsObject;
+
+ /* We might still have seen this checksum before, if the object
+ * was stored at some time in the past, but we have decided to
+ * clean the segment the object was originally stored in
+ * (FindObject will not return such objects). When rewriting
+ * the object contents, put it in a separate group, so that old
+ * objects get grouped together. The hope is that these old
+ * objects will continue to be used in the future, and we
+ * obtain segments which will continue to be well-utilized.
+ * 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 (status == NULL)
+ status = "partial";
+ } else {
+ o->set_group("data");
+ status = "new";
+ }
+
+ o->set_data(block_buf, bytes);
+ o->write(tss);
+ ref = o->get_ref();
+ db->StoreObject(ref, block_csum, bytes, block_age);
+ delete o;
+ }
+
+ object_list.push_back(ref.to_string());
+ segment_list.insert(ref.get_segment());
+ db->UseObject(ref);
+ size += bytes;