mail-transaction-log.h revision 894987bf45718f8849cc3898afdfb1ac3cfa2445
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags, v1.2+ */
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen (MAIL_TRANSACTION_EXT_INTRO | MAIL_TRANSACTION_EXT_RESET | \
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE | MAIL_TRANSACTION_EXT_REC_UPDATE)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* since we'll expunge mails based on data read from transaction log,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen try to avoid the possibility of corrupted transaction log expunging
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen messages. this value is ORed to the actual MAIL_TRANSACTION_EXPUNGE
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen flag. if it's not present, assume corrupted log. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Mailbox synchronization noticed this change. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen uint32_t type; /* enum mail_transaction_type */
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen uint8_t modify_type; /* enum modify_type : MODIFY_ADD / MODIFY_REMOVE */
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen /* unsigned char name[];
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen array of { uint32_t uid1, uid2; }
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainen /* unsigned char data[]; */
894987bf45718f8849cc3898afdfb1ac3cfa2445Timo Sirainen /* Don't shrink hdr_size, record_size or record_align but grow them
894987bf45718f8849cc3898afdfb1ac3cfa2445Timo Sirainen if necessary. */
894987bf45718f8849cc3898afdfb1ac3cfa2445Timo Sirainen MAIL_TRANSACTION_EXT_INTRO_FLAG_NO_SHRINK = 0x01
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen /* old extension: set ext_id. don't set name.
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen new extension: ext_id = (uint32_t)-1. give name. */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* unsigned char name[]; */
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen/* these are set for the last ext_intro */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* unsigned char data[]; */
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainen /* unsigned char data[]; */
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainen#define LOG_IS_BEFORE(seq1, offset1, seq2, offset2) \
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainen (((offset1) < (offset2) && (seq1) == (seq2)) || (seq1) < (seq2))
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenmail_transaction_log_alloc(struct mail_index *index);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **log);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Open the transaction log. Returns 1 if ok, 0 if file doesn't exist or it's
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen is corrupted, -1 if there was some I/O error. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenint mail_transaction_log_open(struct mail_transaction_log *log);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Create, or recreate, the transaction log. Returns 0 if ok, -1 if error. */
94aa90d2d17a7aebcda5a4193a62e80ddbb169b7Timo Sirainenint mail_transaction_log_create(struct mail_transaction_log *log, bool reset);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Close all the open transactions log files. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid mail_transaction_log_close(struct mail_transaction_log *log);
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen/* Notify of indexid change */
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainenvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Returns the file seq/offset where the mailbox is currently synced at.
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen Since the log is rotated only when mailbox is fully synced, the sequence
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen points always to the latest file. This function doesn't actually find the
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen latest sync position, so you'll need to use eg. log_view_set() before
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen calling this. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid mail_transaction_log_get_mailbox_sync_pos(struct mail_transaction_log *log,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Set the current mailbox sync position. file_seq must always be the latest
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen log file's sequence. The offset written automatically to the log when
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen other transactions are being written. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid mail_transaction_log_set_mailbox_sync_pos(struct mail_transaction_log *log,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_transaction_log_view_open(struct mail_transaction_log *log);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_transaction_log_view_close(struct mail_transaction_log_view **view);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen/* Set view boundaries. Returns -1 if error, 0 if files are lost, 1 if ok.
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen reset_r=TRUE if the whole index should be reset before applying any
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenint mail_transaction_log_view_set(struct mail_transaction_log_view *view,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen uint32_t min_file_seq, uoff_t min_file_offset,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen uint32_t max_file_seq, uoff_t max_file_offset,
c680a6b35b459045e92814778908da5a93922107Timo Sirainen/* Clear the view. Keep oldest_file_seq log referenced so we don't get
c680a6b35b459045e92814778908da5a93922107Timo Sirainenvoid mail_transaction_log_view_clear(struct mail_transaction_log_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Read next transaction record from current position. The position is updated.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Returns -1 if error, 0 if we're at end of the view, 1 if ok. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_transaction_log_view_next(struct mail_transaction_log_view *view,
5f78b33aa505b17e23cdf27b071a24e127b3db54Timo Sirainen const void **data_r);
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen/* Mark the current view's position to the record returned previously with
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen _log_view_next(). */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenvoid mail_transaction_log_view_mark(struct mail_transaction_log_view *view);
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen/* Seek to previously marked position. */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenvoid mail_transaction_log_view_rewind(struct mail_transaction_log_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the position of the record returned previously with
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_transaction_log_view_next() */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen/* Return the modseq of the change returned previously with _view_next(). */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenmail_transaction_log_view_get_prev_modseq(struct mail_transaction_log_view *view);
c9c24293550541307f1bb41bba4a0fdfe2fa59e0Timo Sirainen/* Returns TRUE if we're at the end of the view window. */
c9c24293550541307f1bb41bba4a0fdfe2fa59e0Timo Sirainenbool mail_transaction_log_view_is_last(struct mail_transaction_log_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Marks the log file in current position to be corrupted. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *fmt, ...)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
93b29720c5141f787bd1861796867e4595c9d084Timo Sirainenvoid mail_transaction_log_views_close(struct mail_transaction_log *log);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Write data to transaction log. This is atomic operation. Sequences in
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen updates[] and expunges[] are relative to given view, they're modified
8a3d609fdd84f5938c82e8e7eeb84a24ab41b317Timo Sirainen to real ones. If nothing is written, log_file_seq_r and log_file_offset_r
8a3d609fdd84f5938c82e8e7eeb84a24ab41b317Timo Sirainen will be set to 0. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_transaction_log_append(struct mail_index_transaction *t,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Lock transaction log for index synchronization. Log cannot be read or
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen written to while it's locked. Returns end offset. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_transaction_log_sync_lock(struct mail_transaction_log *log,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_transaction_log_sync_unlock(struct mail_transaction_log *log);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the current head. Works only when log is locked. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_transaction_log_get_head(struct mail_transaction_log *log,
a050ca9def13949dbaa67bd6574a41c4f397ae26Timo Sirainen/* Returns TRUE if given seq/offset is current head log's rotate point. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool mail_transaction_log_is_head_prev(struct mail_transaction_log *log,
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen/* Move currently opened log head file to memory (called by
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen mail_index_move_to_memory()) */