Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8060F10974 for ; Mon, 15 Jul 2013 23:08:09 +0000 (UTC) Received: (qmail 76672 invoked by uid 500); 15 Jul 2013 23:08:09 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 76647 invoked by uid 500); 15 Jul 2013 23:08:09 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 76579 invoked by uid 99); 15 Jul 2013 23:08:09 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jul 2013 23:08:09 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 09F0A8A862C; Mon, 15 Jul 2013 23:08:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yasker@apache.org To: commits@cloudstack.apache.org Date: Mon, 15 Jul 2013 23:08:09 -0000 Message-Id: <3a4c6a8e3abe42308843fe6575831a3b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: updated refs/heads/4.2 to 9c1e02a Updated Branches: refs/heads/4.2 c1b0228f1 -> 9c1e02ae5 CLOUDSTACK-3434: Improve the atomic of file lock used in VR Now we would retry if "ls" failed, since the list of files changed. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fd06009d Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fd06009d Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fd06009d Branch: refs/heads/4.2 Commit: fd06009d509db01774d7da0a424592548661d007 Parents: c1b0228 Author: Sheng Yang Authored: Fri Jul 12 17:34:47 2013 -0700 Committer: Sheng Yang Committed: Mon Jul 15 16:07:36 2013 -0700 ---------------------------------------------------------------------- patches/systemvm/debian/config/root/func.sh | 41 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd06009d/patches/systemvm/debian/config/root/func.sh ---------------------------------------------------------------------- diff --git a/patches/systemvm/debian/config/root/func.sh b/patches/systemvm/debian/config/root/func.sh index 9c7c494..1796345 100644 --- a/patches/systemvm/debian/config/root/func.sh +++ b/patches/systemvm/debian/config/root/func.sh @@ -21,10 +21,26 @@ # getLockFile() parameters # $1 lock filename # $2 timeout seconds + +#set -x + +getCurrLock() { + result=`ls $__LOCKDIR/*-$1.lock 2>/dev/null | head -n1` + while [ $? -ne 0 ] + do + result=`ls $__LOCKDIR/*-$1.lock 2>/dev/null| head -n1` + done + echo $result +} + getLockFile() { + lock=$1 + __locked=0 __TS=`date +%s%N` - __LOCKFILE="/tmp/$__TS-$$-$1.lock" + __LOCKDIR="/tmp" + __LOCKFILE="$__LOCKDIR/$__TS-$$-$lock.lock" + if [ $2 ] then __TIMEOUT=$2 @@ -34,7 +50,7 @@ getLockFile() { if [ -e $__LOCKFILE ] then - logger -t cloud "Process $0 pid $$ want to get ECLUSIVE LOCK $1 RECURSIVELY!" + logger -t cloud "Process $0 pid $$ want to get ECLUSIVE LOCK $lock RECURSIVELY!" psline=`ps u $$` logger -t cloud "Failed job detail: $psline" echo 0 @@ -47,26 +63,32 @@ getLockFile() { then return fi - + for i in `seq 1 $(($__TIMEOUT * 10))` do - currlock=`ls /tmp/*-$1.lock | head -n1` + currlock=$(getCurrLock $lock) if [ $currlock -ef $__LOCKFILE ] then __locked=1 break fi + sleep 0.1 if [ $((i % 10)) -eq 0 ] then - logger -t cloud "Process $0 pid $$ waiting for the lock $1 for another 1 second" + logger -t cloud "Process $0 pid $$ waiting for the lock $lock for another 1 second" fi done if [ $__locked -ne 1 ] then - logger -t cloud "fail to acquire the lock $1 for process $0 pid $$ after $__TIMEOUT seconds time out!" - cmd=`cat $currlock` - logger -t cloud "waiting for command: $cmd" + logger -t cloud "fail to acquire the lock $lock for process $0 pid $$ after $__TIMEOUT seconds time out!" + cmd=`cat $currlock 2>/dev/null` + if [ $? -eq 0 ] + then + logger -t cloud "waiting for process: $cmd" + else + logger -t cloud "didn't get info about process who we're waiting for" + fi psline=`ps u $$` logger -t cloud "Failed job detail: $psline" rm $__LOCKFILE @@ -78,7 +100,8 @@ getLockFile() { # $1 lock filename # $2 locked(1) or not(0) releaseLockFile() { - __LOCKFILE="/tmp/*-$$-$1.lock" + __LOCKDIR="/tmp" + __LOCKFILE="$__LOCKDIR/*-$$-$1.lock" __locked=$2 if [ "$__locked" == "1" ] then