17b94a
From aff18f761ef64d55635daa9a1d2140fe35632820 Mon Sep 17 00:00:00 2001
17b94a
From: Mohit Agrawal <moagrawal@redhat.com>
17b94a
Date: Fri, 29 Mar 2019 11:48:32 +0530
17b94a
Subject: [PATCH 109/124] glusterd: Optimize glusterd handshaking code path
17b94a
17b94a
Problem: At the time of handshaking glusterd populate volume
17b94a
         data in a dictionary.While no. of volumes are configured
17b94a
         more than 1500 glusterd takes more than 10 min to generated
17b94a
         the data.Due to taking more time rpc request times out and
17b94a
         rpc start bailing of call frames.
17b94a
17b94a
Solution: To optimize the code done below changes
17b94a
          1) Spawn multiple threads to populate volumes data in bulk
17b94a
             in separate dictionary and introduce an option
17b94a
             glusterd.brick-dict-thread-count to configure no. of threads
17b94a
             to populate volume data.
17b94a
          2) Populate tier data only while volume type is tier
17b94a
          3) Compare snap data only while snap_count is non zero
17b94a
17b94a
> Fixes: bz#1699339
17b94a
> Change-Id: I38dc71970c049217f9d1a06fc0aaf4c26eab18f5
17b94a
> Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
17b94a
> (Cherry picked from commit 26a19d9da3ab5604db02d4ca02ce868fb57193a4)
17b94a
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22556/)
17b94a
17b94a
Bug: 1652461
17b94a
Change-Id: Ia81671a7e1f173bcb32da9dc439be9e61c18bde1
17b94a
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/167981
17b94a
Tested-by: Mohit Agrawal <moagrawa@redhat.com>
17b94a
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
---
17b94a
 libglusterfs/src/glusterfs/globals.h               |   4 +-
17b94a
 tests/bugs/glusterd/bug-1699339.t                  |  69 ++++++
17b94a
 xlators/mgmt/glusterd/src/glusterd-op-sm.c         |   1 +
17b94a
 .../mgmt/glusterd/src/glusterd-snapshot-utils.c    |   3 +
17b94a
 xlators/mgmt/glusterd/src/glusterd-utils.c         | 269 +++++++++++++++++----
17b94a
 xlators/mgmt/glusterd/src/glusterd-volume-set.c    |  55 +++++
17b94a
 xlators/mgmt/glusterd/src/glusterd.h               |  10 +
17b94a
 7 files changed, 362 insertions(+), 49 deletions(-)
17b94a
 create mode 100644 tests/bugs/glusterd/bug-1699339.t
17b94a
17b94a
diff --git a/libglusterfs/src/glusterfs/globals.h b/libglusterfs/src/glusterfs/globals.h
17b94a
index 6642ba0..e45db14 100644
17b94a
--- a/libglusterfs/src/glusterfs/globals.h
17b94a
+++ b/libglusterfs/src/glusterfs/globals.h
17b94a
@@ -50,7 +50,7 @@
17b94a
     1 /* MIN is the fresh start op-version, mostly                             \
17b94a
          should not change */
17b94a
 #define GD_OP_VERSION_MAX                                                      \
17b94a
-    GD_OP_VERSION_6_0 /* MAX VERSION is the maximum                            \
17b94a
+    GD_OP_VERSION_7_0 /* MAX VERSION is the maximum                            \
17b94a
                          count in VME table, should                            \
17b94a
                          keep changing with                                    \
17b94a
                          introduction of newer                                 \
17b94a
@@ -134,6 +134,8 @@
17b94a
 
17b94a
 #define GD_OP_VERSION_6_0 60000 /* Op-version for GlusterFS 6.0 */
17b94a
 
17b94a
+#define GD_OP_VERSION_7_0 70000 /* Op-version for GlusterFS 7.0 */
17b94a
+
17b94a
 #include "glusterfs/xlator.h"
17b94a
 #include "glusterfs/options.h"
17b94a
 
