From 8a4fa4e5c041f94e6dffa5524542e97b5c5f71fd Mon Sep 17 00:00:00 2001 From: Ned Bass Date: Thu, 13 Jun 2013 15:41:12 -0700 Subject: [PATCH] LU-3446 mdd: changelog index to survive MDT restart If all changelog records are cleared the current changelog index is initialized to zero when the MDT starts. This confuses applications that rely on the index to track their position in the changelog history. To avoid this, initialize the current index from the registered user with the highest end record index. Add a sanity.sh regression test. Update changelog test function test_160() and its helpers according to current style guidelines. Signed-off-by: Ned Bass Change-Id: I841bbf84c718bac560b6eea4b18de9918b889a90 Reviewed-on: http://review.whamcloud.com/6642 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/mdd/mdd_device.c | 2 + lustre/tests/sanity.sh | 204 +++++++++++++++++++++++++----------------------- 2 files changed, 108 insertions(+), 98 deletions(-) diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index c327c9b..6db4bb2 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -196,6 +196,8 @@ static int changelog_user_init_cb(const struct lu_env *env, spin_lock(&mdd->mdd_cl.mc_user_lock); mdd->mdd_cl.mc_lastuser = rec->cur_id; + if (rec->cur_endrec > mdd->mdd_cl.mc_index) + mdd->mdd_cl.mc_index = rec->cur_endrec; spin_unlock(&mdd->mdd_cl.mc_user_lock); return LLOG_PROC_BREAK; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 47c4f21..db05a37 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -9161,113 +9161,121 @@ run_test 156 "Verification of tunables ============================" #Changelogs err17935 () { - if [ $MDSCOUNT -gt 1 ]; then - error_ignore 17935 $* - else - error $* - fi + if [ $MDSCOUNT -gt 1 ]; then + error_ignore 17935 $* + else + error $* + fi } changelog_chmask() { - MASK=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_mask |\ - grep -c $1) + local CL_MASK_PARAM="mdd.$MDT0.changelog_mask" - if [ $MASK -eq 1 ]; then - do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="-$1" - else - do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_mask="+$1" - fi + MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1") + + if [ $MASK -eq 1 ]; then + do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1" + else + do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1" + fi } test_160() { [ $PARALLEL == "yes" ] && skip "skip parallel run" && return - remote_mds_nodsh && skip "remote MDS with nodsh" && return - [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] || - { skip "Need MDS version at least 2.2.0"; return; } - USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n) - echo "Registered as changelog user $USER" - do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \ - grep -q $USER || error "User $USER not found in changelog_users" - - # change something - test_mkdir -p $DIR/$tdir/pics/2008/zachy - touch $DIR/$tdir/pics/2008/zachy/timestamp - cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg - mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach - ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg - ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg - rm $DIR/$tdir/pics/desktop.jpg - - $LFS changelog $MDT0 | tail -5 - - echo "verifying changelog mask" - changelog_chmask "MKDIR" - changelog_chmask "CLOSE" - - test_mkdir -p $DIR/$tdir/pics/zach/sofia - echo "zzzzzz" > $DIR/$tdir/pics/zach/file - - changelog_chmask "MKDIR" - changelog_chmask "CLOSE" - - test_mkdir -p $DIR/$tdir/pics/2008/sofia - echo "zzzzzz" > $DIR/$tdir/pics/zach/file - - $LFS changelog $MDT0 - MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR") - CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE") - [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1" - [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1" - - # verify contents - echo "verifying target fid" - fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \ - tail -1 | awk '{print $6}') - fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp) - [ "$fidc" == "t=$fidf" ] || \ - err17935 "fid in changelog $fidc != file fid $fidf" - echo "verifying parent fid" - fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \ - tail -1 | awk '{print $7}') - fidf=$($LFS path2fid $DIR/$tdir/pics/zach) - [ "$fidc" == "p=$fidf" ] || \ - err17935 "pfid in changelog $fidc != dir fid $fidf" - - USER_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \ - mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}') - $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5)) - USER_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \ - mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}') - echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2" - [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \ - err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2" - - MIN_REC=$(do_facet $SINGLEMDS $LCTL get_param mdd.$MDT0.changelog_users | \ - awk 'min == "" || $2 < min {min = $2}; END {print min}') - FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}') - echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC" - [ $FIRST_REC == $(($MIN_REC + 1)) ] || \ - err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC" - - echo "verifying user deregister" - do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER - do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_users | \ - grep -q $USER && error "User $USER still found in changelog_users" - - USERS=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \ - mdd.$MDT0.changelog_users | wc -l) - 2 )) - if [ $USERS -eq 0 ]; then - LAST_REC1=$(do_facet $SINGLEMDS $LCTL get_param -n \ - mdd.$MDT0.changelog_users | head -1 | awk '{print $3}') - touch $DIR/$tdir/chloe - LAST_REC2=$(do_facet $SINGLEMDS $LCTL get_param -n \ - mdd.$MDT0.changelog_users | head -1 | awk '{print $3}') - echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2" - [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off" - else - echo "$USERS other changelog users; can't verify off" - fi + remote_mds_nodsh && skip "remote MDS with nodsh" && return + [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] || + { skip "Need MDS version at least 2.2.0"; return; } + + local CL_USERS="mdd.$MDT0.changelog_users" + local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS" + USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n) + echo "Registered as changelog user $USER" + $GET_CL_USERS | grep -q $USER || + error "User $USER not found in changelog_users" + + # change something + test_mkdir -p $DIR/$tdir/pics/2008/zachy + touch $DIR/$tdir/pics/2008/zachy/timestamp + cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg + mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach + ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg + ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg + rm $DIR/$tdir/pics/desktop.jpg + + $LFS changelog $MDT0 | tail -5 + + echo "verifying changelog mask" + changelog_chmask "MKDIR" + changelog_chmask "CLOSE" + + test_mkdir -p $DIR/$tdir/pics/zach/sofia + echo "zzzzzz" > $DIR/$tdir/pics/zach/file + + changelog_chmask "MKDIR" + changelog_chmask "CLOSE" + + test_mkdir -p $DIR/$tdir/pics/2008/sofia + echo "zzzzzz" > $DIR/$tdir/pics/zach/file + + $LFS changelog $MDT0 + MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR") + CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE") + [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1" + [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1" + + # verify contents + echo "verifying target fid" + fidc=$($LFS changelog $MDT0|awk '/CREAT.*timestamp$/{print $6}'|tail -1) + fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp) + [ "$fidc" == "t=$fidf" ] || + err17935 "fid in changelog $fidc != file fid $fidf" + echo "verifying parent fid" + fidc=$($LFS changelog $MDT0|awk '/CREAT.*timestamp$/{print $7}'|tail -1) + fidf=$($LFS path2fid $DIR/$tdir/pics/zach) + [ "$fidc" == "p=$fidf" ] || + err17935 "pfid in changelog $fidc != dir fid $fidf" + + USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}") + $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5)) + USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}") + echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2" + [ $USER_REC2 == $(($USER_REC1 + 5)) ] || + err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2" + + MIN_REC=$($GET_CL_USERS | + awk 'min == "" || $2 < min {min = $2}; END {print min}') + FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}') + echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC" + [ $FIRST_REC == $(($MIN_REC + 1)) ] || + err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC" + + # LU-3446 changelog index reset on MDT restart + local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/}) + CUR_REC1=$($GET_CL_USERS | head -1 | cut -f3 -d' ') + $LFS changelog_clear $MDT0 $USER 0 + stop $SINGLEMDS || error "Fail to stop MDT." + start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT." + CUR_REC2=$($GET_CL_USERS | head -1 | cut -f3 -d' ') + echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2" + [ $CUR_REC1 == $CUR_REC2 ] || + err17935 "current index should be $CUR_REC1 is $CUR_REC2" + + echo "verifying user deregister" + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER + $GET_CL_USERS | grep -q $USER && + error "User $USER still in changelog_users" + + USERS=$(( $($GET_CL_USERS | wc -l) - 2 )) + if [ $USERS -eq 0 ]; then + LAST_REC1=$($GET_CL_USERS | head -1 | cut -f3 -d' ') + touch $DIR/$tdir/chloe + LAST_REC2=$($GET_CL_USERS | head -1 | cut -f3 -d' ') + echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2" + [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off" + else + echo "$USERS other changelog users; can't verify off" + fi } run_test 160 "changelog sanity" -- 1.8.3.1