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