mail-transaction-log.c revision fe5799cb926d65e895d7916d1ecacf5d09ac11e6
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2003-2017 Dovecot authors, see the included COPYING file */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkmail_transaction_log_set_head(struct mail_transaction_log *log,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk i_assert(log->files->next != NULL || log->files == file);
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainenmail_transaction_log_alloc(struct mail_index *index)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstatic void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk uint32_t log2_rotate_time = log->index->map->hdr.log2_rotate_time;
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk ioloop_time - (time_t)log2_rotate_time >= (time_t)log->index->log_rotate_log2_stale_secs &&
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk if (log2_rotate_time != log->index->map->hdr.log2_rotate_time) {
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* Write this as part of the next sync's transaction. We're
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk here because we're already opening a sync lock, so it'll
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk always happen. It's also required especially with mdbox map
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk index, which doesn't like changes done outside syncing. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk log->index->pending_log2_rotate_time = log2_rotate_time;
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkint mail_transaction_log_open(struct mail_transaction_log *log)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk log->filepath = i_strconcat(log->index->filepath,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* these settings aren't available at alloc() time, so we need to
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk set them here: */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk (log->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk mail_transaction_log_file_free(&log->open_file);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk file = mail_transaction_log_file_alloc(log, log->filepath);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk if ((ret = mail_transaction_log_file_open(file, &reason)) <= 0) {
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* leave the file for _create() */
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainenint mail_transaction_log_create(struct mail_transaction_log *log, bool reset)
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi file = mail_transaction_log_file_alloc_in_memory(log);
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi file = mail_transaction_log_file_alloc(log, log->filepath);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* remember what file we tried to open. if someone else created
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk a new file, use it instead of recreating it */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi if (mail_transaction_log_file_create(file, reset) < 0) {
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkvoid mail_transaction_log_close(struct mail_transaction_log *log)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk mail_transaction_log_file_free(&log->open_file);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkvoid mail_transaction_log_free(struct mail_transaction_log **_log)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkint mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk if (!log->index->initial_mapped && log->files != NULL &&
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* we couldn't read dovecot.index and we don't have the first
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk .log file, so just start from scratch */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk log->filepath = i_strconcat(log->index->filepath,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk return mail_transaction_log_file_move_to_memory(log->head);
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi file = mail_transaction_log_file_alloc_in_memory(log);
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomivoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log)
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi for (file = log->files; file != NULL; file = file->next) {
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi "indexid changed: %u -> %u",
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk log->head->hdr.indexid != log->index->indexid) {
633a1bf10559b9a8d85bfab662fa2a7ba97d45baAki Tuomivoid mail_transaction_logs_clean(struct mail_transaction_log *log)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* remove only files from the beginning. this way if a view has
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk referenced an old file, it can still find the new files even if
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk there aren't any references to it currently. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk for (file = log->files; file != NULL; file = next) {
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi /* sanity check: we shouldn't have locked refcount=0 files */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk i_assert(log->head == NULL || log->files != NULL);
return TRUE;
return TRUE;
return FALSE;
int ret;
if (reset) {
if (ret == 0) {
const char **reason_r)
const char **reason_r)
const char *reason;
int ret;
return ret;
const char *lock_reason)
const char *reason;
int ret = 0;
if (ret < 0)
return ret;
const char *lock_reason,
const char *reason;
const char *lock_reason)
*mtime_r = 0;