Mercurial > dovecot > core-2.2
annotate src/lib-index/mail-cache-private.h @ 5002:82747a8b0b8b HEAD
Removed file offset caching from mail_cache_foreach(). It didn't work
correctly when cache file was just compressed, and caused "cache file
corrupted" errors.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 14 Jan 2007 05:17:07 +0200 |
parents | bb4ec18672fe |
children | 5f0832288007 |
rev | line source |
---|---|
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 #ifndef __MAIL_CACHE_PRIVATE_H |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 #define __MAIL_CACHE_PRIVATE_H |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 |
3106 | 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-index-private.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "mail-cache.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
8 #define MAIL_CACHE_VERSION 1 |
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
9 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 /* Never compress the file if it's smaller than this */ |
4928
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
11 #define MAIL_CACHE_COMPRESS_MIN_SIZE (1024*50) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
13 /* Don't bother remembering holes smaller than this */ |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
14 #define MAIL_CACHE_MIN_HOLE_SIZE 1024 |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
15 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 /* Compress the file when deleted space reaches n% of total size */ |
4928
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
17 #define MAIL_CACHE_COMPRESS_PERCENTAGE 20 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 /* Compress the file when n% of rows contain continued rows. |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 200% means that there's 2 continued rows per record. */ |
4928
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
21 #define MAIL_CACHE_COMPRESS_CONTINUED_PERCENTAGE 200 |
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 /* Initial size for the file */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 #define MAIL_CACHE_INITIAL_SIZE (sizeof(struct mail_cache_header) + 10240) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 /* When more space is needed, grow the file n% larger than the previous size */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 #define MAIL_CACHE_GROW_PERCENTAGE 10 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
2341
b3c0ed666757
Limit how much a single transaction can reserve space
Timo Sirainen <tss@iki.fi>
parents:
2339
diff
changeset
|
29 /* When allocating space for transactions, don't use blocks larger than this. */ |
b3c0ed666757
Limit how much a single transaction can reserve space
Timo Sirainen <tss@iki.fi>
parents:
2339
diff
changeset
|
30 #define MAIL_CACHE_MAX_RESERVED_BLOCK_SIZE (1024*512) |
b3c0ed666757
Limit how much a single transaction can reserve space
Timo Sirainen <tss@iki.fi>
parents:
2339
diff
changeset
|
31 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 #define MAIL_CACHE_LOCK_TIMEOUT 120 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 #define MAIL_CACHE_LOCK_CHANGE_TIMEOUT 60 |
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 #define CACHE_RECORD(cache, offset) \ |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
36 ((const struct mail_cache_record *) \ |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
37 ((const char *) (cache)->data + offset)) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
39 #define MAIL_CACHE_IS_UNUSABLE(cache) \ |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
40 ((cache)->hdr == NULL) |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
41 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 struct mail_cache_header { |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
43 /* version is increased only when you can't have backwards |
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
44 compatibility. */ |
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
45 uint8_t version; |
3819
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3627
diff
changeset
|
46 uint8_t compat_sizeof_uoff_t; |
4657
a2a9b6a92831
Don't use time_t anymore in cache file. uint32_t is large enough and makes
Timo Sirainen <tss@iki.fi>
parents:
4655
diff
changeset
|
47 uint8_t unused[2]; |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
48 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 uint32_t indexid; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 uint32_t file_seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 uint32_t continued_record_count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
54 uint32_t hole_offset; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 uint32_t used_file_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 uint32_t deleted_space; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
58 uint32_t field_header_offset; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
59 }; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
60 |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
61 struct mail_cache_header_fields { |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
62 uint32_t next_offset; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
63 uint32_t size; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
64 uint32_t fields_count; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
66 #if 0 |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
67 /* last time the field was accessed. not updated more often than |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
68 once a day. */ |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
69 uint32_t last_used[fields_count]; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
70 /* (uint32_t)-1 for variable sized fields */ |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
71 uint32_t size[fields_count]; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
72 /* enum mail_cache_field_type */ |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
73 uint8_t type[fields_count]; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
74 /* enum mail_cache_decision_type */ |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
75 uint8_t decision[fields_count]; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
76 /* NUL-separated list of field names */ |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
77 char name[fields_count][]; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
78 #endif |
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 |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
81 #define MAIL_CACHE_FIELD_LAST_USED() \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
82 (sizeof(uint32_t) * 3) |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
83 #define MAIL_CACHE_FIELD_SIZE(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
84 (MAIL_CACHE_FIELD_LAST_USED() + sizeof(uint32_t) * (count)) |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
85 #define MAIL_CACHE_FIELD_TYPE(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
86 (MAIL_CACHE_FIELD_SIZE(count) + sizeof(uint32_t) * (count)) |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
87 #define MAIL_CACHE_FIELD_DECISION(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
88 (MAIL_CACHE_FIELD_TYPE(count) + sizeof(uint8_t) * (count)) |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
89 #define MAIL_CACHE_FIELD_NAMES(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
90 (MAIL_CACHE_FIELD_DECISION(count) + sizeof(uint8_t) * (count)) |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
91 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 struct mail_cache_record { |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
93 uint32_t prev_offset; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 uint32_t size; /* full record size, including this header */ |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
2277
diff
changeset
|
95 /* array of { uint32_t field; [ uint32_t size; ] { .. } } */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
98 struct mail_cache_hole_header { |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
99 uint32_t next_offset; /* 0 if no holes left */ |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
100 uint32_t size; /* including this header */ |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
101 |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
102 /* make sure we notice if we're treating hole as mail_cache_record. |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
103 magic is a large number so if it's treated as size field, it'll |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
104 point outside the file */ |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
105 #define MAIL_CACHE_HOLE_HEADER_MAGIC 0xffeedeff |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
106 uint32_t magic; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
107 }; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
108 |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
109 struct mail_cache_field_private { |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
110 struct mail_cache_field field; |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
111 |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
112 uint32_t uid_highwater; |
2342 | 113 uint32_t last_used; |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
114 |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
115 unsigned int decision_dirty:1; |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
116 }; |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
117 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 struct mail_cache { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 struct mail_index *index; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
120 uint32_t ext_id; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 char *filepath; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 void *mmap_base; |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
126 const void *data; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 size_t mmap_length; |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
128 struct file_cache *file_cache; |
3106 | 129 |
130 struct dotlock_settings dotlock_settings; | |
131 struct dotlock *dotlock; | |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
132 struct file_lock *file_lock; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
134 const struct mail_cache_header *hdr; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
135 struct mail_cache_header hdr_copy; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
137 pool_t field_pool; |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
138 struct mail_cache_field_private *fields; |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
139 uint32_t *field_file_map; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
140 unsigned int fields_count; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
141 struct hash_table *field_name_hash; /* name -> idx */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
3981
diff
changeset
|
143 /* 0 is no need for compression, otherwise the file sequence number |
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
3981
diff
changeset
|
144 which we want compressed. */ |
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
3981
diff
changeset
|
145 uint32_t need_compress_file_seq; |
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
3981
diff
changeset
|
146 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
147 unsigned int *file_field_map; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
148 unsigned int file_fields_count; |
2247
2d51bb58a070
Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
2201
diff
changeset
|
149 |
4655
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4490
diff
changeset
|
150 unsigned int opened:1; |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
151 unsigned int locked:1; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
152 unsigned int hdr_modified:1; |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
153 unsigned int field_header_write_pending:1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 struct mail_cache_view { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 struct mail_cache *cache; |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
158 struct mail_index_view *view, *trans_view; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
2277
diff
changeset
|
160 struct mail_cache_transaction_ctx *transaction; |
2315
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
161 uint32_t trans_seq1, trans_seq2; |
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
162 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
163 /* temporary array, just to avoid mallocs. */ |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4247
diff
changeset
|
164 ARRAY_DEFINE(tmp_offsets, uint32_t); |
2632
ec5601f71ba0
Fix for circular record list detection, we can't use data stack for buffer.
Timo Sirainen <tss@iki.fi>
parents:
2619
diff
changeset
|
165 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
166 /* if cached_exists_buf[field] == cached_exists_value, it's cached. |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
167 this allows us to avoid constantly clearing the whole buffer. |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
168 it needs to be cleared only when cached_exists_value is wrapped. */ |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
169 buffer_t *cached_exists_buf; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
170 uint8_t cached_exists_value; |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
2277
diff
changeset
|
171 uint32_t cached_exists_seq; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 |
2315
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
174 typedef int mail_cache_foreach_callback_t(struct mail_cache_view *view, |
2619 | 175 uint32_t field, |
2315
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
176 const void *data, size_t data_size, |
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
177 void *context); |
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
178 |
4655
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4490
diff
changeset
|
179 int mail_cache_open_and_verify(struct mail_cache *cache); |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4490
diff
changeset
|
180 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
181 /* Explicitly lock the cache file. Returns -1 if error, 1 if ok, 0 if we |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
182 couldn't lock */ |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
183 int mail_cache_lock(struct mail_cache *cache); |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3375
diff
changeset
|
184 /* Returns -1 if cache is / just got corrupted, 0 if ok. */ |
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3375
diff
changeset
|
185 int mail_cache_unlock(struct mail_cache *cache); |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
186 |
3375
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
187 int mail_cache_write(struct mail_cache *cache, const void *data, size_t size, |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
188 uoff_t offset); |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
189 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
190 int mail_cache_header_fields_read(struct mail_cache *cache); |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
191 int mail_cache_header_fields_update(struct mail_cache *cache); |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
192 void mail_cache_header_fields_get(struct mail_cache *cache, buffer_t *dest); |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
193 int mail_cache_header_fields_get_next_offset(struct mail_cache *cache, |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
194 uint32_t *offset_r); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 |
2917
e657c7874962
Crashfixes for reading corrupted cache files.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
196 int mail_cache_get_record(struct mail_cache *cache, uint32_t offset, |
e657c7874962
Crashfixes for reading corrupted cache files.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
197 const struct mail_cache_record **rec_r); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
2277
diff
changeset
|
199 int mail_cache_foreach(struct mail_cache_view *view, uint32_t seq, |
2315
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
200 mail_cache_foreach_callback_t *callback, void *context); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
202 int mail_cache_transaction_commit(struct mail_cache_transaction_ctx *ctx); |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
203 void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx *ctx); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
205 int mail_cache_map(struct mail_cache *cache, size_t offset, size_t size); |
2247
2d51bb58a070
Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
2201
diff
changeset
|
206 void mail_cache_file_close(struct mail_cache *cache); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
207 int mail_cache_reopen(struct mail_cache *cache); |
2247
2d51bb58a070
Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
2201
diff
changeset
|
208 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
209 /* Update new_offset's prev_offset field to old_offset. */ |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
210 int mail_cache_link(struct mail_cache *cache, uint32_t old_offset, |
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
211 uint32_t new_offset); |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
212 /* Mark record in given offset to be deleted. */ |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
213 int mail_cache_delete(struct mail_cache *cache, uint32_t offset); |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
214 |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
2277
diff
changeset
|
215 void mail_cache_decision_lookup(struct mail_cache_view *view, uint32_t seq, |
2999
1d328531c466
mail_cache_decision_*() prototypes were wrong.
Timo Sirainen <tss@iki.fi>
parents:
2941
diff
changeset
|
216 unsigned int field); |
2298
5beb0c20b6e8
Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents:
2277
diff
changeset
|
217 void mail_cache_decision_add(struct mail_cache_view *view, uint32_t seq, |
2999
1d328531c466
mail_cache_decision_*() prototypes were wrong.
Timo Sirainen <tss@iki.fi>
parents:
2941
diff
changeset
|
218 unsigned int field); |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
219 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
220 int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx, |
4490
56d17f2e1d66
Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
221 uint32_t seq, const void *data, |
56d17f2e1d66
Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents:
4451
diff
changeset
|
222 void **sync_context, void *context); |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
223 int mail_cache_sync_handler(struct mail_index_sync_map_ctx *sync_ctx, |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
224 uint32_t seq, void *old_data, const void *new_data, |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
225 void **context); |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2917
diff
changeset
|
226 void mail_cache_sync_lost_handler(struct mail_index *index); |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
227 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 void mail_cache_set_syscall_error(struct mail_cache *cache, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 const char *function); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 #endif |