From d76e9b83454786e6845d0cad3c2c0695815fae1b Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Wed, 27 May 2015 16:27:25 +0530 Subject: featuress/changelog: On snapshot, notify irrespective of failures During snapshot, changelog barrier is enabled and a explicit rollover of changelog is initiated. During rollover of changelog, if any error or changelog is empty, the notification was not sent to reconfigure and hence snapshot was failing because of timeout. This patch addresses it by sending notification irrespective of failures and sends error if any back to barrier. Change-Id: I898af624b44555281a9e43c69066077e0e121c17 BUG: 1225542 Signed-off-by: Kotresh HR Reviewed-on: http://review.gluster.org/10951 Tested-by: NetBSD Build System Tested-by: Gluster Build System Reviewed-by: Aravinda VK Reviewed-by: Venky Shankar --- tests/bugs/changelog/bug-1225542.t | 30 +++++++++++++++ xlators/features/changelog/src/changelog-helpers.c | 43 ++++++++++++---------- xlators/features/changelog/src/changelog-helpers.h | 1 + xlators/features/changelog/src/changelog.c | 12 ++++-- 4 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 tests/bugs/changelog/bug-1225542.t diff --git a/tests/bugs/changelog/bug-1225542.t b/tests/bugs/changelog/bug-1225542.t new file mode 100644 index 00000000000..a646aa88014 --- /dev/null +++ b/tests/bugs/changelog/bug-1225542.t @@ -0,0 +1,30 @@ +#!/bin/bash + +#Testcase: +#On snapshot, notify changelog reconfigure upon explicit rollover +#irrespective of any failures and send error back to barrier if any. + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../snapshot.rc + +cleanup; +TEST verify_lvm_version +TEST glusterd; +TEST pidof glusterd; + +TEST setup_lvm 1 + +## Create a volume +TEST $CLI volume create $V0 $H0:$L1 + +## Start volume and verify +TEST $CLI volume start $V0 + +TEST $CLI volume set $V0 changelog.changelog on +##Wait for changelog init to complete. +sleep 1 + +## Take snapshot +TEST $CLI snapshot create snap1 $V0 + +cleanup; diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c index 11e60dcbf4a..a604891f0b3 100644 --- a/xlators/features/changelog/src/changelog-helpers.c +++ b/xlators/features/changelog/src/changelog-helpers.c @@ -493,30 +493,33 @@ changelog_rollover_changelog (xlator_t *this, ev.ev_type = CHANGELOG_OP_TYPE_JOURNAL; memcpy (ev.u.journal.path, nfile, strlen (nfile) + 1); changelog_dispatch_event (this, priv, &ev); + } + out: + /* If this is explicit rollover initiated by snapshot, + * wakeup reconfigure thread waiting for changelog to + * rollover. This should happen even in failure cases as + * well otherwise snapshot will timeout and fail. Hence + * moved under out. + */ + if (priv->explicit_rollover) { + priv->explicit_rollover = _gf_false; - /* If this is explicit rollover initiated by snapshot, - * wakeup reconfigure thread waiting for changelog to - * rollover - */ - if (priv->explicit_rollover) { - priv->explicit_rollover = _gf_false; - - ret = pthread_mutex_lock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - { - priv->bn.bnotify = _gf_false; - ret = pthread_cond_signal - (&priv->bn.bnotify_cond); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); - gf_log (this->name, GF_LOG_INFO, - "Changelog published: %s signalled" - " bnotify", nfile); + pthread_mutex_lock (&priv->bn.bnotify_mutex); + { + if (ret) { + priv->bn.bnotify_error = _gf_true; + gf_log (this->name, GF_LOG_ERROR, "Fail " + "snapshot because of previous errors"); + } else { + gf_log (this->name, GF_LOG_INFO, "Explicit " + "rollover changelog: %s signaling " + "bnotify", nfile); } - ret = pthread_mutex_unlock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out); + priv->bn.bnotify = _gf_false; + pthread_cond_signal (&priv->bn.bnotify_cond); } + pthread_mutex_unlock (&priv->bn.bnotify_mutex); } - out: return ret; } diff --git a/xlators/features/changelog/src/changelog-helpers.h b/xlators/features/changelog/src/changelog-helpers.h index ccfbf9113d8..4416b9cdfdb 100644 --- a/xlators/features/changelog/src/changelog-helpers.h +++ b/xlators/features/changelog/src/changelog-helpers.h @@ -152,6 +152,7 @@ typedef struct barrier_notify { pthread_mutex_t bnotify_mutex; pthread_cond_t bnotify_cond; gf_boolean_t bnotify; + gf_boolean_t bnotify_error; } barrier_notify_t; /* Two separate mutex and conditional variable set is used diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c index 91b0ae7a6e5..ed29bb83556 100644 --- a/xlators/features/changelog/src/changelog.c +++ b/xlators/features/changelog/src/changelog.c @@ -1958,6 +1958,7 @@ notify (xlator_t *this, int event, void *data, ...) int barrier = DICT_DEFAULT; gf_boolean_t bclean_req = _gf_false; int ret = 0; + int ret1 = 0; struct list_head queue = {0, }; INIT_LIST_HEAD (&queue); @@ -2108,13 +2109,17 @@ notify (xlator_t *this, int event, void *data, ...) out, bclean_req); } + if (priv->bn.bnotify_error == _gf_true) { + ret = -1; + priv->bn.bnotify_error = _gf_false; + } } - ret = pthread_mutex_unlock (&priv->bn.bnotify_mutex); - CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, out, bclean_req); + ret1 = pthread_mutex_unlock (&priv->bn.bnotify_mutex); + CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret1, out, + bclean_req); gf_log (this->name, GF_LOG_INFO, "Woke up: bnotify conditional wait"); - ret = 0; goto out; case DICT_DEFAULT: @@ -2632,6 +2637,7 @@ init (xlator_t *this) /* Mutex is not needed as threads are not spawned yet */ priv->bn.bnotify = _gf_false; + priv->bn.bnotify_error = _gf_false; ret = changelog_barrier_pthread_init (this, priv); if (ret) goto cleanup_options; -- cgit