a3470f
From 76b5366d4f346d5010bd153d20668f8860262c4e Mon Sep 17 00:00:00 2001
a3470f
From: Xavier Hernandez <jahernan@redhat.com>
a3470f
Date: Mon, 16 Oct 2017 13:57:59 +0200
a3470f
Subject: [PATCH 158/180] cluster/ec: create eager-lock option for non-regular
a3470f
 files
a3470f
a3470f
A new option is added to allow independent configuration of eager
a3470f
locking for regular files and non-regular files.
a3470f
a3470f
> Upstream patch: https://review.gluster.org/18530
a3470f
a3470f
Change-Id: I8f80e46d36d8551011132b15c0fac549b7fb1c60
a3470f
BUG: 1530519
a3470f
Signed-off-by: Xavier Hernandez <jahernan@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/130432
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 libglusterfs/src/globals.h                      |  2 ++
a3470f
 tests/basic/ec/ec-background-heals.t            |  1 +
a3470f
 tests/basic/ec/ec-optimistic-changelog.t        |  1 +
a3470f
 tests/bugs/cli/bug-1320388.t                    |  1 +
a3470f
 xlators/cluster/ec/src/ec-common.c              | 22 +++++++++++++++-
a3470f
 xlators/cluster/ec/src/ec-types.h               |  1 +
a3470f
 xlators/cluster/ec/src/ec.c                     | 34 ++++++++++++++++---------
a3470f
 xlators/mgmt/glusterd/src/glusterd-volume-set.c |  5 ++++
a3470f
 8 files changed, 54 insertions(+), 13 deletions(-)
a3470f
a3470f
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
a3470f
index 692d49d..6bbe3e6 100644
a3470f
--- a/libglusterfs/src/globals.h
a3470f
+++ b/libglusterfs/src/globals.h
a3470f
@@ -101,6 +101,8 @@
a3470f
 
a3470f
 #define GD_OP_VERSION_3_12_2   31202 /* Op-version for GlusterFS 3.12.2 */
a3470f
 
a3470f
+#define GD_OP_VERSION_3_12_3   31203 /* Op-version for GlusterFS 3.12.3 */
a3470f
+
a3470f
 #define GD_OP_VERSION_3_13_0   31300 /* Op-version for GlusterFS 3.13.0 */
a3470f
 
a3470f
 #define GD_OP_VERSION_3_13_1   31301 /* Op-version for GlusterFS 3.13.1 */
a3470f
diff --git a/tests/basic/ec/ec-background-heals.t b/tests/basic/ec/ec-background-heals.t
a3470f
index b9291bc..29778a4 100644
a3470f
--- a/tests/basic/ec/ec-background-heals.t
a3470f
+++ b/tests/basic/ec/ec-background-heals.t
a3470f
@@ -17,6 +17,7 @@ TEST $CLI volume set $V0 performance.read-ahead off
a3470f
 TEST $CLI volume set $V0 performance.io-cache off
a3470f
 TEST $CLI volume set $V0 disperse.background-heals 0
a3470f
 TEST $CLI volume set $V0 disperse.eager-lock off
a3470f
+TEST $CLI volume set $V0 disperse.other-eager-lock off
a3470f
 TEST $CLI volume start $V0
a3470f
 
a3470f
 TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
a3470f
diff --git a/tests/basic/ec/ec-optimistic-changelog.t b/tests/basic/ec/ec-optimistic-changelog.t
a3470f
index 1277da6..a372cd3 100644
a3470f
--- a/tests/basic/ec/ec-optimistic-changelog.t
a3470f
+++ b/tests/basic/ec/ec-optimistic-changelog.t
a3470f
@@ -19,6 +19,7 @@ TEST $CLI volume set $V0 performance.io-cache off
a3470f
 TEST $CLI volume set $V0 disperse.background-heals 0
a3470f
 TEST $CLI volume set $V0 disperse.optimistic-change-log off
a3470f
 TEST $CLI volume set $V0 disperse.eager-lock off
a3470f
+TEST $CLI volume set $V0 disperse.other-eager-lock off
a3470f
 TEST $CLI volume start $V0
a3470f
 
a3470f
 TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
a3470f
diff --git a/tests/bugs/cli/bug-1320388.t b/tests/bugs/cli/bug-1320388.t
a3470f
index ca23ab8..bed1392 100755
a3470f
--- a/tests/bugs/cli/bug-1320388.t
a3470f
+++ b/tests/bugs/cli/bug-1320388.t
a3470f
@@ -29,6 +29,7 @@ TEST glusterd
a3470f
 TEST pidof glusterd
