Add an inode map data structure to track the location of inodes in logs.
[bluesky.git] / bluesky / log.c
index 5fd6e28..1fe6176 100644 (file)
 // no absolute guarantees on the size of a log segment.
 #define LOG_SEGMENT_SIZE (1 << 22)
 
-// Target amount of disk space to use for the journal and cache files, in
-// kilobytes.
-#define DISK_CACHE_SIZE_TARGET (64 * 1024)
-
 #define HEADER_MAGIC 0x676f4c0a
 #define FOOTER_MAGIC 0x2e435243
 
@@ -520,10 +516,24 @@ void bluesky_cachefile_gc(BlueSkyFS *fs)
                 g_print(" (fetching)");
             g_print("\n");
 
-            if (g_atomic_int_get(&fs->log->disk_used) > DISK_CACHE_SIZE_TARGET
+            gboolean deletion_candidate = FALSE;
+            if (g_atomic_int_get(&fs->log->disk_used)
+                    > bluesky_options.cache_size
                 && g_atomic_int_get(&cachefile->refcount) == 0
                 && g_atomic_int_get(&cachefile->mapcount) == 0)
             {
+                deletion_candidate = TRUE;
+            }
+
+            /* Don't allow journal files to be reclaimed until all data is
+             * known to be durably stored in the cloud. */
+            if (cachefile->type == CLOUDLOG_JOURNAL
+                && cachefile->log_seq >= fs->log->journal_watermark)
+            {
+                deletion_candidate = FALSE;
+            }
+
+            if (deletion_candidate) {
                 g_print("   ...deleting\n");
                 if (unlinkat(fs->log->dirfd, cachefile->filename, 0) < 0) {
                     fprintf(stderr, "Unable to unlink journal %s: %m\n",