Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5653:965e401fcb7b HEAD
mail_index_view_add_hidden_transaction() takes now a whole area parameter so
it has to be called only once for each transaction, instead of each for each
transaction record.
mail_index_view_add_synced_transaction() is no longer public.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 22 May 2007 22:44:50 +0300 |
parents | aff5fb7bb580 |
children | 29764126e1a6 |
files | src/lib-index/mail-index-transaction.c src/lib-index/mail-index-view-private.h src/lib-index/mail-index-view-sync.c src/lib-index/mail-transaction-log-append.c |
diffstat | 4 files changed, 59 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-transaction.c Tue May 22 21:32:10 2007 +0300 +++ b/src/lib-index/mail-index-transaction.c Tue May 22 22:44:50 2007 +0300 @@ -495,6 +495,7 @@ void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq) { + i_assert(!t->hide_transaction); i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(t->view)); t->log_updates = TRUE;
--- a/src/lib-index/mail-index-view-private.h Tue May 22 21:32:10 2007 +0300 +++ b/src/lib-index/mail-index-view-private.h Tue May 22 22:44:50 2007 +0300 @@ -3,11 +3,12 @@ #include "mail-index-private.h" -struct mail_index_view_log_sync_pos { +struct mail_index_view_log_sync_area { uint32_t log_file_seq; + unsigned int length; uoff_t log_file_offset; }; -ARRAY_DEFINE_TYPE(view_log_sync_pos, struct mail_index_view_log_sync_pos); +ARRAY_DEFINE_TYPE(view_log_sync_area, struct mail_index_view_log_sync_area); struct mail_index_view_vfuncs { void (*close)(struct mail_index_view *view); @@ -56,9 +57,9 @@ uint32_t log_file_seq; uoff_t log_file_offset; /* Transaction log offsets which we have already synced */ - ARRAY_TYPE(view_log_sync_pos) syncs_done; + ARRAY_TYPE(view_log_sync_area) syncs_done; /* Transaction log offsets which we don't want to return in view sync */ - ARRAY_TYPE(view_log_sync_pos) syncs_hidden; + ARRAY_TYPE(view_log_sync_area) syncs_hidden; /* Module-specific contexts. */ ARRAY_DEFINE(module_contexts, union mail_index_view_module_context *); @@ -80,12 +81,10 @@ int mail_index_view_lock(struct mail_index_view *view); int mail_index_view_lock_head(struct mail_index_view *view, bool update_index); void mail_index_view_unref_maps(struct mail_index_view *view); -void mail_index_view_add_synced_transaction(struct mail_index_view *view, - uint32_t log_file_seq, - uoff_t log_file_offset); void mail_index_view_add_hidden_transaction(struct mail_index_view *view, uint32_t log_file_seq, - uoff_t log_file_offset); + uoff_t log_file_offset, + unsigned int length); struct mail_index_view *mail_index_dummy_view_open(struct mail_index *index);
--- a/src/lib-index/mail-index-view-sync.c Tue May 22 21:32:10 2007 +0300 +++ b/src/lib-index/mail-index-view-sync.c Tue May 22 22:44:50 2007 +0300 @@ -368,10 +368,25 @@ return 0; } -static bool view_sync_pos_find(ARRAY_TYPE(view_log_sync_pos) *sync_arr, - uint32_t seq, uoff_t offset) +static void +view_add_synced_transaction(struct mail_index_view *view, + uint32_t log_file_seq, uoff_t log_file_offset) { - const struct mail_index_view_log_sync_pos *syncs; + struct mail_index_view_log_sync_area *pos; + + if (!array_is_created(&view->syncs_done)) + i_array_init(&view->syncs_done, 32); + + pos = array_append_space(&view->syncs_done); + pos->log_file_seq = log_file_seq; + pos->log_file_offset = log_file_offset; + pos->length = 1; +} + +static bool view_sync_area_find(ARRAY_TYPE(view_log_sync_area) *sync_arr, + uint32_t seq, uoff_t offset) +{ + const struct mail_index_view_log_sync_area *syncs; unsigned int i, count; if (!array_is_created(sync_arr)) @@ -379,7 +394,8 @@ syncs = array_get(sync_arr, &count); for (i = 0; i < count; i++) { - if (syncs[i].log_file_offset == offset && + if (syncs[i].log_file_offset <= offset && + offset - syncs[i].log_file_offset < syncs[i].length && syncs[i].log_file_seq == seq) return TRUE; } @@ -429,7 +445,7 @@ } /* skip everything we've already synced */ - if (view_sync_pos_find(&view->syncs_done, seq, offset)) + if (view_sync_area_find(&view->syncs_done, seq, offset)) continue; if (ctx->skipped_some) { @@ -437,8 +453,7 @@ we'll go through these same transactions again later. Since we're syncing this one, we don't want to do it again. */ - mail_index_view_add_synced_transaction(view, seq, - offset); + view_add_synced_transaction(view, seq, offset); } /* if we started from a map that we didn't create ourself, @@ -469,7 +484,7 @@ /* skip changes committed by hidden transactions (eg. in IMAP store +flags.silent command) */ - if (view_sync_pos_find(&view->syncs_hidden, seq, offset)) + if (view_sync_area_find(&view->syncs_hidden, seq, offset)) continue; break; } @@ -594,16 +609,19 @@ static void mail_index_view_sync_clean_log_syncs(struct mail_index_view_sync_ctx *ctx, - ARRAY_TYPE(view_log_sync_pos) *sync_arr) + ARRAY_TYPE(view_log_sync_area) *sync_arr, + bool fast_clean) { struct mail_index_view *view = ctx->view; - const struct mail_index_view_log_sync_pos *syncs; + const struct mail_index_view_log_sync_area *syncs; + uint32_t seq = view->log_file_seq; + uoff_t offset = view->log_file_offset; unsigned int i, count; if (!array_is_created(sync_arr)) return; - if (!ctx->skipped_some) { + if (!ctx->skipped_some && fast_clean) { /* Nothing skipped. Clean it up the quick way. */ array_clear(sync_arr); return; @@ -612,9 +630,9 @@ /* Clean up until view's current syncing position */ syncs = array_get(sync_arr, &count); for (i = 0; i < count; i++) { - if ((syncs[i].log_file_offset >= view->log_file_offset && - syncs[i].log_file_seq == view->log_file_seq) || - syncs[i].log_file_seq > view->log_file_seq) + if ((syncs[i].log_file_offset + syncs[i].length > offset && + syncs[i].log_file_seq == seq) || + syncs[i].log_file_seq > seq) break; } if (i > 0) @@ -630,8 +648,8 @@ *_ctx = NULL; mail_index_sync_map_deinit(&ctx->sync_map_ctx); - mail_index_view_sync_clean_log_syncs(ctx, &view->syncs_done); - mail_index_view_sync_clean_log_syncs(ctx, &view->syncs_hidden); + mail_index_view_sync_clean_log_syncs(ctx, &view->syncs_done, TRUE); + mail_index_view_sync_clean_log_syncs(ctx, &view->syncs_hidden, FALSE); if (!ctx->last_read && ctx->hdr != NULL && ctx->data_offset != ctx->hdr->size) { @@ -685,29 +703,18 @@ i_free(ctx); } -static void log_sync_pos_add(ARRAY_TYPE(view_log_sync_pos) *sync_arr, - uint32_t log_file_seq, uoff_t log_file_offset) -{ - struct mail_index_view_log_sync_pos *pos; - - if (!array_is_created(sync_arr)) - i_array_init(sync_arr, 32); - - pos = array_append_space(sync_arr); - pos->log_file_seq = log_file_seq; - pos->log_file_offset = log_file_offset; -} - -void mail_index_view_add_synced_transaction(struct mail_index_view *view, - uint32_t log_file_seq, - uoff_t log_file_offset) -{ - log_sync_pos_add(&view->syncs_done, log_file_seq, log_file_offset); -} - void mail_index_view_add_hidden_transaction(struct mail_index_view *view, uint32_t log_file_seq, - uoff_t log_file_offset) + uoff_t log_file_offset, + unsigned int length) { - log_sync_pos_add(&view->syncs_hidden, log_file_seq, log_file_offset); + struct mail_index_view_log_sync_area *area; + + if (!array_is_created(&view->syncs_hidden)) + i_array_init(&view->syncs_hidden, 32); + + area = array_append_space(&view->syncs_hidden); + area->log_file_seq = log_file_seq; + area->log_file_offset = log_file_offset; + area->length = length; }
--- a/src/lib-index/mail-transaction-log-append.c Tue May 22 21:32:10 2007 +0300 +++ b/src/lib-index/mail-transaction-log-append.c Tue May 22 22:44:50 2007 +0300 @@ -321,11 +321,6 @@ if ((hdr_buf->used % 4) != 0) buffer_append_zero(hdr_buf, 4 - (hdr_buf->used % 4)); - if (t->hide_transaction) { - mail_index_view_add_hidden_transaction(t->view, - file->hdr.file_seq, file->sync_offset); - } - return log_append_buffer(file, buffer, hdr_buf, MAIL_TRANSACTION_KEYWORD_UPDATE, t->external); } @@ -449,18 +444,10 @@ t->external); } if (array_is_created(&t->appends) && ret == 0) { - if (t->hide_transaction) { - mail_index_view_add_hidden_transaction(view, - file->hdr.file_seq, file->sync_offset); - } ret = log_append_buffer(file, t->appends.arr.buffer, NULL, MAIL_TRANSACTION_APPEND, t->external); } if (array_is_created(&t->updates) && ret == 0) { - if (t->hide_transaction) { - mail_index_view_add_hidden_transaction(view, - file->hdr.file_seq, file->sync_offset); - } ret = log_append_buffer(file, t->updates.arr.buffer, NULL, MAIL_TRANSACTION_FLAG_UPDATE, t->external); @@ -471,10 +458,6 @@ /* keyword resets before updates */ if (array_is_created(&t->keyword_resets) && ret == 0) { - if (t->hide_transaction) { - mail_index_view_add_hidden_transaction(view, - file->hdr.file_seq, file->sync_offset); - } ret = log_append_buffer(file, t->keyword_resets.arr.buffer, NULL, MAIL_TRANSACTION_KEYWORD_RESET, t->external); @@ -483,7 +466,6 @@ ret = log_append_keyword_updates(file, t); if (array_is_created(&t->expunges) && ret == 0) { - /* Expunges cannot be hidden */ ret = log_append_buffer(file, t->expunges.arr.buffer, NULL, MAIL_TRANSACTION_EXPUNGE, t->external); } @@ -527,16 +509,13 @@ } } - if (ret < 0) { - if (array_is_created(&view->syncs_hidden)) { - /* revert changes to log_syncs */ - array_delete(&view->syncs_hidden, - old_hidden_syncs_count, - array_count(&view->syncs_hidden) - - old_hidden_syncs_count); - } + if (t->hide_transaction && ret == 0) { + /* mark the area covered by this transaction hidden */ + mail_index_view_add_hidden_transaction(view, file->hdr.file_seq, + append_offset, file->sync_offset - append_offset); + } + if (ret < 0) file->sync_offset = append_offset; - } *log_file_seq_r = file->hdr.file_seq; *log_file_offset_r = file->sync_offset;