17b94a
diff --git a/tests/bugs/glusterd/bug-1699339.t b/tests/bugs/glusterd/bug-1699339.t
17b94a
new file mode 100644
17b94a
index 0000000..3e950f4
17b94a
--- /dev/null
17b94a
+++ b/tests/bugs/glusterd/bug-1699339.t
17b94a
@@ -0,0 +1,69 @@
17b94a
+#!/bin/bash
17b94a
+
17b94a
+. $(dirname $0)/../../include.rc
17b94a
+. $(dirname $0)/../../volume.rc
17b94a
+. $(dirname $0)/../../cluster.rc
17b94a
+
17b94a
+cleanup;
17b94a
+
17b94a
+NUM_VOLS=15
17b94a
+
17b94a
+
17b94a
+get_brick_base () {
17b94a
+	printf "%s/vol%02d" $B0 $1
17b94a
+}
17b94a
+
17b94a
+function count_up_bricks {
17b94a
+        vol=$1;
17b94a
+        $CLI_1 --xml volume status $vol | grep '<status>1' | wc -l
17b94a
+}
17b94a
+
17b94a
+create_volume () {
17b94a
+
17b94a
+	local vol_name=$(printf "%s-vol%02d" $V0 $1)
17b94a
+
17b94a
+        TEST $CLI_1 volume create $vol_name replica 3 $H1:$B1/${vol_name} $H2:$B2/${vol_name} $H3:$B3/${vol_name}
17b94a
+	TEST $CLI_1 volume start $vol_name
17b94a
+}
17b94a
+
17b94a
+TEST launch_cluster 3
17b94a
+TEST $CLI_1 volume set all cluster.brick-multiplex on
17b94a
+
17b94a
+# The option accepts the value in the range from 5 to 200
17b94a
+TEST ! $CLI_1 volume set all glusterd.vol_count_per_thread 210
17b94a
+TEST ! $CLI_1 volume set all glusterd.vol_count_per_thread 4
17b94a
+
17b94a
+TEST $CLI_1 volume set all glusterd.vol_count_per_thread 5
17b94a
+
17b94a
+TEST $CLI_1 peer probe $H2;
17b94a
+EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count
17b94a
+
17b94a
+TEST $CLI_1 peer probe $H3;
17b94a
+EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count
17b94a
+
17b94a
+# Our infrastructure can't handle an arithmetic expression here.  The formula
17b94a
+# is (NUM_VOLS-1)*5 because it sees each TEST/EXPECT once but needs the other
17b94a
+# NUM_VOLS-1 and there are 5 such statements in each iteration.
17b94a
+TESTS_EXPECTED_IN_LOOP=28
17b94a
+for i in $(seq 1 $NUM_VOLS); do
17b94a
+        starttime="$(date +%s)";
17b94a
+	create_volume $i
17b94a
+done
17b94a
+
17b94a
+TEST kill_glusterd 1
17b94a
+
17b94a
+vol1=$(printf "%s-vol%02d" $V0 1)
17b94a
+TEST $CLI_2 volume set $vol1 performance.readdir-ahead on
17b94a
+vol2=$(printf "%s-vol%02d" $V0 2)
17b94a
+TEST $CLI_2 volume set $vol2 performance.readdir-ahead on
17b94a
+
17b94a
+# Bring back 1st glusterd
17b94a
+TEST $glusterd_1
17b94a
+EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count
17b94a
+
17b94a
+EXPECT_WITHIN $PROBE_TIMEOUT "on" volinfo_field_1 $vol1 performance.readdir-ahead
17b94a
+
17b94a
+vol_name=$(printf "%s-vol%02d" $V0 2)
17b94a
+EXPECT_WITHIN $PROBE_TIMEOUT "on" volinfo_field_1 $vol2 performance.readdir-ahead
17b94a
+
17b94a
+cleanup
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
17b94a
index 95f9707..94a5e1f 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
17b94a
@@ -87,6 +87,7 @@ glusterd_all_vol_opts valid_all_vol_opts[] = {
17b94a
      * TBD: Discuss the default value for this. Maybe this should be a
17b94a
      * dynamic value depending on the memory specifications per node */
17b94a
     {GLUSTERD_BRICKMUX_LIMIT_KEY, GLUSTERD_BRICKMUX_LIMIT_DFLT_VALUE},
17b94a
+    {GLUSTERD_VOL_CNT_PER_THRD, GLUSTERD_VOL_CNT_PER_THRD_DEFAULT_VALUE},
17b94a
     /*{GLUSTERD_LOCALTIME_LOGGING_KEY, "disable"},*/
17b94a
     {GLUSTERD_DAEMON_LOG_LEVEL_KEY, "INFO"},
17b94a
     {NULL},
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
17b94a
index b3c4158..d225854 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
17b94a
@@ -2099,6 +2099,9 @@ glusterd_compare_friend_snapshots(dict_t *peer_data, char *peername,
17b94a
         goto out;
17b94a
     }
17b94a
 
17b94a
+    if (!snap_count)
17b94a
+        goto out;
17b94a
+
17b94a
     for (i = 1; i <= snap_count; i++) {
17b94a
         /* Compare one snapshot from peer_data at a time */
17b94a
         ret = glusterd_compare_snap(peer_data, i, peername, peerid);
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
17b94a
index fdd7d91..ff6102b 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
17b94a
@@ -155,6 +155,47 @@ out:
17b94a
     return ret;
17b94a
 }
17b94a
 
17b94a
+int
17b94a
+get_gd_vol_thread_limit(int *thread_limit)
17b94a
+{
17b94a
+    char *value = NULL;
17b94a
+    int ret = -1;
17b94a
+    int vol_per_thread_limit = 0;
17b94a
+    xlator_t *this = NULL;
17b94a
+    glusterd_conf_t *priv = NULL;
17b94a
+
17b94a
+    this = THIS;
17b94a
+    GF_VALIDATE_OR_GOTO("glusterd", this, out);
17b94a
+
17b94a
+    priv = this->private;
17b94a
+    GF_VALIDATE_OR_GOTO(this->name, priv, out);
17b94a
+
17b94a
+    if (!is_brick_mx_enabled()) {
17b94a
+        vol_per_thread_limit = 1;
17b94a
+        ret = 0;
17b94a
+        goto out;
17b94a
+    }
17b94a
+
17b94a
+    ret = dict_get_strn(priv->opts, GLUSTERD_VOL_CNT_PER_THRD,
17b94a
+                        SLEN(GLUSTERD_VOL_CNT_PER_THRD), &value);
17b94a
+    if (ret) {
17b94a
+        value = GLUSTERD_VOL_CNT_PER_THRD_DEFAULT_VALUE;
17b94a
+    }
17b94a
+    ret = gf_string2int(value, &vol_per_thread_limit);
17b94a
+    if (ret)
17b94a
+        goto out;
17b94a
+
17b94a
+out:
17b94a
+    *thread_limit = vol_per_thread_limit;
17b94a
+
17b94a
+    gf_msg_debug("glusterd", 0,
17b94a
+                 "Per Thread volume limit set to %d glusterd to populate dict "
17b94a
+                 "data parallel",
17b94a
+                 *thread_limit);
17b94a
+
17b94a
+    return ret;
17b94a
+}
17b94a
+
17b94a
 extern struct volopt_map_entry glusterd_volopt_map[];
17b94a
 extern glusterd_all_vol_opts valid_all_vol_opts[];
17b94a
 
17b94a
@@ -3070,50 +3111,55 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict,
17b94a
 
17b94a
     /* tiering related variables */
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.cold_brick_count", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_brick_count);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+    if (volinfo->type == GF_CLUSTER_TYPE_TIER) {
17b94a
+        snprintf(key, sizeof(key), "%s%d.cold_brick_count", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_brick_count);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.cold_type", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_type);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.cold_type", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_type);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.cold_replica_count", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_replica_count);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.cold_replica_count", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_replica_count);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.cold_disperse_count", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_disperse_count);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.cold_disperse_count", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key,
17b94a
+                              volinfo->tier_info.cold_disperse_count);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.cold_redundancy_count", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_redundancy_count);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.cold_redundancy_count", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key,
17b94a
+                              volinfo->tier_info.cold_redundancy_count);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.cold_dist_count", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_dist_leaf_count);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.cold_dist_count", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key,
17b94a
+                              volinfo->tier_info.cold_dist_leaf_count);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.hot_brick_count", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_brick_count);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.hot_brick_count", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_brick_count);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.hot_type", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_type);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.hot_type", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_type);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
 
