mail-transaction-log-private.h revision 366eb7178f2c90d97134e0c2d1958f93fcdaba12
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef __MAIL_TRANSACTION_LOG_VIEW_H
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen#define __MAIL_TRANSACTION_LOG_VIEW_H
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen#include "file-dotlock.h"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen#include "mail-transaction-log.h"
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*32)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen/* If log is larger than MAX_SIZE, rotate regardless of the time */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*1024)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen#define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstruct mail_transaction_log_file {
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_transaction_log *log;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_transaction_log_file *next;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* refcount=0 is a valid state. files start that way, and they're
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen freed only when mail_transaction_logs_clean() is called. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen int refcount;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen char *filepath;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen int fd;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen ino_t st_ino;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen dev_t st_dev;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen time_t last_mtime;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen uoff_t last_size;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_transaction_log_header hdr;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen buffer_t *buffer;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen uoff_t buffer_offset;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen void *mmap_base;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen size_t mmap_size;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* points to the next uncommitted transaction. usually same as EOF. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen uoff_t sync_offset;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* saved_tail_offset is the offset that was last written to transaction
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen log. max_tail_offset is what should be written to the log the next
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen time a transaction is written. transaction log handling may update
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen max_tail_offset automatically by making it skip external transactions
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen after the last saved offset (to avoid re-reading them unneededly). */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen uoff_t saved_tail_offset, max_tail_offset;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct file_lock *file_lock;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen unsigned int locked:1;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen};
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstruct mail_transaction_log {
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_index *index;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_transaction_log_view *views;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* files is a linked list of all the opened log files. the list is
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen sorted by the log file sequence, so that transaction views can use
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen them easily. head contains a pointer to the newest log file. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_transaction_log_file *files, *head;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* open_file is used temporarily while opening the log file.
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen if _open() failed, it's left there for _create(). */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_transaction_log_file *open_file;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen unsigned int dotlock_count;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct dotlock_settings dotlock_settings, new_dotlock_settings;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct dotlock *dotlock;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen};
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenvoid
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen const char *fmt, ...)
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen __attr_format__(2, 3);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstruct mail_transaction_log_file *
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenmail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstruct mail_transaction_log_file *
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenmail_transaction_log_file_alloc(struct mail_transaction_log *log,
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen const char *path);
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainenvoid mail_transaction_log_file_free(struct mail_transaction_log_file **file);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
12e5ac049bd74f8b98d9dc62adcb0bf3217beef6Martti Rannanjärviint mail_transaction_log_file_open(struct mail_transaction_log_file *file,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen bool check_existing);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenint mail_transaction_log_file_create(struct mail_transaction_log_file *file);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainenint mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainenint mail_transaction_log_find_file(struct mail_transaction_log *log,
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen uint32_t file_seq,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen struct mail_transaction_log_file **file_r);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen/* Returns 1 if ok, 0 if file is corrupted or offset range is invalid,
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen -1 if I/O error */
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainenint mail_transaction_log_file_map(struct mail_transaction_log_file *file,
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen uoff_t start_offset, uoff_t end_offset);
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainenvoid mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen *file);
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainenvoid mail_transaction_logs_clean(struct mail_transaction_log *log);
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainen
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainenbool mail_transaction_log_want_rotate(struct mail_transaction_log *log);
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainenint mail_transaction_log_rotate(struct mail_transaction_log *log);
12e5ac049bd74f8b98d9dc62adcb0bf3217beef6Martti Rannanjärviint mail_transaction_log_lock_head(struct mail_transaction_log *log);
498eecf19b1b408d5321cb048697744d7cee90b2Timo Sirainenvoid mail_transaction_log_file_unlock(struct mail_transaction_log_file *file);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen#endif
11d72d764c104b4f1a8c44ec8a5fee420517645bTimo Sirainen