Mercurial > dovecot > core-2.2
changeset 13750:fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 23 Nov 2011 19:01:28 +0200 |
parents | 90ecb83a9ca7 |
children | db51a627d726 |
files | src/lib-index/mail-index-modseq.c src/lib-index/mail-index-sync.c src/lib-index/mail-index-view-sync.c src/lib-index/mail-transaction-log.h |
diffstat | 4 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-modseq.c Wed Nov 23 17:01:51 2011 +0200 +++ b/src/lib-index/mail-index-modseq.c Wed Nov 23 19:01:28 2011 +0200 @@ -426,8 +426,8 @@ I_MAX(1, hdr->log_seq), hdr->log_offset, end_seq, end_offset, &reset); - if (ret == 0) { - /* missing files - try with only the last file */ + if (ret <= 0) { + /* missing files / error - try with only the last file */ ret = mail_transaction_log_view_set(ctx->log_view, end_seq, 0, end_seq, end_offset, &reset);
--- a/src/lib-index/mail-index-sync.c Wed Nov 23 17:01:51 2011 +0200 +++ b/src/lib-index/mail-index-sync.c Wed Nov 23 19:01:28 2011 +0200 @@ -315,15 +315,17 @@ ret = mail_transaction_log_view_set(view->log_view, start_file_seq, start_file_offset, log_seq, log_offset, &reset); - if (ret <= 0) { + if (ret < 0) + return -1; + if (ret == 0) { /* either corrupted or the file was deleted for some reason. either way, we can't go forward */ mail_index_set_error(view->index, "Unexpected transaction log desync with index %s", view->index->filepath); - return -1; + return 0; } - return 0; + return 1; } int mail_index_sync_begin(struct mail_index *index, @@ -468,8 +470,13 @@ /* we wish to see all the changes from last mailbox sync position to the end of the transaction log */ - if (mail_index_sync_set_log_view(ctx->view, hdr->log_file_seq, - hdr->log_file_tail_offset) < 0) { + ret = mail_index_sync_set_log_view(ctx->view, hdr->log_file_seq, + hdr->log_file_tail_offset); + if (ret < 0) { + mail_index_sync_rollback(&ctx); + return -1; + } + if (ret == 0) { /* if a log file is missing, there's nothing we can do except to skip over it. fix the problem with fsck and try again. */ mail_index_fsck_locked(index);
--- a/src/lib-index/mail-index-view-sync.c Wed Nov 23 17:01:51 2011 +0200 +++ b/src/lib-index/mail-index-view-sync.c Wed Nov 23 19:01:28 2011 +0200 @@ -500,7 +500,7 @@ view->map->hdr.log_file_head_offset; if (mail_transaction_log_view_set(view->log_view, seq, offset, - seq, offset, &reset) < 0) + seq, offset, &reset) <= 0) return -1; view->inconsistent = FALSE; return 0;
--- a/src/lib-index/mail-transaction-log.h Wed Nov 23 17:01:51 2011 +0200 +++ b/src/lib-index/mail-transaction-log.h Wed Nov 23 19:01:28 2011 +0200 @@ -210,8 +210,8 @@ mail_transaction_log_view_open(struct mail_transaction_log *log); void mail_transaction_log_view_close(struct mail_transaction_log_view **view); -/* Set view boundaries. Returns -1 if error, 0 if files are lost, 1 if ok. - reset_r=TRUE if the whole index should be reset before applying any +/* Set view boundaries. Returns -1 if error, 0 if files are lost or corrupted, + 1 if ok. reset_r=TRUE if the whole index should be reset before applying any changes. */ int mail_transaction_log_view_set(struct mail_transaction_log_view *view, uint32_t min_file_seq, uoff_t min_file_offset,