Preliminary support for dropping cached file data from memory.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Tue, 3 Aug 2010 03:48:21 +0000 (20:48 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Tue, 3 Aug 2010 03:48:21 +0000 (20:48 -0700)
bluesky/bluesky-private.h
bluesky/cloudlog.c
bluesky/file.c
bluesky/init.c

index 60c10c1..ad8dea1 100644 (file)
@@ -230,6 +230,7 @@ void bluesky_cloudlog_unref(BlueSkyCloudLog *log);
 void bluesky_cloudlog_sync(BlueSkyCloudLog *log);
 void bluesky_cloudlog_insert(BlueSkyCloudLog *log);
 void bluesky_cloudlog_write_log(BlueSkyFS *fs);
+void bluesky_cloudlog_fetch(BlueSkyCloudLog *log);
 
 /* Logging infrastructure for ensuring operations are persistently recorded to
  * disk. */
index d7cea63..60f4594 100644 (file)
@@ -258,4 +258,6 @@ void bluesky_cloudlog_fetch(BlueSkyCloudLog *log)
 
     log->data = bluesky_log_map_object(log->fs->log, log->log_seq,
                                        log->log_offset, log->log_size);
+
+    g_cond_broadcast(log->cond);
 }
index 4824dd8..cb9d5f0 100644 (file)
@@ -219,52 +219,18 @@ void bluesky_file_read(BlueSkyInode *inode, uint64_t offset,
     }
 }
 
-#if 0
-/* Read the given block from cloud-backed storage if the data is not already
- * cached. */
-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);
-
-    if (block->data == NULL) {
-        g_warning("Failed to fetch data block from store!\n");
-        block->data = bluesky_string_new(g_malloc0(BLUESKY_BLOCK_SIZE),
-                                         BLUESKY_BLOCK_SIZE);
-    }
-
-    block->type = BLUESKY_BLOCK_CACHED;
-}
-#endif
-
 void bluesky_block_fetch(BlueSkyInode *inode, BlueSkyBlock *block,
                          BlueSkyStoreAsync *barrier)
 {
-    // TODO: Implement this
-
-#if 0
-    BlueSkyFS *fs = inode->fs;
-
     if (block->type != BLUESKY_BLOCK_REF)
         return;
 
-    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);
-
-    if (barrier != NULL)
-        bluesky_store_add_barrier(barrier, async);
-    else
-        bluesky_store_async_wait(async);
-
-    bluesky_store_async_unref(async);
-    g_atomic_int_add(&fs->cache_total, 1);
-#endif
+    g_mutex_lock(block->cloudref->lock);
+    bluesky_cloudlog_fetch(block->cloudref);
+    block->data = block->cloudref->data;
+    bluesky_string_ref(block->data);
+    g_mutex_unlock(block->cloudref->lock);
+    block->type = BLUESKY_BLOCK_CACHED;
 }
 
 /* Write the given block to cloud-backed storage and mark it clean. */
@@ -311,7 +277,6 @@ void bluesky_file_flush(BlueSkyInode *inode, GList **log_items)
 /* Drop clean data blocks for a file from cache. */
 void bluesky_file_drop_cached(BlueSkyInode *inode)
 {
-#if 0
     g_return_if_fail(inode->type == BLUESKY_REGULAR);
 
     for (int i = 0; i < inode->blocks->len; i++) {
@@ -329,7 +294,10 @@ void bluesky_file_drop_cached(BlueSkyInode *inode)
             b->data = NULL;
             b->type = BLUESKY_BLOCK_REF;
             g_atomic_int_add(&inode->fs->cache_total, -1);
+            g_mutex_lock(b->cloudref->lock);
+            bluesky_string_unref(b->cloudref->data);
+            b->cloudref->data = NULL;
+            g_mutex_unlock(b->cloudref->lock);
         }
     }
-#endif
 }
index 1db4283..3abc473 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "bluesky-private.h"
 
-int bluesky_verbose = 0;
+int bluesky_verbose = 1;
 
 BlueSkyOptions bluesky_options;