Mercurial > dovecot > core-2.2
annotate src/lib-index/mail-transaction-log-private.h @ 5716:4a08705e97f5 HEAD
Fixes to mail_transaction_log_file_map() error handling.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 13 Jun 2007 19:49:51 +0300 |
parents | dcf5dbb6a76a |
children | 420a386fa27a |
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_VIEW_H |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 #define __MAIL_TRANSACTION_LOG_VIEW_H |
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 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
7 #if 0 // FIXME |
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
|
8 /* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */ |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
9 #define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*4) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
10 /* If log is larger than MAX_SIZE, rotate regardless of the time */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
11 #define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*16) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
12 #define MAIL_TRANSACTION_LOG_ROTATE_TIME (30) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
13 |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
14 #define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
15 #else |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
16 /* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
17 #define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*256) |
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
|
18 /* 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
|
19 #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
|
20 #define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5) |
ef16bb8091aa
Several transaction log cleanups and fixes.
Timo Sirainen <tss@iki.fi>
parents:
3146
diff
changeset
|
21 |
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
|
22 #define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1) |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
23 #endif |
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
|
24 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 struct mail_transaction_log_file { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 struct mail_transaction_log *log; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 struct mail_transaction_log_file *next; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
4828
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
29 /* 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
|
30 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
|
31 int refcount; |
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 char *filepath; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 ino_t st_ino; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 dev_t st_dev; |
1976
4e0269adb24a
Don't rotate transaction log too often
Timo Sirainen <tss@iki.fi>
parents:
1974
diff
changeset
|
38 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
|
39 uoff_t last_size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
41 struct mail_transaction_log_header hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 buffer_t *buffer; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 uoff_t buffer_offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 void *mmap_base; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 size_t mmap_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
47 /* 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
|
48 uoff_t sync_offset; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
49 /* saved_offset is the offset that was last written to transaction log. |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
50 max_offset is what should be written to the log the next time a |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
51 transaction is written. transaction log handling may update |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
52 max_offset automatically by making it skip external transactions |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
53 after the last saved offset (to avoid re-reading them unneededly). */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
54 uoff_t mailbox_sync_saved_offset, mailbox_sync_max_offset; |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
1976
diff
changeset
|
55 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4828
diff
changeset
|
56 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
|
57 |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
1976
diff
changeset
|
58 unsigned int locked:1; |
1915
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 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 struct mail_transaction_log { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 struct mail_index *index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 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
|
64 |
4785 | 65 /* files is a linked list of all the opened log files. the list is |
66 sorted by the log file sequence, so that transaction views can use | |
67 them easily. head contains a pointer to the newest log file. */ | |
68 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
|
69 /* 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
|
70 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
|
71 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
|
72 |
d85f71ffeb8f
file_dotlock_open/delete/replace now has lock_suffix parameter. NULL
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
73 unsigned int dotlock_count; |
3106 | 74 struct dotlock_settings dotlock_settings, new_dotlock_settings; |
75 struct dotlock *dotlock; | |
1915
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 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 void |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file, |
3342 | 80 const char *fmt, ...) |
81 __attr_format__(2, 3); | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 |
5687
d28185a3131a
Moved mail transaction log file related code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
5283
diff
changeset
|
83 struct mail_transaction_log_file * |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 const char *path); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
88 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
|
89 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
90 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
|
91 bool check_existing); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
92 int mail_transaction_log_file_create(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
|
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); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5687
diff
changeset
|
109 int mail_transaction_log_rotate(struct mail_transaction_log *log); |
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 |