changeset 3169:ec17099a6490 HEAD

Added versioning to transaction log header. Added create_stamp to its header and it's not used to determine if the transaction log should be rotated, not the last time the log was updated. So now if the log is over 128kB, it's rotated as soon as it's at least 5 minutes old.
author Timo Sirainen <tss@iki.fi>
date Sat, 05 Mar 2005 12:19:37 +0200
parents 62f8366cb89c
children 42e1e9dbf19e
files src/lib-index/mail-transaction-log-append.c src/lib-index/mail-transaction-log.c src/lib-index/mail-transaction-log.h
diffstat 3 files changed, 42 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log-append.c	Wed Mar 02 22:46:25 2005 +0200
+++ b/src/lib-index/mail-transaction-log-append.c	Sat Mar 05 12:19:37 2005 +0200
@@ -344,7 +344,7 @@
 	}
 
 	if (log->head->sync_offset > MAIL_TRANSACTION_LOG_ROTATE_SIZE &&
-	    log->head->last_mtime <
+	    (time_t)log->head->hdr.create_stamp <
 	    ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_MIN_TIME) {
 		/* we might want to rotate, but check first that everything is
 		   synced in index. */
--- a/src/lib-index/mail-transaction-log.c	Wed Mar 02 22:46:25 2005 +0200
+++ b/src/lib-index/mail-transaction-log.c	Sat Mar 05 12:19:37 2005 +0200
@@ -50,8 +50,11 @@
 	t_pop();
 	va_end(va);
 
-	/* this may have happened because of broken index. make sure it's ok. */
-	(void)mail_index_fsck(file->log->index);
+	if (file->log->index->log != NULL) {
+		/* this may have happened because of broken index.
+		   make sure it's ok. */
+		(void)mail_index_fsck(file->log->index);
+	}
 }
 
 static int
@@ -295,6 +298,22 @@
 		return 0;
 	}
 
+	if (file->hdr.major_version != MAIL_TRANSACTION_LOG_MAJOR_VERSION) {
+		/* incompatible version - fix silently */
+		return 0;
+	}
+	if (file->hdr.hdr_size < MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE) {
+		mail_transaction_log_file_set_corrupted(file,
+			"Header size too small");
+		return 0;
+	}
+	if (file->hdr.hdr_size < sizeof(file->hdr)) {
+		/* @UNSAFE: smaller than we expected - zero out the fields we
+		   shouldn't have filled */
+		memset(PTR_OFFSET(&file->hdr, file->hdr.hdr_size), 0,
+		       sizeof(file->hdr) - file->hdr.hdr_size);
+	}
+
 	if (file->hdr.indexid == 0) {
 		/* corrupted */
 		mail_index_set_error(file->log->index,
@@ -311,10 +330,9 @@
 
 		/* index file was probably just rebuilt and we don't know
 		   about it yet */
-		mail_index_set_error(file->log->index,
-			"Transaction log file %s: invalid indexid (%u != %u)",
-			file->filepath, file->hdr.indexid,
-			file->log->index->indexid);
+		mail_transaction_log_file_set_corrupted(file,
+			"invalid indexid (%u != %u)",
+			file->hdr.indexid, file->log->index->indexid);
 		return 0;
 	}
 	return 1;
@@ -355,7 +373,11 @@
 	}
 
 	memset(&hdr, 0, sizeof(hdr));
+	hdr.major_version = MAIL_TRANSACTION_LOG_MAJOR_VERSION;
+	hdr.minor_version = MAIL_TRANSACTION_LOG_MINOR_VERSION;
+	hdr.hdr_size = sizeof(struct mail_transaction_log_header);
 	hdr.indexid = index->indexid;
+	hdr.create_stamp = ioloop_time;
 
 	if (index->fd != -1) {
 		if (mail_index_lock_shared(index, TRUE, &lock_id) < 0)
@@ -450,7 +472,6 @@
 	file->st_dev = st.st_dev;
 	file->st_ino = st.st_ino;
 	file->last_mtime = st.st_mtime;
-	file->sync_offset = sizeof(struct mail_transaction_log_header);
 
 	ret = mail_transaction_log_file_read_hdr(file);
 	if (ret == 0) {
@@ -491,6 +512,8 @@
 		   sync_offset from it so we don't have to read the whole log
 		   file from beginning. */
 		file->sync_offset = log->index->map->hdr.log_file_int_offset;
+	} else {
+		file->sync_offset = file->hdr.hdr_size;
 	}
 
 	for (p = &log->tail; *p != NULL; p = &(*p)->next) {
@@ -790,10 +813,10 @@
 		return 0;
 	}
 
-	if (start_offset < sizeof(file->hdr)) {
+	if (start_offset < file->hdr.hdr_size) {
 		mail_transaction_log_file_set_corrupted(file,
 			"offset (%"PRIuUOFF_T") < header size (%"PRIuSIZE_T")",
-			start_offset, sizeof(file->hdr));
+			start_offset, file->hdr.hdr_size);
 		return -1;
 	}
 
--- a/src/lib-index/mail-transaction-log.h	Wed Mar 02 22:46:25 2005 +0200
+++ b/src/lib-index/mail-transaction-log.h	Sat Mar 05 12:19:37 2005 +0200
@@ -1,15 +1,24 @@
 #ifndef __MAIL_TRANSACTION_LOG_H
 #define __MAIL_TRANSACTION_LOG_H
 
+#define MAIL_TRANSACTION_LOG_MAJOR_VERSION 1
+#define MAIL_TRANSACTION_LOG_MINOR_VERSION 0
+#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
+
 #define MAIL_TRANSACTION_LOG_PREFIX ".log"
 #define MAIL_TRANSACTION_LOG_ROTATE_SIZE (1024*128)
 #define MAIL_TRANSACTION_LOG_ROTATE_MIN_TIME (60*5)
 
 struct mail_transaction_log_header {
+	uint8_t major_version;
+	uint8_t minor_version;
+	uint16_t hdr_size;
+
 	uint32_t indexid;
 	uint32_t file_seq;
 	uint32_t prev_file_seq;
 	uint32_t prev_file_offset;
+	uint32_t create_stamp;
 };
 
 enum mail_transaction_type {