]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Don't update max_tail_offset if write to dovecot.index.log fails
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sun, 5 Feb 2023 18:47:08 +0000 (20:47 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 15 Jun 2023 17:21:25 +0000 (17:21 +0000)
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.

src/lib-index/mail-transaction-log-append.c

index 662f72a9f97a23e447bab3b1515f4a51acc61cf4..7ed2984deb2daf0dd1eda7fd450d80edae90e00d 100644 (file)
@@ -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;