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)
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
19557f192d37cd54a1a090a8a26d9d47265e4413Aki Tuomi after the last saved offset (to avoid re-reading them needlessly). */
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);
c0d1bfc45e224251cb549de8d8804861e8acb517Timo Sirainen/* Returns 1 if log was opened, 0 if it didn't exist or was already open,
c0d1bfc45e224251cb549de8d8804861e8acb517Timo Sirainen -1 if error. */
c0d1bfc45e224251cb549de8d8804861e8acb517Timo Sirainenint mail_transaction_log_file_open(struct mail_transaction_log_file *file,
c0d1bfc45e224251cb549de8d8804861e8acb517Timo Sirainen const char **reason_r);
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,
6321d9d33937c7fc13a8ff04c220a9e377efeeb8Timo Sirainen const char **reason_r);
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,
ce9d23c7c1e621398d2572a1d95171136f7ef6a2Timo Sirainen const char **reason_r);
5b809b97673fb0a73aa5b9d82122612d699f6c5bTimo Sirainenint mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file *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);
6ded8819b9002150a95a7615e4f64f091c250464Timo 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,
92dab926b2f2270057b40a907a00cf8eb2309ed6Timo Sirainen unsigned int version);
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenint mail_transaction_log_file_get_highest_modseq_at(
a0c8af555ec481ab12c2a99518cf7b20debd1627Timo Sirainen const char **error_r);