Blob Blame History Raw
From 67b8b290c6a46dcc0dc20e3589f9c1f58110f332 Mon Sep 17 00:00:00 2001
From: Dan Lambright <dlambrig@redhat.com>
Date: Tue, 2 Jun 2015 14:46:46 -0400
Subject: [PATCH 53/57] cluster/dht: maintain start state of rebalance daemon across graph switch

This is a backport of 10977

When we did a graph switch on a rebalance daemon, a second call
to gf_degrag_start() was done. This lead to multiple threads
doing migration. When multiple threads try to move the same
file there can be deadlocks.

> Change-Id: I931ca7fe600022f245e3dccaabb1ad004f732c56
> BUG: 1226005
> Signed-off-by: Dan Lambright <dlambrig@redhat.com>
> Reviewed-on: http://review.gluster.org/10977
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>

Change-Id: I7797492cc6f32c0bf155b542d51184eb9a84a53d
BUG: 1227469
Signed-off-by: Dan Lambright <dlambrig@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/49748
Reviewed-by: Joseph Fernandes <josferna@redhat.com>
Tested-by: Joseph Fernandes <josferna@redhat.com>
Reviewed-by: Shyam Ranganathan <srangana@redhat.com>
---
 xlators/cluster/dht/src/dht-common.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index a3a48ea..6d70f82 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -37,6 +37,9 @@ dht_removexattr2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame);
 int
 dht_setxattr2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame);
 
+int run_defrag = 0;
+
+
 int
 dht_aggregate_quota_xattr (dict_t *dst, char *key, data_t *value)
 {
@@ -6895,11 +6898,16 @@ unlock:
                         }
                 }
 
-                /* rebalance is started with assert_no_child_down. So we do
+                /* Rebalance is started with assert_no_child_down. So we do
                  * not need to handle CHILD_DOWN event here.
+                 *
+                 * If there is a graph switch, we should not restart the
+                 * rebalance daemon. Use 'run_defrag' to indicate if the
+                 * thread has already started.
                  */
-                if (conf->defrag) {
+                 if (conf->defrag && !run_defrag) {
                         if (methods->migration_needed(this)) {
+                                run_defrag = 1;
                                 ret = gf_thread_create(&conf->defrag->th,
                                                        NULL,
                                                        gf_defrag_start, this);
-- 
1.7.1