mail-transaction-log.h revision 0c909e3461607eadcd66f4eac69b7f34e37fccf1
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint64_t initial_modseq; /* v1.1+ (note: log's major/minor version) */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t compat_flags; /* enum mail_index_header_compat_flags, v1.2+ */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t unused2; /* so that this struct is 64bit aligned */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch (MAIL_TRANSACTION_EXT_INTRO | MAIL_TRANSACTION_EXT_RESET | \
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_HDR_UPDATE | MAIL_TRANSACTION_EXT_REC_UPDATE | \
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* since we'll expunge mails based on data read from transaction log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch try to avoid the possibility of corrupted transaction log expunging
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch messages. this value is ORed to the actual MAIL_TRANSACTION_EXPUNGE*
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch flag. if it's not present, assume corrupted log. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* Mailbox synchronization noticed this change. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t type; /* enum mail_transaction_type */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t modify_type; /* enum modify_type : MODIFY_ADD / MODIFY_REMOVE */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char name[];
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch array of { uint32_t uid1, uid2; }
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char data[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* Don't shrink hdr_size, record_size or record_align but grow them
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch if necessary. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_INTRO_FLAG_NO_SHRINK = 0x01
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* old extension: set ext_id. don't set name.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch new extension: ext_id = (uint32_t)-1. give name. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char name[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* these are set for the last ext_intro */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char data[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char data[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define LOG_IS_BEFORE(seq1, offset1, seq2, offset2) \
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch (((offset1) < (offset2) && (seq1) == (seq2)) || (seq1) < (seq2))
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_alloc(struct mail_index *index);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_free(struct mail_transaction_log **log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Open the transaction log. Returns 1 if ok, 0 if file doesn't exist or it's
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch is corrupted, -1 if there was some I/O error. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_open(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Create, or recreate, the transaction log. Returns 0 if ok, -1 if error. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_create(struct mail_transaction_log *log, bool reset);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Close all the open transactions log files. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_close(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Notify of indexid change */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns the file seq/offset where the mailbox is currently synced at.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch Since the log is rotated only when mailbox is fully synced, the sequence
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch points always to the latest file. This function doesn't actually find the
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch latest sync position, so you'll need to use eg. log_view_set() before
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch calling this. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_get_mailbox_sync_pos(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Set the current mailbox sync position. file_seq must always be the latest
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch log file's sequence. The offset written automatically to the log when
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch other transactions are being written. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_set_mailbox_sync_pos(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_open(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_close(struct mail_transaction_log_view **view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Set view boundaries. Returns -1 if error, 0 if files are lost, 1 if ok.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch reset_r=TRUE if the whole index should be reset before applying any
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_view_set(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t min_file_seq, uoff_t min_file_offset,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t max_file_seq, uoff_t max_file_offset,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Clear the view. Keep oldest_file_seq and newer log files referenced so we
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch don't get desynced. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_clear(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Read next transaction record from current position. The position is updated.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch Returns -1 if error, 0 if we're at end of the view, 1 if ok. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_view_next(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const void **data_r);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Mark the current view's position to the record returned previously with
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch _log_view_next(). */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_mark(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Seek to previously marked position. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_rewind(struct mail_transaction_log_view *view);
0afd9a9acab584e770ffcd6a0e1e02e2d18d360aJosef 'Jeff' Sipek/* Returns the position of the record returned previously with
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch mail_transaction_log_view_next() */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Return the modseq of the change returned previously with _view_next(). */
c4588e66e80482994cf0fbc45251cb8e9db6404dJosef 'Jeff' Sipekmail_transaction_log_view_get_prev_modseq(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns TRUE if we're at the end of the view window. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschbool mail_transaction_log_view_is_last(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Marks the log file in current position to be corrupted. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *fmt, ...)
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_views_close(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_append_begin(struct mail_index *index, bool external,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct mail_transaction_log_append_ctx **ctx_r);
4a1af46c8ed806fbc51bedfaf79c019b0afa3aa6Stephan Boschvoid mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx,
a46221f25bbaf310f73f77bec24f2d3f0c80d4feStephan Boschint mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx);
a46221f25bbaf310f73f77bec24f2d3f0c80d4feStephan Bosch/* Lock transaction log for index synchronization. Log cannot be read or
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch written to while it's locked. Returns end offset. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_sync_lock(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_sync_unlock(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns the current head. Works only when log is locked. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_get_head(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns TRUE if given seq/offset is current head log's rotate point. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschbool mail_transaction_log_is_head_prev(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Move currently opened log head file to memory (called by
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch mail_index_move_to_memory()) */