mail-index-sync-update.c revision 3da614c39dd29f536c485089e67839b4cf89fed3
2435290e44809a9e6036dbb2701933c44cb0b0e7Stephan Bosch/* Copyright (c) 2004-2007 Dovecot authors, see the included COPYING file */
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen/* If we have less than this many bytes to sync from log file, don't bother
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen reading the main index */
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen#define MAIL_INDEX_SYNC_MIN_READ_INDEX_SIZE 2048
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenmail_index_sync_update_log_offset(struct mail_index_sync_map_ctx *ctx,
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen mail_transaction_log_view_get_prev_pos(ctx->view->log_view,
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (prev_offset == ctx->ext_intro_end_offset &&
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen /* previous transaction was an extension introduction.
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen we probably came here from
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen mail_index_sync_ext_reset(). if there are any more
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen views which want to continue syncing it needs the
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen intro. so back up a bit more.
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen don't do this in case the last transaction in the
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen log is the extension intro, so we don't keep trying
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen to sync it over and over again. */
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen i_assert(ctx->view->index->log->head->hdr.file_seq == prev_seq);
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainenstatic void mail_index_sync_replace_map(struct mail_index_sync_map_ctx *ctx,
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen mail_index_sync_update_log_offset(ctx, view->map, FALSE);
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (ctx->type != MAIL_INDEX_SYNC_HANDLER_VIEW)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainenmail_index_sync_move_to_private_memory(struct mail_index_sync_map_ctx *ctx)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (!MAIL_INDEX_MAP_IS_IN_MEMORY(ctx->view->map))
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen mail_index_map_move_to_memory(ctx->view->map);
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainenmail_index_sync_get_atomic_map(struct mail_index_sync_map_ctx *ctx)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen mail_index_record_map_move_to_private(ctx->view->map);
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainenmail_index_header_update_counts(struct mail_index_header *hdr,
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen const char **error_r)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (((old_flags ^ new_flags) & MAIL_SEEN) != 0) {
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen /* different seen-flag */
5329bb264c32fa887e53063ff53272160cb8d7e8Timo Sirainen if (hdr->seen_messages_count >= hdr->messages_count) {
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (++hdr->seen_messages_count == hdr->messages_count)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen hdr->first_unseen_uid_lowwater = hdr->next_uid;
5329bb264c32fa887e53063ff53272160cb8d7e8Timo Sirainen if (((old_flags ^ new_flags) & MAIL_DELETED) != 0) {
5329bb264c32fa887e53063ff53272160cb8d7e8Timo Sirainen /* different deleted-flag */
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (hdr->deleted_messages_count > hdr->messages_count) {
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen hdr->deleted_messages_count > hdr->messages_count) {
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen hdr->first_deleted_uid_lowwater = hdr->next_uid;
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenmail_index_sync_header_update_counts_all(struct mail_index_sync_map_ctx *ctx,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen unsigned int i, count;
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen maps = array_get(&ctx->view->map->rec_map->maps, &count);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen for (i = 0; i < count; i++) {
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (mail_index_header_update_counts(&maps[i]->hdr,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen mail_index_sync_set_corrupted(ctx, "%s", error);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenmail_index_sync_header_update_counts(struct mail_index_sync_map_ctx *ctx,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen mail_index_sync_header_update_counts_all(ctx, uid, old_flags,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (mail_index_header_update_counts(&ctx->view->map->hdr,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen mail_index_sync_set_corrupted(ctx, "%s", error);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenmail_index_header_update_lowwaters(struct mail_index_sync_map_ctx *ctx,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen unsigned int i, count;
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen maps = array_get(&ctx->view->map->rec_map->maps, &count);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen for (i = 0; i < count; i++) {
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen uid < maps[i]->hdr.first_deleted_uid_lowwater)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen maps[i]->hdr.first_deleted_uid_lowwater = uid;
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainensync_expunge_call_handlers(struct mail_index_sync_map_ctx *ctx,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen unsigned int i, count;
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen /* call expunge handlers only when syncing index file */
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (ctx->type != MAIL_INDEX_SYNC_HANDLER_FILE)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (!array_is_created(&ctx->expunge_handlers))
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen eh = array_get(&ctx->expunge_handlers, &count);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen rec = MAIL_INDEX_MAP_IDX(ctx->view->map, seq1-1);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainensync_expunge(const struct mail_transaction_expunge *e, unsigned int count,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen unsigned int i;
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen for (i = 0; i < count; i++, e++) {
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (!mail_index_lookup_seq_range(ctx->view, e->uid1, e->uid2,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen /* everything expunged already */
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen mail_index_sync_header_update_counts(ctx, rec->uid,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (sync_expunge_call_handlers(ctx, seq1, seq2) < 0)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen /* @UNSAFE */
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenvoid mail_index_sync_write_seq_update(struct mail_index_sync_map_ctx *ctx,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenstatic int sync_append(const struct mail_index_record *rec,
/* we're not modifying any counted/lowwatered flags */
const void *data)
int ret = 0;
t_push();
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)
case MAIL_TRANSACTION_EXT_REC_UPDATE: {
unsigned int i, record_size;
if (ret <= 0)
case MAIL_TRANSACTION_KEYWORD_UPDATE: {
case MAIL_TRANSACTION_KEYWORD_RESET: {
i_unreached();
t_pop();
return ret;
#ifdef DEBUG
del++;
seen++;
const void *tdata;
int ret;
if (!force) {
if (ret <= 0) {
if (had_dirty) {
if (reset) {
&tdata)) > 0) {
if (had_dirty)
#ifdef DEBUG