dovecot-2.1: mdbox: Fixed finding appendable m.* files in alt st...

dovecot at dovecot.org dovecot at dovecot.org
Thu Feb 9 03:44:25 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/6881d8c59d9f
changeset: 14089:6881d8c59d9f
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Feb 09 03:44:09 2012 +0200
description:
mdbox: Fixed finding appendable m.* files in alt storage.

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-file.c |  11 ++++--
 src/lib-storage/index/dbox-multi/mdbox-map.c  |  47 +++++++-------------------
 2 files changed, 20 insertions(+), 38 deletions(-)

diffs (139 lines):

diff -r 2500de8f1f51 -r 6881d8c59d9f src/lib-storage/index/dbox-multi/mdbox-file.c
--- a/src/lib-storage/index/dbox-multi/mdbox-file.c	Thu Feb 09 02:58:36 2012 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-file.c	Thu Feb 09 03:44:09 2012 +0200
@@ -84,7 +84,8 @@
 	}
 }
 
-static void mdbox_file_init_paths(struct mdbox_file *file, const char *fname)
+static void
+mdbox_file_init_paths(struct mdbox_file *file, const char *fname, bool alt)
 {
 	i_free(file->file.primary_path);
 	i_free(file->file.alt_path);
@@ -95,7 +96,8 @@
 			i_strdup_printf("%s/%s", file->storage->alt_storage_dir,
 					fname);
 	}
-	file->file.cur_path = file->file.primary_path;
+	file->file.cur_path = !alt ? file->file.primary_path :
+		file->file.alt_path;
 }
 
 static int mdbox_file_create(struct mdbox_file *file)
@@ -159,7 +161,7 @@
 	file->file_id = file_id;
 	fname = file_id == 0 ? dbox_generate_tmp_filename() :
 		t_strdup_printf(MDBOX_MAIL_FILE_FORMAT, file_id);
-	mdbox_file_init_paths(file, fname);
+	mdbox_file_init_paths(file, fname, FALSE);
 	dbox_file_init(&file->file);
 	if (alt_dir)
 		file->file.cur_path = file->file.alt_path;
@@ -210,7 +212,8 @@
 					  old_path, new_path);
 		return -1;
 	}
-	mdbox_file_init_paths(file, new_fname);
+	mdbox_file_init_paths(file, new_fname,
+			      dbox_file_is_in_alt(&file->file));
 	file->file_id = file_id;
 	array_append(&file->storage->open_files, &file, 1);
 	return 0;
diff -r 2500de8f1f51 -r 6881d8c59d9f src/lib-storage/index/dbox-multi/mdbox-map.c
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c	Thu Feb 09 02:58:36 2012 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.c	Thu Feb 09 03:44:09 2012 +0200
@@ -937,22 +937,21 @@
 }
 
 static int
-mdbox_map_find_first_alt(struct mdbox_map_append_context *ctx,
-			 uint32_t *min_file_id_r, uint32_t *seq_r)
+mdbox_map_find_primary_files(struct mdbox_map_append_context *ctx,
+			     ARRAY_TYPE(seq_range) *file_ids_r)
 {
 	struct mdbox_storage *dstorage = ctx->map->storage;
 	struct mail_storage *storage = &dstorage->storage.storage;
 	DIR *dir;
 	struct dirent *d;
-	const struct mail_index_header *hdr;
-	const struct mdbox_map_mail_index_record *rec;
-	uint32_t seq, file_id, min_file_id = -1U;
+	uint32_t file_id;
 	int ret = 0;
 
 	/* we want to quickly find the latest alt file, but we also want to
-	   avoid accessing the alt storage as much as possible. so we'll do
-	   this by finding the lowest numbered file (n) from primary storage.
-	   hopefully one of n-[1..m] is appendable in alt storage. */
+	   avoid accessing the alt storage as much as possible. typically most
+	   of the older mails would be in alt storage, so we'll just put the
+	   few m.* files in primary storage to checked_file_ids array. other
+	   files are then known to exist in alt storage. */
 	dir = opendir(dstorage->storage_dir);
 	if (dir == NULL) {
 		mail_storage_set_critical(storage,
@@ -968,8 +967,7 @@
 				  &file_id) < 0)
 			continue;
 
-		if (min_file_id > file_id)
-			min_file_id = file_id;
+		seq_range_array_add(file_ids_r, 0, file_id);
 	}
 	if (errno != 0) {
 		mail_storage_set_critical(storage,
@@ -981,22 +979,7 @@
 			"closedir(%s) failed: %m", dstorage->storage_dir);
 		ret = -1;
 	}
-	if (ret < 0)
-		return -1;
-
-	/* find the newest message in alt storage from map view */
-	hdr = mail_index_get_header(ctx->map->view);
-	for (seq = hdr->messages_count; seq > 0; seq--) {
-		if (mdbox_map_lookup_seq(ctx->map, seq, &rec) < 0)
-			return -1;
-
-		if (rec->file_id < min_file_id)
-			break;
-	}
-
-	*min_file_id_r = min_file_id;
-	*seq_r = seq;
-	return 0;
+	return ret;
 }
 
 static int
@@ -1010,7 +993,7 @@
 	const struct mail_index_header *hdr;
 	const struct mdbox_map_mail_index_record *rec;
 	unsigned int backwards_lookup_count;
-	uint32_t seq, seq1, uid, min_file_id;
+	uint32_t seq, seq1, uid;
 	time_t stamp;
 	bool retry_later;
 
@@ -1024,17 +1007,13 @@
 	backwards_lookup_count = 0;
 	t_array_init(&checked_file_ids, 16);
 
-	if (!want_altpath)
-		seq = hdr->messages_count;
-	else {
+	if (want_altpath) {
 		/* we want to save to alt storage. */
-		if (mdbox_map_find_first_alt(ctx, &min_file_id, &seq) < 0)
+		if (mdbox_map_find_primary_files(ctx, &checked_file_ids) < 0)
 			return -1;
-		seq_range_array_add_range(&checked_file_ids,
-					  min_file_id, (uint32_t)-1);
 	}
 
-	for (; seq > 0; seq--) {
+	for (seq = hdr->messages_count; seq > 0; seq--) {
 		if (mdbox_map_lookup_seq(map, seq, &rec) < 0)
 			return -1;
 


More information about the dovecot-cvs mailing list