struct uuid segment_uuid;
int object_id;
OutputStream *index_data = index_segment->new_object(&segment_uuid,
- &object_id);
+ &object_id,
+ "DREF");
SHA1Checksum hash;
while (true) {
hash.process(block_buf, bytes);
OutputStream *block = data_segment->new_object(&block_segment_uuid,
- &block_object_id);
+ &block_object_id,
+ "DATA");
block->write(block_buf, bytes);
index_data->write_uuid(block_segment_uuid);
index_data->write_u32(block_object_id);
segment_store = new SegmentStore(".");
SegmentWriter *sw = segment_store->new_segment();
- info_dump = sw->new_object(NULL);
+ info_dump = sw->new_object(NULL, "ROOT");
index_segment = new SegmentPartitioner(segment_store);
data_segment = new SegmentPartitioner(segment_store);
for (object_table::const_iterator i = objects.begin();
i != objects.end(); ++i) {
- out->write_s64(i->first);
- out->write_s64(i->second);
+ out->write_s64(i->offset);
+ out->write_s64(i->size);
+ out->write(i->type, sizeof(i->type));
}
static const char signature2[] = "LBSEND";
delete raw_out;
}
-OutputStream *SegmentWriter::new_object(int *id)
+OutputStream *SegmentWriter::new_object(int *id, const char *type)
{
if (object_stream)
finish_object();
- object_start_offset = out->get_pos();
- object_stream = new WrapperOutputStream(*out);
-
- if (id != NULL) {
+ if (id != NULL)
*id = objects.size();
- }
+ struct index_info info;
+ info.offset = out->get_pos();
+ info.size = -1; // Will be filled in when object is finished
+ strncpy(info.type, type, sizeof(info.type));
+ objects.push_back(info);
+
+ object_stream = new WrapperOutputStream(*out);
return object_stream;
}
{
assert(object_stream != NULL);
- // store (start, length) information for locating this object
- objects.push_back(std::make_pair(object_start_offset,
- object_stream->get_pos()));
+ // Fill in object size, which could not be stored at start
+ objects.back().size = object_stream->get_pos();
delete object_stream;
object_stream = NULL;
delete segment;
}
-OutputStream *SegmentPartitioner::new_object(struct uuid *uuid, int *id)
+OutputStream *SegmentPartitioner::new_object(struct uuid *uuid, int *id,
+ const char *type)
{
if (segment != NULL && segment->get_size() > target_size) {
delete segment;
if (uuid != NULL)
*uuid = segment->get_uuid();
- return segment->new_object(id);
+ return segment->new_object(id, type);
}
struct uuid get_uuid() const { return id; }
// Start writing out a new object to this segment.
- OutputStream *new_object(int *id);
+ OutputStream *new_object(int *id, const char *type);
void finish_object();
// Determine size of segment data written out so far.
static std::string format_uuid(const struct uuid u);
private:
- typedef std::vector<std::pair<int64_t, int64_t> > object_table;
+ struct index_info {
+ int64_t offset; // File offset at which object starts
+ int64_t size; // Size of object in bytes
+ char type[4]; // Object type code
+ };
+
+ typedef std::vector<struct index_info> object_table;
ChecksumOutputStream *out; // Output stream with checksumming enabled
OutputStream *raw_out; // Raw output stream, without checksumming
struct uuid id;
- int64_t object_start_offset;
OutputStream *object_stream;
object_table objects;
explicit SegmentPartitioner(SegmentStore *s);
~SegmentPartitioner();
- OutputStream *new_object(struct uuid *uuid, int *id);
+ OutputStream *new_object(struct uuid *uuid, int *id, const char *type);
private:
size_t target_size;