mail-transaction-log.h revision 6ded8819b9002150a95a7615e4f64f091c250464
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef MAIL_TRANSACTION_LOG_H
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen#define MAIL_TRANSACTION_LOG_H
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen#include "mail-index.h"
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen#define MAIL_TRANSACTION_LOG_SUFFIX ".log"
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen#define MAIL_TRANSACTION_LOG_MAJOR_VERSION 1
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen#define MAIL_TRANSACTION_LOG_MINOR_VERSION 2
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_log_header {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t major_version;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t minor_version;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint16_t hdr_size;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t indexid;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t file_seq;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t prev_file_seq;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t prev_file_offset;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t create_stamp;
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen uint64_t initial_modseq; /* v1.1+ (note: log's major/minor version) */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags, v1.2+ */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t unused[3];
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t unused2; /* so that this struct is 64bit aligned */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenenum mail_transaction_type {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXPUNGE = 0x00000001,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_APPEND = 0x00000002,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_FLAG_UPDATE = 0x00000004,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_HEADER_UPDATE = 0x00000020,
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen MAIL_TRANSACTION_EXT_INTRO = 0x00000040,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_RESET = 0x00000080,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE = 0x00000100,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_REC_UPDATE = 0x00000200,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_KEYWORD_UPDATE = 0x00000400,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_KEYWORD_RESET = 0x00000800,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_ATOMIC_INC = 0x00001000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXPUNGE_GUID = 0x00002000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_MODSEQ_UPDATE = 0x00008000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE32 = 0x00010000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_INDEX_DELETED = 0x00020000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_INDEX_UNDELETED = 0x00040000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_BOUNDARY = 0x00080000,
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen MAIL_TRANSACTION_ATTRIBUTE_UPDATE = 0x00100000,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen MAIL_TRANSACTION_TYPE_MASK = 0x0fffffff,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
2200adee458ca662d32b5ec0e01d8c5cba0cc0a8Timo Sirainen#define MAIL_TRANSACTION_EXT_MASK \
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
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 MAIL_TRANSACTION_EXPUNGE_PROT = 0x0000cd90,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* Mailbox storage backend synchronization noticed this change. */
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen MAIL_TRANSACTION_EXTERNAL = 0x10000000,
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. */
35ef661bd85c64834e3e34eeeb3c393b81108760Timo Sirainen MAIL_TRANSACTION_SYNC = 0x20000000
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
35ef661bd85c64834e3e34eeeb3c393b81108760Timo Sirainenstruct mail_transaction_header {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t size;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t type; /* enum mail_transaction_type */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_modseq_update {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t uid;
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 uint32_t modseq_low32;
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainen uint32_t modseq_high32;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_expunge {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t uid1, uid2;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_expunge_guid {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t uid;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen guid_128_t guid_128;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_flag_update {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t uid1, uid2;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t add_flags;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t remove_flags;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t modseq_inc_flag;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t padding;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_keyword_update {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t modify_type; /* enum modify_type : MODIFY_ADD / MODIFY_REMOVE */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint8_t padding;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint16_t name_size;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* unsigned char name[];
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen array of { uint32_t uid1, uid2; }
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_keyword_reset {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t uid1, uid2;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_header_update {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint16_t offset;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint16_t size;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* unsigned char data[]; */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenenum {
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
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen};
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenstruct mail_transaction_ext_intro {
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen /* old extension: set ext_id. don't set name.
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen new extension: ext_id = (uint32_t)-1. give name. */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint32_t ext_id;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t reset_id;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint32_t hdr_size;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint16_t record_size;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint16_t record_align;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint16_t flags;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint16_t name_size;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen /* unsigned char name[]; */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen};
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainenstruct mail_transaction_ext_reset {
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint32_t new_reset_id;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint8_t preserve_data;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint8_t unused_padding[3];
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen};
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen/* these are set for the last ext_intro */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainenstruct mail_transaction_ext_hdr_update {
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint16_t offset;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint16_t size;
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen /* unsigned char data[]; */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen};
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. */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainenstruct mail_transaction_ext_hdr_update32 {
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint32_t offset;
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen uint32_t size;
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen /* unsigned char data[]; */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen};
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_ext_rec_update {
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint32_t uid;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen /* unsigned char data[]; */
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen};
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenstruct mail_transaction_ext_atomic_inc {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t uid;
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen int32_t diff;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_boundary {
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uint32_t size;
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_log_append_ctx {
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen struct mail_transaction_log *log;
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen buffer_t *output;
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen enum mail_transaction_type trans_flags;
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen uint64_t new_highest_modseq;
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen unsigned int transaction_count;
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen /* same as mail_index_transaction->sync_transaction */
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen unsigned int index_sync_transaction:1;
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen /* same as mail_index_transaction->tail_offset_changed */
8c3872c26b18421d62c52cbfe0b81b1d79239f89Timo Sirainen unsigned int tail_offset_changed:1;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen unsigned int sync_includes_this:1;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen unsigned int want_fsync:1;
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen};
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen#define LOG_IS_BEFORE(seq1, offset1, seq2, offset2) \
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen (((offset1) < (offset2) && (seq1) == (seq2)) || (seq1) < (seq2))
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenstruct mail_transaction_log *
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_alloc(struct mail_index *index);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **log);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
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
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen/* Notify of indexid change */
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen
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 uint32_t *file_seq_r,
e18e90938ffd9e31c796c405404be0b7dcd5c807Timo Sirainen uoff_t *file_offset_r);
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 Sirainen uint32_t file_seq,
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen uoff_t file_offset);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainenstruct mail_transaction_log_view *
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
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 Sirainen changes. */
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,
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen bool *reset_r, const char **reason_r);
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 uint32_t oldest_file_seq);
31fd39a3a3d544b1a8afb9aef07f180d0d40fda2Timo Sirainen
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 struct mail_transaction_header **hdr_r,
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
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Returns the position of the record returned previously with
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen mail_transaction_log_view_next() */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenvoid
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t *file_seq_r,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uoff_t *file_offset_r);
1c3dc4c08ced3948f52c3c6c171ed77310b2cbfdTimo Sirainen/* Return the modseq of the change returned previously with _view_next(). */
1c3dc4c08ced3948f52c3c6c171ed77310b2cbfdTimo Sirainenuint64_t
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);
1c3dc4c08ced3948f52c3c6c171ed77310b2cbfdTimo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen/* Marks the log file in current position to be corrupted. */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenvoid
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen const char *fmt, ...)
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen ATTR_FORMAT(2, 3);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenbool
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenmail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_append_begin(struct mail_index *index,
b215322367dbd94df3e2e4bb643b53460e6adc51Timo Sirainen enum mail_transaction_type flags,
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 Sirainen enum mail_transaction_type type,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen const void *data, size_t size);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx);
b10c3f9ed997748fdbb03b9daadc8c31eed02120Timo Sirainen
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 Sirainen const char *lock_reason,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen uint32_t *file_seq_r, uoff_t *file_offset_r);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenvoid mail_transaction_log_sync_unlock(struct mail_transaction_log *log,
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen const char *lock_reason);
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 uint32_t *file_seq_r, uoff_t *file_offset_r);
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 uint32_t *file_seq_r);
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,
b3070aca2aa0dbdcc7f30e6e2bb1f0455127a343Timo Sirainen uint32_t file_seq, uoff_t file_offset);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
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 time_t *mtime_r);
b215322367dbd94df3e2e4bb643b53460e6adc51Timo Sirainen/* Unlink transaction log files */
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainenint mail_transaction_log_unlink(struct mail_transaction_log *log);
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen#endif
c8593b070319d0ff83f8d6c4b5ed5abf2d578a06Timo Sirainen