annotate src/lib-index/mail-cache-sync-update.c @ 22576:707ae9de3812

lib: istream-multiplex - Minor code cleanup Avoid propagating the error twice, and avoid any confusion about what "got" actually contains.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 05 Oct 2017 20:24:11 +0300
parents 7d09937dc4ff
children cb108f786fb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 19552
diff changeset
1 /* Copyright (c) 2004-2017 Dovecot authors, see the included COPYING file */
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "mail-cache-private.h"
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "mail-index-sync-private.h"
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 struct mail_cache_sync_context {
17899
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
8 unsigned expunge_count;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 };
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
22037
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
11 void mail_cache_expunge_count(struct mail_cache *cache, unsigned int count)
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
12 {
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
13 if (mail_cache_lock(cache) > 0) {
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
14 cache->hdr_copy.deleted_record_count += count;
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
15 if (cache->hdr_copy.record_count >= count)
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
16 cache->hdr_copy.record_count -= count;
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
17 else
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
18 cache->hdr_copy.record_count = 0;
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
19 cache->hdr_modified = TRUE;
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
20 (void)mail_cache_unlock(cache);
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
21 }
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
22 }
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
23
6753
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
24 static struct mail_cache_sync_context *mail_cache_handler_init(void **context)
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
25 {
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
26 struct mail_cache_sync_context *ctx;
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
27
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
28 if (*context != NULL)
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
29 ctx = *context;
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
30 else {
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
31 *context = i_new(struct mail_cache_sync_context, 1);
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
32 ctx = *context;
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
33 }
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
34 return ctx;
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
35 }
de67ceff3199 Flush cache file's NFS attribute cache only once per sync. Don't invalidate
Timo Sirainen <tss@iki.fi>
parents: 6510
diff changeset
36
17899
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
37 static void mail_cache_handler_deinit(struct mail_index_sync_map_ctx *sync_ctx,
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
38 struct mail_cache_sync_context *ctx)
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 {
17899
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
40 struct mail_cache *cache = sync_ctx->view->index->cache;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41
17899
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
42 if (ctx == NULL)
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
43 return;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44
22037
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
45 mail_cache_expunge_count(cache, ctx->expunge_count);
7d09937dc4ff lib-index: Add mail_cache_expunge_count
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
46
17899
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
47 i_free(ctx);
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 }
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 5972
diff changeset
51 uint32_t seq ATTR_UNUSED, const void *data,
17899
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
52 void **sync_context, void *context ATTR_UNUSED)
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 {
4490
56d17f2e1d66 Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents: 4283
diff changeset
54 struct mail_cache_sync_context *ctx = *sync_context;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 const uint32_t *cache_offset = data;
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 if (data == NULL) {
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 mail_cache_handler_deinit(sync_ctx, ctx);
4490
56d17f2e1d66 Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents: 4283
diff changeset
59 *sync_context = NULL;
56d17f2e1d66 Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents: 4283
diff changeset
60 return 0;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 }
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 if (*cache_offset == 0)
4490
56d17f2e1d66 Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents: 4283
diff changeset
64 return 0;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
6756
e78c51d6305f Fixes to handling cache file syncs and expunging.
Timo Sirainen <tss@iki.fi>
parents: 6753
diff changeset
66 ctx = mail_cache_handler_init(sync_context);
17899
d6e08d98a170 lib-index: Don't keep cache file locked for as long while syncing index.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
67 ctx->expunge_count++;
4490
56d17f2e1d66 Added support for calling expunge handler for an extension even if the
Timo Sirainen <tss@iki.fi>
parents: 4283
diff changeset
68 return 0;
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 }