a3470f
From 87a24e342c422ba6b04563d63d431430c0156b52 Mon Sep 17 00:00:00 2001
a3470f
From: N Balachandran <nbalacha@redhat.com>
a3470f
Date: Fri, 6 Apr 2018 16:06:51 +0530
a3470f
Subject: [PATCH 217/236] cluster/dht: Handle file migrations when brick down
a3470f
a3470f
The decision as to which node would migrate a file
a3470f
was based on the gfid of the file. Files were divided
a3470f
among the nodes for the replica/disperse set. However,
a3470f
if a brick was down when rebalance started, the nodeuuids
a3470f
would be saved as NULL and a set of files would not be migrated.
a3470f
a3470f
Now, if the nodeuuid is NULL, the first non-null entry in
a3470f
the set is the node responsible for migrating the file.
a3470f
a3470f
upstream master: https://review.gluster.org/#/c/19831/
a3470f
a3470f
> Change-Id: I72554c107792c7d534e0f25640654b6f8417d373
a3470f
> fixes: bz#1564198
a3470f
> Signed-off-by: N Balachandran <nbalacha@redhat.com>
a3470f
a3470f
Change-Id: Ia0e15339aefee2712e85d7e282c9b7934665376b
a3470f
BUG: 1553677
a3470f
Signed-off-by: N Balachandran <nbalacha@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/135515
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
---
a3470f
 xlators/cluster/dht/src/dht-rebalance.c | 56 ++++++++++++++++++++++++++++++---
a3470f
 1 file changed, 51 insertions(+), 5 deletions(-)
a3470f
a3470f
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
a3470f
index bba44b9..a4be348 100644
a3470f
--- a/xlators/cluster/dht/src/dht-rebalance.c
a3470f
+++ b/xlators/cluster/dht/src/dht-rebalance.c
a3470f
@@ -2469,6 +2469,27 @@ gf_defrag_ctx_subvols_init (dht_dfoffset_ctx_t *offset_var, xlator_t *this) {
a3470f
 }
a3470f
 
a3470f
 
a3470f
+static int
a3470f
+dht_get_first_non_null_index (subvol_nodeuuids_info_t *entry)
a3470f
+{
a3470f
+        int      i        = 0;
a3470f
+        int      index    = 0;
a3470f
+
a3470f
+        for (i = 0; i < entry->count; i++) {
a3470f
+                if (!gf_uuid_is_null (entry->elements[i].uuid)) {
a3470f
+                        index = i;
a3470f
+                        goto out;
a3470f
+                }
a3470f
+        }
a3470f
+
a3470f
+        if (i == entry->count) {
a3470f
+                index = -1;
a3470f
+        }
a3470f
+out:
a3470f
+        return index;
a3470f
+}
a3470f
+
a3470f
+
a3470f
 /* Return value
a3470f
  * 0 : this node does not migrate the file
a3470f
  * 1 : this node migrates the file
a3470f
@@ -2485,28 +2506,53 @@ gf_defrag_should_i_migrate (xlator_t *this, int local_subvol_index, uuid_t gfid)
a3470f
         int         i                 = local_subvol_index;
a3470f
         char       *str               = NULL;
a3470f
         uint32_t    hashval           = 0;
a3470f
-        int32_t     index        = 0;
a3470f
+        int32_t     index             = 0;
a3470f
         dht_conf_t *conf              = NULL;
a3470f
         char        buf[UUID_CANONICAL_FORM_LEN + 1] = {0, };
a3470f
+        subvol_nodeuuids_info_t *entry = NULL;
a3470f
+
a3470f
 
a3470f
         conf = this->private;
a3470f
 
a3470f
-        /* Pure distribute */
a3470f
+        /* Pure distribute. A subvol in this case
a3470f
+            will be handled by only one node */
a3470f
 
a3470f
-        if (conf->local_nodeuuids[i].count == 1) {
a3470f
+        entry = &(conf->local_nodeuuids[i]);
a3470f
+        if (entry->count == 1) {
a3470f
                 return 1;
a3470f
         }
a3470f
 
a3470f
         str = uuid_utoa_r (gfid, buf);
a3470f
         ret = dht_hash_compute (this, 0, str, &hashval);
a3470f
         if (ret == 0) {
a3470f
-                index = (hashval % conf->local_nodeuuids[i].count);
a3470f
-                if (conf->local_nodeuuids[i].elements[index].info
a3470f
+                index = (hashval % entry->count);
a3470f
+                if (entry->elements[index].info
a3470f
                                  == REBAL_NODEUUID_MINE) {
a3470f
                         /* Index matches this node's nodeuuid.*/
a3470f
                         ret = 1;
a3470f
+                        goto out;
a3470f
+                }
a3470f
+
a3470f
+                /* Brick down - some other node has to migrate these files*/
a3470f
+                if (gf_uuid_is_null (entry->elements[index].uuid)) {
a3470f
+                        /* Fall back to the first non-null index */
a3470f
+                        index = dht_get_first_non_null_index (entry);
a3470f
+
a3470f
+                        if (index == -1) {
a3470f
+                                /* None of the bricks in the subvol are up.
a3470f
+                                 * CHILD_DOWN will kill the process soon */
a3470f
+
a3470f
+                                return 0;
a3470f
+                        }
a3470f
+
a3470f
+                        if (entry->elements[index].info == REBAL_NODEUUID_MINE) {
a3470f
+                                /* Index matches this node's nodeuuid.*/
a3470f
+                                ret = 1;
a3470f
+                                goto out;
a3470f
+                        }
a3470f
                 }
a3470f
         }
a3470f
+out:
a3470f
         return ret;
a3470f
 }
a3470f
 
a3470f
-- 
a3470f
1.8.3.1
a3470f