void LocalDb::SetSegmentChecksum(const std::string &segment,
const std::string &path,
- const std::string &checksum)
+ const std::string &checksum,
+ int size)
{
int rc;
sqlite3_stmt *stmt;
- stmt = Prepare("update segments set path = ?, checksum = ?, "
- "size = (select sum(size) from block_index "
- " where segmentid = ?) "
+ stmt = Prepare("update segments set path = ?, checksum = ?, size = ? "
"where segmentid = ?");
sqlite3_bind_text(stmt, 1, path.c_str(), path.size(),
SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, checksum.c_str(), checksum.size(),
SQLITE_TRANSIENT);
- sqlite3_bind_int64(stmt, 3, SegmentToId(segment));
+ sqlite3_bind_int64(stmt, 3, size);
sqlite3_bind_int64(stmt, 4, SegmentToId(segment));
rc = sqlite3_step(stmt);
void UseObject(const ObjectReference& ref);
void SetSegmentChecksum(const std::string &segment, const std::string &path,
- const std::string &checksum);
+ const std::string &checksum, int size);
bool GetSegmentChecksum(const std::string &segment,
std::string *seg_path, std::string *seg_checksum);
private:
segment->fullname = path + "/" + segment->basename;
segment->file = new Tarfile(segment->fullname, segment->name);
segment->count = 0;
+ segment->size = 0;
segments[group] = segment;
} else {
segment->file->write_object(id, data, len);
segment->count++;
+ segment->size += len;
group_sizes[group] += len;
SHA1Checksum segment_checksum;
if (segment_checksum.process_file(segment->fullname.c_str())) {
string checksum = segment_checksum.checksum_str();
- db->SetSegmentChecksum(segment->name, segment->basename, checksum);
+ db->SetSegmentChecksum(segment->name, segment->basename, checksum,
+ segment->size);
}
}
Tarfile *file;
std::string name; // UUID
int count; // Objects written to this segment
+ int size; // Combined size of objects written
std::string basename; // Name of segment without directory
std::string fullname; // Full path to stored segment
};