annotate src/lib-index/mail-transaction-log.h @ 2009:2e77ee652e2e HEAD

When committing with no changes, don't try to sync them later.
author Timo Sirainen <tss@iki.fi>
date Tue, 11 May 2004 00:09:15 +0300
parents 4e0269adb24a
children 4f6b1118a53d
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,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 MAIL_TRANSACTION_TYPE_MASK = 0x0000ffff,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 /* 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
25 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
26 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
27 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
28 MAIL_TRANSACTION_EXPUNGE_PROT = 0x0000cd90,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 /* Mailbox synchronization noticed this change. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 MAIL_TRANSACTION_EXTERNAL = 0x10000000
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 };
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 struct mail_transaction_header {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 uint32_t size;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 uint32_t type; /* enum mail_transaction_type */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 };
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 struct mail_transaction_expunge {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 uint32_t seq1, seq2;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 uint32_t uid1, uid2; /* only to avoid accidental expunges due to bugs */
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_cache_update {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 uint32_t seq;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 uint32_t cache_offset;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 struct mail_transaction_flag_update {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 uint32_t seq1, seq2;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 uint8_t add_flags;
1958
4dec6a3d79fd s/custom flags/keywords/
Timo Sirainen <tss@iki.fi>
parents: 1942
diff changeset
52 keywords_mask_t add_keywords;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 uint8_t remove_flags;
1958
4dec6a3d79fd s/custom flags/keywords/
Timo Sirainen <tss@iki.fi>
parents: 1942
diff changeset
54 keywords_mask_t remove_keywords;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 struct mail_transaction_log *
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 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
59 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
60
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 struct mail_transaction_log_view *
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 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
63 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
64
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 /* 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
66 int
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 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
68 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
69 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
70 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
71 /* 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
72 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
73
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 /* 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
75 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
76 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
77 const struct mail_transaction_header **hdr_r,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 const void **data_r, int *skipped_r);
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 /* 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
81 mail_transaction_log_view_next() */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 void
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 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
84 uint32_t *file_seq_r,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 uoff_t *file_offset_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 buffer_t *
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 mail_transaction_log_view_get_expunges(struct mail_transaction_log_view *view);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 /* 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
91 void
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 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
93 const char *fmt, ...)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 __attr_format__(2, 3);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 int
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 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
97
1942
2b114aa7eeec handle losing index file
Timo Sirainen <tss@iki.fi>
parents: 1941
diff changeset
98 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
99
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 /* 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
101 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
102 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
103 will be set to 0. */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 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
105 uint32_t *log_file_seq_r,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 uoff_t *log_file_offset_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 /* 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
109 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
110 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
111 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
112 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
113 /* 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
114 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
115 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
116
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 #endif