Track journal files which contain dirty data and which can be reclaimed.
[bluesky.git] / bluesky / bluesky-private.h
index 73f38e1..c066fd3 100644 (file)
@@ -192,6 +192,13 @@ struct _BlueSkyCloudLog {
     int location_flags;
     int pending_read, pending_write;
 
+    // If the object is not yet flushed to cloud storage but is written to a
+    // journal file locally, a reference to that journal file so that we can
+    // keep the dirty_refs count updated.  When the object is deleted or
+    // becomes clean, decrement the dirty_refs counter of the journal file and
+    // set this pointer to NULL.
+    BlueSkyCacheFile *dirty_journal;
+
     // A stable identifier for the object (only changes when authenticated data
     // is written out, but stays the same when the in-cloud cleaner relocates
     // the object).
@@ -248,12 +255,16 @@ uint32_t crc32c(uint32_t crc, const char *buf, unsigned int length);
 uint32_t crc32c_finalize(uint32_t crc);
 
 struct _BlueSkyLog {
+    BlueSkyFS *fs;
     char *log_directory;
     GAsyncQueue *queue;
     int fd, dirfd;
     int seq_num;
     GSList *committed;
 
+    /* The currently-open log file. */
+    BlueSkyCacheFile *current_log;
+
     /* Cache of log segments which have been memory-mapped. */
     GMutex *mmap_lock;
     GHashTable *mmap_cache;
@@ -279,8 +290,13 @@ struct _BlueSkyCacheFile {
     size_t len;
     BlueSkyFS *fs;
     BlueSkyLog *log;
-    gboolean fetching, ready;
+    gboolean fetching, ready;   // Cloud data: downloading or ready for use
     int64_t atime;              // Access time, for cache management
+
+    /* Journal: Count of objects which are not yet committed to cloud storage
+     * but need to be; a non-zero value prevents the journal file from being
+     * deleted. */
+    gint dirty_refs;
 };
 
 BlueSkyLog *bluesky_log_new(const char *log_directory);
@@ -289,7 +305,10 @@ void bluesky_log_finish_all(GList *log_items);
 BlueSkyRCStr *bluesky_log_map_object(BlueSkyFS *fs, int log_dir, int log_seq,
                                      int log_offset, int log_size);
 void bluesky_mmap_unref(BlueSkyCacheFile *mmap);
+void bluesky_cachefile_unref(BlueSkyCacheFile *cachefile);
 
+BlueSkyCacheFile *bluesky_cachefile_lookup(BlueSkyFS *fs,
+                                           int clouddir, int log_seq);
 void bluesky_cachefile_gc(BlueSkyFS *fs);
 
 #ifdef __cplusplus