17b94a
-    snprintf(key, sizeof(key), "%s%d.hot_replica_count", prefix, count);
17b94a
-    ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_replica_count);
17b94a
-    if (ret)
17b94a
-        goto out;
17b94a
+        snprintf(key, sizeof(key), "%s%d.hot_replica_count", prefix, count);
17b94a
+        ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_replica_count);
17b94a
+        if (ret)
17b94a
+            goto out;
17b94a
+    }
17b94a
 
17b94a
     snprintf(key, sizeof(key), "%s%d", prefix, count);
17b94a
     ret = gd_add_vol_snap_details_to_dict(dict, key, volinfo);
17b94a
@@ -3363,33 +3409,40 @@ out:
17b94a
     return ret;
17b94a
 }
17b94a
 
17b94a
-int32_t
17b94a
-glusterd_add_volumes_to_export_dict(dict_t **peer_data)
17b94a
+void *
17b94a
+glusterd_add_bulk_volumes_create_thread(void *data)
17b94a
 {
17b94a
     int32_t ret = -1;
17b94a
-    dict_t *dict = NULL;
17b94a
     glusterd_conf_t *priv = NULL;
17b94a
     glusterd_volinfo_t *volinfo = NULL;
17b94a
     int32_t count = 0;
17b94a
-    glusterd_dict_ctx_t ctx = {0};
17b94a
     xlator_t *this = NULL;
17b94a
+    glusterd_add_dict_args_t *arg = NULL;
17b94a
+    dict_t *dict = NULL;
17b94a
+    int start = 0;
17b94a
+    int end = 0;
17b94a
 
17b94a
-    this = THIS;
17b94a
-    GF_ASSERT(this);
17b94a
+    GF_ASSERT(data);
17b94a
+
17b94a
+    arg = data;
17b94a
+    dict = arg->voldict;
17b94a
+    start = arg->start;
17b94a
+    end = arg->end;
17b94a
+    this = arg->this;
17b94a
+    THIS = arg->this;
17b94a
     priv = this->private;
17b94a
     GF_ASSERT(priv);
17b94a
 
17b94a
-    dict = dict_new();
17b94a
-    if (!dict)
17b94a
-        goto out;
17b94a
-
17b94a
     cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
17b94a
     {
17b94a
         count++;
17b94a
+        if ((count < start) || (count > end))
17b94a
+            continue;
17b94a
+
17b94a
         ret = glusterd_add_volume_to_dict(volinfo, dict, count, "volume");
17b94a
         if (ret)
17b94a
             goto out;
17b94a
-        if (!glusterd_is_volume_quota_enabled(volinfo))
17b94a
+        if (!dict_get_sizen(volinfo->dict, VKEY_FEATURES_QUOTA))
17b94a
             continue;
17b94a
         ret = glusterd_vol_add_quota_conf_to_dict(volinfo, dict, count,
17b94a
                                                   "volume");
17b94a
@@ -3397,7 +3450,122 @@ glusterd_add_volumes_to_export_dict(dict_t **peer_data)
17b94a
             goto out;
17b94a
     }
17b94a
 
17b94a
-    ret = dict_set_int32n(dict, "count", SLEN("count"), count);
17b94a
+out:
17b94a
+    GF_ATOMIC_DEC(priv->thread_count);
17b94a
+    free(arg);
17b94a
+    return NULL;
17b94a
+}
17b94a
+
17b94a
+int32_t
17b94a
+glusterd_add_volumes_to_export_dict(dict_t **peer_data)
17b94a
+{
17b94a
+    int32_t ret = -1;
17b94a
+    dict_t *dict = NULL;
17b94a
+    dict_t *dict_arr[128] = {
17b94a
+        0,
17b94a
+    };
17b94a
+    glusterd_conf_t *priv = NULL;
17b94a
+    glusterd_volinfo_t *volinfo = NULL;
17b94a
+    int32_t count = 0;
17b94a
+    glusterd_dict_ctx_t ctx = {0};
17b94a
+    xlator_t *this = NULL;
17b94a
+    int totthread = 0;
17b94a
+    int volcnt = 0;
17b94a
+    int start = 1;
17b94a
+    int endindex = 0;
17b94a
+    int vol_per_thread_limit = 0;
17b94a
+    glusterd_add_dict_args_t *arg = NULL;
17b94a
+    pthread_t th_id = {
17b94a
+        0,
17b94a
+    };
17b94a
+    int th_ret = 0;
17b94a
+    int i = 0;
17b94a
+
17b94a
+    this = THIS;
17b94a
+    GF_ASSERT(this);
17b94a
+    priv = this->private;
17b94a
+    GF_ASSERT(priv);
17b94a
+
17b94a
+    dict = dict_new();
17b94a
+    if (!dict)
17b94a
+        goto out;
17b94a
+
17b94a
+    /* Count the total number of volumes */
17b94a
+    cds_list_for_each_entry(volinfo, &priv->volumes, vol_list) volcnt++;
17b94a
+
17b94a
+    get_gd_vol_thread_limit(&vol_per_thread_limit);
17b94a
+
17b94a
+    if ((vol_per_thread_limit == 1) || (vol_per_thread_limit > 100)) {
17b94a
+        totthread = 0;
17b94a
+    } else {
17b94a
+        totthread = volcnt / vol_per_thread_limit;
17b94a
+        endindex = volcnt % vol_per_thread_limit;
17b94a
+        if (endindex)
17b94a
+            totthread++;
17b94a
+    }
17b94a
+
17b94a
+    if (totthread == 0) {
17b94a
+        cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
17b94a
+        {
17b94a
+            count++;
17b94a
+            ret = glusterd_add_volume_to_dict(volinfo, dict, count, "volume");
17b94a
+            if (ret)
17b94a
+                goto out;
17b94a
+
17b94a
+            if (!dict_get_sizen(volinfo->dict, VKEY_FEATURES_QUOTA))
17b94a
+                continue;
17b94a
+
17b94a
+            ret = glusterd_vol_add_quota_conf_to_dict(volinfo, dict, count,
17b94a
+                                                      "volume");
17b94a
+            if (ret)
17b94a
+                goto out;
17b94a
+        }
17b94a
+    } else {
17b94a
+        for (i = 0; i < totthread; i++) {
17b94a
+            arg = calloc(1, sizeof(*arg));
17b94a
+            dict_arr[i] = dict_new();
17b94a
+            arg->this = this;
17b94a
+            arg->voldict = dict_arr[i];
17b94a
+            arg->start = start;
17b94a
+            if (!endindex) {
17b94a
+                arg->end = ((i + 1) * vol_per_thread_limit);
17b94a
+            } else {
17b94a
+                arg->end = (start + endindex);
17b94a
+            }
17b94a
+            th_ret = gf_thread_create_detached(
17b94a
+                &th_id, glusterd_add_bulk_volumes_create_thread, arg,
17b94a
+                "bulkvoldict");
17b94a
+            if (th_ret) {
17b94a
+                gf_log(this->name, GF_LOG_ERROR,
17b94a
+                       "glusterd_add_bulk_volume %s"
17b94a
+                       " thread creation failed",
17b94a
+                       "bulkvoldict");
17b94a
+                free(arg);
17b94a
+                goto out;
17b94a
+            }
17b94a
+
17b94a
+            start = start + vol_per_thread_limit;
17b94a
+            GF_ATOMIC_INC(priv->thread_count);
17b94a
+            gf_log(this->name, GF_LOG_INFO,
17b94a
+                   "Create thread %d to populate dict data for volume"
17b94a
+                   " start index is %d end index is %d",
17b94a
+                   (i + 1), arg->start, arg->end);
17b94a
+        }
17b94a
+        while (GF_ATOMIC_GET(priv->thread_count)) {
17b94a
+            sleep(1);
17b94a
+        }
17b94a
+
17b94a
+        gf_log(this->name, GF_LOG_INFO,
17b94a
+               "Finished dictionary popluation in all threads");
17b94a
+        for (i = 0; i < totthread; i++) {
17b94a
+            dict_copy_with_ref(dict_arr[i], dict);
17b94a
+            dict_unref(dict_arr[i]);
17b94a
+        }
17b94a
+        gf_log(this->name, GF_LOG_INFO,
17b94a
+               "Finished merger of all dictionraies into single one");
17b94a
+    }
17b94a
+
17b94a
+    ret = dict_set_int32n(dict, "count", SLEN("count"), volcnt);
17b94a
     if (ret)
17b94a
         goto out;
17b94a
 
17b94a
@@ -3499,6 +3667,9 @@ glusterd_compare_friend_volume(dict_t *peer_data, int32_t count,
17b94a
         goto out;
17b94a
     }
17b94a
 
17b94a
+    if (!dict_get_sizen(volinfo->dict, VKEY_FEATURES_QUOTA))
17b94a
+        goto skip_quota;
17b94a
+
17b94a
     snprintf(key, sizeof(key), "volume%d.quota-version", count);
17b94a
     ret = dict_get_uint32(peer_data, key, &quota_version);
17b94a
     if (ret) {
17b94a
@@ -3550,6 +3721,8 @@ glusterd_compare_friend_volume(dict_t *peer_data, int32_t count,
17b94a
             goto out;
17b94a
         }
17b94a
     }
17b94a
+
17b94a
+skip_quota:
17b94a
     *status = GLUSTERD_VOL_COMP_SCS;
17b94a
 
17b94a
 out:
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
17b94a
index 42ca9bb..10aa2ae 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
17b94a
@@ -1058,6 +1058,51 @@ out:
17b94a
 }
