dovecot: View's counters can no longer be unreliable or broken.
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jun 18 01:34:21 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/901a9ba8cff7
changeset: 5769:901a9ba8cff7
user: Timo Sirainen <tss at iki.fi>
date: Mon Jun 18 01:34:17 2007 +0300
description:
View's counters can no longer be unreliable or broken.
diffstat:
6 files changed, 16 insertions(+), 110 deletions(-)
src/lib-index/mail-index-private.h | 1
src/lib-index/mail-index-sync-private.h | 1
src/lib-index/mail-index-sync-update.c | 55 ++------------------------
src/lib-index/mail-index-view-private.h | 1
src/lib-index/mail-index-view-sync.c | 65 +++++--------------------------
src/lib-index/mail-index-view.c | 3 -
diffs (255 lines):
diff -r 35806800d2bd -r 901a9ba8cff7 src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h Mon Jun 18 01:32:48 2007 +0300
+++ b/src/lib-index/mail-index-private.h Mon Jun 18 01:34:17 2007 +0300
@@ -271,7 +271,6 @@ int mail_index_map_get_ext_idx(struct ma
uint32_t ext_id, uint32_t *idx_r);
const struct mail_index_ext *
mail_index_view_get_ext(struct mail_index_view *view, uint32_t ext_id);
-void mail_index_view_recalc_counters(struct mail_index_view *view);
int mail_index_map_parse_keywords(struct mail_index *index,
struct mail_index_map *map);
diff -r 35806800d2bd -r 901a9ba8cff7 src/lib-index/mail-index-sync-private.h
--- a/src/lib-index/mail-index-sync-private.h Mon Jun 18 01:32:48 2007 +0300
+++ b/src/lib-index/mail-index-sync-private.h Mon Jun 18 01:34:17 2007 +0300
@@ -39,7 +39,6 @@ struct mail_index_sync_map_ctx {
unsigned int expunge_handlers_set:1;
unsigned int expunge_handlers_used:1;
unsigned int cur_ext_ignore:1;
- unsigned int unreliable_flags:1;
};
extern struct mail_transaction_map_functions mail_index_map_sync_funcs;
diff -r 35806800d2bd -r 901a9ba8cff7 src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c Mon Jun 18 01:32:48 2007 +0300
+++ b/src/lib-index/mail-index-sync-update.c Mon Jun 18 01:34:17 2007 +0300
@@ -179,39 +179,9 @@ mail_index_sync_header_update_counts(str
{
const char *error;
- if (ctx->view->broken_counters)
- return;
-
if (mail_index_header_update_counts(&ctx->view->map->hdr,
- old_flags, new_flags, &error) < 0) {
+ old_flags, new_flags, &error) < 0)
mail_index_sync_set_corrupted(ctx, "%s", error);
- ctx->view->broken_counters = TRUE;
- }
-}
-
-void mail_index_view_recalc_counters(struct mail_index_view *view)
-{
- struct mail_index_map *map = view->map;
- const struct mail_index_record *rec;
- const char *error;
- unsigned int i;
-
- map->hdr.recent_messages_count = 0;
- map->hdr.seen_messages_count = 0;
- map->hdr.deleted_messages_count = 0;
-
- for (i = 0; i < view->hdr.messages_count; i++) {
- rec = MAIL_INDEX_MAP_IDX(map, i);
- if (mail_index_header_update_counts(&map->hdr, 0, rec->flags,
- &error) < 0)
- i_panic("mail_index_view_recalc_counters(): %s", error);
- }
-
- view->hdr.recent_messages_count = map->hdr.recent_messages_count;
- view->hdr.seen_messages_count = map->hdr.seen_messages_count;
- view->hdr.deleted_messages_count = map->hdr.deleted_messages_count;
-
- view->broken_counters = FALSE;
}
static void
@@ -285,14 +255,10 @@ sync_expunge(const struct mail_transacti
continue;
}
- if (ctx->unreliable_flags || ctx->view->broken_counters)
- ctx->view->broken_counters = TRUE;
- else {
- for (seq = seq1; seq <= seq2; seq++) {
- rec = MAIL_INDEX_MAP_IDX(map, seq-1);
- mail_index_sync_header_update_counts(ctx,
- rec->flags, 0);
- }
+ for (seq = seq1; seq <= seq2; seq++) {
+ rec = MAIL_INDEX_MAP_IDX(map, seq-1);
+ mail_index_sync_header_update_counts(ctx,
+ rec->flags, 0);
}
if (sync_expunge_call_handlers(ctx, seq1, seq2) < 0)
@@ -407,14 +373,6 @@ static int sync_flag_update(const struct
for (idx = seq1-1; idx < seq2; idx++) {
rec = MAIL_INDEX_MAP_IDX(view->map, idx);
rec->flags = (rec->flags & flag_mask) | u->add_flags;
- }
- } else if (view->broken_counters || ctx->unreliable_flags) {
- view->broken_counters = TRUE;
- for (idx = seq1-1; idx < seq2; idx++) {
- rec = MAIL_INDEX_MAP_IDX(view->map, idx);
- rec->flags = (rec->flags & flag_mask) | u->add_flags;
-
- mail_index_header_update_lowwaters(hdr, rec);
}
} else {
for (idx = seq1-1; idx < seq2; idx++) {
@@ -821,9 +779,6 @@ int mail_index_sync_map(struct mail_inde
}
map = view->map;
- if (view->broken_counters)
- mail_index_view_recalc_counters(view);
-
if (had_dirty)
mail_index_sync_update_hdr_dirty_flag(map);
diff -r 35806800d2bd -r 901a9ba8cff7 src/lib-index/mail-index-view-private.h
--- a/src/lib-index/mail-index-view-private.h Mon Jun 18 01:32:48 2007 +0300
+++ b/src/lib-index/mail-index-view-private.h Mon Jun 18 01:34:17 2007 +0300
@@ -72,7 +72,6 @@ struct mail_index_view {
unsigned int index_sync_view:1;
/* this view is being synced */
unsigned int syncing:1;
- unsigned int broken_counters:1;
};
struct mail_index_view *
diff -r 35806800d2bd -r 901a9ba8cff7 src/lib-index/mail-index-view-sync.c
--- a/src/lib-index/mail-index-view-sync.c Mon Jun 18 01:32:48 2007 +0300
+++ b/src/lib-index/mail-index-view-sync.c Mon Jun 18 01:34:17 2007 +0300
@@ -170,21 +170,6 @@ view_sync_get_expunges(struct mail_index
return 0;
}
-static void mail_index_view_hdr_drop_appends(struct mail_index_view *view,
- struct mail_index_map *map)
-{
- /* Keep message count the same. */
- map->hdr.next_uid = view->hdr.next_uid;
- map->hdr.messages_count = view->hdr.messages_count;
-
- /* Keep the old message flag counts also, although they may be
- somewhat stale already. We just don't want them to be more than
- our old messages_count. */
- map->hdr.recent_messages_count = view->hdr.recent_messages_count;
- map->hdr.seen_messages_count = view->hdr.seen_messages_count;
- map->hdr.deleted_messages_count = view->hdr.deleted_messages_count;
-}
-
#ifdef DEBUG
static void mail_index_view_check(struct mail_index_view *view)
{
@@ -263,9 +248,6 @@ int mail_index_view_sync_begin(struct ma
view->sync_new_map = view->index->map;
view->sync_new_map->refcount++;
- /* since we're syncing everything, the counters get fixed */
- view->broken_counters = FALSE;
-
/* keep the old mapping without expunges until we're
fully synced */
} else {
@@ -276,8 +258,6 @@ int mail_index_view_sync_begin(struct ma
already all the latest changes and there's no need for us
to apply any changes to it. This can only happen if there
hadn't been any expunges. */
- uint32_t old_records_count = view->map->records_count;
-
if (view->map != view->index->map) {
/* Using non-head mapping. We have to apply
transactions to it to get latest changes into it. */
@@ -290,49 +270,27 @@ int mail_index_view_sync_begin(struct ma
old information if another process updated the
index file since. */
if (view->map->mmap_base != NULL) {
+ // FIXME: locking should do this..?..
const struct mail_index_header *hdr;
hdr = view->map->mmap_base;
view->map->hdr = *hdr;
}
- ctx->sync_map_ctx.unreliable_flags =
- !VIEW_IS_SYNCED_TO_SAME(&view->map->hdr,
- view->log_file_expunge_seq,
- view->log_file_expunge_offset);
-
- if (ctx->sync_map_update) {
- /* Copy only the mails that we see currently, since
- we're going to append the new ones when we see
- their transactions. */
- i_assert(view->map->records_count >=
- view->hdr.messages_count);
- view->map->records_count = view->hdr.messages_count;
- }
-
#ifdef DEBUG
- if (!ctx->sync_map_ctx.unreliable_flags) {
- i_assert(view->map->hdr.messages_count ==
- view->hdr.messages_count);
- mail_index_view_check(view);
- }
+ i_assert(view->map->hdr.messages_count ==
+ view->hdr.messages_count);
+ mail_index_view_check(view);
#endif
- map = mail_index_map_clone(view->map);
- view->map->records_count = old_records_count;
- mail_index_unmap(view->index, &view->map);
- view->map = map;
-
- if (ctx->sync_map_update) {
- /* Start the sync using our old view's header.
- The old view->hdr may differ from map->hdr if
- another view sharing the map with us had synced
- itself. */
- i_assert(map->hdr_base == map->hdr_copy_buf->data);
- mail_index_view_hdr_drop_appends(view, map);
+ if (view->map->refcount > 1) {
+ map = mail_index_map_clone(view->map);
+ mail_index_unmap(view->index, &view->map);
+ view->map = map;
+ } else {
+ map = view->map;
}
view->hdr = map->hdr;
-
i_assert(map->records_count == map->hdr.messages_count);
}
@@ -652,8 +610,7 @@ void mail_index_view_sync_end(struct mai
mail_index_view_sync_clean_log_syncs(ctx->view);
#ifdef DEBUG
- if (!view->broken_counters && !ctx->sync_map_ctx.unreliable_flags)
- mail_index_view_check(view);
+ mail_index_view_check(view);
#endif
/* set log view to empty range so unneeded memory gets freed */
diff -r 35806800d2bd -r 901a9ba8cff7 src/lib-index/mail-index-view.c
--- a/src/lib-index/mail-index-view.c Mon Jun 18 01:32:48 2007 +0300
+++ b/src/lib-index/mail-index-view.c Mon Jun 18 01:34:17 2007 +0300
@@ -23,7 +23,6 @@ void mail_index_view_clone(struct mail_i
if (dest->map != NULL)
dest->map->refcount++;
dest->hdr = src->hdr;
- dest->broken_counters = src->broken_counters;
dest->log_file_expunge_seq = src->log_file_expunge_seq;
dest->log_file_expunge_offset = src->log_file_expunge_offset;
@@ -188,8 +187,6 @@ static const struct mail_index_header *
static const struct mail_index_header *
_view_get_header(struct mail_index_view *view)
{
- if (view->broken_counters)
- mail_index_view_recalc_counters(view);
return &view->hdr;
}
More information about the dovecot-cvs
mailing list