annotate src/lib-storage/index/mbox/mbox-transaction.c @ 4678:6272561fa12d HEAD

After saving messages the mailbox wasn't synced, which caused deliver to treat the mailbox as unsynced and not update the indexes.
author Timo Sirainen <tss@iki.fi>
date Sun, 15 Oct 2006 15:59:43 +0300
parents 85fcdb478608
children 967de900c73a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2004 Timo Sirainen */
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
4 #include "array.h"
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "mbox-storage.h"
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "mbox-lock.h"
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "mbox-sync-private.h"
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
9 static void (*next_hook_mail_index_transaction_created)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
10 (struct mail_index_transaction *t) = NULL;
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
12 static int mbox_transaction_commit(struct mail_index_transaction *t,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
13 uint32_t *log_file_seq_r,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
14 uoff_t *log_file_offset_r)
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 {
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
16 struct mbox_transaction_context *mt = MAIL_STORAGE_TRANSACTION(t);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
17 struct mbox_mailbox *mbox = (struct mbox_mailbox *)mt->ictx.ibox;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
18 unsigned int lock_id = mt->mbox_lock_id;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
19 enum mailbox_sync_flags flags = mt->ictx.commit_flags;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3279
diff changeset
20 bool mbox_modified;
4678
6272561fa12d After saving messages the mailbox wasn't synced, which caused deliver to
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
21 bool syncing = t->sync_transaction;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3279
diff changeset
22 int ret = 0;
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
24 if (mt->save_ctx != NULL)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
25 ret = mbox_transaction_save_commit(mt->save_ctx);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
26 mbox_modified = mt->mbox_modified;
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
28 if (ret < 0)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
29 index_transaction_finish_rollback(&mt->ictx);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
30 else {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
31 if (index_transaction_finish_commit(&mt->ictx, log_file_seq_r,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
32 log_file_offset_r) < 0)
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 ret = -1;
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 }
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
35
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
36 /* transaction is destroyed now. */
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
37 mt = NULL;
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
3279
b698ae839a18 Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
39 if (lock_id != 0 && mbox->mbox_lock_type != F_WRLCK) {
2724
0b4d8354737a Don't lock/unlock mbox separately for each message. Drop the lock only at
Timo Sirainen <tss@iki.fi>
parents: 2665
diff changeset
40 /* unlock before writing any changes */
3279
b698ae839a18 Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
41 (void)mbox_unlock(mbox, lock_id);
2724
0b4d8354737a Don't lock/unlock mbox separately for each message. Drop the lock only at
Timo Sirainen <tss@iki.fi>
parents: 2665
diff changeset
42 lock_id = 0;
0b4d8354737a Don't lock/unlock mbox separately for each message. Drop the lock only at
Timo Sirainen <tss@iki.fi>
parents: 2665
diff changeset
43 }
0b4d8354737a Don't lock/unlock mbox separately for each message. Drop the lock only at
Timo Sirainen <tss@iki.fi>
parents: 2665
diff changeset
44
4678
6272561fa12d After saving messages the mailbox wasn't synced, which caused deliver to
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
45 if (ret == 0 && !syncing) {
2518
f8be7a5e273a Added sync flags parameter to mailbox_transaction_commit(), so EXPUNGE can
Timo Sirainen <tss@iki.fi>
parents: 2511
diff changeset
46 enum mbox_sync_flags mbox_sync_flags = MBOX_SYNC_LAST_COMMIT;
2967
b31f48d152c4 Added mbox_very_dirty_syncs setting.
Timo Sirainen <tss@iki.fi>
parents: 2724
diff changeset
47 if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&
3279
b698ae839a18 Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
48 !mbox->mbox_very_dirty_syncs)
2518
f8be7a5e273a Added sync flags parameter to mailbox_transaction_commit(), so EXPUNGE can
Timo Sirainen <tss@iki.fi>
parents: 2511
diff changeset
49 mbox_sync_flags |= MBOX_SYNC_UNDIRTY;
2665
ccf563859be5 Split sync_flag_full into sync_flag_full_read and _write. Closing mailbox
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
50 if ((flags & MAILBOX_SYNC_FLAG_FULL_WRITE) != 0)
ccf563859be5 Split sync_flag_full into sync_flag_full_read and _write. Closing mailbox
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
51 mbox_sync_flags |= MBOX_SYNC_REWRITE;
2518
f8be7a5e273a Added sync flags parameter to mailbox_transaction_commit(), so EXPUNGE can
Timo Sirainen <tss@iki.fi>
parents: 2511
diff changeset
52 if (mbox_modified)
f8be7a5e273a Added sync flags parameter to mailbox_transaction_commit(), so EXPUNGE can
Timo Sirainen <tss@iki.fi>
parents: 2511
diff changeset
53 mbox_sync_flags |= MBOX_SYNC_HEADER;
3279
b698ae839a18 Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
54 if (mbox_sync(mbox, mbox_sync_flags) < 0)
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 ret = -1;
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 }
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 if (lock_id != 0) {
3279
b698ae839a18 Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
59 if (mbox_unlock(mbox, lock_id) < 0)
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 ret = -1;
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 }
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 return ret;
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 }
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
65 static void mbox_transaction_rollback(struct mail_index_transaction *t)
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 {
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
67 struct mbox_transaction_context *mt = MAIL_STORAGE_TRANSACTION(t);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
68 struct mbox_mailbox *mbox = (struct mbox_mailbox *)mt->ictx.ibox;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
69
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
70 if (mt->save_ctx != NULL)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
71 mbox_transaction_save_rollback(mt->save_ctx);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
72
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
73 if (mt->mbox_lock_id != 0)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
74 (void)mbox_unlock(mbox, mt->mbox_lock_id);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
75 index_transaction_finish_rollback(&mt->ictx);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
76 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
77
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
78 void mbox_transaction_created(struct mail_index_transaction *t)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
79 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
80 struct mailbox *box = MAIL_STORAGE_INDEX(t->view->index);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
81
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
82 if (strcmp(box->storage->name, MBOX_STORAGE_NAME) == 0) {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
83 struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
84 struct mbox_transaction_context *mt;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
85
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
86 mt = i_new(struct mbox_transaction_context, 1);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
87 mt->ictx.trans = t;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
88 mt->ictx.super = t->v;
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
90 t->v.commit = mbox_transaction_commit;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
91 t->v.rollback = mbox_transaction_rollback;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
92
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
93 array_idx_set(&t->mail_index_transaction_module_contexts,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
94 mail_storage_mail_index_module_id, &mt);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
95
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
96 index_transaction_init(&mt->ictx, &mbox->ibox);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
97 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
98
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
99 if (next_hook_mail_index_transaction_created != NULL)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
100 next_hook_mail_index_transaction_created(t);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
101 }
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
103 void mbox_transaction_class_init(void)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
104 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
105 next_hook_mail_index_transaction_created =
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
106 hook_mail_index_transaction_created;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
107 hook_mail_index_transaction_created = mbox_transaction_created;
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 }
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
109
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
110 void mbox_transaction_class_deinit(void)
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
111 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
112 i_assert(hook_mail_index_transaction_created ==
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
113 mbox_transaction_created);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
114 hook_mail_index_transaction_created =
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
115 next_hook_mail_index_transaction_created;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3863
diff changeset
116 }