}
}
+/* Return a committed cloud log record that can be used as a watermark for how
+ * much of the journal has been written. */
+BlueSkyCloudLog *bluesky_log_get_commit_point(BlueSkyFS *fs)
+{
+ BlueSkyCloudLog *marker = bluesky_cloudlog_new(fs, NULL);
+ marker->type = LOGTYPE_JOURNAL_MARKER;
+ marker->data = bluesky_string_new(g_strdup(""), 0);
+ bluesky_cloudlog_sync(marker);
+
+ g_mutex_lock(marker->lock);
+ while ((marker->pending_write & CLOUDLOG_JOURNAL))
+ g_cond_wait(marker->cond, marker->lock);
+ g_mutex_unlock(marker->lock);
+
+ return marker;
+}
+
+void bluesky_log_write_commit_point(BlueSkyFS *fs, BlueSkyCloudLog *marker)
+{
+ BlueSkyCloudLog *commit = bluesky_cloudlog_new(fs, NULL);
+ commit->type = LOGTYPE_JOURNAL_CHECKPOINT;
+
+ uint32_t seq, offset;
+ seq = GUINT32_TO_LE(marker->log_seq);
+ offset = GUINT32_TO_LE(marker->log_offset);
+ GString *loc = g_string_new("");
+ 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_sync(commit);
+
+ g_mutex_lock(commit->lock);
+ while ((commit->pending_write & CLOUDLOG_JOURNAL))
+ g_cond_wait(commit->cond, commit->lock);
+ g_mutex_unlock(commit->lock);
+
+ bluesky_cloudlog_unref(marker);
+ bluesky_cloudlog_unref(commit);
+}
+
/* Memory-map the given log object into memory (read-only) and return a pointer
* to it. */
static int page_size = 0;
/* Scan through a journal segment to extract correctly-written items (those
* that pass sanity checks and have a valid checksum). */
-static void bluesky_replay_scan_journal(const char *buf, size_t len)
+static void bluesky_replay_scan_journal(const char *buf, size_t len,
+ uint32_t *seq, uint32_t *start_offset)
{
const struct log_header *header;
off_t offset = 0;
size_t size = GUINT32_FROM_LE(header->size1)
+ GUINT32_FROM_LE(header->size2)
+ GUINT32_FROM_LE(header->size3);
+
+ if (header->type - '0' == LOGTYPE_JOURNAL_CHECKPOINT) {
+ const uint32_t *data = (const uint32_t *)((const char *)header + sizeof(struct log_header));
+ *seq = GUINT32_FROM_LE(data[0]);
+ *start_offset = GUINT32_FROM_LE(data[1]);
+ }
+
offset += sizeof(struct log_header) + size + sizeof(struct log_footer);
}
}
}
static void bluesky_replay_scan_journal2(BlueSkyFS *fs, GList **objects,
- int log_seq,
+ int log_seq, int start_offset,
const char *buf, size_t len)
{
const struct log_header *header;
- off_t offset = 0;
+ off_t offset = start_offset;
while (validate_journal_item(buf, len, offset)) {
header = (const struct log_header *)(buf + offset);
/* Scan through log files in reverse order to find the most recent commit
* record. */
logfiles = g_list_reverse(logfiles);
+ uint32_t seq_num = 0, start_offset = 0;
while (logfiles != NULL) {
char *filename = g_strdup_printf("%s/%s", log->log_directory,
(char *)logfiles->data);
g_warning("Mapping logfile %s failed!\n", filename);
} else {
bluesky_replay_scan_journal(g_mapped_file_get_contents(map),
- g_mapped_file_get_length(map));
+ g_mapped_file_get_length(map),
+ &seq_num, &start_offset);
g_mapped_file_unref(map);
}
g_free(filename);
g_free(logfiles->data);
logfiles = g_list_delete_link(logfiles, logfiles);
+ if (seq_num != 0 || start_offset != 0)
+ break;
}
g_list_foreach(logfiles, (GFunc)g_free, NULL);
g_list_free(logfiles);
* references, so that any objects which were not linked into persistent
* filesystem data structures are freed. */
GList *objects = NULL;
- int seq_num = 0;
while (TRUE) {
char *filename = g_strdup_printf("%s/journal-%08d",
log->log_directory, seq_num);
- g_print("Replaying file %s\n", filename);
+ g_print("Replaying file %s from offset %d\n", filename, start_offset);
GMappedFile *map = g_mapped_file_new(filename, FALSE, NULL);
g_free(filename);
if (map == NULL) {
break;
}
- bluesky_replay_scan_journal2(fs, &objects, seq_num,
+ bluesky_replay_scan_journal2(fs, &objects, seq_num, start_offset,
g_mapped_file_get_contents(map),
g_mapped_file_get_length(map));
g_mapped_file_unref(map);
seq_num++;
+ start_offset = 0;
}
while (objects != NULL) {