X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=store.cc;h=70be12664a4553f4271623b95845e8bee1b08e35;hb=da87780779a2f165503d019ee0b59d10e5d31ec8;hp=804992f105f4ff9b6ab0989ce82d52be717ef1e5;hpb=51859528c5de1c90c553d1f174869005711f162a;p=cumulus.git diff --git a/store.cc b/store.cc index 804992f..70be126 100644 --- a/store.cc +++ b/store.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -21,13 +20,12 @@ #include #include "store.h" +#include "ref.h" using std::list; using std::set; using std::string; -list TarSegmentStore::norefs; - Tarfile::Tarfile(const string &path, const string &segment) : size(0), segment_name(segment) @@ -39,9 +37,6 @@ Tarfile::Tarfile(const string &path, const string &segment) Tarfile::~Tarfile() { - string checksum_list = checksums.str(); - internal_write_object(segment_name + "/checksums", - checksum_list.data(), checksum_list.size()); tar_append_eof(t); if (tar_close(t) != 0) @@ -55,13 +50,6 @@ void Tarfile::write_object(int id, const char *data, size_t len) string path = segment_name + "/" + buf; internal_write_object(path, data, len); - - // Compute a checksum for the data block, which will be stored at the end - // of the TAR file. - SHA1Checksum hash; - hash.process(data, len); - sprintf(buf, "%08x", id); - checksums << buf << " " << hash.checksum_str() << "\n"; } void Tarfile::internal_write_object(const string &path, @@ -105,9 +93,8 @@ void Tarfile::internal_write_object(const string &path, static const size_t SEGMENT_SIZE = 4 * 1024 * 1024; -string TarSegmentStore::write_object(const char *data, size_t len, const - std::string &group, - const std::list &refs) +ObjectReference TarSegmentStore::write_object(const char *data, size_t len, + const std::string &group) { struct segment_info *segment; @@ -116,11 +103,7 @@ string TarSegmentStore::write_object(const char *data, size_t len, const if (segments.find(group) == segments.end()) { segment = new segment_info; - uint8_t uuid[16]; - char uuid_buf[40]; - uuid_generate(uuid); - uuid_unparse_lower(uuid, uuid_buf); - segment->name = uuid_buf; + segment->name = generate_uuid(); string filename = path + "/" + segment->name + ".tar"; segment->file = new Tarfile(filename, segment->name); @@ -139,20 +122,14 @@ string TarSegmentStore::write_object(const char *data, size_t len, const segment->file->write_object(id, data, len); segment->count++; - string full_name = segment->name + "/" + id_buf; - - // Store any dependencies this object has on other segments, so they can be - // written when the segment is closed. - for (list::const_iterator i = refs.begin(); i != refs.end(); ++i) { - segment->refs.insert(*i); - } + ObjectReference ref(segment->name, id_buf); // If this segment meets or exceeds the size target, close it so that // future objects will go into a new segment. if (segment->file->size_estimate() >= SEGMENT_SIZE) close_segment(group); - return full_name; + return ref; } void TarSegmentStore::sync() @@ -164,16 +141,6 @@ void TarSegmentStore::sync() void TarSegmentStore::close_segment(const string &group) { struct segment_info *segment = segments[group]; - fprintf(stderr, "Closing segment group %s (%s)\n", - group.c_str(), segment->name.c_str()); - - string reflist; - for (set::iterator i = segment->refs.begin(); - i != segment->refs.end(); ++i) { - reflist += *i + "\n"; - } - segment->file->internal_write_object(segment->name + "/references", - reflist.data(), reflist.size()); delete segment->file; segments.erase(segments.find(group)); @@ -194,18 +161,20 @@ LbsObject::~LbsObject() { } -void LbsObject::add_reference(const LbsObject *o) -{ - // TODO: Implement -} - void LbsObject::write(TarSegmentStore *store) { assert(data != NULL); assert(!written); - name = store->write_object(data, data_len, group); - + ref = store->write_object(data, data_len, group); written = true; - data = NULL; +} + +void LbsObject::checksum() +{ + assert(written); + + SHA1Checksum hash; + hash.process(data, data_len); + ref.set_checksum(hash.checksum_str()); }