17b94a
 
17b94a
 static int
17b94a
+validate_volume_per_thread_limit(glusterd_volinfo_t *volinfo, dict_t *dict,
17b94a
+                                 char *key, char *value, char **op_errstr)
17b94a
+{
17b94a
+    xlator_t *this = NULL;
17b94a
+    uint val = 0;
17b94a
+    int ret = -1;
17b94a
+
17b94a
+    this = THIS;
17b94a
+    GF_VALIDATE_OR_GOTO("glusterd", this, out);
17b94a
+
17b94a
+    if (!is_brick_mx_enabled()) {
17b94a
+        gf_asprintf(op_errstr,
17b94a
+                    "Brick-multiplexing is not enabled. "
17b94a
+                    "Please enable brick multiplexing before trying "
17b94a
+                    "to set this option.");
17b94a
+        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_WRONG_OPTS_SETTING, "%s",
17b94a
+               *op_errstr);
17b94a
+        goto out;
17b94a
+    }
17b94a
+
17b94a
+    ret = gf_string2uint(value, &val;;
17b94a
+    if (ret) {
17b94a
+        gf_asprintf(op_errstr,
17b94a
+                    "%s is not a valid count. "
17b94a
+                    "%s expects an unsigned integer.",
17b94a
+                    value, key);
17b94a
+        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_INVALID_ENTRY, "%s",
17b94a
+               *op_errstr);
17b94a
+    }
17b94a
+
17b94a
+    if ((val < 5) || (val > 200)) {
17b94a
+        gf_asprintf(
17b94a
+            op_errstr,
17b94a
+            "Please set this option to a greater than 5 or less than 200 "
17b94a
+            "to optimize dict generated while no. of volumes are more");
17b94a
+        ret = -1;
17b94a
+        goto out;
17b94a
+    }
17b94a
+out:
17b94a
+    gf_msg_debug("glusterd", 0, "Returning %d", ret);
17b94a
+
17b94a
+    return ret;
17b94a
+}
17b94a
+
17b94a
+static int
17b94a
 validate_boolean(glusterd_volinfo_t *volinfo, dict_t *dict, char *key,
17b94a
                  char *value, char **op_errstr)