a3470f
 TEST $CLI volume create $V0 disperse 6 redundancy 2 $H0:$B0/${V0}{0..5}
a3470f
 TEST $CLI volume set $V0 disperse.eager-lock off
a3470f
+TEST $CLI volume set $V0 disperse.other-eager-lock off
a3470f
 TEST $CLI volume start $V0
a3470f
 TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0
a3470f
 EXPECT_WITHIN $CHILD_UP_TIMEOUT "^6$" ec_child_up_count $V0 0
a3470f
diff --git a/xlators/cluster/ec/src/ec-common.c b/xlators/cluster/ec/src/ec-common.c
a3470f
index 18ed274..051fff6 100644
a3470f
--- a/xlators/cluster/ec/src/ec-common.c
a3470f
+++ b/xlators/cluster/ec/src/ec-common.c
a3470f
@@ -2553,6 +2553,26 @@ void ec_flush_size_version(ec_fop_data_t * fop)
a3470f
     ec_update_info(&fop->locks[0]);
a3470f
 }
a3470f
 
a3470f
+static gf_boolean_t
a3470f
+ec_use_eager_lock(ec_t *ec, ec_fop_data_t *fop)
a3470f
+{
a3470f
+        /* Fops with no locks at this point mean that they are sent as sub-fops
a3470f
+         * of other higher level fops. In this case we simply assume that the
a3470f
+         * parent fop will take correct care of the eager lock. */
a3470f
+        if (fop->lock_count == 0) {
a3470f
+                return _gf_true;
a3470f
+        }
a3470f
+
a3470f
+        /* We may have more than one lock, but this only happens in the rename
a3470f
+         * fop, and both locks will reference an inode of the same type (a
a3470f
+         * directory in this case), so we only need to check the first lock. */
a3470f
+        if (fop->locks[0].lock->loc.inode->ia_type == IA_IFREG) {
a3470f
+                return ec->eager_lock;
a3470f
+        }
a3470f
+
a3470f
+        return ec->other_eager_lock;
a3470f
+}
a3470f
+
a3470f
 void ec_lock_reuse(ec_fop_data_t *fop)
