# HG changeset patch # User Timo Sirainen # Date 1137626083 -7200 # Node ID fc0b638330a4cbcf4f69dc4377c68958e0f19d8a # Parent 3a2fe49912f3413833347cda67b0ac9ad9404c5a Added mbox_min_index_size setting. diff -r 3a2fe49912f3 -r fc0b638330a4 dovecot-example.conf --- a/dovecot-example.conf Thu Jan 19 01:04:15 2006 +0200 +++ b/dovecot-example.conf Thu Jan 19 01:14:43 2006 +0200 @@ -382,6 +382,10 @@ # aren't immediately visible to other MUAs. #mbox_lazy_writes = yes +# If mbox size is smaller than this (in kilobytes), don't write index files. +# If an index file already exists it's still read, just not updated. +#mbox_min_index_size = 0 + # Maximum dbox file size in kilobytes until it's rotated. #dbox_rotate_size = 2048 diff -r 3a2fe49912f3 -r fc0b638330a4 src/lib-index/mail-index.c --- a/src/lib-index/mail-index.c Thu Jan 19 01:04:15 2006 +0200 +++ b/src/lib-index/mail-index.c Thu Jan 19 01:14:43 2006 +0200 @@ -1393,7 +1393,8 @@ hdr = *index->hdr; else if (ret == 0) { /* doesn't exist, or corrupted */ - if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0) + if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0 && + !MAIL_INDEX_IS_IN_MEMORY(index)) return 0; mail_index_header_init(&hdr); index->hdr = &hdr; @@ -1701,6 +1702,13 @@ /* set the index as being into memory */ i_free_and_null(index->dir); + if (index->map == NULL) { + /* mbox file was never even opened. just mark it as being in + memory and let the caller re-open the index. */ + i_assert(index->fd == -1); + return -1; + } + /* move index map to memory */ map = mail_index_map_clone(index->map, index->map->hdr.record_size); mail_index_unmap(index, &index->map); diff -r 3a2fe49912f3 -r fc0b638330a4 src/lib-storage/index/dbox/dbox-storage.c --- a/src/lib-storage/index/dbox/dbox-storage.c Thu Jan 19 01:04:15 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-storage.c Thu Jan 19 01:14:43 2006 +0200 @@ -296,7 +296,8 @@ mbox->ibox.mail_vfuncs = &dbox_mail_vfuncs; mbox->ibox.is_recent = dbox_is_recent; - if (index_storage_mailbox_init(&mbox->ibox, index, name, flags) < 0) { + if (index_storage_mailbox_init(&mbox->ibox, index, name, flags, + FALSE) < 0) { /* the memory was already freed */ return NULL; } diff -r 3a2fe49912f3 -r fc0b638330a4 src/lib-storage/index/index-storage.c --- a/src/lib-storage/index/index-storage.c Thu Jan 19 01:04:15 2006 +0200 +++ b/src/lib-storage/index/index-storage.c Thu Jan 19 01:14:43 2006 +0200 @@ -311,11 +311,13 @@ int index_storage_mailbox_init(struct index_mailbox *ibox, struct mail_index *index, const char *name, - enum mailbox_open_flags flags) + enum mailbox_open_flags flags, + bool move_to_memory) { struct mail_storage *storage = &ibox->storage->storage; enum mail_index_open_flags index_flags; enum mail_index_lock_method lock_method = 0; + int ret; i_assert(name != NULL); @@ -324,7 +326,7 @@ array_create(&ibox->box.module_contexts, ibox->box.pool, sizeof(void *), 5); - index_flags = MAIL_INDEX_OPEN_FLAG_CREATE; + index_flags = move_to_memory ? 0 : MAIL_INDEX_OPEN_FLAG_CREATE; if ((flags & MAILBOX_OPEN_FAST) != 0) index_flags |= MAIL_INDEX_OPEN_FLAG_FAST; if ((storage->flags & MAIL_STORAGE_FLAG_MMAP_DISABLE) != 0) @@ -355,10 +357,18 @@ ibox->mail_read_mmaped = (storage->flags & MAIL_STORAGE_FLAG_MMAP_MAILS) != 0; - if (mail_index_open(index, index_flags, lock_method) < 0) { - mail_storage_set_index_error(ibox); - index_storage_mailbox_free(&ibox->box); - return -1; + ret = mail_index_open(index, index_flags, lock_method); + if (ret <= 0 || move_to_memory) { + if (mail_index_move_to_memory(index) < 0) { + /* try opening once more. it should be created + directly into memory now. */ + ret = mail_index_open(index, index_flags, lock_method); + if (ret <= 0) { + mail_storage_set_index_error(ibox); + index_storage_mailbox_free(&ibox->box); + return -1; + } + } } ibox->md5hdr_ext_idx = diff -r 3a2fe49912f3 -r fc0b638330a4 src/lib-storage/index/index-storage.h --- a/src/lib-storage/index/index-storage.h Thu Jan 19 01:04:15 2006 +0200 +++ b/src/lib-storage/index/index-storage.h Thu Jan 19 01:14:43 2006 +0200 @@ -114,7 +114,8 @@ int index_storage_mailbox_init(struct index_mailbox *ibox, struct mail_index *index, const char *name, - enum mailbox_open_flags flags); + enum mailbox_open_flags flags, + bool move_to_memory); void index_storage_mailbox_free(struct mailbox *box); bool index_storage_is_readonly(struct mailbox *box); diff -r 3a2fe49912f3 -r fc0b638330a4 src/lib-storage/index/maildir/maildir-storage.c --- a/src/lib-storage/index/maildir/maildir-storage.c Thu Jan 19 01:04:15 2006 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Thu Jan 19 01:14:43 2006 +0200 @@ -437,7 +437,8 @@ mbox->ibox.mail_vfuncs = &maildir_mail_vfuncs; mbox->ibox.is_recent = maildir_is_recent; - if (index_storage_mailbox_init(&mbox->ibox, index, name, flags) < 0) { + if (index_storage_mailbox_init(&mbox->ibox, index, name, flags, + FALSE) < 0) { /* the memory was already freed */ return NULL; } diff -r 3a2fe49912f3 -r fc0b638330a4 src/lib-storage/index/mbox/mbox-storage.c --- a/src/lib-storage/index/mbox/mbox-storage.c Thu Jan 19 01:04:15 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Thu Jan 19 01:14:43 2006 +0200 @@ -479,9 +479,35 @@ return FALSE; } +static bool want_memory_indexes(struct mbox_storage *storage, const char *path) +{ + const char *env; + struct stat st; + unsigned int min_size; + + env = getenv("MBOX_MIN_INDEXED_SIZE"); + if (env == NULL) + return FALSE; + + min_size = strtoul(env, NULL, 10); + if (min_size == 0) + return FALSE; + + if (stat(path, &st) < 0) { + if (errno == ENOENT) + st.st_size = 0; + else { + mail_storage_set_critical(STORAGE(storage), + "stat(%s) failed: %m", path); + return FALSE; + } + } + return st.st_size / 1024 < min_size; +} + static struct mbox_mailbox * mbox_alloc(struct mbox_storage *storage, struct mail_index *index, - const char *name, enum mailbox_open_flags flags) + const char *name, const char *path, enum mailbox_open_flags flags) { struct mbox_mailbox *mbox; pool_t pool; @@ -494,7 +520,8 @@ mbox->ibox.mail_vfuncs = &mbox_mail_vfuncs; mbox->ibox.is_recent = mbox_mail_is_recent; - if (index_storage_mailbox_init(&mbox->ibox, index, name, flags) < 0) { + if (index_storage_mailbox_init(&mbox->ibox, index, name, flags, + want_memory_indexes(storage, path)) < 0) { /* the memory is already freed here, no need to deinit */ return NULL; } @@ -548,7 +575,7 @@ } index = index_storage_alloc(index_dir, path, MBOX_INDEX_PREFIX); - mbox = mbox_alloc(storage, index, name, flags); + mbox = mbox_alloc(storage, index, name, path, flags); if (mbox == NULL) return NULL; @@ -589,7 +616,7 @@ } index = index_storage_alloc(index_dir, path, MBOX_INDEX_PREFIX); - mbox = mbox_alloc(storage, index, name, flags); + mbox = mbox_alloc(storage, index, name, path, flags); if (mbox == NULL) return NULL; diff -r 3a2fe49912f3 -r fc0b638330a4 src/master/mail-process.c --- a/src/master/mail-process.c Thu Jan 19 01:04:15 2006 +0200 +++ b/src/master/mail-process.c Thu Jan 19 01:14:43 2006 +0200 @@ -251,6 +251,8 @@ set->mbox_lock_timeout)); env_put(t_strdup_printf("MBOX_DOTLOCK_CHANGE_TIMEOUT=%u", set->mbox_dotlock_change_timeout)); + env_put(t_strdup_printf("MBOX_MIN_INDEX_SIZE=%u", + set->mbox_min_index_size)); if (set->mail_use_modules && set->mail_modules != NULL && *set->mail_modules != '\0') { diff -r 3a2fe49912f3 -r fc0b638330a4 src/master/master-settings.c --- a/src/master/master-settings.c Thu Jan 19 01:04:15 2006 +0200 +++ b/src/master/master-settings.c Thu Jan 19 01:14:43 2006 +0200 @@ -118,6 +118,7 @@ DEF(SET_STR, mbox_write_locks), DEF(SET_INT, mbox_lock_timeout), DEF(SET_INT, mbox_dotlock_change_timeout), + DEF(SET_INT, mbox_min_index_size), DEF(SET_BOOL, mbox_dirty_syncs), DEF(SET_BOOL, mbox_very_dirty_syncs), DEF(SET_BOOL, mbox_lazy_writes), @@ -319,6 +320,7 @@ MEMBER(mbox_write_locks) "dotlock fcntl", MEMBER(mbox_lock_timeout) 300, MEMBER(mbox_dotlock_change_timeout) 30, + MEMBER(mbox_min_index_size) 0, MEMBER(mbox_dirty_syncs) TRUE, MEMBER(mbox_very_dirty_syncs) FALSE, MEMBER(mbox_lazy_writes) TRUE, diff -r 3a2fe49912f3 -r fc0b638330a4 src/master/master-settings.h --- a/src/master/master-settings.h Thu Jan 19 01:04:15 2006 +0200 +++ b/src/master/master-settings.h Thu Jan 19 01:14:43 2006 +0200 @@ -83,6 +83,7 @@ const char *mbox_write_locks; unsigned int mbox_lock_timeout; unsigned int mbox_dotlock_change_timeout; + unsigned int mbox_min_index_size; bool mbox_dirty_syncs; bool mbox_very_dirty_syncs; bool mbox_lazy_writes;