]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
plugins: fts - replace i_assert under _expunge_log_subtract with warning (API change)
authorPhil Carmody <phil@dovecot.fi>
Mon, 5 Sep 2016 13:26:56 +0000 (16:26 +0300)
committerGitLab <gitlab@git.dovecot.net>
Mon, 12 Sep 2016 07:31:07 +0000 (10:31 +0300)
The helper whose interface is changing currently has no other known
clients (there's little need for it to be exposed at all).

This should never happen, but if it does, just tally the number of times
it happened, and squirt out a warning message after the whole subtract.
If it happens at all, there's no reason not to expect a lot, so only
warn once per file.

In particular - do not assert crash when this is seen - it has been seen
on live test systems where file corruption seems to have occured. As
this can only be associated with corrupt fts indexes, seeing this error
implies that the whole FTS index should be rebuilt for that user.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/plugins/fts/fts-expunge-log.c
src/plugins/fts/fts-expunge-log.h

index d58d4444596de3b92b3c8333760fb50b5333982b..1af23631e32c6b977b42a485d9de497ca105cddb 100644 (file)
@@ -564,24 +564,32 @@ bool fts_expunge_log_contains(const struct fts_expunge_log_append_ctx *ctx,
                return FALSE;
        return seq_range_exists(&mailbox->uids, uid);   
 }
-void fts_expunge_log_append_remove(struct fts_expunge_log_append_ctx *from,
+int fts_expunge_log_append_remove(struct fts_expunge_log_append_ctx *from,
                                   const struct fts_expunge_log_read_record *record)
 {
        const uint8_t *guid_p = record->mailbox_guid;
        struct fts_expunge_log_mailbox *mailbox = hash_table_lookup(from->mailboxes, guid_p);
-       i_assert(mailbox != NULL); /* may only remove things that exist */
+       if (mailbox == NULL)
+               return 0; /* may only remove things that exist */
+
        mailbox->uids_count -= seq_range_array_remove_seq_range(&mailbox->uids, &record->uids);
+       return 1;
 }
 int fts_expunge_log_subtract(struct fts_expunge_log_append_ctx *from,
                             struct fts_expunge_log *subtract)
 {
+       unsigned int failures = 0;
        struct fts_expunge_log_read_ctx *read_ctx = fts_expunge_log_read_begin(subtract);
        read_ctx->unlink = FALSE;
 
        const struct fts_expunge_log_read_record *record;
-       while ((record = fts_expunge_log_read_next(read_ctx)) != NULL)
-               fts_expunge_log_append_remove(from, record);
-
+       while ((record = fts_expunge_log_read_next(read_ctx)) != NULL) {
+               if (fts_expunge_log_append_remove(from, record) <= 0)
+                       failures++;
+       }
+       if (failures > 0)
+               i_warning("fts: Expunge log subtract ignored %u nonexistent mailbox GUIDs",
+                         failures);
        return fts_expunge_log_read_end(&read_ctx);
 }
 /* It could be argued that somehow adding a log (file) to the append context
index 557dbe2d8d6c34b5c50289a3ed194aef03d1f498..cc15f29a1a69208933a3a382fcbce45918717b54 100644 (file)
@@ -22,9 +22,11 @@ void fts_expunge_log_append_range(struct fts_expunge_log_append_ctx *ctx,
                                  const struct seq_range *uids);
 void fts_expunge_log_append_record(struct fts_expunge_log_append_ctx *ctx,
                                   const struct fts_expunge_log_read_record *record);
-/* in-memory flattened structures may have records removed from them, file-backed ones may not */
-void fts_expunge_log_append_remove(struct fts_expunge_log_append_ctx *ctx,
-                                  const struct fts_expunge_log_read_record *record);
+/* In-memory flattened structures may have records removed from them,
+   file-backed ones may not. Non-existence of UIDs is not an error,
+   non-existence of mailbox GUID causes an error return of 0. */
+int fts_expunge_log_append_remove(struct fts_expunge_log_append_ctx *ctx,
+                                 const struct fts_expunge_log_read_record *record);
 int fts_expunge_log_append_commit(struct fts_expunge_log_append_ctx **ctx);
 /* Do not commit non-backed structures, abort them after use. */
 int fts_expunge_log_append_abort(struct fts_expunge_log_append_ctx **ctx);
@@ -46,7 +48,8 @@ int fts_expunge_log_flatten(const char *path,
                            struct fts_expunge_log_append_ctx **flattened_r);
 bool fts_expunge_log_contains(const struct fts_expunge_log_append_ctx *ctx,
                              const guid_128_t mailbox_guid, uint32_t uid);
-/* Modify in-place a flattened log. */
+/* Modify in-place a flattened log. If non-existent mailbox GUIDs are
+   encountered, a warning will be logged. */
 int fts_expunge_log_subtract(struct fts_expunge_log_append_ctx *from,
                             struct fts_expunge_log *subtract);
 /* Write a modified flattened log as a new file. */