g_mutex_lock(item->lock);
bluesky_cloudlog_stats_update(item, -1);
item->pending_write &= ~CLOUDLOG_JOURNAL;
- item->location_flags |= CLOUDLOG_JOURNAL;
+ item->location_flags
+ = (item->location_flags & ~CLOUDLOG_UNCOMMITTED) | CLOUDLOG_JOURNAL;
bluesky_cloudlog_stats_update(item, 1);
g_cond_signal(item->cond);
g_mutex_unlock(item->lock);
log->mmap_lock = g_mutex_new();
log->mmap_cache = g_hash_table_new(g_str_hash, g_str_equal);
+ /* Determine the highest-numbered log file, so that we can start writing
+ * out new journal entries at the next sequence number. */
+ GDir *dir = g_dir_open(log_directory, 0, NULL);
+ if (dir != NULL) {
+ const gchar *file;
+ while ((file = g_dir_read_name(dir)) != NULL) {
+ if (strncmp(file, "journal-", 8) == 0) {
+ log->seq_num = MAX(log->seq_num, atoi(&file[8]) + 1);
+ }
+ }
+ g_dir_close(dir);
+ g_print("Starting journal at sequence number %d\n", log->seq_num);
+ }
+
log->dirfd = open(log->log_directory, O_DIRECTORY);
if (log->dirfd < 0) {
fprintf(stderr, "Unable to open logging directory: %m\n");
void bluesky_log_item_submit(BlueSkyCloudLog *item, BlueSkyLog *log)
{
- bluesky_cloudlog_ref(item);
- g_atomic_int_add(&item->data_lock_count, 1);
- g_async_queue_push(log->queue, item);
+ if (!(item->location_flags & CLOUDLOG_JOURNAL)) {
+ bluesky_cloudlog_ref(item);
+ item->location_flags |= CLOUDLOG_UNCOMMITTED;
+ g_atomic_int_add(&item->data_lock_count, 1);
+ g_async_queue_push(log->queue, item);
+ }
}
void bluesky_log_finish_all(GList *log_items)
BlueSkyCloudLog *item = (BlueSkyCloudLog *)log_items->data;
g_mutex_lock(item->lock);
- while ((item->pending_write & CLOUDLOG_JOURNAL))
+ while ((item->location_flags & CLOUDLOG_UNCOMMITTED))
g_cond_wait(item->cond, item->lock);
g_mutex_unlock(item->lock);
bluesky_cloudlog_unref(item);
BlueSkyCloudLog *marker = bluesky_cloudlog_new(fs, NULL);
marker->type = LOGTYPE_JOURNAL_MARKER;
marker->data = bluesky_string_new(g_strdup(""), 0);
+ bluesky_cloudlog_stats_update(marker, 1);
bluesky_cloudlog_sync(marker);
g_mutex_lock(marker->lock);
g_string_append_len(loc, (const gchar *)&seq, sizeof(seq));
g_string_append_len(loc, (const gchar *)&offset, sizeof(offset));
commit->data = bluesky_string_new_from_gstring(loc);
+ bluesky_cloudlog_stats_update(commit, 1);
bluesky_cloudlog_sync(commit);
g_mutex_lock(commit->lock);
- while ((commit->pending_write & CLOUDLOG_JOURNAL))
+ while ((commit->location_flags & CLOUDLOG_UNCOMMITTED))
g_cond_wait(commit->cond, commit->lock);
g_mutex_unlock(commit->lock);
char *pathname = g_strdup_printf("%s/%s",
cachefile->log->log_directory,
cachefile->filename);
+ async->data = bluesky_string_dup(async->data);
+ bluesky_cloudlog_decrypt(async->data->data, async->data->len,
+ cachefile->fs->keys);
if (!g_file_set_contents(pathname, async->data->data, async->data->len,
NULL))
g_print("Error writing out fetched file to cache!\n");
close(fd);
}
- g_mutex_unlock(log->mmap_lock);
-
BlueSkyRCStr *str;
map->atime = bluesky_get_current_time();
str = bluesky_string_new_from_mmap(map, log_offset, log_size);