In-progress work to implement inode map loading at server start.
[bluesky.git] / bluesky / cloudlog.c
index cc186a5..c6c2735 100644 (file)
@@ -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);