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