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