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