a3470f
 {
a3470f
     ec_cbk_data_t *cbk;
a3470f
@@ -2562,7 +2582,7 @@ void ec_lock_reuse(ec_fop_data_t *fop)
a3470f
     ec = fop->xl->private;
a3470f
     cbk = fop->answer;
a3470f
 
a3470f
-    if (ec->eager_lock && cbk != NULL) {
a3470f
+    if (ec_use_eager_lock(ec, fop) && cbk != NULL) {
a3470f
         if (cbk->xdata != NULL) {
a3470f
             if ((dict_get_int32(cbk->xdata, GLUSTERFS_INODELK_COUNT,
a3470f
                                 &count) == 0) && (count > 1)) {
a3470f
diff --git a/xlators/cluster/ec/src/ec-types.h b/xlators/cluster/ec/src/ec-types.h
a3470f
index 3129586..f6e2cd9 100644
a3470f
--- a/xlators/cluster/ec/src/ec-types.h
a3470f
+++ b/xlators/cluster/ec/src/ec-types.h
a3470f
@@ -594,6 +594,7 @@ struct _ec {
a3470f
     gf_timer_t        *timer;
a3470f
     gf_boolean_t       shutdown;
a3470f
     gf_boolean_t       eager_lock;
a3470f
+    gf_boolean_t       other_eager_lock;
a3470f
     gf_boolean_t       optimistic_changelog;
a3470f
     gf_boolean_t       parallel_writes;
a3470f
     uint32_t           background_heals;
a3470f
diff --git a/xlators/cluster/ec/src/ec.c b/xlators/cluster/ec/src/ec.c
a3470f
index 09c5fa8..13ce7fb 100644
a3470f
--- a/xlators/cluster/ec/src/ec.c
a3470f
+++ b/xlators/cluster/ec/src/ec.c
a3470f
@@ -276,6 +276,8 @@ reconfigure (xlator_t *this, dict_t *options)
a3470f
                           bool, failed);
a3470f
         GF_OPTION_RECONF ("eager-lock", ec->eager_lock, options,
a3470f
                           bool, failed);
a3470f
+        GF_OPTION_RECONF ("other-eager-lock", ec->other_eager_lock, options,
a3470f
+                          bool, failed);
a3470f
         GF_OPTION_RECONF ("background-heals", background_heals, options,
a3470f
                           uint32, failed);
a3470f
         GF_OPTION_RECONF ("heal-wait-qlength", heal_wait_qlen, options,
a3470f
@@ -654,6 +656,7 @@ init (xlator_t *this)
a3470f
     GF_OPTION_INIT ("self-heal-daemon", ec->shd.enabled, bool, failed);
a3470f
     GF_OPTION_INIT ("iam-self-heal-daemon", ec->shd.iamshd, bool, failed);
a3470f
     GF_OPTION_INIT ("eager-lock", ec->eager_lock, bool, failed);
a3470f
+    GF_OPTION_INIT ("other-eager-lock", ec->other_eager_lock, bool, failed);
a3470f
     GF_OPTION_INIT ("background-heals", ec->background_heals, uint32, failed);
a3470f
     GF_OPTION_INIT ("heal-wait-qlength", ec->heal_wait_qlen, uint32, failed);
a3470f
     GF_OPTION_INIT ("self-heal-window-size", ec->self_heal_window_size, uint32,
a3470f
@@ -1397,18 +1400,25 @@ struct volume_options options[] =
a3470f
     { .key = {"eager-lock"},
a3470f
       .type = GF_OPTION_TYPE_BOOL,
a3470f
       .default_value = "on",
a3470f
-      .description = "Enable/Disable eager lock for disperse volume. "
a3470f
-                     "If a fop takes a lock and completes its operation, "
a3470f
-                     "it waits for next 1 second before releasing the lock, "
a3470f
-                     "to see if the lock can be reused for next fop from "
a3470f
-                     "the same client. If ec finds any lock contention within "
a3470f
-                     "1 second it releases the lock immediately before time "
a3470f
-                     "expires. This improves the performance of file operations."
a3470f
-                     "However, as it takes lock on first brick, for few operations "
a3470f
-                     "like read, discovery of lock contention might take long time "
a3470f
-                     "and can actually degrade the performance. "
a3470f
-                     "If eager lock is disabled, lock will be released as soon as fop "
a3470f
-                     "completes. "
a3470f
+      .description = "Enable/Disable eager lock for regular files on a "
a3470f
+                     "disperse volume. If a fop takes a lock and completes "
a3470f
+                     "its operation, it waits for next 1 second before "
a3470f
+                     "releasing the lock, to see if the lock can be reused "
a3470f
+                     "for next fop from the same client. If ec finds any lock "
a3470f
+                     "contention within 1 second it releases the lock "
a3470f
+                     "immediately before time expires. This improves the "
a3470f
+                     "performance of file operations. However, as it takes "
a3470f
+                     "lock on first brick, for few operations like read, "
a3470f
+                     "discovery of lock contention might take long time and "
a3470f
+                     "can actually degrade the performance. If eager lock is "
a3470f
+                     "disabled, lock will be released as soon as fop "
a3470f
+                     "completes."
a3470f
+    },
a3470f
+    { .key = {"other-eager-lock"},
a3470f
+      .type = GF_OPTION_TYPE_BOOL,
a3470f
+      .default_value = "on",
a3470f
+      .description = "It's equivalent to the eager-lock option but for non "
a3470f
+                     "regular files."
a3470f
     },
a3470f
     { .key = {"background-heals"},
a3470f
       .type = GF_OPTION_TYPE_INT,
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
a3470f
index 693c917..af0a982 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
a3470f
@@ -1445,6 +1445,11 @@ struct volopt_map_entry glusterd_volopt_map[] = {
a3470f
           .op_version = GD_OP_VERSION_3_7_10,
a3470f
           .flags      = OPT_FLAG_CLIENT_OPT
a3470f
         },
a3470f
+        { .key        = "disperse.other-eager-lock",
a3470f
+          .voltype    = "cluster/disperse",
a3470f
+          .op_version = GD_OP_VERSION_3_12_2,
a3470f
+          .flags      = OPT_FLAG_CLIENT_OPT
a3470f
+        },
a3470f
         { .key        = "cluster.quorum-type",
a3470f
           .voltype    = "cluster/replicate",
a3470f
           .option     = "quorum-type",
a3470f
-- 
a3470f
1.8.3.1
a3470f