changeset 17926:623a9f46c747

lib-index: Replaced some automatic transaction log unlocks with asserts. Some earlier Dovecot versions were read-locking transaction logs and this was useful there. But now we only do exclusive locking for the log head, so it's an error not to explicitly unlock the files.
author Timo Sirainen <tss@iki.fi>
date Thu, 09 Oct 2014 18:23:41 +0300
parents ec1fd3dc0a74
children fce66ec2ac1c
files src/lib-index/mail-transaction-log-file.c src/lib-index/mail-transaction-log.c
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log-file.c	Thu Oct 09 18:20:56 2014 +0300
+++ b/src/lib-index/mail-transaction-log-file.c	Thu Oct 09 18:23:41 2014 +0300
@@ -101,7 +101,7 @@
 
 	*_file = NULL;
 
-	mail_transaction_log_file_unlock(file);
+	i_assert(!file->locked);
 
 	for (p = &file->log->files; *p != NULL; p = &(*p)->next) {
 		if (*p == file) {
--- a/src/lib-index/mail-transaction-log.c	Thu Oct 09 18:20:56 2014 +0300
+++ b/src/lib-index/mail-transaction-log.c	Thu Oct 09 18:23:41 2014 +0300
@@ -210,10 +210,9 @@
 
 		mail_transaction_log_file_free(&file);
 	}
-	/* if we still have locked files with refcount=0, unlock them */
+	/* sanity check: we shouldn't have locked refcount=0 files */
 	for (; file != NULL; file = file->next) {
-		if (file->locked && file->refcount == 0)
-			mail_transaction_log_file_unlock(file);
+		i_assert(!file->locked || file->refcount > 0);
 	}
 	i_assert(log->head == NULL || log->files != NULL);
 }
@@ -267,8 +266,11 @@
 
 	if (--log->head->refcount == 0)
 		mail_transaction_logs_clean(log);
-	else
+	else {
+		/* the newly created log file is already locked */
+		i_assert(file->locked);
 		mail_transaction_log_file_unlock(log->head);
+	}
 	mail_transaction_log_set_head(log, file);
 	return 0;
 }