X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fcloudlog.c;h=9d2fe373dcbe1f75116d692e696f4904dee63b4b;hb=6955b27db8185d222adb07e57d207f7f421037e6;hp=cc186a5263d558ceef9179a5f1017a4726d2ad03;hpb=2ad1881ef34f84f3dc8ded636ada9b21e3fd906b;p=bluesky.git diff --git a/bluesky/cloudlog.c b/bluesky/cloudlog.c index cc186a5..9d2fe37 100644 --- a/bluesky/cloudlog.c +++ b/bluesky/cloudlog.c @@ -212,8 +212,37 @@ void bluesky_cloudlog_fetch(BlueSkyCloudLog *log) if (log->data != NULL) return; - int offset; + /* There are actually two cases: a full deserialization if we have not ever + * read the object before, and a partial deserialization where the metadata + * is already in memory and we just need to remap the data. If the object + * type has not yet been set, we'll need to read and parse the metadata. + * Once that is done, we can fall through the case of remapping the data + * itself. */ + if (log->type == LOGTYPE_UNKNOWN) { + BlueSkyRCStr *raw = NULL; + if ((log->location_flags | log->pending_write) & CLOUDLOG_JOURNAL) { + raw = bluesky_log_map_object(log->fs, -1, log->log_seq, + log->log_offset, log->log_size); + } + + if (raw == NULL && (log->location_flags & CLOUDLOG_CLOUD)) { + log->location_flags &= ~CLOUDLOG_JOURNAL; + raw = bluesky_log_map_object(log->fs, + log->location.directory, + log->location.sequence, + log->location.offset, + log->location.size); + } + g_assert(raw != NULL); + bluesky_deserialize_cloudlog(log, raw->data, raw->len); + bluesky_string_unref(raw); + } + + /* At this point all metadata should be available and we need only remap + * the object data. */ + + int offset; if ((log->location_flags | log->pending_write) & CLOUDLOG_JOURNAL) { bluesky_cloudlog_stats_update(log, -1); offset = log->log_offset + sizeof(struct log_header); @@ -279,6 +308,7 @@ BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log, header.size2 = GUINT32_TO_LE(data2->len); header.size3 = GUINT32_TO_LE(data3->len); header.id = log->id; + header.inum = GUINT64_TO_LE(log->inum); g_string_append_len(state->data, (const char *)&header, sizeof(header)); g_string_append_len(state->data, data1->str, data1->len); @@ -294,6 +324,8 @@ BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log, log->inum, 1); entry->id = log->id; entry->location = log->location; + entry->item = log; + bluesky_cloudlog_ref(entry->item); g_mutex_unlock(fs->lock); }