Rework caching of data blocks to eliminate double-caching.
[bluesky.git] / bluesky / bluesky-private.h
index fbc765c..418c1e5 100644 (file)
@@ -165,6 +165,7 @@ typedef struct {
 } BlueSkyCloudPointer;
 
 typedef enum {
+    LOGTYPE_INVALID = -1,
     LOGTYPE_UNKNOWN = 0,
     LOGTYPE_DATA = 1,
     LOGTYPE_INODE = 2,
@@ -209,8 +210,11 @@ struct _BlueSkyCloudLog {
     // Pointers to other objects
     GArray *pointers;
 
-    // Serialized data, if available in memory (otherwise NULL).
+    // Serialized data, if available in memory (otherwise NULL), and a lock
+    // count which tracks if there are users that require the data to be kept
+    // around.
     BlueSkyRCStr *data;
+    int data_lock_count;
 };
 
 /* Serialize objects into a log segment to be written to the cloud. */
@@ -230,6 +234,7 @@ void bluesky_cloudlog_unref(BlueSkyCloudLog *log);
 void bluesky_cloudlog_sync(BlueSkyCloudLog *log);
 void bluesky_cloudlog_insert(BlueSkyCloudLog *log);
 void bluesky_cloudlog_write_log(BlueSkyFS *fs);
+void bluesky_cloudlog_fetch(BlueSkyCloudLog *log);
 
 /* Logging infrastructure for ensuring operations are persistently recorded to
  * disk. */
@@ -240,13 +245,32 @@ uint32_t crc32c_finalize(uint32_t crc);
 struct _BlueSkyLog {
     char *log_directory;
     GAsyncQueue *queue;
-    int fd;
+    int fd, dirfd;
     int seq_num;
+    GSList *committed;
+
+    /* Cache of log segments which have been memory-mapped. */
+    GMutex *mmap_lock;
+    GHashTable *mmap_cache;
+};
+
+/* Reference-counted blocks of memory, used for passing data in and out of
+ * storage backends and in other places.  This may also refer to read-only
+ * mmaped data. */
+struct _BlueSkyMmap {
+    gint refcount;
+    int log_seq;
+    const char *addr;
+    size_t len;
+    BlueSkyLog *log;
 };
 
 BlueSkyLog *bluesky_log_new(const char *log_directory);
 void bluesky_log_item_submit(BlueSkyCloudLog *item, BlueSkyLog *log);
 void bluesky_log_finish_all(GList *log_items);
+BlueSkyRCStr *bluesky_log_map_object(BlueSkyLog *log, int log_seq,
+                                     int log_offset, int log_size);
+void bluesky_mmap_unref(BlueSkyMmap *mmap);
 
 #ifdef __cplusplus
 }