index->map = mail_index_map_alloc(index);
/* first try updating the existing mapping from transaction log. */
- if (index->initial_mapped && !index->reopen_main_index) {
- /* we're not creating/opening the index.
- sync this as a view from transaction log. */
- ret = mail_index_sync_map(&index->map, type, FALSE, "initial mapping");
- } else {
+ if (!index->initial_mapped || index->reopen_main_index) {
+ /* index is being created/opened for the first time */
+ ret = 0;
+ } else if (mail_index_sync_map_want_index_reopen(index->map, type)) {
+ /* it's likely more efficient to reopen the index file than
+ sync from the transaction log. */
ret = 0;
+ } else {
+ /* sync the map from the transaction log. */
+ ret = mail_index_sync_map(&index->map, type, FALSE, "initial mapping");
}
if (ret == 0) {
struct mail_index_view *view,
enum mail_index_sync_handler_type type);
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);
}
#endif
-static bool
-mail_index_sync_map_want_index_reopen(struct mail_index_map *map,
- enum mail_index_sync_handler_type type)
+bool mail_index_sync_map_want_index_reopen(struct mail_index_map *map,
+ enum mail_index_sync_handler_type type)
{
struct mail_index *index = map->index;
int ret;
bool had_dirty, reset;
+ i_assert(index->log->head != NULL);
i_assert(index->map == map || type == MAIL_INDEX_SYNC_HANDLER_VIEW);
i_assert(!force || index->log->head != NULL);
- if (mail_index_sync_map_want_index_reopen(map, type))
- return 0;
-
- i_assert(index->log->head != NULL);
start_offset = type == MAIL_INDEX_SYNC_HANDLER_FILE ?
map->hdr.log_file_tail_offset : map->hdr.log_file_head_offset;