Mercurial > dovecot > core-2.2
annotate src/lib-index/mail-cache-private.h @ 3819:61f0e1fe9b55 HEAD
Moved uoff_t and time_t compatibility checks to cache file, since they're
not needed for index/log. Only index file incompatibility check is now
endianess flag.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 06 Jan 2006 16:21:21 +0200 |
parents | c0e35566dd14 |
children | 0d64f8888dcd |
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 */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #define COMPRESS_MIN_SIZE (1024*50) |
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 */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #define COMPRESS_PERCENTAGE 20 |
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. */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 #define COMPRESS_CONTINUED_PERCENTAGE 200 |
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 #define MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT (5*60) |
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 #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
|
37 ((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
|
38 ((const char *) (cache)->data + offset)) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
40 #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
|
41 ((cache)->hdr == NULL) |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
42 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 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
|
44 /* 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
|
45 compatibility. */ |
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
46 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
|
47 uint8_t compat_sizeof_uoff_t; |
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3627
diff
changeset
|
48 uint8_t compat_sizeof_time_t; |
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3627
diff
changeset
|
49 uint8_t unused; |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
50 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 uint32_t indexid; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 uint32_t file_seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 uint32_t continued_record_count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
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
|
56 uint32_t hole_offset; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 uint32_t used_file_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 uint32_t deleted_space; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
60 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
|
61 }; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
62 |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
63 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
|
64 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
|
65 uint32_t size; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
66 uint32_t fields_count; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
68 #if 0 |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
69 /* 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
|
70 once a day. */ |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
71 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
|
72 /* (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
|
73 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
|
74 /* 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
|
75 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
|
76 /* 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
|
77 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
|
78 /* 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
|
79 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
|
80 #endif |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
83 #define MAIL_CACHE_FIELD_LAST_USED() \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
84 (sizeof(uint32_t) * 3) |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
85 #define MAIL_CACHE_FIELD_SIZE(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
86 (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
|
87 #define MAIL_CACHE_FIELD_TYPE(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
88 (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
|
89 #define MAIL_CACHE_FIELD_DECISION(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
90 (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
|
91 #define MAIL_CACHE_FIELD_NAMES(count) \ |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
92 (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
|
93 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 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
|
95 uint32_t prev_offset; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 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
|
97 /* 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
|
98 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 |
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
|
100 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
|
101 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
|
102 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
|
103 |
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 /* 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
|
105 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
|
106 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
|
107 #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
|
108 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
|
109 }; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
110 |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
111 struct mail_cache_field_private { |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
112 struct mail_cache_field field; |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
113 |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
114 uint32_t uid_highwater; |
2342 | 115 uint32_t last_used; |
2339
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 unsigned int decision_dirty:1; |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
118 }; |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
119 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 struct mail_cache { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 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
|
122 uint32_t ext_id; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 char *filepath; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 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
|
128 const void *data; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 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
|
130 struct file_cache *file_cache; |
3106 | 131 |
132 struct dotlock_settings dotlock_settings; | |
133 struct dotlock *dotlock; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 |
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
|
135 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
|
136 struct mail_cache_header hdr_copy; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
138 pool_t field_pool; |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 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
|
143 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
144 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
|
145 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
|
146 |
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
|
147 unsigned int locked:1; |
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
|
148 unsigned int need_compress: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
|
149 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
|
150 unsigned int field_header_write_pending:1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 struct mail_cache_view { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 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
|
155 struct mail_index_view *view, *trans_view; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 |
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
|
157 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
|
158 uint32_t trans_seq1, trans_seq2; |
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
159 |
3191
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
160 /* temporary array, just to avoid mallocs. */ |
0df3f5d71958
Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
161 array_t 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
|
162 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
163 /* 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 uint32_t cached_exists_seq; |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
169 uint32_t cached_offset, cached_offset_seq; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 |
2315
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
172 typedef int mail_cache_foreach_callback_t(struct mail_cache_view *view, |
2619 | 173 uint32_t field, |
2315
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
174 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
|
175 void *context); |
22210d6cf238
Cache fixes. Lookups now look into transactions too.
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
176 |
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
|
177 /* 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
|
178 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
|
179 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
|
180 /* 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
|
181 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
|
182 |
3375
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
183 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
|
184 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
|
185 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2315
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 uint32_t *offset_r); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 |
2917
e657c7874962
Crashfixes for reading corrupted cache files.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
192 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
|
193 const struct mail_cache_record **rec_r); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 |
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
|
195 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
|
196 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
|
197 |
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
|
198 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
|
199 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
|
200 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 |
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
|
205 /* 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
|
206 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
|
207 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
|
208 /* 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
|
209 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
|
210 |
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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
216 int mail_cache_expunge_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
|
217 uint32_t seq, const void *data, void **context); |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 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
|
222 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 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
|
224 const char *function); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 #endif |