dovecot-2.0: lib-index, mmap_disable=yes: Save data also to memo...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 14 17:21:02 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/664d1b2f6b46
changeset: 11314:664d1b2f6b46
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 14 16:20:58 2010 +0200
description:
lib-index, mmap_disable=yes: Save data also to memory after appending to transaction log.
This seems to fix a bug at least with CentOS 4.8 kernel (2.6.9-89.0.25.ELsmp)
where after a write() a read() didn't realize that data was written, so it
returned EOF too early.

Of course, this change also improves performance since it avoids re-reading
the same data that was just written.

diffstat:

 src/lib-index/mail-transaction-log-append.c |  12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diffs (29 lines):

diff -r 361157623f2a -r 664d1b2f6b46 src/lib-index/mail-transaction-log-append.c
--- a/src/lib-index/mail-transaction-log-append.c	Fri May 14 16:18:03 2010 +0200
+++ b/src/lib-index/mail-transaction-log-append.c	Fri May 14 16:20:58 2010 +0200
@@ -98,6 +98,7 @@
 
 	/* now that the whole transaction has been written, rewrite the first
 	   record's size so the transaction becomes visible */
+	hdr->size = first_size;
 	if (pwrite_full(file->fd, &first_size, sizeof(uint32_t),
 			file->sync_offset +
 			offsetof(struct mail_transaction_header, size)) < 0) {
@@ -123,6 +124,17 @@
 	   if it crashes before doing that, we'll need to overwrite it with
 	   a dummy record */
 
+	if (file->mmap_base == NULL) {
+		/* we're reading from a file. avoid re-reading the data that
+		   we just wrote. this is also important for some NFS clients,
+		   which for some reason sometimes can't read() this data we
+		   just wrote in the same process */
+		i_assert(file->buffer != NULL);
+		i_assert(file->buffer_offset +
+			 file->buffer->used == file->sync_offset);
+		buffer_append(file->buffer, ctx->output->data,
+			      ctx->output->used);
+	}
 	file->sync_offset += ctx->output->used;
 	return 0;
 }


More information about the dovecot-cvs mailing list