X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=store.cc;h=70be12664a4553f4271623b95845e8bee1b08e35;hb=6ac0cb32a08c81ddb87cd3a1373e8e64e8757534;hp=00fd26ca809cb3a98bd7a857217bfa0e03bf0324;hpb=d5afe2c08724b4b263a76f187e39861c1e6e0cf5;p=cumulus.git diff --git a/store.cc b/store.cc index 00fd26c..70be126 100644 --- a/store.cc +++ b/store.cc @@ -6,13 +6,13 @@ * is built on top of libtar, and represents segments as TAR files and objects * as files within them. */ +#include #include #include #include #include #include #include -#include #include #include @@ -20,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) @@ -38,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) @@ -54,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, @@ -104,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; @@ -115,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); @@ -138,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() @@ -163,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)); @@ -183,3 +151,30 @@ string TarSegmentStore::object_reference_to_segment(const string &object) { return object; } + +LbsObject::LbsObject() + : group(""), data(NULL), data_len(0), written(false) +{ +} + +LbsObject::~LbsObject() +{ +} + +void LbsObject::write(TarSegmentStore *store) +{ + assert(data != NULL); + assert(!written); + + ref = store->write_object(data, data_len, group); + written = true; +} + +void LbsObject::checksum() +{ + assert(written); + + SHA1Checksum hash; + hash.process(data, data_len); + ref.set_checksum(hash.checksum_str()); +}