]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Determine better when rename-algorithm might have gotten stuck.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 22 Apr 2016 13:28:56 +0000 (16:28 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 22 Apr 2016 22:43:27 +0000 (01:43 +0300)
A hardcoded value of 100 isn't necessarily enough if there are a lot of
mailboxes with a lot of renames. Base the max count on the total number
of mailboxes on both local and remote. And just in case multiple it by 3.
Probably smaller number would be fine too.

src/doveadm/dsync/dsync-mailbox-tree-sync.c

index 3ad3eec04e1aa9c9cf5a675428f715291aba2e88..aee5f6425b77dfb28b0a4e29f86aaddc91be7bfe 100644 (file)
@@ -15,8 +15,6 @@
 #define TEMP_SUFFIX_MAX_LEN (sizeof("temp-")-1 + 8)
 #define TEMP_SUFFIX_FORMAT "temp-%x"
 
-#define MAX_RENAMES 100
-
 struct dsync_mailbox_tree_bfs_iter {
        struct dsync_mailbox_tree *tree;
 
@@ -30,6 +28,7 @@ struct dsync_mailbox_tree_sync_ctx {
        struct dsync_mailbox_tree *local_tree, *remote_tree;
        enum dsync_mailbox_trees_sync_type sync_type;
        enum dsync_mailbox_trees_sync_flags sync_flags;
+       unsigned int combined_mailboxes_count;
 
        ARRAY(struct dsync_mailbox_tree_sync_change) changes;
        unsigned int change_idx;
@@ -237,6 +236,7 @@ sync_tree_sort_and_delete_mailboxes(struct dsync_mailbox_tree_sync_ctx *ctx,
                                sync_set_node_deleted(tree, node);
                        }
                }
+               ctx->combined_mailboxes_count++;
                array_append(&siblings, &node, 1);
        }
        sort_siblings(&siblings);
@@ -1078,9 +1078,10 @@ sync_rename_temp_mailboxes(struct dsync_mailbox_tree_sync_ctx *ctx,
 static int
 dsync_mailbox_tree_handle_renames(struct dsync_mailbox_tree_sync_ctx *ctx)
 {
-       unsigned int count = 0;
+       unsigned int max_renames, count = 0;
        bool changed;
 
+       max_renames = ctx->combined_mailboxes_count * 3;
        do {
                T_BEGIN {
                        changed = sync_rename_mailboxes(ctx, &ctx->local_tree->root,
@@ -1091,7 +1092,7 @@ dsync_mailbox_tree_handle_renames(struct dsync_mailbox_tree_sync_ctx *ctx)
                        i_debug("brain %c: -- Mailbox renamed, restart sync --",
                                (ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_MASTER_BRAIN) != 0 ? 'M' : 'S');
                }
-       } while (changed && ++count <= MAX_RENAMES);
+       } while (changed && ++count <= max_renames);
 
        if (changed) {
                i_error("BUG: Mailbox renaming algorithm got into a potentially infinite loop, aborting");