#include <time.h>
#include <uuid/uuid.h>
+#include <list>
+#include <set>
#include <string>
#include <iostream>
#include "tarstore.h"
+using std::list;
+using std::set;
using std::string;
+list<string> TarSegmentStore::norefs;
+
Tarfile::Tarfile(const string &path, const string &segment)
: size(0),
segment_name(segment)
static const size_t SEGMENT_SIZE = 4 * 1024 * 1024;
string TarSegmentStore::write_object(const char *data, size_t len, const
- std::string &group)
+ std::string &group,
+ const std::list<std::string> &refs)
{
struct segment_info *segment;
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<string>::const_iterator i = refs.begin(); i != refs.end(); ++i) {
+ segment->refs.insert(*i);
+ }
+
// 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)
fprintf(stderr, "Closing segment group %s (%s)\n",
group.c_str(), segment->name.c_str());
+ string reflist;
+ for (set<string>::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));
delete segment;
}
+
+string TarSegmentStore::object_reference_to_segment(const string &object)
+{
+ return object;
+}
#include <stdint.h>
#include <libtar.h>
+#include <list>
+#include <set>
#include <string>
#include <iostream>
#include <sstream>
// Return an estimate of the size of the file.
size_t size_estimate() { return size; }
-private:
void internal_write_object(const std::string &path,
const char *data, size_t len);
+private:
size_t size;
std::string segment_name;
std::ostringstream checksums;
// used to control object placement; objects with different group
// parameters are kept in separate segments.
std::string write_object(const char *data, size_t len,
- const std::string &group = "");
+ const std::string &group = "",
+ const std::list<std::string> &refs = norefs);
// Ensure all segments have been fully written.
void sync();
private:
struct segment_info {
Tarfile *file;
- std::string name; // UUID
- int count; // Objects written to this segment
+ std::string name; // UUID
+ std::set<std::string> refs; // Other segments this one refers to
+ int count; // Objects written to this segment
};
std::string path;
std::map<std::string, struct segment_info *> segments;
+ // An empty list which can be used as an argument to write_object to
+ // indicate that this object depends on no others.
+ static std::list<std::string> norefs;
+
// Ensure that all segments in the given group have been fully written.
void close_segment(const std::string &group);
+
+ // Parse an object reference string and return just the segment name
+ // portion.
+ std::string object_reference_to_segment(const std::string &object);
};
#endif // _LBS_TARSTORE_H