#include "mail-index-private.h"
#include "mail-index-sync-private.h"
#include "mail-transaction-log-private.h"
+#include "mail-index-modseq.h"
#include "ioloop.h"
static void mail_index_map_copy_hdr(struct mail_index_map *map,
index->main_index_hdr_log_file_seq = new_map->hdr.log_file_seq;
index->main_index_hdr_log_file_tail_offset =
new_map->hdr.log_file_tail_offset;
+ mail_index_modseq_hdr_snapshot_update(new_map);
mail_index_unmap(&index->map);
index->map = new_map;
return mail_index_map_get_modseq_header(index->map) != NULL;
}
+void mail_index_modseq_hdr_snapshot_update(struct mail_index_map *map)
+{
+ const struct mail_index_modseq_header *hdr =
+ mail_index_map_get_modseq_header(map);
+ if (hdr != NULL)
+ map->modseq_hdr_snapshot = *hdr;
+ else
+ i_zero(&map->modseq_hdr_snapshot);
+}
+
const struct mail_index_modseq_header *
mail_index_map_get_modseq_header(struct mail_index_map *map)
{
struct mail_index_map_modseq;
struct mail_index_sync_map_ctx;
-struct mail_index_modseq_header {
- /* highest used modseq */
- uint64_t highest_modseq;
- /* last tracked log file position */
- uint32_t log_seq;
- uint32_t log_offset;
-};
-
void mail_index_modseq_init(struct mail_index *index);
+/* Save a copy of the current modseq header to map->modseq_hdr_snapshot. This
+ is expected to be called when reading the dovecot.index header before any
+ changes are applied on top of it from dovecot.index.log. */
+void mail_index_modseq_hdr_snapshot_update(struct mail_index_map *map);
+
const struct mail_index_modseq_header *
mail_index_map_get_modseq_header(struct mail_index_map *map);
uint64_t mail_index_map_modseq_get_highest(struct mail_index_map *map);
mail_index_expunge_handler_t *expunge_handler;
};
+struct mail_index_modseq_header {
+ /* highest used modseq */
+ uint64_t highest_modseq;
+ /* last tracked log file position */
+ uint32_t log_seq;
+ uint32_t log_offset;
+};
+
struct mail_index_record_map {
ARRAY(struct mail_index_map *) maps;
ARRAY(unsigned int) keyword_idx_map; /* file -> index */
+ struct mail_index_modseq_header modseq_hdr_snapshot;
+
struct mail_index_record_map *rec_map;
};
#include "lib.h"
#include "mail-index-private.h"
+#include "mail-index-modseq.h"
#include "mail-transaction-log-private.h"
static struct modseq_cache *
cur_modseq = cache->highest_modseq;
}
+ /* See if we can use the "modseq" header in dovecot.index to further
+ reduce how much we have to scan. */
+ const struct mail_index_modseq_header *modseq_hdr =
+ file->log->index->map == NULL ? NULL :
+ &file->log->index->map->modseq_hdr_snapshot;
+ if (modseq_hdr != NULL &&
+ modseq_hdr->log_seq == file->hdr.file_seq &&
+ modseq_hdr->log_offset <= offset &&
+ modseq_hdr->log_offset >= cur_offset) {
+ cur_offset = modseq_hdr->log_offset;
+ cur_modseq = modseq_hdr->highest_modseq;
+ }
+
ret = mail_transaction_log_file_map(file, cur_offset, offset, &reason);
if (ret <= 0) {
*error_r = t_strdup_printf(