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