[dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.127, 1.128 mail-transaction-log-view.c, 1.16, 1.17 mail-transaction-log.c, 1.31, 1.32

cras at procontrol.fi cras at procontrol.fi
Sun May 30 19:35:21 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv802

Modified Files:
	mail-index.c mail-transaction-log-view.c 
	mail-transaction-log.c 
Log Message:
fixes



Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -d -r1.127 -r1.128
--- a/mail-index.c	28 May 2004 01:04:01 -0000	1.127
+++ b/mail-index.c	30 May 2004 16:35:18 -0000	1.128
@@ -65,7 +65,7 @@
 	}
 
 	if ((map->hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
-		/* either a crash or we've already complained about it */
+		/* we've already complained about it */
 		return -1;
 	}
 
@@ -292,7 +292,12 @@
 	} else if (map->mmap_base != NULL) {
 		/* see if re-mmaping is needed (file has grown) */
 		hdr = map->mmap_base;
-                used_size = hdr->header_size +
+
+		/* always check corrupted-flag to avoid errors later */
+		if ((map->hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0)
+			return -1;
+
+		used_size = hdr->header_size +
 			hdr->messages_count * sizeof(struct mail_index_record);
 		if (map->mmap_size >= used_size && !force) {
 			map->records_count = hdr->messages_count;
@@ -476,9 +481,6 @@
 	if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0)
 		return -1;
 
-	hdr->log_file_seq = seq;
-	hdr->log_file_offset = offset;
-
 	ret = mail_index_try_open(index, NULL);
 	if (ret != 0) {
 		mail_transaction_log_sync_unlock(index->log);

Index: mail-transaction-log-view.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-transaction-log-view.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- a/mail-transaction-log-view.c	30 May 2004 05:07:09 -0000	1.16
+++ b/mail-transaction-log-view.c	30 May 2004 16:35:18 -0000	1.17
@@ -139,7 +139,7 @@
 		if (file == NULL || file->hdr.file_seq != seq)  {
 			mail_index_set_error(view->log->index,
 				"Lost transaction log file %s seq %u",
-				file->filepath, seq);
+				view->log->tail->filepath, seq);
 			return -1;
 		}
 

Index: mail-transaction-log.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- a/mail-transaction-log.c	28 May 2004 01:04:01 -0000	1.31
+++ b/mail-transaction-log.c	30 May 2004 16:35:18 -0000	1.32
@@ -314,6 +314,8 @@
 			return 0;
 		}
 
+		/* 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,
@@ -344,6 +346,7 @@
 	struct mail_index *index = log->index;
 	struct mail_transaction_log_header hdr;
 	struct stat st;
+	unsigned int lock_id;
 	int fd, fd2, ret;
 
 	/* With dotlocking we might already have path.lock created, so this
@@ -387,11 +390,16 @@
 	hdr.used_size = sizeof(hdr);
 
 	if (index->fd != -1) {
+		if (mail_index_lock_shared(index, TRUE, &lock_id) < 0)
+			return -1;
 		hdr.prev_file_seq = index->hdr->log_file_seq;
 		hdr.prev_file_offset = index->hdr->log_file_offset;
 	}
 	hdr.file_seq = index->hdr->log_file_seq+1;
 
+	if (index->fd != -1)
+		mail_index_unlock(index, lock_id);
+
 	if (log->head != NULL && hdr.file_seq <= log->head->hdr.file_seq) {
 		/* make sure the sequence grows */
 		hdr.file_seq = log->head->hdr.file_seq+1;
@@ -614,6 +622,8 @@
 	if (file == NULL)
 		return -1;
 
+	i_assert(file->lock_type == F_UNLCK);
+
 	if (log->head != NULL) {
 		if (--log->head->refcount == 0)
 			mail_transaction_logs_clean(log);
@@ -1021,19 +1031,27 @@
 			return -1;
 	}
 
-	/* FIXME: index->hdr may not be up-to-date and so log_file_seq check
-	   might go wrong! sync header before we get here. */
-	if (log->head->hdr.file_seq == index->hdr->log_file_seq &&
-	    log->head->hdr.used_size > MAIL_TRANSACTION_LOG_ROTATE_SIZE &&
+	if (log->head->hdr.used_size > MAIL_TRANSACTION_LOG_ROTATE_SIZE &&
 	    log->head->last_mtime <
 	    ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_MIN_TIME) {
-		/* everything synced in index, we can rotate. */
-		if (mail_transaction_log_rotate(log, F_WRLCK) < 0) {
-			if (!log->index->log_locked) {
-				(void)mail_transaction_log_file_lock(log->head,
-								     F_UNLCK);
+		/* we might want to rotate, but check first that head file
+		   sequence matches the one in index header, ie. we have
+		   everything synced in index. */
+		unsigned int lock_id;
+		uint32_t seq;
+
+		if (mail_index_lock_shared(log->index, TRUE, &lock_id) == 0) {
+			seq = index->hdr->log_file_seq;
+			mail_index_unlock(log->index, lock_id);
+		} else {
+			seq = 0;
+		}
+
+		if (log->head->hdr.file_seq == seq) {
+			if (mail_transaction_log_rotate(log, F_WRLCK) < 0) {
+				/* that didn't work. well, try to continue
+				   anyway */
 			}
-			return -1;
 		}
 	}
 



More information about the dovecot-cvs mailing list