mail-transaction-log-private.h revision 2f8da04d700cc23fcd6630226a4866e828b761bd
cc833a7a4e2258afdc834ace4bfe6579820a1df3Timo Sirainen/* Synchronization can take a while sometimes, especially when copying lots of
97cb20eb77d486ef67eac50567e3080faca025c1Timo Sirainen#define MAIL_TRANSACTION_LOG_LOCK_TIMEOUT (3*60)
97cb20eb77d486ef67eac50567e3080faca025c1Timo Sirainen#define MAIL_TRANSACTION_LOG_LOCK_CHANGE_TIMEOUT (3*60)
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainen/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
366eb7178f2c90d97134e0c2d1958f93fcdaba12Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*32)
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainen/* If log is larger than MAX_SIZE, rotate regardless of the time */
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*1024)
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainen#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
863ea896fb31a16d1baec31e57650243b5547db6Timo Sirainen/* Delete .log.2 files older than this many seconds. Don't be too eager,
863ea896fb31a16d1baec31e57650243b5547db6Timo Sirainen older files are useful for QRESYNC and dsync. */
863ea896fb31a16d1baec31e57650243b5547db6Timo Sirainen#define MAIL_TRANSACTION_LOG2_STALE_SECS (60*60*24*2)
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen#define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainen /* refcount=0 is a valid state. files start that way, and they're
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainen freed only when mail_transaction_logs_clean() is called. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* points to the next uncommitted transaction. usually same as EOF. */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen /* highest modseq at sync_offset */
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen /* saved_tail_offset is the offset that was last written to transaction
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen log. max_tail_offset is what should be written to the log the next
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen time a transaction is written. transaction log handling may update
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen max_tail_offset automatically by making it skip external transactions
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen after the last saved offset (to avoid re-reading them unneededly). */
88b8aea03a24ef7a9efc30399080487b7eb03537Timo Sirainen /* don't give warnings about saved_tail_offset shrinking if
88b8aea03a24ef7a9efc30399080487b7eb03537Timo Sirainen sync_offset is less than this. */
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen /* if we've seen _INDEX_[UN9DELETED transaction in this file,
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen this is the offset. otherwise (uoff_t)-1 */
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen uoff_t index_deleted_offset, index_undeleted_offset;
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen struct modseq_cache modseq_cache[LOG_FILE_MODSEQ_CACHE_SIZE];
45e62043058738e294f89504c319d852e25943ccTimo Sirainen /* files is a linked list of all the opened log files. the list is
45e62043058738e294f89504c319d852e25943ccTimo Sirainen sorted by the log file sequence, so that transaction views can use
45e62043058738e294f89504c319d852e25943ccTimo Sirainen them easily. head contains a pointer to the newest log file. */
45e62043058738e294f89504c319d852e25943ccTimo Sirainen struct mail_transaction_log_file *files, *head;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* open_file is used temporarily while opening the log file.
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if _open() failed, it's left there for _create(). */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
6eb30032b4a50c383dea4c9c74342d906de6ad36Timo Sirainen const char *fmt, ...)
bdd7a96c363346f7c38f389791be1487ca08775bTimo Sirainenvoid mail_transaction_log_get_dotlock_set(struct mail_transaction_log *log,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenmail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenmail_transaction_log_file_alloc(struct mail_transaction_log *log,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen const char *path);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid mail_transaction_log_file_free(struct mail_transaction_log_file **file);
b222354c9553cd60b7dd418885e10c0473f73985Timo Sirainenint mail_transaction_log_file_open(struct mail_transaction_log_file *file);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenint mail_transaction_log_file_create(struct mail_transaction_log_file *file,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenint mail_transaction_log_find_file(struct mail_transaction_log *log,
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainen/* Returns 1 if ok, 0 if file is corrupted or offset range is invalid,
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainen -1 if I/O error */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_transaction_log_file_map(struct mail_transaction_log_file *file,
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainenvoid mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_transaction_logs_clean(struct mail_transaction_log *log);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenbool mail_transaction_log_want_rotate(struct mail_transaction_log *log);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenint mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset);
b87a4156eca6dcf6b29c504eb0cb9be2fdb11b63Timo Sirainenint mail_transaction_log_lock_head(struct mail_transaction_log *log);
2f8da04d700cc23fcd6630226a4866e828b761bdTimo Sirainenvoid mail_transaction_log_file_unlock(struct mail_transaction_log_file *file,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainenvoid mail_transaction_update_modseq(const struct mail_transaction_header *hdr,
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenint mail_transaction_log_file_get_highest_modseq_at(