mail-index-sync-update.c revision 89b7d6ce9266288c156e3513f5798680f1e33572
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina/* Copyright (c) 2004-2014 Dovecot authors, see the included COPYING file */
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina/* If we have less than this many bytes to sync from log file, don't bother
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina reading the main index */
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina#define MAIL_INDEX_SYNC_MIN_READ_INDEX_SIZE 2048
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březinamail_index_sync_update_log_offset(struct mail_index_sync_map_ctx *ctx,
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina mail_transaction_log_view_get_prev_pos(ctx->view->log_view,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina /* handling lost changes in view syncing */
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina if (prev_offset == ctx->ext_intro_end_offset &&
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina /* previous transaction was an extension introduction.
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina we probably came here from
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina mail_index_sync_ext_reset(). if there are any more
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina views which want to continue syncing it needs the
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina intro. so back up a bit more.
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina don't do this in case the last transaction in the
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina log is the extension intro, so we don't keep trying
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina to sync it over and over again. */
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina i_assert(ctx->view->index->log->head->hdr.file_seq == prev_seq);
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březinastatic void mail_index_sync_replace_map(struct mail_index_sync_map_ctx *ctx,
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina mail_index_sync_update_log_offset(ctx, view->map, FALSE);
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina if (ctx->type != MAIL_INDEX_SYNC_HANDLER_VIEW)
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březina mail_index_modseq_sync_map_replaced(ctx->modseq_ctx);
4e5d19f659d8c545c4ed3c307c95cfe4f2ca33cbPavel Březinamail_index_sync_move_to_private_memory(struct mail_index_sync_map_ctx *ctx)
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina if (!MAIL_INDEX_MAP_IS_IN_MEMORY(ctx->view->map))
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina mail_index_map_move_to_memory(ctx->view->map);
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina mail_index_modseq_sync_map_replaced(ctx->modseq_ctx);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinamail_index_sync_get_atomic_map(struct mail_index_sync_map_ctx *ctx)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina (void)mail_index_sync_move_to_private_memory(ctx);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina mail_index_record_map_move_to_private(ctx->view->map);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina mail_index_modseq_sync_map_replaced(ctx->modseq_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinamail_index_header_update_counts(struct mail_index_header *hdr,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **error_r)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (((old_flags ^ new_flags) & MAIL_SEEN) != 0) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina /* different seen-flag */
132e477d69e07e02fe6e4d668c0bb6226206474aPavel Březina if (hdr->seen_messages_count >= hdr->messages_count) {
8fe171bf5a7a570591418e6548105f1d5a0097b3Pavel Březina if (++hdr->seen_messages_count == hdr->messages_count)
8fe171bf5a7a570591418e6548105f1d5a0097b3Pavel Březina hdr->first_unseen_uid_lowwater = hdr->next_uid;
8fe171bf5a7a570591418e6548105f1d5a0097b3Pavel Březina if (((old_flags ^ new_flags) & MAIL_DELETED) != 0) {
8fe171bf5a7a570591418e6548105f1d5a0097b3Pavel Březina /* different deleted-flag */
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina if (hdr->deleted_messages_count > hdr->messages_count) {
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina hdr->deleted_messages_count > hdr->messages_count) {
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina hdr->first_deleted_uid_lowwater = hdr->next_uid;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinamail_index_sync_header_update_counts_all(struct mail_index_sync_map_ctx *ctx,
62ebed8582285bd24efba92b9a06366511507946Pavel Březina unsigned int i, count;
62ebed8582285bd24efba92b9a06366511507946Pavel Březina maps = array_get(&ctx->view->map->rec_map->maps, &count);
9e9ad4cb181c6c0ec70caacfb31319753f889e98Pavel Březina for (i = 0; i < count; i++) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (mail_index_header_update_counts(&maps[i]->hdr,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina mail_index_sync_set_corrupted(ctx, "%s", error);
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březinamail_index_sync_header_update_counts(struct mail_index_sync_map_ctx *ctx,
&error) < 0)
unsigned int i, count;
for (i = 0; i < count; i++) {
return FALSE;
return FALSE;
return TRUE;
unsigned int i, count;
for (i = 0; i < count; i++) {
for (i = count; i > 0; i--) {
void *ret;
return ret;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
const struct mail_transaction_modseq_update *u,
unsigned int size)
int ret;
for (; u < end; u++) {
if (u->uid == 0)
seq = 0;
u->modseq_low32;
if (ret < 0) {
void *dest;
if (!MAIL_TRANSACTION_FLAG_UPDATE_IS_INTERNAL(u)) {
/* we're not modifying any counted/lowwatered flags */
const void *data)
int ret = 0;
case MAIL_TRANSACTION_APPEND: {
if (ret <= 0)
case MAIL_TRANSACTION_EXPUNGE:
case MAIL_TRANSACTION_FLAG_UPDATE: {
if (ret <= 0)
case MAIL_TRANSACTION_HEADER_UPDATE: {
if (ret <= 0)
case MAIL_TRANSACTION_EXT_INTRO: {
if (ret <= 0)
case MAIL_TRANSACTION_EXT_RESET: {
case MAIL_TRANSACTION_EXT_HDR_UPDATE: {
if (ret <= 0)
if (ret <= 0)
case MAIL_TRANSACTION_EXT_REC_UPDATE: {
unsigned int i, record_size;
if (ret <= 0)
case MAIL_TRANSACTION_EXT_ATOMIC_INC: {
if (ret <= 0)
case MAIL_TRANSACTION_KEYWORD_UPDATE: {
case MAIL_TRANSACTION_KEYWORD_RESET: {
case MAIL_TRANSACTION_MODSEQ_UPDATE: {
return ret;
const void *data)
int ret;
T_BEGIN {
} T_END;
return ret;
#ifdef DEBUG
del++;
seen++;
const void *tdata;
int ret;
if (ret <= 0) {
if (had_dirty)
if (reset) {
&tdata)) > 0) {
if (had_dirty)
#ifdef DEBUG