Mercurial > dovecot > core-2.2
changeset 2611:8ab92fe191c9 HEAD
a few more cache fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 11 Sep 2004 22:21:08 +0300 |
parents | 664c732ae195 |
children | 2844c33a1be9 |
files | src/lib-index/mail-cache-lookup.c src/lib-index/mail-index-sync-update.c |
diffstat | 2 files changed, 26 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-cache-lookup.c Sat Sep 11 21:30:50 2004 +0300 +++ b/src/lib-index/mail-cache-lookup.c Sat Sep 11 22:21:08 2004 +0300 @@ -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;
--- a/src/lib-index/mail-index-sync-update.c Sat Sep 11 21:30:50 2004 +0300 +++ b/src/lib-index/mail-index-sync-update.c Sat Sep 11 22:21:08 2004 +0300 @@ -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)