]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index, mmap_disable=yes: Save data also to memory after appending to transaction...
authorTimo Sirainen <tss@iki.fi>
Fri, 14 May 2010 14:20:58 +0000 (16:20 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 14 May 2010 14:20:58 +0000 (16:20 +0200)
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.

--HG--
branch : HEAD

src/lib-index/mail-transaction-log-append.c

index f2c7960e884543abc4bfa7150a567b962c584b4a..55b896aac855e5b5c45f2c4254567036d6f5c301 100644 (file)
@@ -98,6 +98,7 @@ static int log_buffer_write(struct mail_transaction_log_append_ctx *ctx)
 
        /* 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 @@ static int log_buffer_write(struct mail_transaction_log_append_ctx *ctx)
           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;
 }