changeset 12249:41e99ee5c1dd

lib-index: Avoid unnecessary pread()s at end of transaction log file. If we've already read until EOF while the file has been locked, there's no need to do it again. Previously this worked while index was being synced, but not while committing a transaction.
author Timo Sirainen <tss@iki.fi>
date Wed, 06 Oct 2010 17:15:51 +0100
parents 814adaed5b00
children d0ddc30f0eef
files src/lib-index/mail-index-fsck.c src/lib-index/mail-index-private.h src/lib-index/mail-index-transaction.c src/lib-index/mail-index-write.c src/lib-index/mail-index.c src/lib-index/mail-transaction-log-append.c src/lib-index/mail-transaction-log-file.c src/lib-index/mail-transaction-log-private.h src/lib-index/mail-transaction-log.c src/lib-index/test-mail-transaction-log-view.c
diffstat 10 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-fsck.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-index-fsck.c	Wed Oct 06 17:15:51 2010 +0100
@@ -424,7 +424,7 @@
 
 int mail_index_fsck(struct mail_index *index)
 {
-	bool orig_locked = index->log_locked;
+	bool orig_locked = index->log_sync_locked;
 	struct mail_index_map *map;
 	uint32_t file_seq;
 	uoff_t file_offset;
@@ -465,7 +465,7 @@
 {
 	int ret;
 
-	i_assert(index->log_locked);
+	i_assert(index->log_sync_locked);
 	ret = mail_index_fsck(index);
 	i_assert(ret == 0);
 }
--- a/src/lib-index/mail-index-private.h	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-index-private.h	Wed Oct 06 17:15:51 2010 +0100
@@ -230,7 +230,7 @@
 
 	unsigned int index_delete_requested:1; /* next sync sets it deleted */
 	unsigned int index_deleted:1; /* no changes allowed anymore */
-	unsigned int log_locked:1;
+	unsigned int log_sync_locked:1;
 	unsigned int readonly:1;
 	unsigned int mapping:1;
 	unsigned int syncing:1;
--- a/src/lib-index/mail-index-transaction.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-index-transaction.c	Wed Oct 06 17:15:51 2010 +0100
@@ -109,7 +109,7 @@
 	}
 	file = t->view->index->log->head;
 
-	if (!t->view->index->log_locked) {
+	if (!t->view->index->log_sync_locked) {
 		/* update sync_offset */
 		if (mail_transaction_log_file_map(file, file->sync_offset,
 						  (uoff_t)-1) <= 0)
--- a/src/lib-index/mail-index-write.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-index-write.c	Wed Oct 06 17:15:51 2010 +0100
@@ -185,7 +185,7 @@
 	unsigned int lock_id;
 	int ret;
 
-	i_assert(index->log_locked);
+	i_assert(index->log_sync_locked);
 
 	if (!mail_index_map_has_changed(map) || index->readonly)
 		return;
--- a/src/lib-index/mail-index.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-index.c	Wed Oct 06 17:15:51 2010 +0100
@@ -516,7 +516,7 @@
 	index->readonly = FALSE;
 	index->nodiskspace = FALSE;
 	index->index_lock_timeout = FALSE;
-	index->log_locked = FALSE;
+	index->log_sync_locked = FALSE;
 	index->flags = flags;
 	index->readonly = (flags & MAIL_INDEX_OPEN_FLAG_READONLY) != 0;
 
--- a/src/lib-index/mail-transaction-log-append.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-transaction-log-append.c	Wed Oct 06 17:15:51 2010 +0100
@@ -206,7 +206,7 @@
 {
 	struct mail_transaction_log_append_ctx *ctx;
 
-	if (!index->log_locked) {
+	if (!index->log_sync_locked) {
 		if (mail_transaction_log_lock_head(index->log) < 0)
 			return -1;
 	}
@@ -228,7 +228,7 @@
 	*_ctx = NULL;
 
 	ret = mail_transaction_log_append_locked(ctx);
-	if (!index->log_locked)
+	if (!index->log_sync_locked)
 		mail_transaction_log_file_unlock(index->log->head);
 
 	buffer_free(&ctx->output);
--- a/src/lib-index/mail-transaction-log-file.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-transaction-log-file.c	Wed Oct 06 17:15:51 2010 +0100
@@ -369,6 +369,7 @@
 		return;
 
 	file->locked = FALSE;
+	file->locked_sync_offset_updated = FALSE;
 
 	if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file))
 		return;
@@ -1552,7 +1553,7 @@
 	i_assert(start_offset >= file->hdr.hdr_size);
 	i_assert(start_offset <= end_offset);
 
-	if (index->log_locked && file == file->log->head &&
+	if (file->locked_sync_offset_updated && file == file->log->head &&
 	    end_offset == (uoff_t)-1) {
 		/* we're not interested of going further than sync_offset */
 		if (log_file_map_check_offsets(file, start_offset,
@@ -1562,6 +1563,9 @@
 		end_offset = file->sync_offset;
 	}
 
+	if (file->locked)
+		file->locked_sync_offset_updated = TRUE;
+
 	if (file->buffer != NULL && file->buffer_offset <= start_offset) {
 		/* see if we already have it */
 		size = buffer_get_used_size(file->buffer);
--- a/src/lib-index/mail-transaction-log-private.h	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-transaction-log-private.h	Wed Oct 06 17:15:51 2010 +0100
@@ -76,6 +76,7 @@
 	time_t lock_created;
 
 	unsigned int locked:1;
+	unsigned int locked_sync_offset_updated:1;
 	unsigned int corrupted:1;
 };
 
--- a/src/lib-index/mail-transaction-log.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/mail-transaction-log.c	Wed Oct 06 17:15:51 2010 +0100
@@ -466,7 +466,7 @@
 int mail_transaction_log_sync_lock(struct mail_transaction_log *log,
 				   uint32_t *file_seq_r, uoff_t *file_offset_r)
 {
-	i_assert(!log->index->log_locked);
+	i_assert(!log->index->log_sync_locked);
 
 	if (mail_transaction_log_lock_head(log) < 0)
 		return -1;
@@ -478,7 +478,7 @@
 		return -1;
 	}
 
-	log->index->log_locked = TRUE;
+	log->index->log_sync_locked = TRUE;
 	*file_seq_r = log->head->hdr.file_seq;
 	*file_offset_r = log->head->sync_offset;
 	return 0;
@@ -486,9 +486,9 @@
 
 void mail_transaction_log_sync_unlock(struct mail_transaction_log *log)
 {
-	i_assert(log->index->log_locked);
+	i_assert(log->index->log_sync_locked);
 
-	log->index->log_locked = FALSE;
+	log->index->log_sync_locked = FALSE;
 	mail_transaction_log_file_unlock(log->head);
 }
 
--- a/src/lib-index/test-mail-transaction-log-view.c	Wed Oct 06 17:11:52 2010 +0100
+++ b/src/lib-index/test-mail-transaction-log-view.c	Wed Oct 06 17:15:51 2010 +0100
@@ -126,7 +126,7 @@
 	log = i_new(struct mail_transaction_log, 1);
 	log->index = i_new(struct mail_index, 1);
 	log->index->log = log;
-	log->index->log_locked = TRUE;
+	log->index->log_sync_locked = TRUE;
 	test_transaction_log_file_add(1);
 	test_transaction_log_file_add(2);
 	test_transaction_log_file_add(3);