diff options
author | Anuradha <atalur@redhat.com> | 2015-06-11 14:58:05 +0530 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2015-06-27 06:08:54 -0700 |
commit | b319d712e97e1074cc6030220d00970d1262458b (patch) | |
tree | d892218d723cf38ee3a8f55fe474c4842092a57e /xlators/cluster/afr | |
parent | 9ed31ab1a5718e01b22ea9e39c28759759bf023c (diff) |
cluster/afr : set pending xattrs for replaced brick
Backport of: http://review.gluster.org/10448/
& http://review.gluster.org/11416
This patch is part two change to prevent data loss
in a replicate volume on doing a replace-brick commit
force operation.
Problem: After doing replace-brick commit force, there is a
chance that self heal might happen from the replaced (sink) brick
rather than the source brick leading to data loss.
Solution: Mark pending changelogs on afr children for
the replaced afr-child so that heal is performed in the
correct direction.
Credits to Ravishankar N for patch 11416.
Change-Id: Icb9807e49b4c1c4f1dcab115318d9a58ccf95675
BUG: 1232173
Reviewed-on: http://review.gluster.org/10448
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>
Signed-off-by: Anuradha Talur <atalur@redhat.com>
Reviewed-on: http://review.gluster.org/11254
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'xlators/cluster/afr')
-rw-r--r-- | xlators/cluster/afr/src/afr-inode-write.c | 217 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-messages.h | 12 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-common.c | 16 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-entry.c | 7 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal.h | 8 |
5 files changed, 250 insertions, 10 deletions
diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c index e457a94501f..8800b81eb31 100644 --- a/xlators/cluster/afr/src/afr-inode-write.c +++ b/xlators/cluster/afr/src/afr-inode-write.c @@ -35,9 +35,10 @@ #include "compat-errno.h" #include "compat.h" #include "protocol-common.h" - +#include "byte-order.h" #include "afr-transaction.h" #include "afr-self-heal.h" +#include "afr-messages.h" static void __afr_inode_write_finalize (call_frame_t *frame, xlator_t *this) @@ -973,6 +974,179 @@ afr_setxattr_wind (call_frame_t *frame, xlator_t *this, int subvol) } int +afr_rb_set_pending_changelog_cbk (call_frame_t *frame, void *cookie, + xlator_t *this, int op_ret, int op_errno, + dict_t *xattr, dict_t *xdata) + +{ + afr_local_t *local = NULL; + afr_private_t *priv = NULL; + int i = 0; + + local = frame->local; + priv = this->private; + i = (long) cookie; + + local->replies[i].valid = 1; + local->replies[i].op_ret = op_ret; + local->replies[i].op_errno = op_errno; + gf_msg (this->name, op_ret ? GF_LOG_ERROR : GF_LOG_INFO, + op_ret ? op_errno : 0, + AFR_MSG_REPLACE_BRICK_STATUS, "Set of pending xattr %s on" + " %s.", op_ret ? "failed" : "succeeded", + priv->children[i]->name); + + syncbarrier_wake (&local->barrier); + return 0; +} + +int +afr_rb_set_pending_changelog (call_frame_t *frame, xlator_t *this, + unsigned char *locked_nodes) +{ + afr_local_t *local = NULL; + afr_private_t *priv = NULL; + int ret = 0, i = 0; + + local = frame->local; + priv = this->private; + + AFR_ONLIST (locked_nodes, frame, afr_rb_set_pending_changelog_cbk, + xattrop, &local->loc, GF_XATTROP_ADD_ARRAY, + local->xdata_req, NULL); + + /* It is sufficient if xattrop was successful on one child */ + for (i = 0; i < priv->child_count; i++) { + if (!local->replies[i].valid) + continue; + + if (local->replies[i].op_ret == 0) { + ret = 0; + goto out; + } else { + ret = afr_higher_errno (ret, + local->replies[i].op_errno); + } + } +out: + return -ret; +} + +int +_afr_handle_replace_brick_type (xlator_t *this, call_frame_t *frame, + loc_t *loc, int rb_index, + afr_transaction_type type) +{ + afr_local_t *local = NULL; + afr_private_t *priv = NULL; + unsigned char *locked_nodes = NULL; + int count = 0; + int ret = -ENOMEM; + int idx = -1; + + priv = this->private; + local = frame->local; + + locked_nodes = alloca0 (priv->child_count); + + idx = afr_index_for_transaction_type (type); + + local->pending = afr_matrix_create (priv->child_count, + AFR_NUM_CHANGE_LOGS); + if (!local->pending) + goto out; + + local->pending[rb_index][idx] = hton32 (1); + + local->xdata_req = dict_new (); + if (!local->xdata_req) + goto out; + + ret = afr_set_pending_dict (priv, local->xdata_req, local->pending); + if (ret < 0) + goto out; + + if (AFR_ENTRY_TRANSACTION == type) { + count = afr_selfheal_entrylk (frame, this, loc->inode, + this->name, NULL, locked_nodes); + } else { + count = afr_selfheal_inodelk (frame, this, loc->inode, + this->name, LLONG_MAX - 1, 0, + locked_nodes); + } + + if (!count) { + gf_log (this->name, GF_LOG_ERROR, "Couldn't acquire lock on" + " any child."); + ret = -EAGAIN; + goto unlock; + } + + ret = afr_rb_set_pending_changelog (frame, this, locked_nodes); + if (ret) + goto unlock; + ret = 0; +unlock: + if (AFR_ENTRY_TRANSACTION == type) { + afr_selfheal_unentrylk (frame, this, loc->inode, this->name, + NULL, locked_nodes); + } else { + afr_selfheal_uninodelk (frame, this, loc->inode, this->name, + LLONG_MAX - 1, 0, locked_nodes); + } +out: + return ret; +} + +int +_afr_handle_replace_brick (xlator_t *this, call_frame_t *frame, loc_t *loc, + int rb_index) +{ + + afr_local_t *local = NULL; + afr_private_t *priv = NULL; + int ret = -1; + int op_errno = ENOMEM; + + priv = this->private; + + local = AFR_FRAME_INIT (frame, op_errno); + if (!local) + goto out; + + loc_copy (&local->loc, loc); + + gf_log (this->name, GF_LOG_DEBUG, "Child being replaced is : %s", + priv->children[rb_index]->name); + + ret = _afr_handle_replace_brick_type (this, frame, loc, rb_index, + AFR_METADATA_TRANSACTION); + if (ret) { + op_errno = -ret; + ret = -1; + goto out; + } + + dict_unref (local->xdata_req); + afr_matrix_cleanup (local->pending, priv->child_count); + local->pending = NULL; + local->xdata_req = NULL; + + ret = _afr_handle_replace_brick_type (this, frame, loc, rb_index, + AFR_ENTRY_TRANSACTION); + if (ret) { + op_errno = -ret; + ret = -1; + goto out; + } + ret = 0; +out: + AFR_STACK_UNWIND (setxattr, frame, ret, op_errno, NULL); + return 0; +} + + +int afr_split_brain_resolve_do (call_frame_t *frame, xlator_t *this, loc_t *loc, char *data) { @@ -1170,6 +1344,43 @@ afr_handle_spb_choice_timeout (xlator_t *this, call_frame_t *frame, return ret; } +int +afr_handle_replace_brick (xlator_t *this, call_frame_t *frame, loc_t *loc, + dict_t *dict) +{ + int ret = -1; + int rb_index = -1; + char *replace_brick = NULL; + + ret = dict_get_str (dict, GF_AFR_REPLACE_BRICK, &replace_brick); + + if (!ret) { + if (frame->root->pid != GF_CLIENT_PID_AFR_SELF_HEALD) { + ret = 1; + goto out; + } + rb_index = afr_get_child_index_from_name (this, replace_brick); + + if (rb_index < 0) + /* Didn't belong to this replica pair + * Just do a no-op + */ + AFR_STACK_UNWIND (setxattr, frame, 0, 0, NULL); + else + _afr_handle_replace_brick (this, frame, loc, rb_index); + ret = 0; + } +out: + if (ret == 1) { + gf_log (this->name, GF_LOG_ERROR, "'%s' is an internal" + " extended attribute : %s.", + GF_AFR_REPLACE_BRICK, strerror (EPERM)); + AFR_STACK_UNWIND (setxattr, frame, -1, EPERM, NULL); + ret = 0; + } + return ret; +} + static int afr_handle_special_xattr (xlator_t *this, call_frame_t *frame, loc_t *loc, dict_t *dict) @@ -1181,6 +1392,10 @@ afr_handle_special_xattr (xlator_t *this, call_frame_t *frame, loc_t *loc, goto out; ret = afr_handle_spb_choice_timeout (this, frame, dict); + if (ret == 0) + goto out; + + ret = afr_handle_replace_brick (this, frame, loc, dict); out: return ret; } diff --git a/xlators/cluster/afr/src/afr-messages.h b/xlators/cluster/afr/src/afr-messages.h index 52bdead934b..66b8ed10c62 100644 --- a/xlators/cluster/afr/src/afr-messages.h +++ b/xlators/cluster/afr/src/afr-messages.h @@ -45,7 +45,7 @@ */ #define GLFS_COMP_BASE_AFR GLFS_MSGID_COMP_AFR -#define GLFS_NUM_MESSAGES 10 +#define GLFS_NUM_MESSAGES 11 #define GLFS_MSGID_END (GLFS_COMP_BASE_AFR + GLFS_NUM_MESSAGES + 1) #define glfs_msg_start_x GLFS_COMP_BASE_AFR, "Invalid: Start of messages" @@ -142,6 +142,16 @@ #define AFR_MSG_INODE_UNLOCK_FAIL (GLFS_COMP_BASE_AFR + 10) +/*! + * @messageid 108011 + * @diagnosis Setting of pending xattrs succeeded/failed during replace-brick + * operation. + * @recommendedaction In case of failure, error number in the log should give + * the reason why it failed. Also observe brick logs for more information. +*/ +#define AFR_MSG_REPLACE_BRICK_STATUS (GLFS_COMP_BASE_AFR + 11) + + #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" #endif /* !_AFR_MESSAGES_H_ */ diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c index 207e9b9e9ce..1e46226d943 100644 --- a/xlators/cluster/afr/src/afr-self-heal-common.c +++ b/xlators/cluster/afr/src/afr-self-heal-common.c @@ -807,8 +807,8 @@ afr_selfheal_lock_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int -afr_selfheal_locked_fill (call_frame_t *frame, xlator_t *this, - unsigned char *locked_on) +afr_locked_fill (call_frame_t *frame, xlator_t *this, + unsigned char *locked_on) { int i = 0; afr_private_t *priv = NULL; @@ -851,7 +851,7 @@ afr_selfheal_tryinodelk (call_frame_t *frame, xlator_t *this, inode_t *inode, loc_wipe (&loc); - return afr_selfheal_locked_fill (frame, this, locked_on); + return afr_locked_fill (frame, this, locked_on); } @@ -882,7 +882,7 @@ afr_selfheal_inodelk (call_frame_t *frame, xlator_t *this, inode_t *inode, for (i = 0; i < priv->child_count; i++) { if (local->replies[i].op_ret == -1 && local->replies[i].op_errno == EAGAIN) { - afr_selfheal_locked_fill (frame, this, locked_on); + afr_locked_fill (frame, this, locked_on); afr_selfheal_uninodelk (frame, this, inode, dom, off, size, locked_on); @@ -894,7 +894,7 @@ afr_selfheal_inodelk (call_frame_t *frame, xlator_t *this, inode_t *inode, loc_wipe (&loc); - return afr_selfheal_locked_fill (frame, this, locked_on); + return afr_locked_fill (frame, this, locked_on); } @@ -937,7 +937,7 @@ afr_selfheal_tryentrylk (call_frame_t *frame, xlator_t *this, inode_t *inode, loc_wipe (&loc); - return afr_selfheal_locked_fill (frame, this, locked_on); + return afr_locked_fill (frame, this, locked_on); } @@ -962,7 +962,7 @@ afr_selfheal_entrylk (call_frame_t *frame, xlator_t *this, inode_t *inode, for (i = 0; i < priv->child_count; i++) { if (local->replies[i].op_ret == -1 && local->replies[i].op_errno == EAGAIN) { - afr_selfheal_locked_fill (frame, this, locked_on); + afr_locked_fill (frame, this, locked_on); afr_selfheal_unentrylk (frame, this, inode, dom, name, locked_on); @@ -974,7 +974,7 @@ afr_selfheal_entrylk (call_frame_t *frame, xlator_t *this, inode_t *inode, loc_wipe (&loc); - return afr_selfheal_locked_fill (frame, this, locked_on); + return afr_locked_fill (frame, this, locked_on); } diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c index e64b6e45069..12da920f5f1 100644 --- a/xlators/cluster/afr/src/afr-self-heal-entry.c +++ b/xlators/cluster/afr/src/afr-self-heal-entry.c @@ -295,6 +295,13 @@ __afr_selfheal_merge_dirent (call_frame_t *frame, xlator_t *this, fd_t *fd, return 0; } + /* Set all the sources as 1, otheriwse newentry_mark won't be set */ + for (i = 0; i < priv->child_count; i++) { + if (replies[i].valid && replies[i].op_ret == 0) { + sources[i] = 1; + } + } + /* In case of a gfid or type mismatch on the entry, return -1.*/ ret = afr_selfheal_detect_gfid_and_type_mismatch (this, replies, fd->inode->gfid, diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h index 956f075e25b..a707e20e222 100644 --- a/xlators/cluster/afr/src/afr-self-heal.h +++ b/xlators/cluster/afr/src/afr-self-heal.h @@ -251,4 +251,12 @@ afr_selfheal_unlocked_inspect (call_frame_t *frame, xlator_t *this, int afr_selfheal_do (call_frame_t *frame, xlator_t *this, uuid_t gfid); + +int +afr_selfheal_lock_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *xdata); + +int +afr_locked_fill (call_frame_t *frame, xlator_t *this, + unsigned char *locked_on); #endif /* !_AFR_SELFHEAL_H */ |