Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8160:e76d8777d20c HEAD
strmap: Don't check conflicts for strings known to be unique.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 05 Sep 2008 19:58:51 +0300 |
parents | f6f2af2db365 |
children | eaa3469db1dd |
files | src/lib-index/mail-index-strmap.c |
diffstat | 1 files changed, 38 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-strmap.c Fri Sep 05 19:45:28 2008 +0300 +++ b/src/lib-index/mail-index-strmap.c Fri Sep 05 19:58:51 2008 +0300 @@ -632,10 +632,44 @@ } static int +strmap_view_sync_block_check_conflicts(struct mail_index_strmap_read_context *ctx, + uint32_t crc32) +{ + struct mail_index_strmap_rec *hash_rec; + struct hash2_iter iter; + + if (crc32 == 0) { + /* unique string - there are no conflicts */ + return 0; + } + + /* check for conflicting string indexes. they may happen if + + 1) msgid exists only for a message X that has been expunged + 2) another process doesn't see X, but sees msgid for another + message and writes it using a new string index + 3) if we still see X, we now see the same msgid with two + string indexes. + + if we detect such a conflict, we can't continue using the + strmap index until X has been expunged. */ + memset(&iter, 0, sizeof(iter)); + while ((hash_rec = hash2_iterate(ctx->view->hash, + crc32, &iter)) != NULL && + hash_rec->str_idx != ctx->rec.str_idx) { + /* CRC32 matches, but string index doesn't */ + if (!strmap_view_sync_handle_conflict(ctx, hash_rec, &iter)) { + ctx->lost_expunged_uid = hash_rec->uid; + return -1; + } + } + return 0; +} + +static int mail_index_strmap_view_sync_block(struct mail_index_strmap_read_context *ctx) { struct mail_index_strmap_rec *hash_rec; - struct hash2_iter iter; uint32_t crc32, prev_uid = 0; int ret; @@ -649,29 +683,10 @@ } prev_uid = ctx->rec.uid; - /* check for conflicting string indexes. they may happen if - - 1) msgid exists only for a message X that has been expunged - 2) another process doesn't see X, but sees msgid for another - message and writes it using a new string index - 3) if we still see X, we now see the same msgid with two - string indexes. - - if we detect such a conflict, we can't continue using the - strmap index until X has been expunged. */ - memset(&iter, 0, sizeof(iter)); - while ((hash_rec = hash2_iterate(ctx->view->hash, - crc32, &iter)) != NULL && - hash_rec->str_idx != ctx->rec.str_idx) { - /* CRC32 matches, but string index doesn't */ - if (!strmap_view_sync_handle_conflict(ctx, hash_rec, - &iter)) { - ctx->lost_expunged_uid = hash_rec->uid; - ret = -1; - goto error; - } + if (strmap_view_sync_block_check_conflicts(ctx, crc32) < 0) { + ret = -1; + break; } - ctx->view->last_added_uid = ctx->rec.uid; /* add the record to records array */ @@ -682,7 +697,6 @@ hash_rec = hash2_insert_hash(ctx->view->hash, crc32); memcpy(hash_rec, &ctx->rec, sizeof(*hash_rec)); } -error: return strmap_read_block_deinit(ctx, ret, TRUE); }