From: Timo Sirainen Date: Sun, 5 Feb 2023 18:47:08 +0000 (+0200) Subject: lib-index: Don't update max_tail_offset if write to dovecot.index.log fails X-Git-Tag: 2.3.21~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=830a7db7c030dc831ba11873b09a1c937f095ab3;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Don't update max_tail_offset if write to dovecot.index.log fails The max_tail_offset didn't actually increase in that situation. This fixes wrongly updating mail_index_header.log_file_tail_offset after write to dovecot.index.log failed (due to out of disk space), which in turn can cause some unexpected errors. --- diff --git a/src/lib-index/mail-transaction-log-append.c b/src/lib-index/mail-transaction-log-append.c index 662f72a9f9..7ed2984deb 100644 --- a/src/lib-index/mail-transaction-log-append.c +++ b/src/lib-index/mail-transaction-log-append.c @@ -84,10 +84,6 @@ static int log_buffer_write(struct mail_transaction_log_append_ctx *ctx) return log_buffer_move_to_memory(ctx); } - i_assert(!ctx->sync_includes_this || - file->sync_offset + ctx->output->used == - file->max_tail_offset); - if ((ctx->want_fsync && file->log->index->set.fsync_mode != FSYNC_MODE_NEVER) || file->log->index->set.fsync_mode == FSYNC_MODE_ALWAYS) { @@ -110,6 +106,8 @@ static int log_buffer_write(struct mail_transaction_log_append_ctx *ctx) ctx->output->used); } file->sync_offset += ctx->output->used; + if (ctx->sync_includes_this) + file->max_tail_offset = file->sync_offset; return 0; } @@ -123,6 +121,7 @@ log_append_sync_offset_if_needed(struct mail_transaction_log_append_ctx *ctx) buffer_t buf; unsigned char update_data[sizeof(*u) + sizeof(offset)]; + offset = file->max_tail_offset; if (!ctx->index_sync_transaction) { /* this is a non-syncing transaction. update the tail offset only if we're already writing something else to transaction @@ -148,7 +147,7 @@ log_append_sync_offset_if_needed(struct mail_transaction_log_append_ctx *ctx) can't rely on this. then write non-changed offset + check real offset + rewrite the new offset if other transactions weren't written in the middle */ - file->max_tail_offset += ctx->output->used + + offset = file->max_tail_offset + ctx->output->used + sizeof(*hdr) + sizeof(*u) + sizeof(offset); ctx->sync_includes_this = TRUE; } else { @@ -156,7 +155,6 @@ log_append_sync_offset_if_needed(struct mail_transaction_log_append_ctx *ctx) we may need to update the tail offset even if we don't have anything else to do. */ } - offset = file->max_tail_offset; if (file->last_read_hdr_tail_offset == offset) return;