From: Michael Vrable Date: Wed, 15 Sep 2010 20:29:42 +0000 (-0700) Subject: Restart journal sequence numbering properly. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=85926e10780a15fec8f4785329df8ab59a234e0c;p=bluesky.git Restart journal sequence numbering properly. Handle the case even where some old journal files have been deleted. --- diff --git a/bluesky/log.c b/bluesky/log.c index 97b4f30..19027da 100644 --- a/bluesky/log.c +++ b/bluesky/log.c @@ -252,6 +252,20 @@ BlueSkyLog *bluesky_log_new(const char *log_directory) 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");