mail-transaction-log.h revision 0fa842717a8b163252e55c229c37ca0c5d7ff056
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen uint64_t initial_modseq; /* v1.1+ (note: log's major/minor version) */
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags, v1.2+ */
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen uint32_t unused2; /* so that this struct is 64bit aligned */
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_EXT_HDR_UPDATE32 = 0x00010000,
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen MAIL_TRANSACTION_INDEX_UNDELETED = 0x00040000,
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 /* 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 /* Mailbox storage backend synchronization noticed this change. */
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 uint32_t type; /* enum mail_transaction_type */
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 */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen uint8_t modify_type; /* enum modify_type : MODIFY_ADD / MODIFY_REMOVE */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* unsigned char name[];
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen array of { uint32_t uid1, uid2; }
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* unsigned char data[]; */
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
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* old extension: set ext_id. don't set name.
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen new extension: ext_id = (uint32_t)-1. give name. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* unsigned char name[]; */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen/* these are set for the last ext_intro */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainen /* unsigned char data[]; */
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 Sirainen /* unsigned char data[]; */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen /* unsigned char data[]; */
f153a2cec0319f549388d28f8cfd4d50229d1132Timo Sirainen#define LOG_IS_BEFORE(seq1, offset1, seq2, offset2) \
f153a2cec0319f549388d28f8cfd4d50229d1132Timo Sirainen (((offset1) < (offset2) && (seq1) == (seq2)) || (seq1) < (seq2))
dffa503fd4ce31334346e539496084c80a2d8d37Timo Sirainenmail_transaction_log_alloc(struct mail_index *index);
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **log);
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/* Notify of indexid change */
85144b5f0bc763de14c7d87291a90ef74ac241a2Timo Sirainenvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log);
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/* 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 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/* 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 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,
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,
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 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/* Returns the position of the record returned previously with
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen mail_transaction_log_view_next() */
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainenmail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
8d131435ba4648c8821160ec38d508c97177c715Timo Sirainen/* Return the modseq of the change returned previously with _view_next(). */
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/* Marks the log file in current position to be corrupted. */
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainenmail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainen const char *fmt, ...)
1ff03d2244dd08effadfecec365bec28793a1aa0Timo Sirainenmail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint mail_transaction_log_append_begin(struct mail_index *index,
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 Sirainenint mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx);
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 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/* 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/* 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/* 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/* Unlink transaction log files */