mail-transaction-log.h revision 0fa842717a8b163252e55c229c37ca0c5d7ff056
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef MAIL_TRANSACTION_LOG_H
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#define MAIL_TRANSACTION_LOG_H
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
47e0598840ecffa364ebed523e06939e22738f06Timo Sirainen#include "mail-index.h"
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#define MAIL_TRANSACTION_LOG_SUFFIX ".log"
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#define MAIL_TRANSACTION_LOG_MAJOR_VERSION 1
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#define MAIL_TRANSACTION_LOG_MINOR_VERSION 2
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenstruct mail_transaction_log_header {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t major_version;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t minor_version;
1d738cce754bc64bbc66d3355ebdaf3f6eac55f1Timo Sirainen uint16_t hdr_size;
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen
bdd7a96c363346f7c38f389791be1487ca08775bTimo Sirainen uint32_t indexid;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t file_seq;
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen uint32_t prev_file_seq;
f9f30736bc6e4cf535085824e7e124506fe2dbbbTimo Sirainen uint32_t prev_file_offset;
ce9d23c7c1e621398d2572a1d95171136f7ef6a2Timo Sirainen uint32_t create_stamp;
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen uint64_t initial_modseq; /* v1.1+ (note: log's major/minor version) */
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags, v1.2+ */
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen uint8_t unused[3];
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen uint32_t unused2; /* so that this struct is 64bit aligned */
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen};
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainenenum mail_transaction_type {
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen MAIL_TRANSACTION_EXPUNGE = 0x00000001,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_APPEND = 0x00000002,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_FLAG_UPDATE = 0x00000004,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_HEADER_UPDATE = 0x00000020,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_EXT_INTRO = 0x00000040,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_EXT_RESET = 0x00000080,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE = 0x00000100,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_EXT_REC_UPDATE = 0x00000200,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_KEYWORD_UPDATE = 0x00000400,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_KEYWORD_RESET = 0x00000800,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_EXT_ATOMIC_INC = 0x00001000,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_EXPUNGE_GUID = 0x00002000,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_MODSEQ_UPDATE = 0x00008000,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE32 = 0x00010000,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_INDEX_DELETED = 0x00020000,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_INDEX_UNDELETED = 0x00040000,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_BOUNDARY = 0x00080000,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_TYPE_MASK = 0x000fffff,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen#define MAIL_TRANSACTION_EXT_MASK \
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen (MAIL_TRANSACTION_EXT_INTRO | MAIL_TRANSACTION_EXT_RESET | \
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE | MAIL_TRANSACTION_EXT_HDR_UPDATE32 | \
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_EXT_REC_UPDATE | MAIL_TRANSACTION_EXT_ATOMIC_INC)
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen /* since we'll expunge mails based on data read from transaction log,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen try to avoid the possibility of corrupted transaction log expunging
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen messages. this value is ORed to the actual MAIL_TRANSACTION_EXPUNGE*
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen flag. if it's not present, assume corrupted log. */
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_EXPUNGE_PROT = 0x0000cd90,
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen /* Mailbox storage backend synchronization noticed this change. */
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen MAIL_TRANSACTION_EXTERNAL = 0x10000000,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* This change syncs the state with another mailbox (dsync),
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen i.e. the change isn't something that a user requested locally. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen MAIL_TRANSACTION_SYNC = 0x20000000
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_header {
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen uint32_t size;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t type; /* enum mail_transaction_type */
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_modseq_update {
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen uint32_t uid;
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen /* don't use uint64_t here. it adds extra 32 bits of paddiong and also
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainen causes problems with CPUs that require alignment */
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainen uint32_t modseq_low32;
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainen uint32_t modseq_high32;
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainen};
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_expunge {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t uid1, uid2;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_expunge_guid {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t uid;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen guid_128_t guid_128;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_flag_update {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t uid1, uid2;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t add_flags;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t remove_flags;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t modseq_inc_flag;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t padding;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstruct mail_transaction_keyword_update {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t modify_type; /* enum modify_type : MODIFY_ADD / MODIFY_REMOVE */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen uint8_t padding;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint16_t name_size;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* unsigned char name[];
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen array of { uint32_t uid1, uid2; }
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen};
da4376093d4e1b26b14ea1e945689fb7056fe0a0Timo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_keyword_reset {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t uid1, uid2;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_header_update {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint16_t offset;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint16_t size;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* unsigned char data[]; */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenenum {
6307d76096764e66bddc63d4a3e5a1aa19cc528fJosef 'Jeff' Sipek /* Don't shrink hdr_size, record_size or record_align but grow them
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen if necessary. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen MAIL_TRANSACTION_EXT_INTRO_FLAG_NO_SHRINK = 0x01
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen};
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_ext_intro {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* old extension: set ext_id. don't set name.
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen new extension: ext_id = (uint32_t)-1. give name. */
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen uint32_t ext_id;
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen uint32_t reset_id;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t hdr_size;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint16_t record_size;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint16_t record_align;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint16_t flags;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint16_t name_size;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* unsigned char name[]; */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstruct mail_transaction_ext_reset {
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint32_t new_reset_id;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t preserve_data;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t unused_padding[3];
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen};
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen/* these are set for the last ext_intro */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct mail_transaction_ext_hdr_update {
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint16_t offset;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint16_t size;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen /* unsigned char data[]; */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen};
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen/* this _update32 version should have been the only ext_hdr_update,
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen but since 16bit integers were originally used for now we'll just use this
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen only when actually needed to be backwards compatible. */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenstruct mail_transaction_ext_hdr_update32 {
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint32_t offset;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint32_t size;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen /* unsigned char data[]; */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen};
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenstruct mail_transaction_ext_rec_update {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t uid;
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen /* unsigned char data[]; */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen};
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenstruct mail_transaction_ext_atomic_inc {
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint32_t uid;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen int32_t diff;
0bf3eac1110a902e7ec7e695c64e8e46c114e623Timo Sirainen};
0bf3eac1110a902e7ec7e695c64e8e46c114e623Timo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenstruct mail_transaction_boundary {
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint32_t size;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen};
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenstruct mail_transaction_log_append_ctx {
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen struct mail_transaction_log *log;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen buffer_t *output;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen enum mail_transaction_type trans_flags;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen uint64_t new_highest_modseq;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen unsigned int append_sync_offset:1;
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen unsigned int sync_includes_this:1;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen unsigned int want_fsync:1;
f153a2cec0319f549388d28f8cfd4d50229d1132Timo Sirainen};
f153a2cec0319f549388d28f8cfd4d50229d1132Timo Sirainen
f153a2cec0319f549388d28f8cfd4d50229d1132Timo Sirainen#define LOG_IS_BEFORE(seq1, offset1, seq2, offset2) \
f153a2cec0319f549388d28f8cfd4d50229d1132Timo Sirainen (((offset1) < (offset2) && (seq1) == (seq2)) || (seq1) < (seq2))
f153a2cec0319f549388d28f8cfd4d50229d1132Timo Sirainen
dffa503fd4ce31334346e539496084c80a2d8d37Timo Sirainenstruct mail_transaction_log *
dffa503fd4ce31334346e539496084c80a2d8d37Timo Sirainenmail_transaction_log_alloc(struct mail_index *index);
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **log);
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen/* Open the transaction log. Returns 1 if ok, 0 if file doesn't exist or it's
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen is corrupted, -1 if there was some I/O error. */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenint mail_transaction_log_open(struct mail_transaction_log *log);
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen/* Create, or recreate, the transaction log. Returns 0 if ok, -1 if error. */
ce9d23c7c1e621398d2572a1d95171136f7ef6a2Timo Sirainenint mail_transaction_log_create(struct mail_transaction_log *log, bool reset);
f9f30736bc6e4cf535085824e7e124506fe2dbbbTimo Sirainen/* Close all the open transactions log files. */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenvoid mail_transaction_log_close(struct mail_transaction_log *log);
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen/* Notify of indexid change */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Returns the file seq/offset where the mailbox is currently synced at.
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen Since the log is rotated only when mailbox is fully synced, the sequence
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen points always to the latest file. This function doesn't actually find the
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen latest sync position, so you'll need to use eg. log_view_set() before
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen calling this. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenvoid mail_transaction_log_get_mailbox_sync_pos(struct mail_transaction_log *log,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t *file_seq_r,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uoff_t *file_offset_r);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Set the current mailbox sync position. file_seq must always be the latest
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen log file's sequence. The offset written automatically to the log when
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen other transactions are being written. */
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainenvoid mail_transaction_log_set_mailbox_sync_pos(struct mail_transaction_log *log,
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen uint32_t file_seq,
ce9d23c7c1e621398d2572a1d95171136f7ef6a2Timo Sirainen uoff_t file_offset);
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainenstruct mail_transaction_log_view *
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainenmail_transaction_log_view_open(struct mail_transaction_log *log);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenvoid mail_transaction_log_view_close(struct mail_transaction_log_view **view);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Set view boundaries. Returns -1 if error, 0 if files are lost or corrupted,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen 1 if ok. reset_r=TRUE if the whole index should be reset before applying any
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen changes. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint mail_transaction_log_view_set(struct mail_transaction_log_view *view,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t min_file_seq, uoff_t min_file_offset,
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainen uint32_t max_file_seq, uoff_t max_file_offset,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen bool *reset_r);
57dd2621d4230bc2e06c69a4b9f8cf8f0ff2bc93Timo Sirainen/* Scan through all of the log files that we can find.
57dd2621d4230bc2e06c69a4b9f8cf8f0ff2bc93Timo Sirainen Returns -1 if error, 0 if ok. */
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Boschint mail_transaction_log_view_set_all(struct mail_transaction_log_view *view);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Clear the view. If oldest_file_seq > 0, keep it and newer log files
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen referenced so we don't get desynced. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenvoid mail_transaction_log_view_clear(struct mail_transaction_log_view *view,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t oldest_file_seq);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
40ad2c4902e9d83557f2e8a4bff3d98fea2c8aa1Timo Sirainen/* Read next transaction record from current position. The position is updated.
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainen Returns -1 if error, 0 if we're at end of the view, 1 if ok. */
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainenint mail_transaction_log_view_next(struct mail_transaction_log_view *view,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen const struct mail_transaction_header **hdr_r,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen const void **data_r);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Mark the current view's position to the record returned previously with
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen _log_view_next(). */
14c474d9f4591c397ed0b5206af6537c7b52c924Timo Sirainenvoid mail_transaction_log_view_mark(struct mail_transaction_log_view *view);
14c474d9f4591c397ed0b5206af6537c7b52c924Timo Sirainen/* Seek to previously marked position. */
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainenvoid mail_transaction_log_view_rewind(struct mail_transaction_log_view *view);
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen/* Returns the position of the record returned previously with
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen mail_transaction_log_view_next() */
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainenvoid
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainenmail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t *file_seq_r,
8d131435ba4648c8821160ec38d508c97177c715Timo Sirainen uoff_t *file_offset_r);
8d131435ba4648c8821160ec38d508c97177c715Timo Sirainen/* Return the modseq of the change returned previously with _view_next(). */
8d131435ba4648c8821160ec38d508c97177c715Timo Sirainenuint64_t
8d131435ba4648c8821160ec38d508c97177c715Timo Sirainenmail_transaction_log_view_get_prev_modseq(struct mail_transaction_log_view *view);
b6612c334604eeb27e1ca2bd804ac66dcbc2eaadTimo Sirainen/* Returns TRUE if we're at the end of the view window. */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenbool mail_transaction_log_view_is_last(struct mail_transaction_log_view *view);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Marks the log file in current position to be corrupted. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainenmail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainen const char *fmt, ...)
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainen ATTR_FORMAT(2, 3);
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainenbool
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainenmail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint mail_transaction_log_append_begin(struct mail_index *index,
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainen enum mail_transaction_type flags,
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainen struct mail_transaction_log_append_ctx **ctx_r);
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainenvoid mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx,
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainen enum mail_transaction_type type,
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainen const void *data, size_t size);
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainenint mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx);
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainen
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainen/* Lock transaction log for index synchronization. Log cannot be read or
b5b3b4c9159f506cdfdce7399faaeeffdf73faf7Timo Sirainen written to while it's locked. Returns end offset. */
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainenint mail_transaction_log_sync_lock(struct mail_transaction_log *log,
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainen uint32_t *file_seq_r, uoff_t *file_offset_r);
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainenvoid mail_transaction_log_sync_unlock(struct mail_transaction_log *log);
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainen/* Returns the current head. Works only when log is locked. */
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainenvoid mail_transaction_log_get_head(struct mail_transaction_log *log,
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainen uint32_t *file_seq_r, uoff_t *file_offset_r);
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainen/* Returns the current tail from which all files are open to head. */
e64d7b6f388fecd0c83a4f2acb54e30d5ac98c6cTimo Sirainenvoid mail_transaction_log_get_tail(struct mail_transaction_log *log,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t *file_seq_r);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Returns TRUE if given seq/offset is current head log's rotate point. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenbool mail_transaction_log_is_head_prev(struct mail_transaction_log *log,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint32_t file_seq, uoff_t file_offset);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Move currently opened log head file to memory (called by
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen mail_index_move_to_memory()) */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenvoid mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Returns mtime of the transaction log head file.
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen If it doesn't exist, mtime_r is set to 0. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint mail_transaction_log_get_mtime(struct mail_transaction_log *log,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen time_t *mtime_r);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Unlink transaction log files */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint mail_transaction_log_unlink(struct mail_transaction_log *log);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#endif
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen