annotate src/lib-index/mail-cache-compress.c @ 5736:b3ed52bbeca7 HEAD

Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
author Timo Sirainen <tss@iki.fi>
date Thu, 14 Jun 2007 04:40:34 +0300
parents 4b5ce642957d
children 615a8c31ff47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
1 /* Copyright (C) 2003-2004 Timo Sirainen */
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
2
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
3 #include "lib.h"
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
4 #include "array.h"
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
5 #include "ostream.h"
4247
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
6 #include "nfs-workarounds.h"
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
7 #include "read-full.h"
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
8 #include "close-keep-errno.h"
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
9 #include "file-dotlock.h"
2866
bf1e718e7370 Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
10 #include "file-cache.h"
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
11 #include "file-set-size.h"
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
12 #include "mail-cache-private.h"
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
13
2879
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
14 #include <sys/stat.h>
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
15
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
16 struct mail_cache_copy_context {
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
17 struct mail_cache *cache;
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
18
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
19 buffer_t *buffer, *field_seen;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
20 uint8_t field_seen_value;
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
21 bool new_msg;
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
22 };
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
23
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
24 static void mail_cache_merge_bitmask(struct mail_cache *cache, buffer_t *buffer,
2619
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
25 uint32_t field, const void *data,
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
26 size_t data_size)
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
27 {
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
28 void *buf_data;
2620
Timo Sirainen <tss@iki.fi>
parents: 2619
diff changeset
29 uint32_t buf_field;
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
30 unsigned int i, buf_data_size;
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
31 size_t pos, buf_size;
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
32
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4247
diff changeset
33 buf_data = buffer_get_modifiable_data(buffer, &buf_size);
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
34 for (pos = sizeof(struct mail_cache_record); pos < buf_size; ) {
2620
Timo Sirainen <tss@iki.fi>
parents: 2619
diff changeset
35 buf_field = *((uint32_t *)PTR_OFFSET(buf_data, pos));
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
36 pos += sizeof(uint32_t);
2700
5b07b6fd9bf8 Added asserts
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
37 i_assert(buf_field < cache->fields_count);
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
38
2623
0157839e3c78 bitmask merging code was corrupting the cache file
Timo Sirainen <tss@iki.fi>
parents: 2620
diff changeset
39 buf_data_size = cache->fields[buf_field].field.field_size;
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
40 if (buf_data_size == (unsigned int)-1) {
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
41 buf_data_size =
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
42 *((uint32_t *)PTR_OFFSET(buf_data, pos));
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
43 pos += sizeof(uint32_t);
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
44 }
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
45
2620
Timo Sirainen <tss@iki.fi>
parents: 2619
diff changeset
46 if (buf_field == field) {
2700
5b07b6fd9bf8 Added asserts
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
47 /* @UNSAFE: found it, do the merging */
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
48 unsigned char *dest = PTR_OFFSET(buf_data, pos);
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
49
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
50 i_assert(buf_data_size == data_size);
2700
5b07b6fd9bf8 Added asserts
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
51 i_assert(pos + buf_data_size <= buf_size);
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
52 for (i = 0; i < buf_data_size; i++)
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
53 dest[i] |= ((const unsigned char*)data)[i];
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
54 break;
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
55 }
2950
30110ac226a7 mail_cache_merge_bitmask() was broken, cache compression could have crashed
Timo Sirainen <tss@iki.fi>
parents: 2949
diff changeset
56 pos += (buf_data_size + 3) & ~3;
2700
5b07b6fd9bf8 Added asserts
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
57 i_assert(pos <= buf_size);
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
58 }
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
59 }
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
60
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
61 static void
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
62 mail_cache_compress_field(struct mail_cache_copy_context *ctx,
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
63 const struct mail_cache_iterate_field *field)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 {
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
65 uint32_t field_idx = field->field_idx;
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
66 struct mail_cache_field *cache_field;
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
67 enum mail_cache_decision_type dec;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
68 uint8_t *field_seen;
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
69 uint32_t size32;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
71 cache_field = &ctx->cache->fields[field_idx].field;
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
72
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
73 field_seen = buffer_get_space_unsafe(ctx->field_seen, field_idx, 1);
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
74 if (*field_seen == ctx->field_seen_value) {
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
75 /* duplicate */
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
76 if (cache_field->type == MAIL_CACHE_FIELD_BITMASK) {
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
77 mail_cache_merge_bitmask(ctx->cache, ctx->buffer,
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
78 field_idx, field->data,
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
79 field->size);
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
80 }
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
81 return;
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
82 }
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
83 *field_seen = ctx->field_seen_value;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
84
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
85 dec = cache_field->decision & ~MAIL_CACHE_DECISION_FORCED;
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
86 if (ctx->new_msg) {
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
87 if (dec == MAIL_CACHE_DECISION_NO)
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
88 return;
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
89 } else {
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
90 if (dec != MAIL_CACHE_DECISION_YES)
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
91 return;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
94 buffer_append(ctx->buffer, &field_idx, sizeof(field_idx));
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95
2555
87af1f39a69e Added support for bitmask type.
Timo Sirainen <tss@iki.fi>
parents: 2407
diff changeset
96 if (cache_field->field_size == (unsigned int)-1) {
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
97 size32 = (uint32_t)field->size;
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
98 buffer_append(ctx->buffer, &size32, sizeof(size32));
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
99 }
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
100
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
101 buffer_append(ctx->buffer, field->data, field->size);
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
102 if ((field->size & 3) != 0)
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
103 buffer_append_zero(ctx->buffer, 4 - (field->size & 3));
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
106 static uint32_t
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
107 get_next_file_seq(struct mail_cache *cache, struct mail_index_view *view)
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
108 {
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
109 const struct mail_index_ext *ext;
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
110 uint32_t file_seq;
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
111
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
112 ext = mail_index_view_get_ext(view, cache->ext_id);
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
113 file_seq = ext != NULL ? ext->reset_id + 1 : (uint32_t)ioloop_time;
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
114 return file_seq != 0 ? file_seq : 1;
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
115 }
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
116
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
117 static int
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
118 mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
119 int fd, uint32_t *file_seq_r,
5733
4b5ce642957d Declare a global uint32_t array type.
Timo Sirainen <tss@iki.fi>
parents: 5652
diff changeset
120 ARRAY_TYPE(uint32_t) *ext_offsets)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 {
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
122 struct mail_cache_copy_context ctx;
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
123 struct mail_cache_lookup_iterate_ctx iter;
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
124 struct mail_cache_iterate_field field;
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
125 struct mail_index_view *view;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
126 struct mail_cache_view *cache_view;
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
127 const struct mail_index_header *idx_hdr;
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
128 struct mail_cache_header hdr;
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
129 struct mail_cache_record cache_rec;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
130 struct ostream *output;
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
131 buffer_t *buffer;
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
132 uint32_t i, message_count, seq, first_new_seq, ext_offset;
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
133
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
134 view = mail_index_transaction_get_view(trans);
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
135
3551
65dc45982df9 Removed fcntl() text from some locking error messages, because if
Timo Sirainen <tss@iki.fi>
parents: 3243
diff changeset
136 /* get sequence of first message which doesn't need its temp fields
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
137 removed. */
2892
62d53b49110d Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents: 2879
diff changeset
138 idx_hdr = mail_index_get_header(view);
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
139 if (idx_hdr->day_first_uid[7] == 0) {
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
140 first_new_seq = 1;
2904
642ba9cd3dac Removed view->messages_count, view->hdr.messages_count is enough. Also fixes
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
141 message_count = mail_index_view_get_messages_count(view);
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
142 } else {
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
143 if (mail_index_lookup_uid_range(view, idx_hdr->day_first_uid[7],
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
144 (uint32_t)-1, &first_new_seq,
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
145 &message_count) < 0)
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
146 return -1;
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
147 if (first_new_seq == 0)
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
148 first_new_seq = message_count+1;
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
149 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
151 cache_view = mail_cache_view_open(cache, view);
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
152 output = o_stream_create_file(fd, default_pool, 0, FALSE);
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
153
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
154 memset(&hdr, 0, sizeof(hdr));
2276
5f374049abdb Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents: 2275
diff changeset
155 hdr.version = MAIL_CACHE_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
156 hdr.compat_sizeof_uoff_t = sizeof(uoff_t);
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
157 hdr.indexid = idx_hdr->indexid;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2708
diff changeset
158 hdr.file_seq = get_next_file_seq(cache, view);
2339
406692edc12d Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
159 o_stream_send(output, &hdr, sizeof(hdr));
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
161 memset(&ctx, 0, sizeof(ctx));
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
162 ctx.cache = cache;
2708
f1e9f3ec8135 Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents: 2700
diff changeset
163 ctx.buffer = buffer_create_dynamic(default_pool, 4096);
f1e9f3ec8135 Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents: 2700
diff changeset
164 ctx.field_seen = buffer_create_dynamic(default_pool, 64);
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
165 ctx.field_seen_value = 0;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
167 t_array_init(ext_offsets, message_count);
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
168 for (seq = 1; seq <= message_count; seq++) {
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
169 if (mail_index_transaction_is_expunged(trans, seq)) {
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
170 (void)array_append_space(ext_offsets);
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
171 continue;
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
172 }
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
173
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
174 ctx.new_msg = seq >= first_new_seq;
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
175 buffer_set_used_size(ctx.buffer, 0);
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
176
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
177 if (++ctx.field_seen_value == 0) {
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4247
diff changeset
178 memset(buffer_get_modifiable_data(ctx.field_seen, NULL),
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
179 0, buffer_get_size(ctx.field_seen));
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
180 ctx.field_seen_value++;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
181 }
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
182
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
183 memset(&cache_rec, 0, sizeof(cache_rec));
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
184 buffer_append(ctx.buffer, &cache_rec, sizeof(cache_rec));
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
185
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
186 mail_cache_lookup_iter_init(cache_view, seq, &iter);
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
187 while (mail_cache_lookup_iter_next(&iter, &field) > 0)
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
188 mail_cache_compress_field(&ctx, &field);
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
189
2299
ef0cd18d674c Fixed compression.
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
190 cache_rec.size = buffer_get_used_size(ctx.buffer);
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
191 if (cache_rec.size == sizeof(cache_rec)) {
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
192 /* nothing cached */
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
193 ext_offset = 0;
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
194 } else {
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
195 ext_offset = output->offset;
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
196 buffer_write(ctx.buffer, 0, &cache_rec,
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
197 sizeof(cache_rec));
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
198 o_stream_send(output, ctx.buffer->data, cache_rec.size);
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
199 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
201 array_append(ext_offsets, &ext_offset, 1);
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
202 }
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
203 i_assert(array_count(ext_offsets) == message_count);
2619
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
204
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
205 if (cache->fields_count != 0) {
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
206 hdr.field_header_offset =
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
207 mail_index_uint32_to_offset(output->offset);
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
208
2671
3b70ddb51771 Renamed "extra record info" and variations of it to "extension" or "ext" in
Timo Sirainen <tss@iki.fi>
parents: 2641
diff changeset
209 /* we wrote everything using our internal field ids. so we want
2619
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
210 mail_cache_header_fields_get() to use them and ignore any
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
211 existing id mappings in the old cache file. */
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
212 cache->file_fields_count = 0;
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
213 for (i = 0; i < cache->fields_count; i++)
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
214 cache->field_file_map[i] = (uint32_t)-1;
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
215
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
216 t_push();
2708
f1e9f3ec8135 Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents: 2700
diff changeset
217 buffer = buffer_create_dynamic(pool_datastack_create(), 256);
2619
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
218 mail_cache_header_fields_get(cache, buffer);
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
219 o_stream_send(output, buffer_get_data(buffer, NULL),
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
220 buffer_get_used_size(buffer));
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
221 t_pop();
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
222 }
ce8647d94bfc ID mapping fixes.
Timo Sirainen <tss@iki.fi>
parents: 2604
diff changeset
223
2276
5f374049abdb Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents: 2275
diff changeset
224 hdr.used_file_size = output->offset;
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2282
diff changeset
225 buffer_free(ctx.buffer);
2641
e357ebb3137b Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 2623
diff changeset
226 buffer_free(ctx.field_seen);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
228 o_stream_seek(output, 0);
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
229 o_stream_send(output, &hdr, sizeof(hdr));
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
230
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
231 mail_cache_view_close(cache_view);
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
232
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
233 if (o_stream_flush(output) < 0) {
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
234 errno = output->stream_errno;
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
235 mail_cache_set_syscall_error(cache, "o_stream_flush()");
4070
71b8faa84ec6 Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
236 o_stream_destroy(&output);
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
237 return -1;
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
238 }
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
239
2299
ef0cd18d674c Fixed compression.
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
240 if (hdr.used_file_size < MAIL_CACHE_INITIAL_SIZE) {
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
241 /* grow the file some more. doesn't matter if it fails */
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
242 (void)file_set_size(fd, MAIL_CACHE_INITIAL_SIZE);
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
243 }
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2257
diff changeset
244
4070
71b8faa84ec6 Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
245 o_stream_destroy(&output);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246
4918
2f9173e103fd Added fsync_disable setting. Also added missing fsync()ing to dbox when
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
247 if (!cache->index->fsync_disable) {
2f9173e103fd Added fsync_disable setting. Also added missing fsync()ing to dbox when
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
248 if (fdatasync(fd) < 0) {
2f9173e103fd Added fsync_disable setting. Also added missing fsync()ing to dbox when
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
249 mail_cache_set_syscall_error(cache, "fdatasync()");
2f9173e103fd Added fsync_disable setting. Also added missing fsync()ing to dbox when
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
250 return -1;
2f9173e103fd Added fsync_disable setting. Also added missing fsync()ing to dbox when
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
251 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
254 *file_seq_r = hdr.file_seq;
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
255 return 0;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257
4247
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
258 static int mail_cache_compress_has_file_changed(struct mail_cache *cache)
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
259 {
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
260 struct mail_cache_header hdr;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
261 unsigned int i;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
262 int fd, ret;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
263
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
264 for (i = 0;; i++) {
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
265 fd = nfs_safe_open(cache->filepath, O_RDONLY);
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
266 if (fd == -1) {
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
267 if (errno == ENOENT)
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
268 return 0;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
269
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
270 mail_cache_set_syscall_error(cache, "open()");
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
271 return -1;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
272 }
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
273
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
274 ret = read_full(fd, &hdr, sizeof(hdr));
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
275 close_keep_errno(fd);
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
276
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
277 if (ret >= 0) {
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
278 if (ret == 0)
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
279 return 0;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
280 if (cache->need_compress_file_seq == (uint32_t)-1) {
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
281 /* previously it didn't exist */
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
282 return 1;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
283 }
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
284 return hdr.file_seq != cache->need_compress_file_seq;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
285 } else if (errno != ESTALE || i >= NFS_ESTALE_RETRY_COUNT) {
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
286 mail_cache_set_syscall_error(cache, "read()");
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
287 return -1;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
288 }
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
289 }
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
290 }
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
291
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
292 static int mail_cache_compress_locked(struct mail_cache *cache,
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
293 struct mail_index_transaction *trans,
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
294 bool *unlock)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 {
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
296 struct dotlock *dotlock;
2879
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
297 mode_t old_mask;
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
298 uint32_t file_seq, old_offset;
5733
4b5ce642957d Declare a global uint32_t array type.
Timo Sirainen <tss@iki.fi>
parents: 5652
diff changeset
299 ARRAY_TYPE(uint32_t) ext_offsets;
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
300 const uint32_t *offsets;
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
301 unsigned int i, count;
4247
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
302 int fd, ret;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303
5736
b3ed52bbeca7 Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents: 5733
diff changeset
304 i_warning("cache compress");
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
305 /* get the latest info on fields */
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
306 if (mail_cache_header_fields_read(cache) < 0)
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
307 return -1;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2299
diff changeset
308
2879
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
309 old_mask = umask(cache->index->mode ^ 0666);
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
310 fd = file_dotlock_open(&cache->dotlock_settings, cache->filepath,
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
311 0, &dotlock);
2879
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
312 umask(old_mask);
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
313
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 if (fd == -1) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 mail_cache_set_syscall_error(cache, "file_dotlock_open()");
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
316 return -1;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318
4247
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
319 if ((ret = mail_cache_compress_has_file_changed(cache)) != 0) {
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
320 if (ret < 0)
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
321 return -1;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
322
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
323 /* was just compressed, forget this */
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
324 cache->need_compress_file_seq = 0;
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
325 file_dotlock_delete(&dotlock);
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
326
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
327 if (*unlock) {
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
328 (void)mail_cache_unlock(cache);
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
329 *unlock = FALSE;
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
330 }
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
331
4247
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
332 return mail_cache_reopen(cache);
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
333 }
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
334
2879
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
335 if (cache->index->gid != (gid_t)-1 &&
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
336 fchown(fd, (uid_t)-1, cache->index->gid) < 0) {
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
337 mail_cache_set_syscall_error(cache, "fchown()");
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
338 file_dotlock_delete(&dotlock);
2879
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
339 return -1;
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
340 }
aa93c7216722 dovecot-shared file was supposed to show permissions/gid for files created
Timo Sirainen <tss@iki.fi>
parents: 2877
diff changeset
341
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
342 t_push();
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
343 if (mail_cache_copy(cache, trans, fd, &file_seq, &ext_offsets) < 0) {
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
344 (void)file_dotlock_delete(&dotlock);
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
345 t_pop();
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
346 return -1;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
347 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
349 if (file_dotlock_replace(&dotlock,
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 2950
diff changeset
350 DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) < 0) {
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
351 mail_cache_set_syscall_error(cache,
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
352 "file_dotlock_replace()");
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
353 (void)close(fd);
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
354 t_pop();
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
355 return -1;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
356 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
357
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
358 /* once we're sure that the compression was successful,
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
359 update the offsets */
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
360 mail_index_ext_reset(trans, cache->ext_id, file_seq);
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
361 offsets = array_get(&ext_offsets, &count);
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
362 for (i = 0; i < count; i++) {
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
363 if (offsets[i] != 0) {
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
364 mail_index_update_ext(trans, i + 1, cache->ext_id,
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
365 &offsets[i], &old_offset);
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
366 }
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
367 }
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
368 t_pop();
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
369
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
370 if (*unlock) {
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
371 (void)mail_cache_unlock(cache);
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
372 *unlock = FALSE;
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
373 }
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
374
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
375 mail_cache_file_close(cache);
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
376 cache->fd = fd;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
377
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
378 if (cache->file_cache != NULL)
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
379 file_cache_set_fd(cache->file_cache, cache->fd);
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
380
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
381 if (mail_cache_map(cache, 0, 0) < 0)
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
382 return -1;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
383 if (mail_cache_header_fields_read(cache) < 0)
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
384 return -1;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
385
4247
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
386 cache->need_compress_file_seq = 0;
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
387 return 0;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
388 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
390 int mail_cache_compress(struct mail_cache *cache,
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
391 struct mail_index_transaction *trans)
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
392 {
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
393 bool unlock = FALSE;
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
394 int ret;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
395
3243
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3106
diff changeset
396 if (MAIL_INDEX_IS_IN_MEMORY(cache->index))
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3106
diff changeset
397 return 0;
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3106
diff changeset
398
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
399 if (cache->index->lock_method == FILE_LOCK_METHOD_DOTLOCK) {
2949
05ae72649fd0 Cache compression didn't work with lock_method = dotlock.
Timo Sirainen <tss@iki.fi>
parents: 2929
diff changeset
400 /* we're using dotlocking, cache file creation itself creates
05ae72649fd0 Cache compression didn't work with lock_method = dotlock.
Timo Sirainen <tss@iki.fi>
parents: 2929
diff changeset
401 the dotlock file we need. */
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
402 return mail_cache_compress_locked(cache, trans, &unlock);
2949
05ae72649fd0 Cache compression didn't work with lock_method = dotlock.
Timo Sirainen <tss@iki.fi>
parents: 2929
diff changeset
403 }
05ae72649fd0 Cache compression didn't work with lock_method = dotlock.
Timo Sirainen <tss@iki.fi>
parents: 2929
diff changeset
404
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
405 switch (mail_cache_lock(cache)) {
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
406 case -1:
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
407 return -1;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
408 case 0:
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
409 /* couldn't lock, either it's broken or doesn't exist.
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
410 just start creating it. */
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
411 return mail_cache_compress_locked(cache, trans, &unlock);
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
412 default:
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
413 /* locking succeeded. */
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
414 unlock = TRUE;
5652
9404d2c41cb2 When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents: 5027
diff changeset
415 ret = mail_cache_compress_locked(cache, trans, &unlock);
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
416 if (unlock) {
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
417 if (mail_cache_unlock(cache) < 0)
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
418 ret = -1;
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4795
diff changeset
419 }
2929
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
420 return ret;
ba9062032877 Locking fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents: 2904
diff changeset
421 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422 }
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
423
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3819
diff changeset
424 bool mail_cache_need_compress(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: 2200
diff changeset
425 {
4247
9c3f19110538 Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
426 return cache->need_compress_file_seq != 0;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents: 2200
diff changeset
427 }