Fix for journal committing.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Mon, 27 Sep 2010 20:28:57 +0000 (13:28 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Mon, 27 Sep 2010 20:28:57 +0000 (13:28 -0700)
Sometimes we could previously, under load, report that journal items were
committed when they were not.  Try to track the uncommitted state more
carefully now.

bluesky/bluesky-private.h
bluesky/log.c

index 61238eb..dd55729 100644 (file)
@@ -229,6 +229,7 @@ struct cloudlog_header {
 #define CLOUDLOG_JOURNAL    0x01
 #define CLOUDLOG_CLOUD      0x02
 #define CLOUDLOG_CACHE      0x04
+#define CLOUDLOG_UNCOMMITTED 0x10
 struct _BlueSkyCloudLog {
     gint refcount;
     GMutex *lock;
index b5c643f..87639db 100644 (file)
@@ -67,7 +67,8 @@ static void log_commit(BlueSkyLog *log)
         g_mutex_lock(item->lock);
         bluesky_cloudlog_stats_update(item, -1);
         item->pending_write &= ~CLOUDLOG_JOURNAL;
-        item->location_flags |= CLOUDLOG_JOURNAL;
+        item->location_flags
+            = (item->location_flags & ~CLOUDLOG_UNCOMMITTED) | CLOUDLOG_JOURNAL;
         bluesky_cloudlog_stats_update(item, 1);
         g_cond_signal(item->cond);
         g_mutex_unlock(item->lock);
@@ -279,9 +280,12 @@ BlueSkyLog *bluesky_log_new(const char *log_directory)
 
 void bluesky_log_item_submit(BlueSkyCloudLog *item, BlueSkyLog *log)
 {
-    bluesky_cloudlog_ref(item);
-    g_atomic_int_add(&item->data_lock_count, 1);
-    g_async_queue_push(log->queue, item);
+    if (!(item->location_flags & CLOUDLOG_JOURNAL)) {
+        bluesky_cloudlog_ref(item);
+        item->location_flags |= CLOUDLOG_UNCOMMITTED;
+        g_atomic_int_add(&item->data_lock_count, 1);
+        g_async_queue_push(log->queue, item);
+    }
 }
 
 void bluesky_log_finish_all(GList *log_items)
@@ -290,7 +294,7 @@ void bluesky_log_finish_all(GList *log_items)
         BlueSkyCloudLog *item = (BlueSkyCloudLog *)log_items->data;
 
         g_mutex_lock(item->lock);
-        while ((item->pending_write & CLOUDLOG_JOURNAL))
+        while ((item->location_flags & CLOUDLOG_UNCOMMITTED))
             g_cond_wait(item->cond, item->lock);
         g_mutex_unlock(item->lock);
         bluesky_cloudlog_unref(item);