Track journal files which contain dirty data and which can be reclaimed.
[bluesky.git] / bluesky / cloudlog.c
index 3809b00..196eeb8 100644 (file)
@@ -158,6 +158,8 @@ void bluesky_cloudlog_unref(BlueSkyCloudLog *log)
         }
         g_array_unref(log->links);
         bluesky_string_unref(log->data);
+        if (log->dirty_journal != NULL)
+            g_atomic_int_add(&log->dirty_journal->dirty_refs, -1);
         g_free(log);
     }
 }
@@ -260,8 +262,14 @@ BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log,
     g_string_append_len(state->data, (const char *)&header, sizeof(header));
     g_string_append_len(state->data, log->data->data, log->data->len);
 
+    /* TODO: We should mark the objects as committed on the cloud until the
+     * data is flushed and acknowledged. */
     log->location_flags |= CLOUDLOG_CLOUD;
     bluesky_cloudlog_stats_update(log, 1);
+    if (log->dirty_journal != NULL) {
+        g_atomic_int_add(&log->dirty_journal->dirty_refs, -1);
+        log->dirty_journal = NULL;
+    }
     g_mutex_unlock(log->lock);
 
     if (state->data->len > CLOUDLOG_SEGMENT_SIZE)