Partial work on parallel data fetches from S3 for large reads.
[bluesky.git] / bluesky / file.c
index 6ba39e3..822c2c8 100644 (file)
@@ -35,7 +35,7 @@ void bluesky_block_touch(BlueSkyInode *inode, uint64_t i)
         block->data = bluesky_string_new(g_malloc0(block_len), block_len);
         break;
     case BLUESKY_BLOCK_REF:
-        bluesky_block_fetch(inode->fs, block);
+        bluesky_block_fetch(inode->fs, block, NULL);
         g_assert(block->type == BLUESKY_BLOCK_CACHED);
         /* Fall through */
     case BLUESKY_BLOCK_CACHED:
@@ -169,7 +169,7 @@ void bluesky_file_read(BlueSkyInode *inode, uint64_t offset,
             memset(buf, 0, bytes);
             break;
         case BLUESKY_BLOCK_REF:
-            bluesky_block_fetch(inode->fs, b);
+            bluesky_block_fetch(inode->fs, b, NULL);
             /* Fall through */
         case BLUESKY_BLOCK_CACHED:
         case BLUESKY_BLOCK_DIRTY:
@@ -185,16 +185,32 @@ void bluesky_file_read(BlueSkyInode *inode, uint64_t offset,
 
 /* Read the given block from cloud-backed storage if the data is not already
  * cached. */
-void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block)
+static void block_fetch_completion(BlueSkyStoreAsync *async, gpointer data)
+{
+    BlueSkyBlock *block = (BlueSkyBlock *)data;
+
+    bluesky_string_unref(block->data);
+    block->data = async->data;
+    bluesky_string_ref(block->data);
+    block->type = BLUESKY_BLOCK_CACHED;
+}
+
+void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block,
+                         BlueSkyStoreAsync *barrier)
 {
     if (block->type != BLUESKY_BLOCK_REF)
         return;
 
-    BlueSkyRCStr *string = bluesky_store_get(fs->store, block->ref);
+    BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
+    async->op = STORE_OP_GET;
+    async->key = g_strdup(block->ref);
+    bluesky_store_async_add_notifier(async, (GFunc)block_fetch_completion, block);
+    bluesky_store_async_submit(async);
 
-    bluesky_string_unref(block->data);
-    block->data = string;
-    block->type = BLUESKY_BLOCK_CACHED;
+    if (barrier != NULL)
+        bluesky_store_add_barrier(barrier, async);
+    else
+        bluesky_store_async_wait(async);
 }
 
 /* Write the given block to cloud-backed storage and mark it clean. */