[dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.207, 1.208 mail-transaction-log.c, 1.101, 1.102

cras at dovecot.org cras at dovecot.org
Sat Aug 27 15:41:24 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv10391

Modified Files:
	mail-index.c mail-transaction-log.c 
Log Message:
Index creation was racy.



Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.207
retrieving revision 1.208
diff -u -d -r1.207 -r1.208
--- mail-index.c	27 Aug 2005 12:40:53 -0000	1.207
+++ mail-index.c	27 Aug 2005 12:41:21 -0000	1.208
@@ -1390,6 +1390,13 @@
 		return -1;
 
 	if (index->fd == -1) {
+		if (index->indexid != hdr.indexid) {
+			/* looks like someone else created the transaction log
+			   before we had the chance. use its indexid so we
+			   don't try to create conflicting ones. */
+			hdr.indexid = index->indexid;
+		}
+
 		if (lock_id != 0) {
 			mail_index_unlock(index, lock_id);
 			lock_id = 0;

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- mail-transaction-log.c	27 Aug 2005 12:40:53 -0000	1.101
+++ mail-transaction-log.c	27 Aug 2005 12:41:21 -0000	1.102
@@ -347,18 +347,19 @@
 		return 0;
 	}
 	if (file->hdr.indexid != file->log->index->indexid) {
-		if (file->log->index->fd == -1) {
-			/* creating index file, silently rebuild
-			   transaction log as well */
+		if (file->log->index->fd != -1) {
+			/* index file was probably just rebuilt and we don't
+			   know about it yet */
+			mail_transaction_log_file_set_corrupted(file,
+				"invalid indexid (%u != %u)",
+				file->hdr.indexid, file->log->index->indexid);
 			return 0;
 		}
 
-		/* index file was probably just rebuilt and we don't know
-		   about it yet */
-		mail_transaction_log_file_set_corrupted(file,
-			"invalid indexid (%u != %u)",
-			file->hdr.indexid, file->log->index->indexid);
-		return 0;
+		/* creating index file. since transaction log is created
+		   first, use the indexid in it to create the main index
+		   to avoid races. */
+		file->log->index->indexid = file->hdr.indexid;
 	}
 
 	/* make sure we already don't have a file with the same sequence



More information about the dovecot-cvs mailing list