Drop a verbose debugging message.
[bluesky.git] / bluesky / log.c
index 88b95df..ad1dac1 100644 (file)
@@ -62,6 +62,16 @@ static void log_commit(BlueSkyLog *log)
         return;
 
     fdatasync(log->fd);
+
+    /* Update disk-space usage statistics for the journal file. */
+    g_atomic_int_add(&log->disk_used, -log->current_log->disk_used);
+    struct stat statbuf;
+    if (fstat(log->fd, &statbuf) >= 0) {
+        /* Convert from 512-byte blocks to 1-kB units */
+        log->current_log->disk_used = (statbuf.st_blocks + 1) / 2;
+    }
+    g_atomic_int_add(&log->disk_used, log->current_log->disk_used);
+
     while (log->committed != NULL) {
         BlueSkyCloudLog *item = (BlueSkyCloudLog *)log->committed->data;
         g_mutex_lock(item->lock);
@@ -514,6 +524,16 @@ static void cloudlog_partial_fetch_complete(BlueSkyStoreAsync *async,
         cloudlog_partial_fetch_start(cachefile, async->start, async->len);
     }
 
+    /* Update disk-space usage statistics, since the writes above may have
+     * consumed more space. */
+    g_atomic_int_add(&cachefile->log->disk_used, -cachefile->disk_used);
+    struct stat statbuf;
+    if (fstatat(cachefile->log->dirfd, cachefile->filename, &statbuf, 0) >= 0) {
+        /* Convert from 512-byte blocks to 1-kB units */
+        cachefile->disk_used = (statbuf.st_blocks + 1) / 2;
+    }
+    g_atomic_int_add(&cachefile->log->disk_used, cachefile->disk_used);
+
     bluesky_cachefile_unref(cachefile);
     g_cond_broadcast(cachefile->cond);
     g_mutex_unlock(cachefile->lock);
@@ -581,26 +601,6 @@ BlueSkyRCStr *bluesky_log_map_object(BlueSkyCloudLog *item, gboolean map_data)
         file_size = item->location.size;
     }
 
-    if (map->addr == NULL) {
-        int fd = openat(log->dirfd, map->filename, O_RDONLY);
-
-        if (fd < 0) {
-            fprintf(stderr, "Error opening logfile %s: %m\n", map->filename);
-            goto exit2;
-        }
-
-        off_t length = lseek(fd, 0, SEEK_END);
-        map->addr = (const char *)mmap(NULL, length, PROT_READ, MAP_SHARED,
-                                       fd, 0);
-        g_atomic_int_add(&log->disk_used, -(map->len / 1024));
-        map->len = length;
-        g_atomic_int_add(&log->disk_used, map->len / 1024);
-
-        g_atomic_int_inc(&map->refcount);
-
-        close(fd);
-    }
-
     /* Log segments fetched from the cloud might only be partially-fetched.
      * Check whether the object we are interested in is available. */
     if (location == CLOUDLOG_CLOUD) {
@@ -627,6 +627,24 @@ BlueSkyRCStr *bluesky_log_map_object(BlueSkyCloudLog *item, gboolean map_data)
         }
     }
 
+    if (map->addr == NULL) {
+        int fd = openat(log->dirfd, map->filename, O_RDONLY);
+
+        if (fd < 0) {
+            fprintf(stderr, "Error opening logfile %s: %m\n", map->filename);
+            goto exit2;
+        }
+
+        off_t length = lseek(fd, 0, SEEK_END);
+        map->addr = (const char *)mmap(NULL, length, PROT_READ, MAP_SHARED,
+                                       fd, 0);
+        map->len = length;
+
+        g_atomic_int_inc(&map->refcount);
+
+        close(fd);
+    }
+
     if (map_data) {
         if (location == CLOUDLOG_JOURNAL)
             file_offset += sizeof(struct log_header);
@@ -638,8 +656,6 @@ BlueSkyRCStr *bluesky_log_map_object(BlueSkyCloudLog *item, gboolean map_data)
     str = bluesky_string_new_from_mmap(map, file_offset, file_size);
     map->atime = bluesky_get_current_time();
 
-    g_print("Returning item at offset 0x%zx.\n", file_offset);
-
 exit2:
     bluesky_cachefile_unref(map);
     g_mutex_unlock(map->lock);