mail-transaction-log-append.c revision d8a786d2069fab818d0b62cd3eaa3ed08fe7c620
/* Copyright (c) 2003-2010 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "write-full.h"
#include "mail-index-private.h"
#include "mail-transaction-log-private.h"
enum mail_transaction_type type,
{
struct mail_transaction_header hdr;
if (size == 0)
return;
if (type == MAIL_TRANSACTION_EXPUNGE ||
}
static int
{
/* first we need to truncate this latest write so that log syncing
doesn't break */
"ftruncate()");
}
return -1;
return 0;
}
{
struct mail_transaction_header *hdr;
return 0;
}
return 0;
}
/* size will be written later once everything is in disk */
i_assert(first_size != 0);
file->sync_offset) < 0) {
/* write failure, fallback to in-memory indexes. */
"pwrite_full()");
return log_buffer_move_to_memory(ctx);
}
/* now that the whole transaction has been written, rewrite the first
record's size so the transaction becomes visible */
file->sync_offset +
"pwrite_full()");
return log_buffer_move_to_memory(ctx);
}
if ((ctx->want_fsync &&
"fdatasync()");
return log_buffer_move_to_memory(ctx);
}
}
/* FIXME: when we're relying on O_APPEND and someone else wrote a
transaction, we'll need to wait for it to commit its transaction.
if it crashes before doing that, we'll need to overwrite it with
a dummy record */
/* 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 */
}
return 0;
}
static void
{
struct mail_transaction_header_update *u;
struct mail_transaction_header *hdr;
unsigned char update_data[sizeof(*u) + sizeof(offset)];
/* FIXME: when we remove exclusive log locking, we
can't rely on this. then write non-changed offset + check
real offset + rewrite the new offset if other transactions
weren't written in the middle */
}
return;
u = buffer_append_space_unsafe(&buf, sizeof(*u));
}
static int
{
/* there is some garbage at the end of the transaction log
(eg. previous write failed). remove it so reader doesn't
break because of it. */
if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
}
}
}
if (ctx->append_sync_offset)
if (log_buffer_write(ctx) < 0)
return -1;
return 0;
}
struct mail_transaction_log_append_ctx **ctx_r)
{
struct mail_transaction_log_append_ctx *ctx;
if (!index->log_locked) {
return -1;
}
return 0;
}
{
int ret = 0;
if (!index->log_locked)
return ret;
}