annotate src/lib-index/mail-transaction-log.c @ 8999:afc1b0ef120d HEAD

When :MAILBOXDIR= was empty, we might have appended extra '/' to it, which caused problems.
author Timo Sirainen <tss@iki.fi>
date Thu, 30 Apr 2009 20:00:09 -0400
parents eb9e5ab575a9
children 73b9d8556f5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8292
diff changeset
1 /* Copyright (c) 2003-2009 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"
1976
4e0269adb24a Don't rotate transaction log too often
Timo Sirainen <tss@iki.fi>
parents: 1974
diff changeset
4 #include "ioloop.h"
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "buffer.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "file-dotlock.h"
4071
cd3d26cf124a Renamed safe-open.* to nfs-workarounds.*, safe_open() to nfs_safe_open() and
Timo Sirainen <tss@iki.fi>
parents: 4023
diff changeset
7 #include "nfs-workarounds.h"
4023
b19ccbaa3802 Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3981
diff changeset
8 #include "close-keep-errno.h"
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "mmap-util.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "mail-index-private.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "mail-transaction-log-private.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include <stddef.h>
3320
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
14 #include <stdio.h>
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <sys/stat.h>
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
2244
e7ccd299e754 fixed some fd leaks in error conditions
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
17 #define LOG_NEW_DOTLOCK_SUFFIX ".newlock"
e7ccd299e754 fixed some fd leaks in error conditions
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
18
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
19 static void
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
20 mail_transaction_log_set_head(struct mail_transaction_log *log,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
21 struct mail_transaction_log_file *file)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 {
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
23 i_assert(log->head != file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24
1940
Timo Sirainen <tss@iki.fi>
parents: 1937
diff changeset
25 file->refcount++;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
26 log->head = file;
5934
181aa61c182a Added asserts
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
27
181aa61c182a Added asserts
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
28 i_assert(log->files != NULL);
181aa61c182a Added asserts
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
29 i_assert(log->files->next != NULL || log->files == file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
32 struct mail_transaction_log *
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
33 mail_transaction_log_alloc(struct mail_index *index)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 struct mail_transaction_log *log;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 log = i_new(struct mail_transaction_log, 1);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 log->index = index;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
4968
1baf9dd3fc40 Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
40 log->dotlock_settings.use_excl_lock = index->use_excl_dotlocks;
6592
b6631550cf84 dotlocks: Flush NFS attribute cache only if nfs_flush setting is TRUE.
Timo Sirainen <tss@iki.fi>
parents: 6458
diff changeset
41 log->dotlock_settings.nfs_flush = index->nfs_flush;
6360
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 6331
diff changeset
42 log->dotlock_settings.timeout = MAIL_TRANSCATION_LOG_LOCK_TIMEOUT;
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 6331
diff changeset
43 log->dotlock_settings.stale_timeout =
461ae76c84da Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents: 6331
diff changeset
44 MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT;
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 3090
diff changeset
45
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 3090
diff changeset
46 log->new_dotlock_settings = log->dotlock_settings;
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 3090
diff changeset
47 log->new_dotlock_settings.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 3090
diff changeset
48
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 return log;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51
5881
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
52 static void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log)
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
53 {
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
54 struct stat st;
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
55 const char *path;
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
56
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
57 path = t_strconcat(log->index->filepath,
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
58 MAIL_TRANSACTION_LOG_SUFFIX".2", NULL);
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
59 if (stat(path, &st) < 0) {
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
60 if (errno != ENOENT && errno != ESTALE) {
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
61 mail_index_set_error(log->index,
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
62 "stat(%s) failed: %m", path);
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
63 }
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
64 return;
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
65 }
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
66
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
67 if (st.st_mtime + MAIL_TRANSACTION_LOG2_STALE_SECS <= ioloop_time) {
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
68 if (unlink(path) < 0 && errno != ENOENT) {
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
69 mail_index_set_error(log->index,
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
70 "unlink(%s) failed: %m", path);
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
71 }
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
72 }
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
73 }
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
74
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
75 int mail_transaction_log_open(struct mail_transaction_log *log)
5247
c1ef15c1a1fa If index file is corrupted, recreate transaction log file instead of trying
Timo Sirainen <tss@iki.fi>
parents: 5236
diff changeset
76 {
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
77 struct mail_transaction_log_file *file;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
78 const char *path;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
79 int ret;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
80
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
81 if (log->open_file != NULL)
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
82 mail_transaction_log_file_free(&log->open_file);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
83
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
84 if (MAIL_INDEX_IS_IN_MEMORY(log->index))
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
85 return 0;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
86
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
87 path = t_strconcat(log->index->filepath,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
88 MAIL_TRANSACTION_LOG_SUFFIX, NULL);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
89
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
90 file = mail_transaction_log_file_alloc(log, path);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
91 if ((ret = mail_transaction_log_file_open(file, FALSE)) <= 0) {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
92 /* leave the file for _create() */
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
93 log->open_file = file;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
94 return ret;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
95 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
96 mail_transaction_log_set_head(log, file);
5881
7b7ce27f2b13 Delete over 30 minutes old .log.2 files when opening indexes.
Timo Sirainen <tss@iki.fi>
parents: 5849
diff changeset
97 mail_transaction_log_2_unlink_old(log);
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
98 return 1;
5247
c1ef15c1a1fa If index file is corrupted, recreate transaction log file instead of trying
Timo Sirainen <tss@iki.fi>
parents: 5236
diff changeset
99 }
c1ef15c1a1fa If index file is corrupted, recreate transaction log file instead of trying
Timo Sirainen <tss@iki.fi>
parents: 5236
diff changeset
100
7573
de08cc81da73 Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents: 7393
diff changeset
101 int mail_transaction_log_create(struct mail_transaction_log *log, bool reset)
5247
c1ef15c1a1fa If index file is corrupted, recreate transaction log file instead of trying
Timo Sirainen <tss@iki.fi>
parents: 5236
diff changeset
102 {
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
103 struct mail_transaction_log_file *file;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
104 const char *path;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
105
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
106 if (MAIL_INDEX_IS_IN_MEMORY(log->index)) {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
107 file = mail_transaction_log_file_alloc_in_memory(log);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
108 mail_transaction_log_set_head(log, file);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
109 return 0;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
110 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
111
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
112 path = t_strconcat(log->index->filepath,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
113 MAIL_TRANSACTION_LOG_SUFFIX, NULL);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
114
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
115 file = mail_transaction_log_file_alloc(log, path);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
116
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
117 if (log->open_file != NULL) {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
118 /* remember what file we tried to open. if someone else created
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
119 a new file, use it instead of recreating it */
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
120 file->st_ino = log->open_file->st_ino;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
121 file->st_dev = log->open_file->st_dev;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
122 file->last_size = log->open_file->last_size;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
123 file->last_mtime = log->open_file->last_mtime;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
124 mail_transaction_log_file_free(&log->open_file);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
125 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
126
7573
de08cc81da73 Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents: 7393
diff changeset
127 if (mail_transaction_log_file_create(file, reset) < 0) {
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
128 mail_transaction_log_file_free(&file);
5953
Timo Sirainen <tss@iki.fi>
parents: 5934
diff changeset
129 return -1;
Timo Sirainen <tss@iki.fi>
parents: 5934
diff changeset
130 }
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
131
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
132 mail_transaction_log_set_head(log, file);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
133 return 1;
5247
c1ef15c1a1fa If index file is corrupted, recreate transaction log file instead of trying
Timo Sirainen <tss@iki.fi>
parents: 5236
diff changeset
134 }
c1ef15c1a1fa If index file is corrupted, recreate transaction log file instead of trying
Timo Sirainen <tss@iki.fi>
parents: 5236
diff changeset
135
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
136 void mail_transaction_log_close(struct mail_transaction_log *log)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 {
1942
2b114aa7eeec handle losing index file
Timo Sirainen <tss@iki.fi>
parents: 1941
diff changeset
138 mail_transaction_log_views_close(log);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
140 if (log->open_file != NULL)
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
141 mail_transaction_log_file_free(&log->open_file);
4777
1dc7ffa3c669 Don't leak opened .log.2 transaction logs.
Timo Sirainen <tss@iki.fi>
parents: 4396
diff changeset
142 if (log->head != NULL)
3106
9c4aa309dbac Changed dotlocking API.
Timo Sirainen <tss@iki.fi>
parents: 3090
diff changeset
143 log->head->refcount--;
4777
1dc7ffa3c669 Don't leak opened .log.2 transaction logs.
Timo Sirainen <tss@iki.fi>
parents: 4396
diff changeset
144 mail_transaction_logs_clean(log);
4785
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
145 i_assert(log->files == NULL);
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
146 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
147
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
148 void mail_transaction_log_free(struct mail_transaction_log **_log)
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
149 {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
150 struct mail_transaction_log *log = *_log;
1967
b6d900688c55 memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 1964
diff changeset
151
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
152 *_log = NULL;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
153
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
154 mail_transaction_log_close(log);
1942
2b114aa7eeec handle losing index file
Timo Sirainen <tss@iki.fi>
parents: 1941
diff changeset
155 log->index->log = NULL;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 i_free(log);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
5714
dcf5dbb6a76a mail_transaction_log_move_to_memory() can't fail anymore. Moved the code to
Timo Sirainen <tss@iki.fi>
parents: 5689
diff changeset
159 void mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
3833
318c70c1d4ec Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents: 3832
diff changeset
160 {
6628
7373240c3d1d Don't crash if we couldn't create transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6592
diff changeset
161 struct mail_transaction_log_file *file;
7373240c3d1d Don't crash if we couldn't create transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6592
diff changeset
162
8941
eb9e5ab575a9 indexes: Error handling fixes.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
163 if (!log->index->initial_mapped && log->files != NULL &&
eb9e5ab575a9 indexes: Error handling fixes.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
164 log->files->hdr.prev_file_seq != 0) {
eb9e5ab575a9 indexes: Error handling fixes.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
165 /* we couldn't read dovecot.index and we don't have the first
eb9e5ab575a9 indexes: Error handling fixes.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
166 .log file, so just start from scratch */
eb9e5ab575a9 indexes: Error handling fixes.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
167 mail_transaction_log_close(log);
eb9e5ab575a9 indexes: Error handling fixes.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
168 }
eb9e5ab575a9 indexes: Error handling fixes.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
169
5714
dcf5dbb6a76a mail_transaction_log_move_to_memory() can't fail anymore. Moved the code to
Timo Sirainen <tss@iki.fi>
parents: 5689
diff changeset
170 if (log->head != NULL)
dcf5dbb6a76a mail_transaction_log_move_to_memory() can't fail anymore. Moved the code to
Timo Sirainen <tss@iki.fi>
parents: 5689
diff changeset
171 mail_transaction_log_file_move_to_memory(log->head);
6628
7373240c3d1d Don't crash if we couldn't create transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6592
diff changeset
172 else {
7373240c3d1d Don't crash if we couldn't create transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6592
diff changeset
173 file = mail_transaction_log_file_alloc_in_memory(log);
7373240c3d1d Don't crash if we couldn't create transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6592
diff changeset
174 mail_transaction_log_set_head(log, file);
7373240c3d1d Don't crash if we couldn't create transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6592
diff changeset
175 }
3833
318c70c1d4ec Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents: 3832
diff changeset
176 }
318c70c1d4ec Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents: 3832
diff changeset
177
5819
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
178 void mail_transaction_log_indexid_changed(struct mail_transaction_log *log)
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
179 {
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
180 struct mail_transaction_log_file *file;
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
181
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
182 mail_transaction_logs_clean(log);
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
183
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
184 for (file = log->files; file != NULL; file = file->next) {
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
185 if (file->hdr.indexid != log->index->indexid) {
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
186 mail_transaction_log_file_set_corrupted(file,
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
187 "indexid changed: %u -> %u",
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
188 file->hdr.indexid, log->index->indexid);
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
189 }
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
190 }
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
191
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
192 if (log->head != NULL &&
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
193 log->head->hdr.indexid != log->index->indexid) {
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
194 if (--log->head->refcount == 0)
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
195 mail_transaction_log_file_free(&log->head);
7573
de08cc81da73 Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents: 7393
diff changeset
196 (void)mail_transaction_log_create(log, FALSE);
5819
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
197 }
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
198 }
4ea31bf18a56 Handle indexid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5749
diff changeset
199
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 void mail_transaction_logs_clean(struct mail_transaction_log *log)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 {
4785
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
202 struct mail_transaction_log_file *file, *next;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203
6458
cca479cb3ef0 Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents: 6450
diff changeset
204 /* remove only files from the beginning. this way if a view has
cca479cb3ef0 Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents: 6450
diff changeset
205 referenced an old file, it can still find the new files even if
cca479cb3ef0 Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents: 6450
diff changeset
206 there aren't any references to it currently. */
4785
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
207 for (file = log->files; file != NULL; file = next) {
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
208 next = file->next;
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
209
4828
7cc1b8fec8ab Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents: 4785
diff changeset
210 i_assert(file->refcount >= 0);
6458
cca479cb3ef0 Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents: 6450
diff changeset
211 if (file->refcount > 0)
cca479cb3ef0 Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents: 6450
diff changeset
212 break;
cca479cb3ef0 Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents: 6450
diff changeset
213
cca479cb3ef0 Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents: 6450
diff changeset
214 mail_transaction_log_file_free(&file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 }
7878
1da72e385de4 Rotated transaction logs weren't always unlocked, potentially causing other
Timo Sirainen <tss@iki.fi>
parents: 7573
diff changeset
216 /* if we still have locked files with refcount=0, unlock them */
1da72e385de4 Rotated transaction logs weren't always unlocked, potentially causing other
Timo Sirainen <tss@iki.fi>
parents: 7573
diff changeset
217 for (; file != NULL; file = file->next) {
1da72e385de4 Rotated transaction logs weren't always unlocked, potentially causing other
Timo Sirainen <tss@iki.fi>
parents: 7573
diff changeset
218 if (file->locked && file->refcount == 0)
1da72e385de4 Rotated transaction logs weren't always unlocked, potentially causing other
Timo Sirainen <tss@iki.fi>
parents: 7573
diff changeset
219 mail_transaction_log_file_unlock(file);
1da72e385de4 Rotated transaction logs weren't always unlocked, potentially causing other
Timo Sirainen <tss@iki.fi>
parents: 7573
diff changeset
220 }
5934
181aa61c182a Added asserts
Timo Sirainen <tss@iki.fi>
parents: 5881
diff changeset
221 i_assert(log->head == NULL || log->files != NULL);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
224 #define LOG_WANT_ROTATE(file) \
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
225 (((file)->sync_offset > MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE && \
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
226 (time_t)(file)->hdr.create_stamp < \
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
227 ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_TIME) || \
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
228 ((file)->sync_offset > MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE))
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
229
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
230 bool mail_transaction_log_want_rotate(struct mail_transaction_log *log)
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
231 {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
232 return LOG_WANT_ROTATE(log->head);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
233 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
234
5849
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
235 int mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 struct mail_transaction_log_file *file;
3243
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
238 const char *path = log->head->filepath;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
239 struct stat st;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240
3173
d137899ea853 We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents: 3170
diff changeset
241 i_assert(log->head->locked);
d137899ea853 We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents: 3170
diff changeset
242
5849
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
243 if (MAIL_INDEX_IS_IN_MEMORY(log->index)) {
3243
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
244 file = mail_transaction_log_file_alloc_in_memory(log);
5849
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
245 if (reset) {
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
246 file->hdr.prev_file_seq = 0;
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
247 file->hdr.prev_file_offset = 0;
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
248 }
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
249 } else {
4023
b19ccbaa3802 Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3981
diff changeset
250 /* we're locked, we shouldn't need to worry about ESTALE
b19ccbaa3802 Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3981
diff changeset
251 problems in here. */
3243
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
252 if (fstat(log->head->fd, &st) < 0) {
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
253 mail_index_file_set_syscall_error(log->index,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
254 file->filepath, "fstat()");
3243
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
255 return -1;
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
256 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257
5013
6c76ed030b60 Fixed a race condition in transaction log rotation, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 4968
diff changeset
258 file = mail_transaction_log_file_alloc(log, path);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
260 file->st_dev = st.st_dev;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
261 file->st_ino = st.st_ino;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
262 file->last_mtime = st.st_mtime;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
263 file->last_size = st.st_size;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
264
5849
a9df50952600 Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents: 5819
diff changeset
265 if (mail_transaction_log_file_create(file, reset) < 0) {
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
266 mail_transaction_log_file_free(&file);
1940
Timo Sirainen <tss@iki.fi>
parents: 1937
diff changeset
267 return -1;
2004
2ab29071a32c some fixes
Timo Sirainen <tss@iki.fi>
parents: 1976
diff changeset
268 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 }
5013
6c76ed030b60 Fixed a race condition in transaction log rotation, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 4968
diff changeset
270
1940
Timo Sirainen <tss@iki.fi>
parents: 1937
diff changeset
271 if (--log->head->refcount == 0)
Timo Sirainen <tss@iki.fi>
parents: 1937
diff changeset
272 mail_transaction_logs_clean(log);
Timo Sirainen <tss@iki.fi>
parents: 1937
diff changeset
273 else
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
274 mail_transaction_log_file_unlock(log->head);
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
275 mail_transaction_log_set_head(log, file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 return 0;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278
6802
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
279 static int
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
280 mail_transaction_log_refresh(struct mail_transaction_log *log, bool nfs_flush)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 struct mail_transaction_log_file *file;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
283 struct stat st;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284 const char *path;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285
5089
18559c7e3a15 Cleanups and minor fixes
Timo Sirainen <tss@iki.fi>
parents: 5021
diff changeset
286 i_assert(log->head != NULL);
18559c7e3a15 Cleanups and minor fixes
Timo Sirainen <tss@iki.fi>
parents: 5021
diff changeset
287
3243
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
288 if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(log->head))
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
289 return 0;
40b4ba3c55b8 In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents: 3218
diff changeset
290
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 path = t_strconcat(log->index->filepath,
3316
62d31be5ae60 s/PREFIX/SUFFIX/ for .cache and .log filename suffixes..
Timo Sirainen <tss@iki.fi>
parents: 3243
diff changeset
292 MAIL_TRANSACTION_LOG_SUFFIX, NULL);
6857
41911abe6fa7 NFS cache flushing updates.
Timo Sirainen <tss@iki.fi>
parents: 6829
diff changeset
293 if (log->index->nfs_flush && nfs_flush)
41911abe6fa7 NFS cache flushing updates.
Timo Sirainen <tss@iki.fi>
parents: 6829
diff changeset
294 nfs_flush_file_handle_cache(path);
4225
abdef9d86a94 Added nfs_safe_stat() to transparently work around ESTALE with stat().
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4072
diff changeset
295 if (nfs_safe_stat(path, &st) < 0) {
4396
208194b3742a Handle transaction log deletions silently. Handle whole index directory
Timo Sirainen <tss@iki.fi>
parents: 4225
diff changeset
296 if (errno != ENOENT) {
208194b3742a Handle transaction log deletions silently. Handle whole index directory
Timo Sirainen <tss@iki.fi>
parents: 4225
diff changeset
297 mail_index_file_set_syscall_error(log->index, path,
208194b3742a Handle transaction log deletions silently. Handle whole index directory
Timo Sirainen <tss@iki.fi>
parents: 4225
diff changeset
298 "stat()");
208194b3742a Handle transaction log deletions silently. Handle whole index directory
Timo Sirainen <tss@iki.fi>
parents: 4225
diff changeset
299 return -1;
208194b3742a Handle transaction log deletions silently. Handle whole index directory
Timo Sirainen <tss@iki.fi>
parents: 4225
diff changeset
300 }
6327
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
301 /* the file should always exist at this point. if it doesn't,
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
302 someone deleted it manually while the index was open. try to
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
303 handle this nicely by creating a new log file. */
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
304 file = log->head;
7573
de08cc81da73 Fixes to handling races in initial index creation.
Timo Sirainen <tss@iki.fi>
parents: 7393
diff changeset
305 if (mail_transaction_log_create(log, FALSE) < 0)
6327
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
306 return -1;
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
307 i_assert(file->refcount > 0);
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
308 file->refcount--;
6331
081fd0acddd2 If we notice that dovecot.index.log gets deleted, make sure that
Timo Sirainen <tss@iki.fi>
parents: 6327
diff changeset
309 log->index->need_recreate = TRUE;
6327
b8b02d155599 If transaction log is deleted under us, recreate it immediately.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
310 return 0;
6808
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
311 } else if (log->head->st_ino == st.st_ino &&
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
312 CMP_DEV_T(log->head->st_dev, st.st_dev)) {
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
313 /* NFS: log files get rotated to .log.2 files instead
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
314 of being unlinked, so we don't bother checking if
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
315 the existing file has already been unlinked here
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
316 (in which case inodes could match but point to
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
317 different files) */
937faba78a68 Don't flush attribute cache twice after locking transaction log.
Timo Sirainen <tss@iki.fi>
parents: 6802
diff changeset
318 return 0;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
321 file = mail_transaction_log_file_alloc(log, path);
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
322 if (mail_transaction_log_file_open(file, FALSE) <= 0) {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
323 mail_transaction_log_file_free(&file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324 return -1;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
325 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
327 i_assert(!file->locked);
2095
Timo Sirainen <tss@iki.fi>
parents: 2073
diff changeset
328
5089
18559c7e3a15 Cleanups and minor fixes
Timo Sirainen <tss@iki.fi>
parents: 5021
diff changeset
329 if (--log->head->refcount == 0)
18559c7e3a15 Cleanups and minor fixes
Timo Sirainen <tss@iki.fi>
parents: 5021
diff changeset
330 mail_transaction_logs_clean(log);
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
331 mail_transaction_log_set_head(log, file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 return 0;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
335 void mail_transaction_log_get_mailbox_sync_pos(struct mail_transaction_log *log,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
336 uint32_t *file_seq_r,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
337 uoff_t *file_offset_r)
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
338 {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
339 *file_seq_r = log->head->hdr.file_seq;
5749
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5715
diff changeset
340 *file_offset_r = log->head->max_tail_offset;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
341 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
342
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
343 void mail_transaction_log_set_mailbox_sync_pos(struct mail_transaction_log *log,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
344 uint32_t file_seq,
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
345 uoff_t file_offset)
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
346 {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
347 i_assert(file_seq == log->head->hdr.file_seq);
5749
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5715
diff changeset
348 i_assert(file_offset >= log->head->saved_tail_offset);
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
349
5749
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5715
diff changeset
350 if (file_offset >= log->head->max_tail_offset)
420a386fa27a int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
Timo Sirainen <tss@iki.fi>
parents: 5715
diff changeset
351 log->head->max_tail_offset = file_offset;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
352 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
353
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
354 int mail_transaction_log_find_file(struct mail_transaction_log *log,
6802
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
355 uint32_t file_seq, bool nfs_flush,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
356 struct mail_transaction_log_file **file_r)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
357 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358 struct mail_transaction_log_file *file;
3320
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
359 const char *path;
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
360 int ret;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
362 if (file_seq > log->head->hdr.file_seq) {
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
363 /* see if the .log file has been recreated */
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
364 if (log->head->locked) {
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
365 /* transaction log is locked. there's no way a newer
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
366 file exists. */
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
367 return 0;
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
368 }
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
369
6802
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
370 if (mail_transaction_log_refresh(log, FALSE) < 0)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 return -1;
6802
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
372 if (file_seq > log->head->hdr.file_seq) {
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
373 if (!nfs_flush || !log->index->nfs_flush)
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
374 return 0;
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
375 /* try again, this time flush attribute cache */
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
376 if (mail_transaction_log_refresh(log, TRUE) < 0)
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
377 return -1;
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
378 if (file_seq > log->head->hdr.file_seq)
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
379 return 0;
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
380 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382
4785
a18fa2b4bf06 Code cleanup
Timo Sirainen <tss@iki.fi>
parents: 4777
diff changeset
383 for (file = log->files; file != NULL; file = file->next) {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
384 if (file->hdr.file_seq == file_seq) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385 *file_r = file;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386 return 1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389
5017
987397c331d7 Fixes to error handling paths.
Timo Sirainen <tss@iki.fi>
parents: 5015
diff changeset
390 if (MAIL_INDEX_IS_IN_MEMORY(log->index))
987397c331d7 Fixes to error handling paths.
Timo Sirainen <tss@iki.fi>
parents: 5015
diff changeset
391 return 0;
987397c331d7 Fixes to error handling paths.
Timo Sirainen <tss@iki.fi>
parents: 5015
diff changeset
392
3320
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
393 /* see if we have it in log.2 file */
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
394 path = t_strconcat(log->index->filepath,
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
395 MAIL_TRANSACTION_LOG_SUFFIX".2", NULL);
5013
6c76ed030b60 Fixed a race condition in transaction log rotation, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 4968
diff changeset
396 file = mail_transaction_log_file_alloc(log, path);
7393
e569788da4e8 Memory leak fix (by Diego Liziero)
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
397 if ((ret = mail_transaction_log_file_open(file, TRUE)) <= 0) {
e569788da4e8 Memory leak fix (by Diego Liziero)
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
398 mail_transaction_log_file_free(&file);
5689
c2362f144f15 Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents: 5687
diff changeset
399 return ret;
7393
e569788da4e8 Memory leak fix (by Diego Liziero)
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
400 }
3320
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
401
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
402 /* but is it what we expected? */
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
403 if (file->hdr.file_seq != file_seq)
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
404 return 0;
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
405
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
406 *file_r = file;
0403596c93fd index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents: 3317
diff changeset
407 return 1;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409
3146
9a8bf1c86699 Moved code into mail-transaction-log-append.c
Timo Sirainen <tss@iki.fi>
parents: 3138
diff changeset
410 int mail_transaction_log_lock_head(struct mail_transaction_log *log)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 struct mail_transaction_log_file *file;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413 int ret = 0;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415 /* we want to get the head file locked. this is a bit racy,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 since by the time we have it locked a new log file may have been
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 created.
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
418
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419 creating new log file requires locking the head file, so if we
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 can lock it and don't see another file, we can be sure no-one is
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
421 creating a new log at the moment */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 for (;;) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424 file = log->head;
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
425 if (mail_transaction_log_file_lock(file) < 0)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426 return -1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428 file->refcount++;
6802
ba58eaf06763 Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents: 6798
diff changeset
429 ret = mail_transaction_log_refresh(log, TRUE);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430 if (--file->refcount == 0) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 mail_transaction_logs_clean(log);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 file = NULL;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 if (ret == 0 && log->head == file) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 /* success */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 break;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
440 if (file != NULL)
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
441 mail_transaction_log_file_unlock(file);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443 if (ret < 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444 break;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 /* try again */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 return ret;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 int mail_transaction_log_sync_lock(struct mail_transaction_log *log,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453 uint32_t *file_seq_r, uoff_t *file_offset_r)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 i_assert(!log->index->log_locked);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457 if (mail_transaction_log_lock_head(log) < 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 return -1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
460 /* update sync_offset */
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
461 if (mail_transaction_log_file_map(log->head, log->head->sync_offset,
5715
11d39b7f07ff Handle mail_transaction_log_file_map() == 0 failures.
Timo Sirainen <tss@iki.fi>
parents: 5714
diff changeset
462 (uoff_t)-1) <= 0) {
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
463 mail_transaction_log_file_unlock(log->head);
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
464 return -1;
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
465 }
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
466
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 log->index->log_locked = TRUE;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 *file_seq_r = log->head->hdr.file_seq;
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
469 *file_offset_r = log->head->sync_offset;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 return 0;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 void mail_transaction_log_sync_unlock(struct mail_transaction_log *log)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 i_assert(log->index->log_locked);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 log->index->log_locked = FALSE;
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
478 mail_transaction_log_file_unlock(log->head);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 void mail_transaction_log_get_head(struct mail_transaction_log *log,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482 uint32_t *file_seq_r, uoff_t *file_offset_r)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
483 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484 *file_seq_r = log->head->hdr.file_seq;
2407
fed6d07bd8ee Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents: 2318
diff changeset
485 *file_offset_r = log->head->sync_offset;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486 }
3832
76f4be7ae499 Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents: 3556
diff changeset
487
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3833
diff changeset
488 bool mail_transaction_log_is_head_prev(struct mail_transaction_log *log,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3833
diff changeset
489 uint32_t file_seq, uoff_t file_offset)
3832
76f4be7ae499 Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents: 3556
diff changeset
490 {
76f4be7ae499 Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents: 3556
diff changeset
491 return log->head->hdr.prev_file_seq == file_seq &&
76f4be7ae499 Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents: 3556
diff changeset
492 log->head->hdr.prev_file_offset == file_offset;
76f4be7ae499 Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents: 3556
diff changeset
493 }