mail-transaction-log-private.h revision 88b8aea03a24ef7a9efc30399080487b7eb03537
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainen/* Synchronization can take a while sometimes, especially when copying lots of
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define MAIL_TRANSCATION_LOG_LOCK_TIMEOUT (3*60)
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen#define MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT (3*60)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*32)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen/* If log is larger than MAX_SIZE, rotate regardless of the time */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*1024)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen/* Delete .log.2 files older than this many seconds */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define MAIL_TRANSACTION_LOG2_STALE_SECS (60*30)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* refcount=0 is a valid state. files start that way, and they're
2e03303e721a293d796c0287829396f5caea76eaTimo Sirainen freed only when mail_transaction_logs_clean() is called. */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* points to the next uncommitted transaction. usually same as EOF. */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* highest modseq at sync_offset */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* saved_tail_offset is the offset that was last written to transaction
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen log. max_tail_offset is what should be written to the log the next
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen time a transaction is written. transaction log handling may update
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen max_tail_offset automatically by making it skip external transactions
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen after the last saved offset (to avoid re-reading them unneededly). */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* don't give warnings about saved_tail_offset shrinking if
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen sync_offset is less than this. */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct modseq_cache modseq_cache[LOG_FILE_MODSEQ_CACHE_SIZE];
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* files is a linked list of all the opened log files. the list is
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen sorted by the log file sequence, so that transaction views can use
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen them easily. head contains a pointer to the newest log file. */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct mail_transaction_log_file *files, *head;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* open_file is used temporarily while opening the log file.
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen if _open() failed, it's left there for _create(). */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct dotlock_settings dotlock_settings, new_dotlock_settings;
87b426af6a2365c6840b14281a98c23e903bf28eTimo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
87b426af6a2365c6840b14281a98c23e903bf28eTimo Sirainen const char *fmt, ...)
87b426af6a2365c6840b14281a98c23e903bf28eTimo Sirainenmail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
87b426af6a2365c6840b14281a98c23e903bf28eTimo Sirainenmail_transaction_log_file_alloc(struct mail_transaction_log *log,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *path);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid mail_transaction_log_file_free(struct mail_transaction_log_file **file);
87b426af6a2365c6840b14281a98c23e903bf28eTimo Sirainenint mail_transaction_log_file_open(struct mail_transaction_log_file *file,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint mail_transaction_log_file_create(struct mail_transaction_log_file *file,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint mail_transaction_log_find_file(struct mail_transaction_log *log,
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen/* Returns 1 if ok, 0 if file is corrupted or offset range is invalid,
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen -1 if I/O error */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenint mail_transaction_log_file_map(struct mail_transaction_log_file *file,
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenvoid mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenvoid mail_transaction_logs_clean(struct mail_transaction_log *log);
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenbool mail_transaction_log_want_rotate(struct mail_transaction_log *log);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenint mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset);
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenint mail_transaction_log_lock_head(struct mail_transaction_log *log);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid mail_transaction_log_file_unlock(struct mail_transaction_log_file *file);
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenmail_transaction_header_has_modseq(const struct mail_transaction_header *hdr,
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenint mail_transaction_log_file_get_highest_modseq_at(