dovecot-2.2: lib-index: Try to minimize race conditions while co...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Oct 7 15:58:44 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/bd55bdba0e75
changeset: 17903:bd55bdba0e75
user: Timo Sirainen <tss at iki.fi>
date: Tue Oct 07 18:58:01 2014 +0300
description:
lib-index: Try to minimize race conditions while compressing cache.
There are some unavoidable race conditions, but try to keep their time
window as small as possible.
diffstat:
src/lib-index/mail-cache-compress.c | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diffs (60 lines):
diff -r 8c84b69e7f69 -r bd55bdba0e75 src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c Tue Oct 07 18:47:09 2014 +0300
+++ b/src/lib-index/mail-cache-compress.c Tue Oct 07 18:58:01 2014 +0300
@@ -93,17 +93,23 @@
buffer_append_zero(ctx->buffer, 4 - (field->size & 3));
}
-static uint32_t
-get_next_file_seq(struct mail_cache *cache, struct mail_index_view *view)
+static uint32_t get_next_file_seq(struct mail_cache *cache)
{
const struct mail_index_ext *ext;
+ struct mail_index_view *view;
uint32_t file_seq;
+ /* make sure we look up the latest reset_id */
+ if (mail_index_refresh(cache->index) < 0)
+ return -1;
+
+ view = mail_index_view_open(cache->index);
ext = mail_index_view_get_ext(view, cache->ext_id);
file_seq = ext != NULL ? ext->reset_id + 1 : (uint32_t)ioloop_time;
if (cache->hdr != NULL && file_seq <= cache->hdr->file_seq)
file_seq = cache->hdr->file_seq + 1;
+ mail_index_view_close(&view);
return file_seq != 0 ? file_seq : 1;
}
@@ -166,6 +172,10 @@
unsigned int i, used_fields_count, orig_fields_count, record_count;
time_t max_drop_time;
+ /* get the latest info on fields */
+ if (mail_cache_header_fields_read(cache) < 0)
+ return -1;
+
view = mail_index_transaction_get_view(trans);
cache_view = mail_cache_view_open(cache, view);
output = o_stream_create_fd_file(fd, 0, FALSE);
@@ -175,7 +185,7 @@
hdr.minor_version = MAIL_CACHE_MINOR_VERSION;
hdr.compat_sizeof_uoff_t = sizeof(uoff_t);
hdr.indexid = cache->index->indexid;
- hdr.file_seq = get_next_file_seq(cache, view);
+ hdr.file_seq = get_next_file_seq(cache);
o_stream_nsend(output, &hdr, sizeof(hdr));
memset(&ctx, 0, sizeof(ctx));
@@ -353,10 +363,6 @@
unsigned int i, count;
int fd, ret;
- /* get the latest info on fields */
- if (mail_cache_header_fields_read(cache) < 0)
- return -1;
-
old_mask = umask(cache->index->mode ^ 0666);
fd = file_dotlock_open(&cache->dotlock_settings, cache->filepath,
DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock);
More information about the dovecot-cvs
mailing list