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