17b94a
 {
17b94a
@@ -3520,6 +3565,16 @@ struct volopt_map_entry glusterd_volopt_map[] = {
17b94a
                     "brick multiplexing. Brick multiplexing ensures that "
17b94a
                     "compatible brick instances can share one single "
17b94a
                     "brick process."},
17b94a
+    {.key = GLUSTERD_VOL_CNT_PER_THRD,
17b94a
+     .voltype = "mgmt/glusterd",
17b94a
+     .value = GLUSTERD_VOL_CNT_PER_THRD_DEFAULT_VALUE,
17b94a
+     .op_version = GD_OP_VERSION_7_0,
17b94a
+     .validate_fn = validate_volume_per_thread_limit,
17b94a
+     .type = GLOBAL_NO_DOC,
17b94a
+     .description =
17b94a
+         "This option can be used to limit the number of volumes "
17b94a
+         "handled by per thread to populate peer data.The option accepts "
17b94a
+         " the value in the range of 5 to 200"},
17b94a
     {.key = GLUSTERD_BRICKMUX_LIMIT_KEY,
17b94a
      .voltype = "mgmt/glusterd",
17b94a
      .value = GLUSTERD_BRICKMUX_LIMIT_DFLT_VALUE,
17b94a
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
17b94a
index 0ac6e63..bd9f509 100644
17b94a
--- a/xlators/mgmt/glusterd/src/glusterd.h
17b94a
+++ b/xlators/mgmt/glusterd/src/glusterd.h
17b94a
@@ -57,8 +57,10 @@
17b94a
 #define GLUSTER_SHARED_STORAGE "gluster_shared_storage"
17b94a
 #define GLUSTERD_SHARED_STORAGE_KEY "cluster.enable-shared-storage"
17b94a
 #define GLUSTERD_BRICK_MULTIPLEX_KEY "cluster.brick-multiplex"
17b94a
+#define GLUSTERD_VOL_CNT_PER_THRD "glusterd.vol_count_per_thread"
17b94a
 #define GLUSTERD_BRICKMUX_LIMIT_KEY "cluster.max-bricks-per-process"
17b94a
 #define GLUSTERD_BRICKMUX_LIMIT_DFLT_VALUE "250"
17b94a
+#define GLUSTERD_VOL_CNT_PER_THRD_DEFAULT_VALUE "100"
17b94a
 #define GLUSTERD_LOCALTIME_LOGGING_KEY "cluster.localtime-logging"
17b94a
 #define GLUSTERD_DAEMON_LOG_LEVEL_KEY "cluster.daemon-log-level"
17b94a
 
17b94a
@@ -225,8 +227,16 @@ typedef struct {
17b94a
                                     which might lead the modification of volinfo
17b94a
                                     list.
17b94a
                                  */
17b94a
+    gf_atomic_t thread_count;
17b94a
 } glusterd_conf_t;
17b94a
 
17b94a
+typedef struct glusterd_add_dict_args {
17b94a
+    xlator_t *this;
17b94a
+    dict_t *voldict;
17b94a
+    int start;
17b94a
+    int end;
17b94a
+} glusterd_add_dict_args_t;
17b94a
+
17b94a
 typedef enum gf_brick_status {
17b94a
     GF_BRICK_STOPPED,
17b94a
     GF_BRICK_STARTED,
17b94a
-- 
17b94a
1.8.3.1
17b94a