[dovecot-cvs] dovecot/src/lib-index mail-cache-lookup.c, 1.19, 1.20 mail-index-sync-update.c, 1.44, 1.45

cras at dovecot.org cras at dovecot.org
Sat Sep 11 22:21:10 EEST 2004


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

Modified Files:
	mail-cache-lookup.c mail-index-sync-update.c 
Log Message:
a few more cache fixes



Index: mail-cache-lookup.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-lookup.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- mail-cache-lookup.c	10 Sep 2004 09:57:42 -0000	1.19
+++ mail-cache-lookup.c	11 Sep 2004 19:21:08 -0000	1.20
@@ -68,17 +68,23 @@
 }
 
 static int
-mail_cache_foreach_rec(struct mail_cache_view *view,
-		       const struct mail_cache_record *cache_rec,
+mail_cache_foreach_rec(struct mail_cache_view *view, uint32_t *offset,
 		       mail_cache_foreach_callback_t *callback, void *context)
 {
 	struct mail_cache *cache = view->cache;
+	const struct mail_cache_record *cache_rec;
 	size_t pos, next_pos, max_size;
 	unsigned int data_size;
 	uint32_t file_field;
 	unsigned int field;
 	int ret;
 
+	cache_rec = mail_cache_get_record(view->cache, *offset);
+	if (cache_rec == NULL) {
+		*offset = 0;
+		return 1;
+	}
+
 	max_size = cache_rec->size;
 	if (max_size < sizeof(*cache_rec) + sizeof(uint32_t)*2) {
 		mail_cache_set_corrupted(cache, "record has invalid size");
@@ -102,6 +108,11 @@
 					file_field, cache->file_fields_count);
 				return -1;
 			}
+
+			/* field reading might have re-mmaped the file and
+			   caused cache_rec to break. need to get it again. */
+			cache_rec = mail_cache_get_record(view->cache, *offset);
+			i_assert(cache_rec != NULL);
 		}
 
 		field = cache->file_field_map[file_field];
@@ -127,13 +138,14 @@
 
 		pos = next_pos;
 	}
+
+	*offset = cache_rec->prev_offset;
 	return 1;
 }
 
 int mail_cache_foreach(struct mail_cache_view *view, uint32_t seq,
                        mail_cache_foreach_callback_t *callback, void *context)
 {
-	const struct mail_cache_record *cache_rec;
 	uint32_t offset;
 	int ret;
 
@@ -150,22 +162,20 @@
 		view->cached_offset = offset;
 	}
 
-	cache_rec = mail_cache_get_record(view->cache, offset);
-	while (cache_rec != NULL) {
-		ret = mail_cache_foreach_rec(view, cache_rec,
+	while (offset != 0) {
+		ret = mail_cache_foreach_rec(view, &offset,
 					     callback, context);
 		if (ret <= 0)
 			return ret;
-		cache_rec = mail_cache_get_record(view->cache,
-						  cache_rec->prev_offset);
 	}
 
 	if (view->trans_seq1 <= seq && view->trans_seq2 >= seq &&
 	    mail_cache_transaction_lookup(view->transaction, seq, &offset)) {
-		cache_rec = mail_cache_get_record(view->cache, offset);
-		if (cache_rec != NULL) {
-			return mail_cache_foreach_rec(view, cache_rec,
-						      callback, context);
+		while (offset != 0) {
+			ret = mail_cache_foreach_rec(view, &offset,
+						     callback, context);
+			if (ret <= 0)
+				return ret;
 		}
 	}
 	return 1;

Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- mail-index-sync-update.c	11 Sep 2004 17:25:39 -0000	1.44
+++ mail-index-sync-update.c	11 Sep 2004 19:21:08 -0000	1.45
@@ -69,7 +69,10 @@
 		ctx->cache_locked = TRUE;
 	}
 
-	(void)mail_cache_delete(ctx->view->index->cache, cache_offset);
+	if (!MAIL_CACHE_IS_UNUSABLE(ctx->view->index->cache) &&
+	    ctx->view->map->hdr->cache_file_seq !=
+	    ctx->view->index->cache->hdr->file_seq)
+		(void)mail_cache_delete(ctx->view->index->cache, cache_offset);
 }
 
 static int sync_expunge(const struct mail_transaction_expunge *e, void *context)



More information about the dovecot-cvs mailing list