changeset 15306:e44579c5b52b

lib-index: Log a warning if locking transaction log takes longer than 30 secs.
author Timo Sirainen <tss@iki.fi>
date Fri, 12 Oct 2012 08:31:15 +0300
parents 9542732069ff
children a79e1a0040de
files src/lib-index/mail-transaction-log-private.h src/lib-index/mail-transaction-log.c
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log-private.h	Fri Oct 12 00:30:23 2012 +0300
+++ b/src/lib-index/mail-transaction-log-private.h	Fri Oct 12 08:31:15 2012 +0300
@@ -10,6 +10,7 @@
    mails. */
 #define MAIL_TRANSCATION_LOG_LOCK_TIMEOUT (3*60)
 #define MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT (3*60)
+#define MAIL_TRANSACTION_LOG_LOCK_WARN_SECS 30
 
 /* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
 #define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*32)
--- a/src/lib-index/mail-transaction-log.c	Fri Oct 12 00:30:23 2012 +0300
+++ b/src/lib-index/mail-transaction-log.c	Fri Oct 12 08:31:15 2012 +0300
@@ -416,6 +416,7 @@
 int mail_transaction_log_lock_head(struct mail_transaction_log *log)
 {
 	struct mail_transaction_log_file *file;
+	time_t lock_wait_started, lock_secs = 0;
 	int ret = 0;
 
 	if (!log->log_2_unlink_checked) {
@@ -437,6 +438,7 @@
 	   can lock it and don't see another file, we can be sure no-one is
 	   creating a new log at the moment */
 
+	lock_wait_started = time(NULL);
 	for (;;) {
 		file = log->head;
 		if (mail_transaction_log_file_lock(file) < 0)
@@ -451,6 +453,7 @@
 
 		if (ret == 0 && log->head == file) {
 			/* success */
+			lock_secs = file->lock_created - lock_wait_started;
 			break;
 		}
 
@@ -462,6 +465,10 @@
 
 		/* try again */
 	}
+	if (lock_secs > MAIL_TRANSACTION_LOG_LOCK_WARN_SECS) {
+		i_warning("Locking transaction log file %s took %ld seconds",
+			  log->head->filepath, (long)lock_secs);
+	}
 
 	i_assert(ret < 0 || log->head != NULL);
 	return ret;