annotate src/lib-index/mail-transaction-log-private.h @ 6410:e4eb71ae8e96 HEAD

Changed .h ifdef/defines to use <NAME>_H format.
author Timo Sirainen <tss@iki.fi>
date Sun, 16 Sep 2007 11:31:27 +0300
parents 461ae76c84da
children 6a64e64fa3a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6410
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 6360
diff changeset
1 #ifndef MAIL_TRANSACTION_LOG_VIEW_H
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 6360
diff changeset
2 #define MAIL_TRANSACTION_LOG_VIEW_H
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
1920
d11efbf1d341 Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
4 #include "file-dotlock.h"
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "mail-transaction-log.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6
6360
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
7 /* Synchronization can take a while sometimes, especially when copying lots of
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
8 mails. */
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
9 #define MAIL_TRANSCATION_LOG_LOCK_TIMEOUT (3*60)
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
10 #define MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT (3*60)
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
11
5283
8f9af66ee313 If transaction log grows larger than 1MB, rotate it even if it was created
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
12 /* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
5813
9b4987348cf6 Removed debug #defines and changed log rotation size defaults.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
13 #define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*32)
5283
8f9af66ee313 If transaction log grows larger than 1MB, rotate it even if it was created
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
14 /* If log is larger than MAX_SIZE, rotate regardless of the time */
8f9af66ee313 If transaction log grows larger than 1MB, rotate it even if it was created
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
15 #define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*1024)
3180
ef16bb8091aa Several transaction log cleanups and fixes.
Timo Sirainen <tss@iki.fi>
parents: 3146
diff changeset
16 #define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
ef16bb8091aa Several transaction log cleanups and fixes.
Timo Sirainen <tss@iki.fi>
parents: 3146
diff changeset
17
5881
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
18 /* Delete .log.2 files older than this many seconds */
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
19 #define MAIL_TRANSACTION_LOG2_STALE_SECS (60*30)
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
20
3243
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3180
diff changeset
21 #define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3180
diff changeset
22
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 struct mail_transaction_log_file {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 struct mail_transaction_log *log;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 struct mail_transaction_log_file *next;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
4828
7cc1b8fec8ab Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents: 4785
diff changeset
27 /* refcount=0 is a valid state. files start that way, and they're
7cc1b8fec8ab Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents: 4785
diff changeset
28 freed only when mail_transaction_logs_clean() is called. */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 int refcount;
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 char *filepath;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 int fd;
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 ino_t st_ino;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 dev_t st_dev;
1976
4e0269adb24a Don't rotate transaction log too often
Timo Sirainen <tss@iki.fi>
parents: 1974
diff changeset
36 time_t last_mtime;
3320
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3243
diff changeset
37 uoff_t last_size;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
39 struct mail_transaction_log_header hdr;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 buffer_t *buffer;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 uoff_t buffer_offset;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 void *mmap_base;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 size_t mmap_size;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
45 /* points to the next uncommitted transaction. usually same as EOF. */
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 1976
diff changeset
46 uoff_t sync_offset;
5749
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5716
diff changeset
47 /* saved_tail_offset is the offset that was last written to transaction
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5716
diff changeset
48 log. max_tail_offset is what should be written to the log the next
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5716
diff changeset
49 time a transaction is written. transaction log handling may update
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5716
diff changeset
50 max_tail_offset automatically by making it skip external transactions
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
51 after the last saved offset (to avoid re-reading them unneededly). */
5749
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5716
diff changeset
52 uoff_t saved_tail_offset, max_tail_offset;
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 1976
diff changeset
53
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4828
diff changeset
54 struct file_lock *file_lock;
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4828
diff changeset
55
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 1976
diff changeset
56 unsigned int locked:1;
5819
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5813
diff changeset
57 unsigned int corrupted:1;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 struct mail_transaction_log {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 struct mail_index *index;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 struct mail_transaction_log_view *views;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
63
4785
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
64 /* files is a linked list of all the opened log files. the list is
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
65 sorted by the log file sequence, so that transaction views can use
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
66 them easily. head contains a pointer to the newest log file. */
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
67 struct mail_transaction_log_file *files, *head;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
68 /* open_file is used temporarily while opening the log file.
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
69 if _open() failed, it's left there for _create(). */
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
70 struct mail_transaction_log_file *open_file;
1974
d85f71ffeb8f file_dotlock_open/delete/replace now has lock_suffix parameter. NULL
Timo Sirainen <tss@iki.fi>
parents: 1933
diff changeset
71
d85f71ffeb8f file_dotlock_open/delete/replace now has lock_suffix parameter. NULL
Timo Sirainen <tss@iki.fi>
parents: 1933
diff changeset
72 unsigned int dotlock_count;
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
73 struct dotlock_settings dotlock_settings, new_dotlock_settings;
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
74 struct dotlock *dotlock;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 void
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
3342
43d4aad84752 Minor error checking fixes.
Timo Sirainen <tss@iki.fi>
parents: 3320
diff changeset
79 const char *fmt, ...)
43d4aad84752 Minor error checking fixes.
Timo Sirainen <tss@iki.fi>
parents: 3320
diff changeset
80 __attr_format__(2, 3);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81
5687
d28185a3131a Moved mail transaction log file related code to its own file.
Timo Sirainen <tss@iki.fi>
parents: 5283
diff changeset
82 struct mail_transaction_log_file *
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
83 mail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
84 struct mail_transaction_log_file *
5687
d28185a3131a Moved mail transaction log file related code to its own file.
Timo Sirainen <tss@iki.fi>
parents: 5283
diff changeset
85 mail_transaction_log_file_alloc(struct mail_transaction_log *log,
d28185a3131a Moved mail transaction log file related code to its own file.
Timo Sirainen <tss@iki.fi>
parents: 5283
diff changeset
86 const char *path);
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
87 void mail_transaction_log_file_free(struct mail_transaction_log_file **file);
5687
d28185a3131a Moved mail transaction log file related code to its own file.
Timo Sirainen <tss@iki.fi>
parents: 5283
diff changeset
88
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
89 int mail_transaction_log_file_open(struct mail_transaction_log_file *file,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
90 bool check_existing);
5849
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
91 int mail_transaction_log_file_create(struct mail_transaction_log_file *file,
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
92 bool reset);
5687
d28185a3131a Moved mail transaction log file related code to its own file.
Timo Sirainen <tss@iki.fi>
parents: 5283
diff changeset
93 int mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
d28185a3131a Moved mail transaction log file related code to its own file.
Timo Sirainen <tss@iki.fi>
parents: 5283
diff changeset
94
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
95 int mail_transaction_log_find_file(struct mail_transaction_log *log,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 uint32_t file_seq,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 struct mail_transaction_log_file **file_r);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98
5716
4a08705e97f5 Fixes to mail_transaction_log_file_map() error handling.
Timo Sirainen <tss@iki.fi>
parents: 5714
diff changeset
99 /* Returns 1 if ok, 0 if file is corrupted or offset range is invalid,
4a08705e97f5 Fixes to mail_transaction_log_file_map() error handling.
Timo Sirainen <tss@iki.fi>
parents: 5714
diff changeset
100 -1 if I/O error */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 int mail_transaction_log_file_map(struct mail_transaction_log_file *file,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 uoff_t start_offset, uoff_t end_offset);
5714
dcf5dbb6a76a mail_transaction_log_move_to_memory() can't fail anymore. Moved the code to
Timo Sirainen <tss@iki.fi>
parents: 5689
diff changeset
103 void mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
dcf5dbb6a76a mail_transaction_log_move_to_memory() can't fail anymore. Moved the code to
Timo Sirainen <tss@iki.fi>
parents: 5689
diff changeset
104 *file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 void mail_transaction_logs_clean(struct mail_transaction_log *log);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
108 bool mail_transaction_log_want_rotate(struct mail_transaction_log *log);
5849
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
109 int mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset);
3146
9a8bf1c86699 Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents: 3106
diff changeset
110 int mail_transaction_log_lock_head(struct mail_transaction_log *log);
9a8bf1c86699 Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents: 3106
diff changeset
111 void mail_transaction_log_file_unlock(struct mail_transaction_log_file *file);
9a8bf1c86699 Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents: 3106
diff changeset
112
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 #endif