annotate src/lib-index/mail-transaction-log.h @ 2050:ee1095ccfd23 HEAD

Index header changes now go through transaction log. Removed the kludgy parameters for mail_index_sync_end(). Removed code duplication of syncing index root mapping and view mapping. Some fixes to handling uidvalidity and nextuid in syncing.
author Timo Sirainen <tss@iki.fi>
date Mon, 24 May 2004 04:50:16 +0300
parents 4f6b1118a53d
children cb5269c052e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 #ifndef __MAIL_TRANSACTION_LOG_H
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2 #define __MAIL_TRANSACTION_LOG_H
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #define MAIL_TRANSACTION_LOG_PREFIX ".log"
1940
Timo Sirainen <tss@iki.fi>
parents: 1935
diff changeset
5 #define MAIL_TRANSACTION_LOG_ROTATE_SIZE (1024*128)
1976
4e0269adb24a Don't rotate transaction log too often
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
6 #define MAIL_TRANSACTION_LOG_ROTATE_MIN_TIME (60*5)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 struct mail_transaction_log_header {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 uint32_t indexid;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 uint32_t file_seq;
1940
Timo Sirainen <tss@iki.fi>
parents: 1935
diff changeset
11 uint32_t prev_file_seq;
1935
ec4d5ff99f6e Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
12 uint32_t prev_file_offset;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 uint32_t used_size;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 enum mail_transaction_type {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 MAIL_TRANSACTION_EXPUNGE = 0x00000001,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 MAIL_TRANSACTION_APPEND = 0x00000002,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 MAIL_TRANSACTION_FLAG_UPDATE = 0x00000004,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 MAIL_TRANSACTION_CACHE_UPDATE = 0x00000008,
2050
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
21 MAIL_TRANSACTION_HEADER_UPDATE = 0x00000010,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 MAIL_TRANSACTION_TYPE_MASK = 0x0000ffff,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 /* since we'll expunge mails based on data read from transaction log,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 try to avoid the possibility of corrupted transaction log expunging
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 messages. this value is ORed to the actual MAIL_TRANSACTION_EXPUNGE
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 flag. if it's not present, assume corrupted log. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 MAIL_TRANSACTION_EXPUNGE_PROT = 0x0000cd90,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 /* Mailbox synchronization noticed this change. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 MAIL_TRANSACTION_EXTERNAL = 0x10000000
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 struct mail_transaction_header {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 uint32_t size;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 uint32_t type; /* enum mail_transaction_type */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 struct mail_transaction_expunge {
2033
4f6b1118a53d Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents: 2009
diff changeset
41 uint32_t uid1, uid2;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 struct mail_transaction_flag_update {
2033
4f6b1118a53d Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents: 2009
diff changeset
45 uint32_t uid1, uid2;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 uint8_t add_flags;
1958
4dec6a3d79fd s/custom flags/keywords/
Timo Sirainen <tss@iki.fi>
parents: 1942
diff changeset
47 keywords_mask_t add_keywords;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 uint8_t remove_flags;
1958
4dec6a3d79fd s/custom flags/keywords/
Timo Sirainen <tss@iki.fi>
parents: 1942
diff changeset
49 keywords_mask_t remove_keywords;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51
2050
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
52 struct mail_transaction_cache_update {
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
53 uint32_t uid;
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
54 uint32_t cache_offset;
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
55 };
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
56
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
57 struct mail_transaction_header_update {
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
58 uint16_t offset;
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
59 uint16_t size;
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
60 unsigned char data[1]; /* variable size */
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
61 };
ee1095ccfd23 Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents: 2033
diff changeset
62
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 struct mail_transaction_log *
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 mail_transaction_log_open_or_create(struct mail_index *index);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 void mail_transaction_log_close(struct mail_transaction_log *log);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 struct mail_transaction_log_view *
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 mail_transaction_log_view_open(struct mail_transaction_log *log);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 void mail_transaction_log_view_close(struct mail_transaction_log_view *view);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 /* Set view boundaries. Returns -1 if error, 0 if ok. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 int
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 mail_transaction_log_view_set(struct mail_transaction_log_view *view,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 uint32_t min_file_seq, uoff_t min_file_offset,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 uint32_t max_file_seq, uoff_t max_file_offset,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 enum mail_transaction_type type_mask);
1941
ced8e41c137a automatically fix broken/missing transaction log files on the fly
Timo Sirainen <tss@iki.fi>
parents: 1940
diff changeset
77 /* Unset view, freeing all it's used resources. */
ced8e41c137a automatically fix broken/missing transaction log files on the fly
Timo Sirainen <tss@iki.fi>
parents: 1940
diff changeset
78 void mail_transaction_log_view_unset(struct mail_transaction_log_view *view);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 /* Read next transaction record from current position. The position is updated.
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 Returns -1 if error, 0 if we're at end of the view, 1 if ok. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 int mail_transaction_log_view_next(struct mail_transaction_log_view *view,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 const struct mail_transaction_header **hdr_r,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 const void **data_r, int *skipped_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 /* Returns the position of the record returned previously with
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 mail_transaction_log_view_next() */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 void
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 mail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 uint32_t *file_seq_r,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 uoff_t *file_offset_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 /* Marks the log file in current position to be corrupted. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 void
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 mail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 const char *fmt, ...)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 __attr_format__(2, 3);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 int
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 mail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100
1942
2b114aa7eeec handle losing index file
Timo Sirainen <tss@iki.fi>
parents: 1941
diff changeset
101 void mail_transaction_log_views_close(struct mail_transaction_log *log);
2b114aa7eeec handle losing index file
Timo Sirainen <tss@iki.fi>
parents: 1941
diff changeset
102
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 /* Write data to transaction log. This is atomic operation. Sequences in
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 updates[] and expunges[] are relative to given view, they're modified
2009
2e77ee652e2e When committing with no changes, don't try to sync them later.
Timo Sirainen <tss@iki.fi>
parents: 1976
diff changeset
105 to real ones. If nothing is written, log_file_seq_r and log_file_offset_r
2e77ee652e2e When committing with no changes, don't try to sync them later.
Timo Sirainen <tss@iki.fi>
parents: 1976
diff changeset
106 will be set to 0. */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 int mail_transaction_log_append(struct mail_index_transaction *t,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 uint32_t *log_file_seq_r,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 uoff_t *log_file_offset_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 /* Lock transaction log for index synchronization. Log cannot be read or
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 written to while it's locked. Returns end offset. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 int mail_transaction_log_sync_lock(struct mail_transaction_log *log,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 uint32_t *file_seq_r, uoff_t *file_offset_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 void mail_transaction_log_sync_unlock(struct mail_transaction_log *log);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 /* Returns the current head. Works only when log is locked. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 void mail_transaction_log_get_head(struct mail_transaction_log *log,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 uint32_t *file_seq_r, uoff_t *file_offset_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 #endif