mail-transaction-log.h revision 6ded8819b9002150a95a7615e4f64f091c250464
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen uint64_t initial_modseq; /* v1.1+ (note: log's major/minor version) */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags, v1.2+ */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t unused2; /* so that this struct is 64bit aligned */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE32 = 0x00010000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_INDEX_UNDELETED = 0x00040000,
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen MAIL_TRANSACTION_ATTRIBUTE_UPDATE = 0x00100000,
b215322367dbd94df3e2e4bb643b53460e6adc51Timo Sirainen (MAIL_TRANSACTION_EXT_INTRO | MAIL_TRANSACTION_EXT_RESET | \
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE | MAIL_TRANSACTION_EXT_HDR_UPDATE32 | \
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_REC_UPDATE | MAIL_TRANSACTION_EXT_ATOMIC_INC)
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* since we'll expunge mails based on data read from transaction log,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen try to avoid the possibility of corrupted transaction log expunging
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen messages. this value is ORed to the actual MAIL_TRANSACTION_EXPUNGE*
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen flag. if it's not present, assume corrupted log. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* Mailbox storage backend synchronization noticed this change. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* This change syncs the state with another mailbox (dsync),
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen i.e. the change isn't something that a user requested locally. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t type; /* enum mail_transaction_type */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* don't use uint64_t here. it adds extra 32 bits of paddiong and also
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen causes problems with CPUs that require alignment */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t modify_type; /* enum modify_type : MODIFY_ADD / MODIFY_REMOVE */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* unsigned char name[];
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen array of { uint32_t uid1, uid2; }
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* unsigned char data[]; */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen /* Don't shrink hdr_size, record_size or record_align but grow them
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen if necessary. */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen MAIL_TRANSACTION_EXT_INTRO_FLAG_NO_SHRINK = 0x01
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen /* old extension: set ext_id. don't set name.
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen new extension: ext_id = (uint32_t)-1. give name. */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen /* unsigned char name[]; */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen/* these are set for the last ext_intro */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen /* unsigned char data[]; */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* this _update32 version should have been the only ext_hdr_update,
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen but since 16bit integers were originally used for now we'll just use this
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen only when actually needed to be backwards compatible. */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen /* unsigned char data[]; */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* unsigned char data[]; */
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen /* same as mail_index_transaction->sync_transaction */
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen /* same as mail_index_transaction->tail_offset_changed */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen#define LOG_IS_BEFORE(seq1, offset1, seq2, offset2) \
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen (((offset1) < (offset2) && (seq1) == (seq2)) || (seq1) < (seq2))
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_alloc(struct mail_index *index);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **log);
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen/* Open the transaction log. Returns 1 if ok, 0 if file doesn't exist or it's
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen is corrupted, -1 if there was some I/O error. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_open(struct mail_transaction_log *log);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Create, or recreate, the transaction log. Returns 0 if ok, -1 if error. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_create(struct mail_transaction_log *log, bool reset);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Close all the open transactions log files. */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_close(struct mail_transaction_log *log);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Notify of indexid change */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Returns the file seq/offset where the mailbox is currently synced at.
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen Since the log is rotated only when mailbox is fully synced, the sequence
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen points always to the latest file. This function doesn't actually find the
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen latest sync position, so you'll need to use eg. log_view_set() before
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen calling this. */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_get_mailbox_sync_pos(struct mail_transaction_log *log,
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen/* Set the current mailbox sync position. file_seq must always be the latest
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen log file's sequence. The offset written automatically to the log when
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen other transactions are being written. */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_set_mailbox_sync_pos(struct mail_transaction_log *log,
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenmail_transaction_log_view_open(struct mail_transaction_log *log);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_view_close(struct mail_transaction_log_view **view);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Set view boundaries. Returns -1 if error, 0 if files are lost or corrupted,
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen 1 if ok. reset_r=TRUE if the whole index should be reset before applying any
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenint mail_transaction_log_view_set(struct mail_transaction_log_view *view,
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen uint32_t min_file_seq, uoff_t min_file_offset,
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen uint32_t max_file_seq, uoff_t max_file_offset,
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen/* Scan through all of the log files that we can find.
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen Returns -1 if error, 0 if ok. */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainenint mail_transaction_log_view_set_all(struct mail_transaction_log_view *view);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Clear the view. If oldest_file_seq > 0, keep it and newer log files
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen referenced so we don't get desynced. */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_view_clear(struct mail_transaction_log_view *view,
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Read next transaction record from current position. The position is updated.
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen Returns -1 if error, 0 if we're at end of the view, 1 if ok. */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenint mail_transaction_log_view_next(struct mail_transaction_log_view *view,
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen const void **data_r);
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen/* Mark the current view's position to the record returned previously with
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen _log_view_next(). */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_view_mark(struct mail_transaction_log_view *view);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Seek to previously marked position. */
1c3dc4c08ced3948f52c3c6c171ed77310b2cbfdTimo Sirainenvoid mail_transaction_log_view_rewind(struct mail_transaction_log_view *view);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Returns the position of the record returned previously with
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen mail_transaction_log_view_next() */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
1c3dc4c08ced3948f52c3c6c171ed77310b2cbfdTimo Sirainen/* Return the modseq of the change returned previously with _view_next(). */
1c3dc4c08ced3948f52c3c6c171ed77310b2cbfdTimo Sirainenmail_transaction_log_view_get_prev_modseq(struct mail_transaction_log_view *view);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Returns TRUE if we're at the end of the view window. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenbool mail_transaction_log_view_is_last(struct mail_transaction_log_view *view);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Marks the log file in current position to be corrupted. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen const char *fmt, ...)
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_append_begin(struct mail_index *index,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen struct mail_transaction_log_append_ctx **ctx_r);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenvoid mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Lock transaction log for index synchronization. Log cannot be read or
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen written to while it's locked. Returns end offset. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_sync_lock(struct mail_transaction_log *log,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenvoid mail_transaction_log_sync_unlock(struct mail_transaction_log *log,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Returns the current head. Works only when log is locked. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenvoid mail_transaction_log_get_head(struct mail_transaction_log *log,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Returns the current tail from which all files are open to head. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenvoid mail_transaction_log_get_tail(struct mail_transaction_log *log,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Returns TRUE if given seq/offset is current head log's rotate point. */
b215322367dbd94df3e2e4bb643b53460e6adc51Timo Sirainenbool mail_transaction_log_is_head_prev(struct mail_transaction_log *log,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Move currently opened log head file to memory (called by
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen mail_index_move_to_memory()) */
7e8bfb5b0af9606f131fc440e61f3752da335ac9Timo Sirainenvoid mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
7e8bfb5b0af9606f131fc440e61f3752da335ac9Timo Sirainen/* Returns mtime of the transaction log head file.
7e8bfb5b0af9606f131fc440e61f3752da335ac9Timo Sirainen If it doesn't exist, mtime_r is set to 0. */
b215322367dbd94df3e2e4bb643b53460e6adc51Timo Sirainenint mail_transaction_log_get_mtime(struct mail_transaction_log *log,
b215322367dbd94df3e2e4bb643b53460e6adc51Timo Sirainen/* Unlink transaction log files */