enum mail_index_sync_handler_type type,
const char *reason)
{
+ const char *map_reason;
int ret;
if (index->log->head == NULL || index->indexid == 0) {
}
/* and update the map with the latest changes from transaction log */
- ret = mail_index_sync_map(&index->map, type, TRUE, reason);
+ ret = mail_index_sync_map(&index->map, type, &map_reason);
if (ret != 0)
return ret;
- /* we fsck'd the index. try opening again. */
+ /* fsck the index and try to reopen */
+ mail_index_set_error(index, "Index %s: %s: %s - fscking",
+ index->filepath, reason, map_reason);
+ if (mail_index_fsck(index) < 0)
+ return -1;
+
ret = mail_index_map_latest_file(index, &reason);
if (ret > 0 && index->indexid != 0) {
- ret = mail_index_sync_map(&index->map,
- type, TRUE, reason);
+ ret = mail_index_sync_map(&index->map, type, &map_reason);
+ if (ret == 0) {
+ mail_index_set_error(index, "Index %s: %s: %s",
+ index->filepath, reason, map_reason);
+ }
}
return ret;
}
ret = 0;
} else {
/* sync the map from the transaction log. */
- ret = mail_index_sync_map(&index->map, type, FALSE, "initial mapping");
+ ret = mail_index_sync_map(&index->map, type, &reason);
+ if (ret == 0) {
+ e_debug(index->event,
+ "Couldn't sync map from transaction log: %s - "
+ "reopening index instead",
+ reason);
+ }
}
if (ret == 0) {
void mail_index_sync_map_deinit(struct mail_index_sync_map_ctx *sync_map_ctx);
bool mail_index_sync_map_want_index_reopen(struct mail_index_map *map,
enum mail_index_sync_handler_type type);
-int mail_index_sync_map(struct mail_index_map **map,
- enum mail_index_sync_handler_type type, bool force,
- const char *sync_reason);
+int mail_index_sync_map(struct mail_index_map **_map,
+ enum mail_index_sync_handler_type type,
+ const char **reason_r);
int mail_index_sync_record(struct mail_index_sync_map_ctx *ctx,
const struct mail_transaction_header *hdr,
}
int mail_index_sync_map(struct mail_index_map **_map,
- enum mail_index_sync_handler_type type, bool force,
- const char *sync_reason)
+ enum mail_index_sync_handler_type type,
+ const char **reason_r)
{
struct mail_index_map *map = *_map;
struct mail_index *index = map->index;
i_assert(index->log->head != NULL);
i_assert(index->map == map || type == MAIL_INDEX_SYNC_HANDLER_VIEW);
- i_assert(!force || index->log->head != NULL);
start_offset = type == MAIL_INDEX_SYNC_HANDLER_FILE ?
map->hdr.log_file_tail_offset : map->hdr.log_file_head_offset;
/* I/O failure */
return -1;
}
- if (force) {
- /* the seq/offset is probably broken */
- mail_index_set_error(index, "Index %s: Lost log for "
- "seq=%u offset=%"PRIuUOFF_T": %s "
- "(initial_mapped=%d, reason=%s)", index->filepath,
- map->hdr.log_file_seq, start_offset, reason,
- index->initial_mapped ? 1 : 0, sync_reason);
- (void)mail_index_fsck(index);
- }
- /* can't use it. sync by re-reading index. */
+ /* the seq/offset is probably broken */
+ *reason_r = t_strdup_printf(
+ "Lost log for seq=%u offset=%"PRIuUOFF_T": %s "
+ "(initial_mapped=%d)",
+ map->hdr.log_file_seq, start_offset, reason,
+ index->initial_mapped ? 1 : 0);
return 0;
}