Mercurial > dovecot > core-2.2
annotate src/lib-index/mail-index-sync.c @ 22576:707ae9de3812
lib: istream-multiplex - Minor code cleanup
Avoid propagating the error twice, and avoid any confusion about what "got"
actually contains.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 05 Oct 2017 20:24:11 +0300 |
parents | 2d9175af5c99 |
children | bf758ce6ee6d |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21389
diff
changeset
|
1 /* Copyright (c) 2003-2017 Dovecot authors, see the included COPYING file */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3445
diff
changeset
|
4 #include "array.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "mail-index-view-private.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "mail-index-sync-private.h" |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
7 #include "mail-index-transaction-private.h" |
2963
c0bdb35277fc
If log file sequences get broken, complain instead of crashing.
Timo Sirainen <tss@iki.fi>
parents:
2904
diff
changeset
|
8 #include "mail-transaction-log-private.h" |
17905
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
9 #include "mail-cache-private.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
11 #include <stdio.h> |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
13 struct mail_index_sync_ctx { |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
14 struct mail_index *index; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
15 struct mail_index_view *view; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
16 struct mail_index_transaction *sync_trans, *ext_trans; |
10367
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
17 struct mail_index_transaction_commit_result *sync_commit_result; |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
18 enum mail_index_sync_flags flags; |
19800
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
19 char *reason; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
20 |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
21 const struct mail_transaction_header *hdr; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
22 const void *data; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
23 |
14920
a097ef0a9d6d
Array API changed: ARRAY_DEFINE(name, type) -> ARRAY(type) name
Timo Sirainen <tss@iki.fi>
parents:
14877
diff
changeset
|
24 ARRAY(struct mail_index_sync_list) sync_list; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
25 uint32_t next_uid; |
17928
193c82411d73
lib-index: Added mail_index_sync_no_warning() to prevent "long transaction lock" warnings.
Timo Sirainen <tss@iki.fi>
parents:
17927
diff
changeset
|
26 |
193c82411d73
lib-index: Added mail_index_sync_no_warning() to prevent "long transaction lock" warnings.
Timo Sirainen <tss@iki.fi>
parents:
17927
diff
changeset
|
27 unsigned int no_warning:1; |
18843
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
28 unsigned int seen_nonexternal_transactions:1; |
21158
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
29 unsigned int fully_synced:1; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
30 }; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
31 |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
32 static void mail_index_sync_add_expunge(struct mail_index_sync_ctx *ctx) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 { |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
34 const struct mail_transaction_expunge *e = ctx->data; |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
35 size_t i, size = ctx->hdr->size / sizeof(*e); |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
36 uint32_t uid; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
38 for (i = 0; i < size; i++) { |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
39 for (uid = e[i].uid1; uid <= e[i].uid2; uid++) |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
40 mail_index_expunge(ctx->sync_trans, uid); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
41 } |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
42 } |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
43 |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
44 static void mail_index_sync_add_expunge_guid(struct mail_index_sync_ctx *ctx) |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
45 { |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
46 const struct mail_transaction_expunge_guid *e = ctx->data; |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
47 size_t i, size = ctx->hdr->size / sizeof(*e); |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
48 |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
49 for (i = 0; i < size; i++) { |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
50 mail_index_expunge_guid(ctx->sync_trans, e[i].uid, |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
51 e[i].guid_128); |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
52 } |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
53 } |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
54 |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
55 static void mail_index_sync_add_flag_update(struct mail_index_sync_ctx *ctx) |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
56 { |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
57 const struct mail_transaction_flag_update *u = ctx->data; |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
58 size_t i, size = ctx->hdr->size / sizeof(*u); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
60 for (i = 0; i < size; i++) { |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
61 if (u[i].add_flags != 0) { |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
62 mail_index_update_flags_range(ctx->sync_trans, |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
63 u[i].uid1, u[i].uid2, |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
64 MODIFY_ADD, |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
65 u[i].add_flags); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 } |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
67 if (u[i].remove_flags != 0) { |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
68 mail_index_update_flags_range(ctx->sync_trans, |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
69 u[i].uid1, u[i].uid2, |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
70 MODIFY_REMOVE, |
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
71 u[i].remove_flags); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
72 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
76 static void mail_index_sync_add_keyword_update(struct mail_index_sync_ctx *ctx) |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
77 { |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
78 const struct mail_transaction_keyword_update *u = ctx->data; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
79 const char *keyword_names[2]; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
80 struct mail_keywords *keywords; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
81 const uint32_t *uids; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
82 uint32_t uid; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
83 size_t uidset_offset, i, size; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
84 |
13889
931436c5f2cc
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
13752
diff
changeset
|
85 i_assert(u->name_size > 0); |
931436c5f2cc
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
13752
diff
changeset
|
86 |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
87 uidset_offset = sizeof(*u) + u->name_size; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
88 if ((uidset_offset % 4) != 0) |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
89 uidset_offset += 4 - (uidset_offset % 4); |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
90 uids = CONST_PTR_OFFSET(u, uidset_offset); |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
91 |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
92 keyword_names[0] = t_strndup(u + 1, u->name_size); |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
93 keyword_names[1] = NULL; |
6354
8476d665530f
Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents:
6332
diff
changeset
|
94 keywords = mail_index_keywords_create(ctx->index, keyword_names); |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
95 |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
96 size = (ctx->hdr->size - uidset_offset) / sizeof(uint32_t); |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
97 for (i = 0; i < size; i += 2) { |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
98 /* FIXME: mail_index_update_keywords_range() */ |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
99 for (uid = uids[i]; uid <= uids[i+1]; uid++) { |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
100 mail_index_update_keywords(ctx->sync_trans, uid, |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
101 u->modify_type, keywords); |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
102 } |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
103 } |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
104 |
9508
094ad127d132
Added reference counting to struct mail_keywords and related APIs.
Timo Sirainen <tss@iki.fi>
parents:
9001
diff
changeset
|
105 mail_index_keywords_unref(&keywords); |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
106 } |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
107 |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
108 static void mail_index_sync_add_keyword_reset(struct mail_index_sync_ctx *ctx) |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
109 { |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
110 const struct mail_transaction_keyword_reset *u = ctx->data; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
111 size_t i, size = ctx->hdr->size / sizeof(*u); |
3150 | 112 struct mail_keywords *keywords; |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
113 uint32_t uid; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
114 |
6354
8476d665530f
Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents:
6332
diff
changeset
|
115 keywords = mail_index_keywords_create(ctx->index, NULL); |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
116 for (i = 0; i < size; i++) { |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
117 for (uid = u[i].uid1; uid <= u[i].uid2; uid++) { |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
118 mail_index_update_keywords(ctx->sync_trans, uid, |
3150 | 119 MODIFY_REPLACE, keywords); |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
120 } |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
121 } |
9508
094ad127d132
Added reference counting to struct mail_keywords and related APIs.
Timo Sirainen <tss@iki.fi>
parents:
9001
diff
changeset
|
122 mail_index_keywords_unref(&keywords); |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
123 } |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
124 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
125 static bool mail_index_sync_add_transaction(struct mail_index_sync_ctx *ctx) |
1915
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 switch (ctx->hdr->type & MAIL_TRANSACTION_TYPE_MASK) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 case MAIL_TRANSACTION_EXPUNGE: |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
129 mail_index_sync_add_expunge(ctx); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 break; |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
131 case MAIL_TRANSACTION_EXPUNGE_GUID: |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
132 mail_index_sync_add_expunge_guid(ctx); |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
133 break; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 case MAIL_TRANSACTION_FLAG_UPDATE: |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
135 mail_index_sync_add_flag_update(ctx); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 break; |
3146
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
137 case MAIL_TRANSACTION_KEYWORD_UPDATE: |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
138 mail_index_sync_add_keyword_update(ctx); |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
139 break; |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
140 case MAIL_TRANSACTION_KEYWORD_RESET: |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
141 mail_index_sync_add_keyword_reset(ctx); |
9a8bf1c86699
Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents:
3140
diff
changeset
|
142 break; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
143 default: |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
144 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
146 return TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6091
diff
changeset
|
149 static void mail_index_sync_add_dirty_updates(struct mail_index_sync_ctx *ctx) |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
150 { |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
151 struct mail_transaction_flag_update update; |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
152 const struct mail_index_record *rec; |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
153 uint32_t seq, messages_count; |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
154 |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21158
diff
changeset
|
155 i_zero(&update); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
156 |
2904
642ba9cd3dac
Removed view->messages_count, view->hdr.messages_count is enough. Also fixes
Timo Sirainen <tss@iki.fi>
parents:
2895
diff
changeset
|
157 messages_count = mail_index_view_get_messages_count(ctx->view); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
158 for (seq = 1; seq <= messages_count; seq++) { |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6091
diff
changeset
|
159 rec = mail_index_lookup(ctx->view, seq); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
160 if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) == 0) |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
161 continue; |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
162 |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
163 mail_index_update_flags(ctx->sync_trans, rec->uid, |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
164 MODIFY_REPLACE, rec->flags); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
165 } |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
166 } |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
167 |
2373 | 168 static int |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
169 mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 { |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
171 struct mail_index_transaction *sync_trans = ctx->sync_trans; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
172 struct mail_index_sync_list *synclist; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
173 const struct mail_index_transaction_keyword_update *keyword_updates; |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
174 unsigned int i, keyword_count; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 |
21530
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
177 if ((ctx->view->map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 && |
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
178 (ctx->flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0 && |
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
179 (ctx->view->index->flags & MAIL_INDEX_OPEN_FLAG_NO_DIRTY) == 0) { |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
180 /* show dirty flags as flag updates */ |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6091
diff
changeset
|
181 mail_index_sync_add_dirty_updates(ctx); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
182 } |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
183 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
184 /* read all transactions from log into a transaction in memory. |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
185 skip the external ones, they're already synced to mailbox and |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
186 included in our view */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 while ((ret = mail_transaction_log_view_next(ctx->view->log_view, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 &ctx->hdr, |
5728
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5725
diff
changeset
|
189 &ctx->data)) > 0) { |
2819
bea9c88c8763
Use separate sync offsets for internal/external transactions. Pending external
Timo Sirainen <tss@iki.fi>
parents:
2760
diff
changeset
|
190 if ((ctx->hdr->type & MAIL_TRANSACTION_EXTERNAL) != 0) |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
191 continue; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
192 |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7145
diff
changeset
|
193 T_BEGIN { |
19323
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
194 if (mail_index_sync_add_transaction(ctx)) { |
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
195 /* update tail_offset if needed */ |
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
196 ctx->seen_nonexternal_transactions = TRUE; |
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
197 } else { |
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
198 /* this is an internal change. we don't |
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
199 necessarily need to update tail_offset, so |
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
200 avoid the extra write caused by it. */ |
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
201 } |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7145
diff
changeset
|
202 } T_END; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
205 /* create an array containing all expunge, flag and keyword update |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
206 arrays so we can easily go through all of the changes. */ |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
207 keyword_count = !array_is_created(&sync_trans->keyword_updates) ? 0 : |
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
208 array_count(&sync_trans->keyword_updates); |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
209 i_array_init(&ctx->sync_list, keyword_count + 2); |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
210 |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
211 if (array_is_created(&sync_trans->expunges)) { |
19786
deed74084f66
lib-index: mail_index_sync_next() didn't always return expunges sorted
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
212 mail_index_transaction_sort_expunges(sync_trans); |
3445
74475a126e2f
Renamed array_modifyable_*() functions. I could never remember how they were
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
213 synclist = array_append_space(&ctx->sync_list); |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
214 synclist->array = (void *)&sync_trans->expunges; |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
215 } |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
216 |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
217 if (array_is_created(&sync_trans->updates)) { |
3445
74475a126e2f
Renamed array_modifyable_*() functions. I could never remember how they were
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
218 synclist = array_append_space(&ctx->sync_list); |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
219 synclist->array = (void *)&sync_trans->updates; |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
220 } |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
221 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
222 keyword_updates = keyword_count == 0 ? NULL : |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
223 array_idx(&sync_trans->keyword_updates, 0); |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
224 for (i = 0; i < keyword_count; i++) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
225 if (array_is_created(&keyword_updates[i].add_seq)) { |
3445
74475a126e2f
Renamed array_modifyable_*() functions. I could never remember how they were
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
226 synclist = array_append_space(&ctx->sync_list); |
10998
be5b93c18203
Avoid casting away const qualifiers wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
10678
diff
changeset
|
227 synclist->array = |
be5b93c18203
Avoid casting away const qualifiers wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
10678
diff
changeset
|
228 (const void *)&keyword_updates[i].add_seq; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
229 synclist->keyword_idx = i; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
230 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
231 if (array_is_created(&keyword_updates[i].remove_seq)) { |
3445
74475a126e2f
Renamed array_modifyable_*() functions. I could never remember how they were
Timo Sirainen <tss@iki.fi>
parents:
3353
diff
changeset
|
232 synclist = array_append_space(&ctx->sync_list); |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4283
diff
changeset
|
233 synclist->array = |
10998
be5b93c18203
Avoid casting away const qualifiers wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
10678
diff
changeset
|
234 (const void *)&keyword_updates[i].remove_seq; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
235 synclist->keyword_idx = i; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
236 synclist->keyword_remove = TRUE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
237 } |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
238 } |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
239 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
243 static bool |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
244 mail_index_need_sync(struct mail_index *index, enum mail_index_sync_flags flags, |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
245 uint32_t log_file_seq, uoff_t log_file_offset) |
1922 | 246 { |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
247 const struct mail_index_header *hdr = &index->map->hdr; |
6809
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
248 if ((flags & MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES) == 0) |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
249 return TRUE; |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
250 |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
251 /* sync only if there's something to do */ |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
252 if (hdr->first_recent_uid < hdr->next_uid && |
5779
b25c9ca2142b
mail_index_sync_begin() takes now flags parameter instead of two booleans.
Timo Sirainen <tss@iki.fi>
parents:
5776
diff
changeset
|
253 (flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0) |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
254 return TRUE; |
2373 | 255 |
21530
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
256 if ((hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 && |
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
257 (flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0 && |
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
258 (index->flags & MAIL_INDEX_OPEN_FLAG_NO_DIRTY) == 0) |
6809
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
259 return TRUE; |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
260 |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
261 if (log_file_seq == (uint32_t)-1) { |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
262 /* we want to sync up to transaction log's head */ |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
263 mail_transaction_log_get_head(index->log, |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
264 &log_file_seq, &log_file_offset); |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
265 } |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
266 if ((hdr->log_file_tail_offset < log_file_offset && |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
267 hdr->log_file_seq == log_file_seq) || |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
268 hdr->log_file_seq < log_file_seq) |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
269 return TRUE; |
1922 | 270 |
6822
f814eecd75cd
When reading an index file created by v1.0, make sure we update the header
Timo Sirainen <tss@iki.fi>
parents:
6810
diff
changeset
|
271 if (index->need_recreate) |
f814eecd75cd
When reading an index file created by v1.0, make sure we update the header
Timo Sirainen <tss@iki.fi>
parents:
6810
diff
changeset
|
272 return TRUE; |
f814eecd75cd
When reading an index file created by v1.0, make sure we update the header
Timo Sirainen <tss@iki.fi>
parents:
6810
diff
changeset
|
273 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
274 /* already synced */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
275 return mail_cache_need_compress(index->cache); |
1922 | 276 } |
277 | |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
278 static int |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
279 mail_index_sync_set_log_view(struct mail_index_view *view, |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
280 uint32_t start_file_seq, uoff_t start_file_offset) |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
281 { |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
282 uint32_t log_seq; |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
283 uoff_t log_offset; |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
284 const char *reason; |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5822
diff
changeset
|
285 bool reset; |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
286 int ret; |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
287 |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
288 mail_transaction_log_get_head(view->index->log, &log_seq, &log_offset); |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
289 |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
290 ret = mail_transaction_log_view_set(view->log_view, |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
291 start_file_seq, start_file_offset, |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
292 log_seq, log_offset, &reset, &reason); |
13750
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
293 if (ret < 0) |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
294 return -1; |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
295 if (ret == 0) { |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
296 /* either corrupted or the file was deleted for |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
297 some reason. either way, we can't go forward */ |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
298 mail_index_set_error(view->index, |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
299 "Unexpected transaction log desync with index %s: %s", |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
300 view->index->filepath, reason); |
13750
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
301 return 0; |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
302 } |
13750
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
303 return 1; |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
304 } |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3825
diff
changeset
|
305 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 int mail_index_sync_begin(struct mail_index *index, |
6332
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
307 struct mail_index_sync_ctx **ctx_r, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 struct mail_index_view **view_r, |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
309 struct mail_index_transaction **trans_r, |
5779
b25c9ca2142b
mail_index_sync_begin() takes now flags parameter instead of two booleans.
Timo Sirainen <tss@iki.fi>
parents:
5776
diff
changeset
|
310 enum mail_index_sync_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 { |
6332
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
312 int ret; |
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
313 |
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
314 ret = mail_index_sync_begin_to(index, ctx_r, view_r, trans_r, |
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
315 (uint32_t)-1, (uoff_t)-1, flags); |
6809
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
316 i_assert(ret != 0 || |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
317 (flags & MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES) != 0); |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
318 return ret; |
6332
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
319 } |
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
320 |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
321 static int |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
322 mail_index_sync_begin_init(struct mail_index *index, |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
323 enum mail_index_sync_flags flags, |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
324 uint32_t log_file_seq, uoff_t log_file_offset) |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
325 { |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
326 const struct mail_index_header *hdr; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
327 uint32_t seq; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
328 uoff_t offset; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
329 bool locked = FALSE; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
330 int ret; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
331 |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
332 /* if we require changes, don't lock transaction log yet. first check |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
333 if there's anything to sync. */ |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
334 if ((flags & MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES) == 0) { |
19799
8dfbf0629359
lib-index: Small improvements to logging the reason for long transaction log lock waits
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19786
diff
changeset
|
335 if (mail_transaction_log_sync_lock(index->log, "syncing", |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
336 &seq, &offset) < 0) |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
337 return -1; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
338 locked = TRUE; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
339 } |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
340 |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
341 /* The view must contain what we expect the mailbox to look like |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
342 currently. That allows the backend to update external flag |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
343 changes (etc.) if the view doesn't match the mailbox. |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
344 |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
345 We'll update the view to contain everything that exist in the |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
346 transaction log except for expunges. They're synced in |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
347 mail_index_sync_commit(). */ |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
348 if ((ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD)) <= 0) { |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
349 if (ret == 0) { |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
350 if (locked) |
17927
fce66ec2ac1c
lib-index: Include reason string in warnings about keeping transaction log locked for too long.
Timo Sirainen <tss@iki.fi>
parents:
17905
diff
changeset
|
351 mail_transaction_log_sync_unlock(index->log, "sync init failure"); |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
352 return -1; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
353 } |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
354 |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
355 /* let's try again */ |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
356 if (mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD) <= 0) { |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
357 if (locked) |
17927
fce66ec2ac1c
lib-index: Include reason string in warnings about keeping transaction log locked for too long.
Timo Sirainen <tss@iki.fi>
parents:
17905
diff
changeset
|
358 mail_transaction_log_sync_unlock(index->log, "sync init failure"); |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
359 return -1; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
360 } |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
361 } |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
362 |
17758
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
363 if (!mail_index_need_sync(index, flags, log_file_seq, log_file_offset) && |
22430
2d9175af5c99
lib-index: Fix wrong mail_index_modseq_header automatically
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22326
diff
changeset
|
364 !index->index_deleted && !index->need_recreate) { |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
365 if (locked) |
17927
fce66ec2ac1c
lib-index: Include reason string in warnings about keeping transaction log locked for too long.
Timo Sirainen <tss@iki.fi>
parents:
17905
diff
changeset
|
366 mail_transaction_log_sync_unlock(index->log, "syncing determined unnecessary"); |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
367 return 0; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
368 } |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
369 |
17758
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
370 if (!locked) { |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
371 /* it looks like we have something to sync. lock the file and |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
372 check again. */ |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
373 flags &= ~MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES; |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
374 return mail_index_sync_begin_init(index, flags, log_file_seq, |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
375 log_file_offset); |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
376 } |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
377 |
13188
6db2f76bc493
lib-index: MAIL_INDEX_SYNC_FLAG_DELETING_INDEX now allows committing changes to deleted index.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
378 if (index->index_deleted && |
6db2f76bc493
lib-index: MAIL_INDEX_SYNC_FLAG_DELETING_INDEX now allows committing changes to deleted index.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
379 (flags & MAIL_INDEX_SYNC_FLAG_DELETING_INDEX) == 0) { |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
380 /* index is already deleted. we can't sync. */ |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
381 if (locked) |
17927
fce66ec2ac1c
lib-index: Include reason string in warnings about keeping transaction log locked for too long.
Timo Sirainen <tss@iki.fi>
parents:
17905
diff
changeset
|
382 mail_transaction_log_sync_unlock(index->log, "syncing detected deleted index"); |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
383 return -1; |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
384 } |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
385 |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
386 hdr = &index->map->hdr; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
387 if (hdr->log_file_tail_offset > hdr->log_file_head_offset || |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
388 hdr->log_file_seq > seq || |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
389 (hdr->log_file_seq == seq && hdr->log_file_tail_offset > offset)) { |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
390 /* broken sync positions. fix them. */ |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
391 mail_index_set_error(index, |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
392 "broken sync positions in index file %s", |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
393 index->filepath); |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
394 mail_index_fsck_locked(index); |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
395 } |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
396 return 1; |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
397 } |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
398 |
13752
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
399 static int |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
400 mail_index_sync_begin_to2(struct mail_index *index, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
401 struct mail_index_sync_ctx **ctx_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
402 struct mail_index_view **view_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
403 struct mail_index_transaction **trans_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
404 uint32_t log_file_seq, uoff_t log_file_offset, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
405 enum mail_index_sync_flags flags, bool *retry_r) |
6332
aa4a78b3c626
Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents:
6331
diff
changeset
|
406 { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
407 const struct mail_index_header *hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 struct mail_index_sync_ctx *ctx; |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
409 struct mail_index_view *sync_view; |
6091
c8d7b9fd500e
Added MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES and
Timo Sirainen <tss@iki.fi>
parents:
6089
diff
changeset
|
410 enum mail_index_transaction_flags trans_flags; |
5822 | 411 int ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 |
6756
e78c51d6305f
Fixes to handling cache file syncs and expunging.
Timo Sirainen <tss@iki.fi>
parents:
6450
diff
changeset
|
413 i_assert(!index->syncing); |
e78c51d6305f
Fixes to handling cache file syncs and expunging.
Timo Sirainen <tss@iki.fi>
parents:
6450
diff
changeset
|
414 |
13752
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
415 *retry_r = FALSE; |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
416 |
13422
9815d3292470
lib-index: Don't allow syncing to begin if index is marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13188
diff
changeset
|
417 if (index->map != NULL && |
9815d3292470
lib-index: Don't allow syncing to begin if index is marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13188
diff
changeset
|
418 (index->map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) { |
9815d3292470
lib-index: Don't allow syncing to begin if index is marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13188
diff
changeset
|
419 /* index is corrupted and need to be reopened */ |
9815d3292470
lib-index: Don't allow syncing to begin if index is marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13188
diff
changeset
|
420 return -1; |
9815d3292470
lib-index: Don't allow syncing to begin if index is marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13188
diff
changeset
|
421 } |
9815d3292470
lib-index: Don't allow syncing to begin if index is marked corrupted.
Timo Sirainen <tss@iki.fi>
parents:
13188
diff
changeset
|
422 |
6809
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
423 if (log_file_seq != (uint32_t)-1) |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
424 flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES; |
9d8c00d4c467
Added MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES flag and changed
Timo Sirainen <tss@iki.fi>
parents:
6756
diff
changeset
|
425 |
6810
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
426 ret = mail_index_sync_begin_init(index, flags, log_file_seq, |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
427 log_file_offset); |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
428 if (ret <= 0) |
a4c87d5d881c
If MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set, check if there's anything to
Timo Sirainen <tss@iki.fi>
parents:
6809
diff
changeset
|
429 return ret; |
6377
29f427039e00
fsck won't fail anymore with "corrupted index", all problems are fixed.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
430 |
5772
002aa9bbfcb2
Removed index->hdr. Use index->map->hdr instead.
Timo Sirainen <tss@iki.fi>
parents:
5753
diff
changeset
|
431 hdr = &index->map->hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 ctx = i_new(struct mail_index_sync_ctx, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 ctx->index = index; |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
435 ctx->flags = flags; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 ctx->view = mail_index_view_open(index); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
439 sync_view = mail_index_dummy_view_open(index); |
6089
a19931ec66db
Changed mail_transaction_begin() API to take flags parameter instead of two
Timo Sirainen <tss@iki.fi>
parents:
6071
diff
changeset
|
440 ctx->sync_trans = mail_index_transaction_begin(sync_view, |
a19931ec66db
Changed mail_transaction_begin() API to take flags parameter instead of two
Timo Sirainen <tss@iki.fi>
parents:
6071
diff
changeset
|
441 MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL); |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
442 mail_index_view_close(&sync_view); |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
443 |
12209
a7a953486a0b
lib-index: If mail_index_sync_begin() fails, don't assert-crash
Timo Sirainen <tss@iki.fi>
parents:
12203
diff
changeset
|
444 /* set before any rollbacks are called */ |
a7a953486a0b
lib-index: If mail_index_sync_begin() fails, don't assert-crash
Timo Sirainen <tss@iki.fi>
parents:
12203
diff
changeset
|
445 index->syncing = TRUE; |
a7a953486a0b
lib-index: If mail_index_sync_begin() fails, don't assert-crash
Timo Sirainen <tss@iki.fi>
parents:
12203
diff
changeset
|
446 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
447 /* we wish to see all the changes from last mailbox sync position to |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
448 the end of the transaction log */ |
13750
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
449 ret = mail_index_sync_set_log_view(ctx->view, hdr->log_file_seq, |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
450 hdr->log_file_tail_offset); |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
451 if (ret < 0) { |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
452 mail_index_sync_rollback(&ctx); |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
453 return -1; |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
454 } |
fb0ffce5a0ba
lib-index: Handle transaction log read errors separately from log corruption.
Timo Sirainen <tss@iki.fi>
parents:
13422
diff
changeset
|
455 if (ret == 0) { |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
456 /* if a log file is missing, there's nothing we can do except |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
457 to skip over it. fix the problem with fsck and try again. */ |
6377
29f427039e00
fsck won't fail anymore with "corrupted index", all problems are fixed.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
458 mail_index_fsck_locked(index); |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
459 mail_index_sync_rollback(&ctx); |
13752
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
460 *retry_r = TRUE; |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
461 return 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 /* we need to have all the transactions sorted to optimize |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 caller's mailbox access patterns */ |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
466 if (mail_index_sync_read_and_sort(ctx) < 0) { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
467 mail_index_sync_rollback(&ctx); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 |
4678
6272561fa12d
After saving messages the mailbox wasn't synced, which caused deliver to
Timo Sirainen <tss@iki.fi>
parents:
4602
diff
changeset
|
471 ctx->view->index_sync_view = TRUE; |
5650
e5f0e8cf6089
Sync transaction needs to be created later or we'll crash
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
472 |
e5f0e8cf6089
Sync transaction needs to be created later or we'll crash
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
473 /* create the transaction after the view has been updated with |
e5f0e8cf6089
Sync transaction needs to be created later or we'll crash
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
474 external transactions and marked as sync view */ |
6091
c8d7b9fd500e
Added MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES and
Timo Sirainen <tss@iki.fi>
parents:
6089
diff
changeset
|
475 trans_flags = MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL; |
c8d7b9fd500e
Added MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES and
Timo Sirainen <tss@iki.fi>
parents:
6089
diff
changeset
|
476 if ((ctx->flags & MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES) != 0) |
c8d7b9fd500e
Added MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES and
Timo Sirainen <tss@iki.fi>
parents:
6089
diff
changeset
|
477 trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES; |
8963
375be2dbeea7
Added FSYNC flag for transactions.
Timo Sirainen <tss@iki.fi>
parents:
8962
diff
changeset
|
478 if ((ctx->flags & MAIL_INDEX_SYNC_FLAG_FSYNC) != 0) |
375be2dbeea7
Added FSYNC flag for transactions.
Timo Sirainen <tss@iki.fi>
parents:
8962
diff
changeset
|
479 trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_FSYNC; |
6091
c8d7b9fd500e
Added MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES and
Timo Sirainen <tss@iki.fi>
parents:
6089
diff
changeset
|
480 ctx->ext_trans = mail_index_transaction_begin(ctx->view, trans_flags); |
8947
e892aa297b85
indexes: Fixes to handling shrinking tail offsets.
Timo Sirainen <tss@iki.fi>
parents:
8929
diff
changeset
|
481 ctx->ext_trans->sync_transaction = TRUE; |
13188
6db2f76bc493
lib-index: MAIL_INDEX_SYNC_FLAG_DELETING_INDEX now allows committing changes to deleted index.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
482 ctx->ext_trans->commit_deleted_index = |
17758
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
483 (flags & (MAIL_INDEX_SYNC_FLAG_DELETING_INDEX | |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
484 MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX)) != 0; |
5650
e5f0e8cf6089
Sync transaction needs to be created later or we'll crash
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
485 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
486 *ctx_r = ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 *view_r = ctx->view; |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
488 *trans_r = ctx->ext_trans; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 |
13752
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
492 int mail_index_sync_begin_to(struct mail_index *index, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
493 struct mail_index_sync_ctx **ctx_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
494 struct mail_index_view **view_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
495 struct mail_index_transaction **trans_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
496 uint32_t log_file_seq, uoff_t log_file_offset, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
497 enum mail_index_sync_flags flags) |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
498 { |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
499 bool retry; |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
500 int ret; |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
501 |
15852 | 502 i_assert(index->open_count > 0); |
503 | |
13752
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
504 ret = mail_index_sync_begin_to2(index, ctx_r, view_r, trans_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
505 log_file_seq, log_file_offset, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
506 flags, &retry); |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
507 if (retry) { |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
508 ret = mail_index_sync_begin_to2(index, ctx_r, view_r, trans_r, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
509 log_file_seq, log_file_offset, |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
510 flags, &retry); |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
511 } |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
512 return ret; |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
513 } |
b9c4a7e4a27f
lib-index: Make sure we never go to infinite loop if fsck can't fix syncing problem.
Timo Sirainen <tss@iki.fi>
parents:
13750
diff
changeset
|
514 |
11646
b2aca3e50f44
lib-index: Added mail_index_sync_has_expunges()
Timo Sirainen <tss@iki.fi>
parents:
10998
diff
changeset
|
515 bool mail_index_sync_has_expunges(struct mail_index_sync_ctx *ctx) |
b2aca3e50f44
lib-index: Added mail_index_sync_has_expunges()
Timo Sirainen <tss@iki.fi>
parents:
10998
diff
changeset
|
516 { |
b2aca3e50f44
lib-index: Added mail_index_sync_has_expunges()
Timo Sirainen <tss@iki.fi>
parents:
10998
diff
changeset
|
517 return array_is_created(&ctx->sync_trans->expunges) && |
b2aca3e50f44
lib-index: Added mail_index_sync_has_expunges()
Timo Sirainen <tss@iki.fi>
parents:
10998
diff
changeset
|
518 array_count(&ctx->sync_trans->expunges) > 0; |
b2aca3e50f44
lib-index: Added mail_index_sync_has_expunges()
Timo Sirainen <tss@iki.fi>
parents:
10998
diff
changeset
|
519 } |
b2aca3e50f44
lib-index: Added mail_index_sync_has_expunges()
Timo Sirainen <tss@iki.fi>
parents:
10998
diff
changeset
|
520 |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
521 static bool mail_index_sync_view_have_any(struct mail_index_view *view, |
19158
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
522 enum mail_index_sync_flags flags, |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
523 bool expunges_only) |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
524 { |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
525 const struct mail_transaction_header *hdr; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
526 const void *data; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
527 uint32_t log_seq; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
528 uoff_t log_offset; |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
529 const char *reason; |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
530 bool reset; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
531 int ret; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
532 |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
533 if (view->map->hdr.first_recent_uid < view->map->hdr.next_uid && |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
534 (flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0) |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
535 return TRUE; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
536 |
21530
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
537 if ((view->map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 && |
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
538 (flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0 && |
c337e4fe88e5
lib-index: Add MAIL_INDEX_OPEN_FLAG_NO_DIRTY
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
539 (view->index->flags & MAIL_INDEX_OPEN_FLAG_NO_DIRTY) == 0) |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
540 return TRUE; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
541 |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
542 mail_transaction_log_get_head(view->index->log, &log_seq, &log_offset); |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
543 if (mail_transaction_log_view_set(view->log_view, |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
544 view->map->hdr.log_file_seq, |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
545 view->map->hdr.log_file_tail_offset, |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
546 log_seq, log_offset, |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
547 &reset, &reason) <= 0) { |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
548 /* let the actual syncing handle the error */ |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
549 return TRUE; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
550 } |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
551 |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
552 while ((ret = mail_transaction_log_view_next(view->log_view, |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
553 &hdr, &data)) > 0) { |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
554 if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) != 0) |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
555 continue; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
556 |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
557 switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) { |
19158
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
558 case MAIL_TRANSACTION_EXPUNGE: |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
559 case MAIL_TRANSACTION_EXPUNGE_GUID: |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
560 return TRUE; |
7145
5187649faa52
Make sure tail offset gets updated when extension records are updated.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
561 case MAIL_TRANSACTION_EXT_REC_UPDATE: |
8929
9c50e7303513
Added mail_index_atomic_inc_ext() for atomically incrementing numbers in extensions.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
562 case MAIL_TRANSACTION_EXT_ATOMIC_INC: |
7145
5187649faa52
Make sure tail offset gets updated when extension records are updated.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
563 /* extension record updates aren't exactly needed |
5187649faa52
Make sure tail offset gets updated when extension records are updated.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
564 to be synced, but cache syncing relies on tail |
5187649faa52
Make sure tail offset gets updated when extension records are updated.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
565 offsets being updated. */ |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
566 case MAIL_TRANSACTION_FLAG_UPDATE: |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
567 case MAIL_TRANSACTION_KEYWORD_UPDATE: |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
568 case MAIL_TRANSACTION_KEYWORD_RESET: |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
569 case MAIL_TRANSACTION_INDEX_DELETED: |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
570 case MAIL_TRANSACTION_INDEX_UNDELETED: |
19158
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
571 if (!expunges_only) |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
572 return TRUE; |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
573 break; |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
574 default: |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
575 break; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
576 } |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
577 } |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
578 return ret < 0; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
579 } |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
580 |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
581 bool mail_index_sync_have_any(struct mail_index *index, |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
582 enum mail_index_sync_flags flags) |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
583 { |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
584 struct mail_index_view *view; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
585 bool ret; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
586 |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
587 view = mail_index_view_open(index); |
19158
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
588 ret = mail_index_sync_view_have_any(view, flags, FALSE); |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
589 mail_index_view_close(&view); |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
590 return ret; |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
591 } |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
592 |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
593 bool mail_index_sync_have_any_expunges(struct mail_index *index) |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
594 { |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
595 struct mail_index_view *view; |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
596 bool ret; |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
597 |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
598 view = mail_index_view_open(index); |
91f68c1b9b36
lib-index: Added mail_index_sync_have_any_expunges()
Timo Sirainen <tss@iki.fi>
parents:
18843
diff
changeset
|
599 ret = mail_index_sync_view_have_any(view, 0, TRUE); |
6450
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
600 mail_index_view_close(&view); |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
601 return ret; |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
602 } |
3132ce8f425d
Added mail_index_sync_have_any().
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
603 |
8962
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
604 void mail_index_sync_get_offsets(struct mail_index_sync_ctx *ctx, |
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
605 uint32_t *seq1_r, uoff_t *offset1_r, |
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
606 uint32_t *seq2_r, uoff_t *offset2_r) |
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
607 { |
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
608 *seq1_r = ctx->view->map->hdr.log_file_seq; |
8974
dc858d9014ae
mail_index_sync_get_offsets() now returns offset1 right.
Timo Sirainen <tss@iki.fi>
parents:
8966
diff
changeset
|
609 *offset1_r = ctx->view->map->hdr.log_file_tail_offset != 0 ? |
dc858d9014ae
mail_index_sync_get_offsets() now returns offset1 right.
Timo Sirainen <tss@iki.fi>
parents:
8966
diff
changeset
|
610 ctx->view->map->hdr.log_file_tail_offset : |
dc858d9014ae
mail_index_sync_get_offsets() now returns offset1 right.
Timo Sirainen <tss@iki.fi>
parents:
8966
diff
changeset
|
611 ctx->view->index->log->head->hdr.hdr_size; |
8962
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
612 mail_transaction_log_get_head(ctx->view->index->log, seq2_r, offset2_r); |
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
613 } |
b12ae0c97069
Added mail_index_sync_get_offsets().
Timo Sirainen <tss@iki.fi>
parents:
8955
diff
changeset
|
614 |
3825
a983412e1976
Changed mail_index_view_sync_next() to return struct
Timo Sirainen <tss@iki.fi>
parents:
3759
diff
changeset
|
615 static void |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
616 mail_index_sync_get_expunge(struct mail_index_sync_rec *rec, |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
617 const struct mail_transaction_expunge_guid *exp) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
618 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
619 rec->type = MAIL_INDEX_SYNC_TYPE_EXPUNGE; |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
620 rec->uid1 = exp->uid; |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
621 rec->uid2 = exp->uid; |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
622 memcpy(rec->guid_128, exp->guid_128, sizeof(rec->guid_128)); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
623 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
624 |
3825
a983412e1976
Changed mail_index_view_sync_next() to return struct
Timo Sirainen <tss@iki.fi>
parents:
3759
diff
changeset
|
625 static void |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
626 mail_index_sync_get_update(struct mail_index_sync_rec *rec, |
14877
ad22bdfe7bdc
lib-index: Message flag syncing was broken due to wrong struct cast.
Timo Sirainen <tss@iki.fi>
parents:
14580
diff
changeset
|
627 const struct mail_index_flag_update *update) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
628 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
629 rec->type = MAIL_INDEX_SYNC_TYPE_FLAGS; |
2033
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2032
diff
changeset
|
630 rec->uid1 = update->uid1; |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2032
diff
changeset
|
631 rec->uid2 = update->uid2; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
632 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
633 rec->add_flags = update->add_flags; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
634 rec->remove_flags = update->remove_flags; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
635 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
636 |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
637 static void |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
638 mail_index_sync_get_keyword_update(struct mail_index_sync_rec *rec, |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
639 const struct uid_range *range, |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
640 struct mail_index_sync_list *sync_list) |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
641 { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
642 rec->type = !sync_list->keyword_remove ? |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
643 MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD : |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
644 MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
645 rec->uid1 = range->uid1; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
646 rec->uid2 = range->uid2; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
647 rec->keyword_idx = sync_list->keyword_idx; |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
648 } |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
649 |
6278
ce83635191d4
mail_index_sync_next() can't fail anymore.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
650 bool mail_index_sync_next(struct mail_index_sync_ctx *ctx, |
ce83635191d4
mail_index_sync_next() can't fail anymore.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
651 struct mail_index_sync_rec *sync_rec) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
652 { |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
653 struct mail_index_transaction *sync_trans = ctx->sync_trans; |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
654 struct mail_index_sync_list *sync_list; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
655 const struct uid_range *uid_range = NULL; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
656 unsigned int i, count, next_i; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
657 uint32_t next_found_uid; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
658 |
15904
d3cf06639864
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents:
15852
diff
changeset
|
659 next_i = UINT_MAX; |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
660 next_found_uid = (uint32_t)-1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
661 |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
662 /* FIXME: replace with a priority queue so we don't have to go |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
663 through the whole list constantly. and remember to make sure that |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
664 keyword resets are sent before adds! */ |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
665 /* FIXME: pretty ugly to do this for expunges, which isn't even a |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
666 seq_range. */ |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4283
diff
changeset
|
667 sync_list = array_get_modifiable(&ctx->sync_list, &count); |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
668 for (i = 0; i < count; i++) { |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
669 if (!array_is_created(sync_list[i].array) || |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
670 sync_list[i].idx == array_count(sync_list[i].array)) |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
671 continue; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
672 |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
673 uid_range = array_idx(sync_list[i].array, sync_list[i].idx); |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
674 if (uid_range->uid1 == ctx->next_uid) { |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
675 /* use this one. */ |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
676 break; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
677 } |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
678 if (uid_range->uid1 < next_found_uid) { |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
679 next_i = i; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
680 next_found_uid = uid_range->uid1; |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2247
diff
changeset
|
681 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
682 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
683 |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
684 if (i == count) { |
15904
d3cf06639864
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents:
15852
diff
changeset
|
685 if (next_i == UINT_MAX) { |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
686 /* nothing left in sync_list */ |
21158
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
687 ctx->fully_synced = TRUE; |
6278
ce83635191d4
mail_index_sync_next() can't fail anymore.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
688 return FALSE; |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
689 } |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
690 ctx->next_uid = next_found_uid; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
691 i = next_i; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
692 uid_range = array_idx(sync_list[i].array, sync_list[i].idx); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
693 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
694 |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
695 if (sync_list[i].array == (void *)&sync_trans->expunges) { |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
696 mail_index_sync_get_expunge(sync_rec, |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
697 (const struct mail_transaction_expunge_guid *)uid_range); |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
698 } else if (sync_list[i].array == (void *)&sync_trans->updates) { |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
699 mail_index_sync_get_update(sync_rec, |
14877
ad22bdfe7bdc
lib-index: Message flag syncing was broken due to wrong struct cast.
Timo Sirainen <tss@iki.fi>
parents:
14580
diff
changeset
|
700 (const struct mail_index_flag_update *)uid_range); |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
701 } else { |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
702 mail_index_sync_get_keyword_update(sync_rec, uid_range, |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
703 &sync_list[i]); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 } |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
705 sync_list[i].idx++; |
6278
ce83635191d4
mail_index_sync_next() can't fail anymore.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
706 return TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
707 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
708 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
709 bool mail_index_sync_have_more(struct mail_index_sync_ctx *ctx) |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
710 { |
3344
09457ba69253
Compiler warning fixes when DEBUG enabled.
Timo Sirainen <tss@iki.fi>
parents:
3342
diff
changeset
|
711 const struct mail_index_sync_list *sync_list; |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
712 |
10000
c610321584ca
Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents:
9624
diff
changeset
|
713 array_foreach(&ctx->sync_list, sync_list) { |
c610321584ca
Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents:
9624
diff
changeset
|
714 if (array_is_created(sync_list->array) && |
c610321584ca
Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents:
9624
diff
changeset
|
715 sync_list->idx != array_count(sync_list->array)) |
3203
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
716 return TRUE; |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
717 } |
391a1064872e
mail_index_sync_next() now returns keyword updates (now only thing left to
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
718 return FALSE; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
719 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
720 |
10367
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
721 void mail_index_sync_set_commit_result(struct mail_index_sync_ctx *ctx, |
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
722 struct mail_index_transaction_commit_result *result) |
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
723 { |
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
724 ctx->sync_commit_result = result; |
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
725 } |
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
726 |
3264
98e3001ca527
Added mail_index_sync_reset() to restart syncing from beginning.
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
727 void mail_index_sync_reset(struct mail_index_sync_ctx *ctx) |
98e3001ca527
Added mail_index_sync_reset() to restart syncing from beginning.
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
728 { |
98e3001ca527
Added mail_index_sync_reset() to restart syncing from beginning.
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
729 struct mail_index_sync_list *sync_list; |
98e3001ca527
Added mail_index_sync_reset() to restart syncing from beginning.
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
730 |
98e3001ca527
Added mail_index_sync_reset() to restart syncing from beginning.
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
731 ctx->next_uid = 0; |
10000
c610321584ca
Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents:
9624
diff
changeset
|
732 array_foreach_modifiable(&ctx->sync_list, sync_list) |
c610321584ca
Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents:
9624
diff
changeset
|
733 sync_list->idx = 0; |
3264
98e3001ca527
Added mail_index_sync_reset() to restart syncing from beginning.
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
734 } |
98e3001ca527
Added mail_index_sync_reset() to restart syncing from beginning.
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
735 |
17928
193c82411d73
lib-index: Added mail_index_sync_no_warning() to prevent "long transaction lock" warnings.
Timo Sirainen <tss@iki.fi>
parents:
17927
diff
changeset
|
736 void mail_index_sync_no_warning(struct mail_index_sync_ctx *ctx) |
193c82411d73
lib-index: Added mail_index_sync_no_warning() to prevent "long transaction lock" warnings.
Timo Sirainen <tss@iki.fi>
parents:
17927
diff
changeset
|
737 { |
193c82411d73
lib-index: Added mail_index_sync_no_warning() to prevent "long transaction lock" warnings.
Timo Sirainen <tss@iki.fi>
parents:
17927
diff
changeset
|
738 ctx->no_warning = TRUE; |
193c82411d73
lib-index: Added mail_index_sync_no_warning() to prevent "long transaction lock" warnings.
Timo Sirainen <tss@iki.fi>
parents:
17927
diff
changeset
|
739 } |
193c82411d73
lib-index: Added mail_index_sync_no_warning() to prevent "long transaction lock" warnings.
Timo Sirainen <tss@iki.fi>
parents:
17927
diff
changeset
|
740 |
19800
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
741 void mail_index_sync_set_reason(struct mail_index_sync_ctx *ctx, |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
742 const char *reason) |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
743 { |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
744 i_free(ctx->reason); |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
745 ctx->reason = i_strdup(reason); |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
746 } |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
747 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
748 static void mail_index_sync_end(struct mail_index_sync_ctx **_ctx) |
2393
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
749 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
750 struct mail_index_sync_ctx *ctx = *_ctx; |
19800
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
751 const char *lock_reason; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
752 |
6756
e78c51d6305f
Fixes to handling cache file syncs and expunging.
Timo Sirainen <tss@iki.fi>
parents:
6450
diff
changeset
|
753 i_assert(ctx->index->syncing); |
e78c51d6305f
Fixes to handling cache file syncs and expunging.
Timo Sirainen <tss@iki.fi>
parents:
6450
diff
changeset
|
754 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
755 *_ctx = NULL; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
756 |
6756
e78c51d6305f
Fixes to handling cache file syncs and expunging.
Timo Sirainen <tss@iki.fi>
parents:
6450
diff
changeset
|
757 ctx->index->syncing = FALSE; |
19800
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
758 if (ctx->no_warning) |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
759 lock_reason = NULL; |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
760 else if (ctx->reason != NULL) |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
761 lock_reason = ctx->reason; |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
762 else |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
763 lock_reason = "Mailbox was synchronized"; |
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
764 mail_transaction_log_sync_unlock(ctx->index->log, lock_reason); |
3114
7c7299d1acfe
Instead of using separate transaction sorting code for syncing, just put the
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
765 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
766 mail_index_view_close(&ctx->view); |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
767 mail_index_transaction_rollback(&ctx->sync_trans); |
4052 | 768 if (array_is_created(&ctx->sync_list)) |
769 array_free(&ctx->sync_list); | |
19800
363311913f82
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19799
diff
changeset
|
770 i_free(ctx->reason); |
2393
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
771 i_free(ctx); |
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
772 } |
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
773 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
774 static void |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
775 mail_index_sync_update_mailbox_offset(struct mail_index_sync_ctx *ctx) |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
776 { |
19323
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
777 const struct mail_index_header *hdr = &ctx->index->map->hdr; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
778 uint32_t seq; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
779 uoff_t offset; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
780 |
21158
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
781 if (!ctx->fully_synced) { |
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
782 /* Everything wasn't synced. This usually means that syncing |
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
783 was used for locking and nothing was synced. Don't update |
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
784 tail offset. */ |
8966
78644bad1263
Mailbox syncing: If syncing wrote to transaction log, update the tail offset to include them.
Timo Sirainen <tss@iki.fi>
parents:
8963
diff
changeset
|
785 mail_transaction_log_view_get_prev_pos(ctx->view->log_view, |
78644bad1263
Mailbox syncing: If syncing wrote to transaction log, update the tail offset to include them.
Timo Sirainen <tss@iki.fi>
parents:
8963
diff
changeset
|
786 &seq, &offset); |
21158
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
787 return; |
8966
78644bad1263
Mailbox syncing: If syncing wrote to transaction log, update the tail offset to include them.
Timo Sirainen <tss@iki.fi>
parents:
8963
diff
changeset
|
788 } |
21158
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
789 /* synced everything, but we might also have committed new |
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
790 transactions. include them also here. */ |
55e5e1983b8d
lib-index: Fix detecting whether caller synced everything in mailbox.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19800
diff
changeset
|
791 mail_transaction_log_get_head(ctx->index->log, &seq, &offset); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
792 mail_transaction_log_set_mailbox_sync_pos(ctx->index->log, seq, offset); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
793 |
5749
420a386fa27a
int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
794 /* If tail offset has changed, make sure it gets written to |
18843
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
795 transaction log. do this only if we're required to make changes. |
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
796 |
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
797 avoid writing a new tail offset if all the transactions were |
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
798 external, because that wouldn't change effective the tail offset. |
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
799 except e.g. mdbox map requires this to happen, so do it |
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
800 optionally. */ |
19323
a26d8492614e
lib-index: tail_offset wasn't updated as often as it should have been.
Timo Sirainen <tss@iki.fi>
parents:
19283
diff
changeset
|
801 if ((hdr->log_file_seq != seq || hdr->log_file_tail_offset < offset) && |
18843
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
802 (ctx->seen_nonexternal_transactions || |
03b3b97b84aa
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
Timo Sirainen <tss@iki.fi>
parents:
18398
diff
changeset
|
803 (ctx->flags & MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET) != 0)) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
804 ctx->ext_trans->log_updates = TRUE; |
17609
16d4cf2c0d65
lib-index: Don't update log_file_tail_offset unnecessarily.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
805 ctx->ext_trans->tail_offset_changed = TRUE; |
16d4cf2c0d65
lib-index: Don't update log_file_tail_offset unnecessarily.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
806 } |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
807 } |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
808 |
6925 | 809 static bool mail_index_sync_want_index_write(struct mail_index *index) |
810 { | |
811 uint32_t log_diff; | |
812 | |
19283
9e3d7e83a075
lib-index: Fixed checking when we want to update dovecot.index
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
813 if (index->last_read_log_file_seq != 0 && |
9e3d7e83a075
lib-index: Fixed checking when we want to update dovecot.index
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
814 index->last_read_log_file_seq != index->map->hdr.log_file_seq) { |
9e3d7e83a075
lib-index: Fixed checking when we want to update dovecot.index
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
815 /* dovecot.index points to an old .log file. we were supposed |
9e3d7e83a075
lib-index: Fixed checking when we want to update dovecot.index
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
816 to rewrite the dovecot.index when rotating the log, so |
9e3d7e83a075
lib-index: Fixed checking when we want to update dovecot.index
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
817 we shouldn't usually get here. */ |
9e3d7e83a075
lib-index: Fixed checking when we want to update dovecot.index
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
818 return TRUE; |
15905
76f576fc28dc
lib-index: Don't unnecessarily update dovecot.index again after log rotation.
Timo Sirainen <tss@iki.fi>
parents:
15904
diff
changeset
|
819 } |
76f576fc28dc
lib-index: Don't unnecessarily update dovecot.index again after log rotation.
Timo Sirainen <tss@iki.fi>
parents:
15904
diff
changeset
|
820 |
6925 | 821 log_diff = index->map->hdr.log_file_tail_offset - |
822 index->last_read_log_file_tail_offset; | |
8993
48d2377939c2
Write to main index file less often.
Timo Sirainen <tss@iki.fi>
parents:
8974
diff
changeset
|
823 if (log_diff > MAIL_INDEX_MAX_WRITE_BYTES || |
48d2377939c2
Write to main index file less often.
Timo Sirainen <tss@iki.fi>
parents:
8974
diff
changeset
|
824 (index->index_min_write && log_diff > MAIL_INDEX_MIN_WRITE_BYTES)) |
6925 | 825 return TRUE; |
826 | |
827 if (index->need_recreate) | |
828 return TRUE; | |
829 return FALSE; | |
830 } | |
831 | |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
832 int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
833 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
834 struct mail_index_sync_ctx *ctx = *_ctx; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
835 struct mail_index *index = ctx->index; |
17905
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
836 struct mail_cache_compress_lock *cache_lock = NULL; |
8955
4d4e1cbb61a0
Removed rarely used parameters from mail_index_transaction_commit().
Timo Sirainen <tss@iki.fi>
parents:
8947
diff
changeset
|
837 uint32_t next_uid; |
10678
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
838 bool want_rotate, index_undeleted, delete_index; |
17905
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
839 int ret = 0, ret2; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
840 |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
841 index_undeleted = ctx->ext_trans->index_undeleted; |
10678
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
842 delete_index = index->index_delete_requested && !index_undeleted && |
17758
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
843 (ctx->flags & (MAIL_INDEX_SYNC_FLAG_DELETING_INDEX | |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
844 MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX)) != 0; |
10678
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
845 if (delete_index) { |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
846 /* finish this sync by marking the index deleted */ |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
847 mail_index_set_deleted(ctx->ext_trans); |
17758
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
848 } else if (index->index_deleted && !index_undeleted && |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
849 (ctx->flags & MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX) == 0) { |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
850 /* another process just marked the index deleted. |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
851 finish the sync, but return error. */ |
6980c53bf7d7
lib-index, lib-storage: Fixed race conditions with deleting mailbox.
Timo Sirainen <tss@iki.fi>
parents:
17609
diff
changeset
|
852 ret = -1; |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
853 } |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
854 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
855 mail_index_sync_update_mailbox_offset(ctx); |
5652
9404d2c41cb2
When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents:
5651
diff
changeset
|
856 if (mail_cache_need_compress(index->cache)) { |
9404d2c41cb2
When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents:
5651
diff
changeset
|
857 /* if cache compression fails, we don't really care. |
9404d2c41cb2
When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents:
5651
diff
changeset
|
858 the cache offsets are updated only if the compression was |
9404d2c41cb2
When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents:
5651
diff
changeset
|
859 successful. */ |
17905
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
860 (void)mail_cache_compress(index->cache, ctx->ext_trans, |
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
861 &cache_lock); |
5652
9404d2c41cb2
When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents:
5651
diff
changeset
|
862 } |
9404d2c41cb2
When compressing cache file, update the cache file offsets using the
Timo Sirainen <tss@iki.fi>
parents:
5651
diff
changeset
|
863 |
6071
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
864 if ((ctx->flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0) { |
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
865 next_uid = mail_index_transaction_get_next_uid(ctx->ext_trans); |
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
866 if (index->map->hdr.first_recent_uid < next_uid) { |
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
867 mail_index_update_header(ctx->ext_trans, |
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
868 offsetof(struct mail_index_header, |
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
869 first_recent_uid), |
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
870 &next_uid, sizeof(next_uid), FALSE); |
c5919ea0cb33
Optimization: If FLAG_DROP_RECENT isn't set, don't bother calculating next_uid
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
871 } |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
872 } |
22326
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
873 if (index->pending_log2_rotate_time != 0) { |
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
874 uint32_t log2_rotate_time = index->pending_log2_rotate_time; |
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
875 |
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
876 mail_index_update_header(ctx->ext_trans, |
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
877 offsetof(struct mail_index_header, log2_rotate_time), |
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
878 &log2_rotate_time, sizeof(log2_rotate_time), TRUE); |
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
879 index->pending_log2_rotate_time = 0; |
ba1a35c5ead7
lib-index: Track .log.2 rotation time in index header
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21530
diff
changeset
|
880 } |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
5867
diff
changeset
|
881 |
17905
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
882 ret2 = mail_index_transaction_commit(&ctx->ext_trans); |
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
883 if (cache_lock != NULL) |
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
884 mail_cache_compress_unlock(&cache_lock); |
51f5680d4108
lib-index: Delay unlocking cache compression until changes to transaction log are committed.
Timo Sirainen <tss@iki.fi>
parents:
17758
diff
changeset
|
885 if (ret2 < 0) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
886 mail_index_sync_end(&ctx); |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
887 return -1; |
2247
2d51bb58a070
Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
2240
diff
changeset
|
888 } |
2d51bb58a070
Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
2240
diff
changeset
|
889 |
10678
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
890 if (delete_index) |
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
891 index->index_deleted = TRUE; |
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10674
diff
changeset
|
892 else if (index_undeleted) { |
10674
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
893 index->index_deleted = FALSE; |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
894 index->index_delete_requested = FALSE; |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
895 } |
22354f505277
lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents:
10673
diff
changeset
|
896 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
897 /* refresh the mapping with newly committed external transactions |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
898 and the synced expunges. sync using file handler here so that the |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
899 expunge handlers get called. */ |
10367
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
900 index->sync_commit_result = ctx->sync_commit_result; |
5854 | 901 if (mail_index_map(ctx->index, MAIL_INDEX_SYNC_HANDLER_FILE) <= 0) |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
902 ret = -1; |
10367
75d3d4374dda
Transaction commits can now track how many uid/modseq updates were ignored.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
903 index->sync_commit_result = NULL; |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2884
diff
changeset
|
904 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
905 want_rotate = mail_transaction_log_want_rotate(index->log); |
6925 | 906 if (ret == 0 && |
907 (want_rotate || mail_index_sync_want_index_write(index))) { | |
6331
081fd0acddd2
If we notice that dovecot.index.log gets deleted, make sure that
Timo Sirainen <tss@iki.fi>
parents:
6278
diff
changeset
|
908 index->need_recreate = FALSE; |
8993
48d2377939c2
Write to main index file less often.
Timo Sirainen <tss@iki.fi>
parents:
8974
diff
changeset
|
909 index->index_min_write = FALSE; |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5652
diff
changeset
|
910 mail_index_write(index, want_rotate); |
6331
081fd0acddd2
If we notice that dovecot.index.log gets deleted, make sure that
Timo Sirainen <tss@iki.fi>
parents:
6278
diff
changeset
|
911 } |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
912 mail_index_sync_end(_ctx); |
2393
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
913 return ret; |
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
914 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
915 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
916 void mail_index_sync_rollback(struct mail_index_sync_ctx **ctx) |
2393
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
917 { |
5651 | 918 if ((*ctx)->ext_trans != NULL) |
919 mail_index_transaction_rollback(&(*ctx)->ext_trans); | |
2393
d598c82a3c22
Renamed mail_index_sync_end() to _commit() and added _rollback(). Fixed mbox
Timo Sirainen <tss@iki.fi>
parents:
2373
diff
changeset
|
920 mail_index_sync_end(ctx); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
921 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
922 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
923 void mail_index_sync_flags_apply(const struct mail_index_sync_rec *sync_rec, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2963
diff
changeset
|
924 uint8_t *flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
925 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
926 i_assert(sync_rec->type == MAIL_INDEX_SYNC_TYPE_FLAGS); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
927 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
928 *flags = (*flags & ~sync_rec->remove_flags) | sync_rec->add_flags; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
929 } |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
930 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
931 bool mail_index_sync_keywords_apply(const struct mail_index_sync_rec *sync_rec, |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4283
diff
changeset
|
932 ARRAY_TYPE(keyword_indexes) *keywords) |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
933 { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
934 const unsigned int *keyword_indexes; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
935 unsigned int idx = sync_rec->keyword_idx; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
936 unsigned int i, count; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
937 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
938 keyword_indexes = array_get(keywords, &count); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
939 switch (sync_rec->type) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
940 case MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD: |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
941 for (i = 0; i < count; i++) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
942 if (keyword_indexes[i] == idx) |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
943 return FALSE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
944 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
945 |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
946 array_append(keywords, &idx, 1); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
947 return TRUE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
948 case MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE: |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
949 for (i = 0; i < count; i++) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
950 if (keyword_indexes[i] == idx) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
951 array_delete(keywords, i, 1); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
952 return TRUE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
953 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
954 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
955 return FALSE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
956 default: |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
957 i_unreached(); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
958 return FALSE; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
959 } |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
960 } |
4279
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
961 |
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
962 void mail_index_sync_set_corrupted(struct mail_index_sync_map_ctx *ctx, |
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
963 const char *fmt, ...) |
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
964 { |
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
965 va_list va; |
5776
5ce403e0ef56
Log also the position in log file for sync errors.
Timo Sirainen <tss@iki.fi>
parents:
5772
diff
changeset
|
966 uint32_t seq; |
5ce403e0ef56
Log also the position in log file for sync errors.
Timo Sirainen <tss@iki.fi>
parents:
5772
diff
changeset
|
967 uoff_t offset; |
5ce403e0ef56
Log also the position in log file for sync errors.
Timo Sirainen <tss@iki.fi>
parents:
5772
diff
changeset
|
968 |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
969 ctx->errors = TRUE; |
16531
3794e6cb0da8
lib-index: If error is found from transaction log, update dovecot.index so it won't be read again.
Timo Sirainen <tss@iki.fi>
parents:
15905
diff
changeset
|
970 /* make sure we don't get to this same error again by updating the |
3794e6cb0da8
lib-index: If error is found from transaction log, update dovecot.index so it won't be read again.
Timo Sirainen <tss@iki.fi>
parents:
15905
diff
changeset
|
971 dovecot.index */ |
3794e6cb0da8
lib-index: If error is found from transaction log, update dovecot.index so it won't be read again.
Timo Sirainen <tss@iki.fi>
parents:
15905
diff
changeset
|
972 ctx->view->index->need_recreate = TRUE; |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
973 |
5776
5ce403e0ef56
Log also the position in log file for sync errors.
Timo Sirainen <tss@iki.fi>
parents:
5772
diff
changeset
|
974 mail_transaction_log_view_get_prev_pos(ctx->view->log_view, |
5ce403e0ef56
Log also the position in log file for sync errors.
Timo Sirainen <tss@iki.fi>
parents:
5772
diff
changeset
|
975 &seq, &offset); |
4279
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
976 |
5820
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
977 if (seq < ctx->view->index->fsck_log_head_file_seq || |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
978 (seq == ctx->view->index->fsck_log_head_file_seq && |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
979 offset < ctx->view->index->fsck_log_head_file_offset)) { |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
980 /* be silent */ |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
981 return; |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
982 } |
e59892590a02
Handle losing index file better. Handle fsck better.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
983 |
4279
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
984 va_start(va, fmt); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7145
diff
changeset
|
985 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6925
diff
changeset
|
986 mail_index_set_error(ctx->view->index, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6925
diff
changeset
|
987 "Log synchronization error at " |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6925
diff
changeset
|
988 "seq=%u,offset=%"PRIuUOFF_T" for %s: %s", |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6925
diff
changeset
|
989 seq, offset, ctx->view->index->filepath, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6925
diff
changeset
|
990 t_strdup_vprintf(fmt, va)); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7145
diff
changeset
|
991 } T_END; |
4279
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
992 va_end(va); |
ca5008de2921
If we're synchronizing a view (and not index itself) from transaction log,
Timo Sirainen <tss@iki.fi>
parents:
4248
diff
changeset
|
993 } |