Return-Path: X-Original-To: apmail-curator-user-archive@minotaur.apache.org Delivered-To: apmail-curator-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CA44E17C72 for ; Wed, 1 Oct 2014 14:53:52 +0000 (UTC) Received: (qmail 10542 invoked by uid 500); 1 Oct 2014 14:53:52 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 10503 invoked by uid 500); 1 Oct 2014 14:53:52 -0000 Mailing-List: contact user-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@curator.apache.org Delivered-To: mailing list user@curator.apache.org Received: (qmail 10493 invoked by uid 99); 1 Oct 2014 14:53:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Oct 2014 14:53:52 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.213.169] (HELO mail-ig0-f169.google.com) (209.85.213.169) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Oct 2014 14:53:48 +0000 Received: by mail-ig0-f169.google.com with SMTP id uq10so354185igb.4 for ; Wed, 01 Oct 2014 07:53:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to :references:subject:mime-version:content-type; bh=voeIvG+8/7Am/7tDJ9gL4ERz8ASH+mXT35DzQ+9Wn+Q=; b=QCEy3lgDX3I58LFIrWFM+M10IfqkfuCB0N4oxHEsiHqzGK3pl2ZIw59AqLGUdnr5E5 35eJon173T3l/61GhExxkAVB6/89dapECZKkKxYF0cSf2AV7tizH8f5D0/B9AJzV2N2G Qvxe7Pn4f5Xse58Z/1r4Gjbhmen9aN8uUyybX0o7p8xduGBOxnBRk8CirHPZZWzFaVEy Wx95gRWFi8tyvBG3xQb3Mm1oUq088yXPvvpdZmNJqdnL2D8TT6xmojbhFda//C76U/tL x3jr1+cuOU3TLIiBGmyvuBNk29gN1SbM97oibhAyt22bbuNpsASBwd7M5Em+w6Plbbk3 /lNQ== X-Gm-Message-State: ALoCoQl718pWG0EGGcbrUDFUjy6JRgZ9utU4L+jTWj1nDl8xhx5stO4y2O0Wz5OVJqdCc+q5xsU6 X-Received: by 10.42.120.72 with SMTP id e8mr65247493icr.64.1412175207389; Wed, 01 Oct 2014 07:53:27 -0700 (PDT) Received: from Jordans-MacBook-Pro.local ([190.141.38.38]) by mx.google.com with ESMTPSA id au4sm15826554igc.3.2014.10.01.07.53.26 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Wed, 01 Oct 2014 07:53:27 -0700 (PDT) Date: Wed, 1 Oct 2014 09:53:25 -0500 From: Jordan Zimmerman To: =?utf-8?Q?Singer=2C_Jill?= Cc: user Message-ID: In-Reply-To: References: Subject: Re: revocation not working X-Mailer: Airmail (247) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="542c1565_79e2a9e3_117" X-Virus-Checked: Checked by ClamAV on apache.org --542c1565_79e2a9e3_117 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline * Damn - looks like getLockPath() is protected. That should be corrected.= =46or now, create a subclass that has a new method that returns the lock= path. * the=C2=A0=C2=A0InterProcessSemaphoreMutex does not allow revoking; so h= ow will that help=3F Damn again. Instead, you=E2=80=99ll need to=C2=A0interrupt=C2=A0the threa= d that owns the lock. I apologize about the lack of features here. Apparently, this hasn=E2=80=99= t been used very much. A PR with improvements would be appreciated. -JZ On October 1, 2014 at 9:44:13 AM, Singer, Jill (jill.singer=40pearson.com= ) wrote: Jordan- =C2=A0 =C2=A0 thanks for the advice=21 Here are my follow-up questions: * I can't find the 'getLockPath()=22 =C2=A0method on the InterProcessMute= x or=C2=A0=C2=A0InterProcessSemaphoreMutex class (I looked here:=C2=A0https://curator.apache.org/apidocs/index.html and co= uldn't find a 'getLockPath()=22 method anywhere (the docs are version 2.5= .1-snapshot, btw) (I am using curator version=C2=A02.5.0) * the=C2=A0=C2=A0InterProcessSemaphoreMutex does not allow revoking; so h= ow will that help=3F On Tue, Sep 30, 2014 at 8:46 PM, Jordan Zimmerman wrote: There are a number of problems: * The docs are not clear on this, but=C2=A0makeRevocable() must be called= BE=46ORE the lock is acquired. Please submit a Jira/PR to fix the doc. * In your test,=C2=A0Revoker.attemptRevoke was using the incorrect path. = It must be the path of the lock, so: =22Revoker.attemptRevoke(client2, ip= Mutex.getLockPath());=E2=80=9D *=C2=A0InterProcessMutex keeps track of the thread that owns the lock. So= , the=C2=A0lock.release(); in your revoker won=E2=80=99t work. I suggest = using=C2=A0InterProcessSemaphoreMutex instead. -JZ On September 30, 2014 at 4:19:58 PM, Singer, Jill (jill.singer=40pearson.= com) wrote: short: =C2=A0I want to create a lock with one client and release it with = another; so I am trying to use revocation for that end.=C2=A0 It isn't wo= rking. =C2=A0more details (and my code) are below. any help is appreciated=21 long: =C2=A0have a system where one thread (with its own client) sets the= first lock (update), =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 then a second thread (with a cl= ient that may or may not be the same as the original client) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 will set a second lock; then do= some work, then release that lock, and then release the first lock =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this code simulates two threads= by having two different clients get locks. =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 the second client is unable to = revoke the lock from the first client, however. =C2=A0the 'revocation lis= tener' is never triggered. =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 I have scoured the web and not = found examples. =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this code assumes that you have= a zookeeper server running on your local host at port 2181 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ideally, I'd also like to look = up from somewhere else real quick to see if the lock is in place, but per= haps=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 an acquire with a very short ti= meout (5 milliseconds) would accomplish that. =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0also, is =C2=A0it a good idea to= reap away locks after releasing them=3F =C2=A0(to not clog up the system= =3F) thanks -Jill ps: =C2=A0also posted on stack overflow. I'll cross-post answers if I have them. >>>>>>>>>>>>> import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.curator.RetryPolicy; import org.apache.curator.framework.Curator=46ramework; import org.apache.curator.framework.Curator=46ramework=46actory; import org.apache.curator.framework.recipes.locks.InterProcessMutex; import org.apache.curator.framework.recipes.locks.RevocationListener; import org.apache.curator.framework.recipes.locks.Revoker; import org.apache.curator.retry.ExponentialBackoffRetry; public class MultipleClientExample =7B =C2=A0 =C2=A0 /*entry point =C2=A0 =C2=A0 =C2=A0*/ =C2=A0 =C2=A0 public static void main(String=5B=5D args)=7B =C2=A0 =C2=A0 =C2=A0 =C2=A0 RetryPolicy retryPolicy =3D new ExponentialBa= ckoffRetry(1000, 3); =C2=A0 =C2=A0 =C2=A0 =C2=A0 String zookeeperConnectionString =3D =22127.0= .0.1:2181=22; =C2=A0 =C2=A0 =C2=A0 =C2=A0 Curator=46ramework client =3D Curator=46ramew= ork=46actory.newClient(zookeeperConnectionString, retryPolicy); =C2=A0 =C2=A0 =C2=A0 =C2=A0 client.start(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 try =7B =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(=22testing l= ocks....=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 InterProcessMutex ipMutex =3D n= ew InterProcessMutex(client, =22/mpx-updates/guid123/update=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 boolean acquired =3D ipMutex.ac= quire(3, TimeUnit.SECONDS); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(=22got the l= ock(update)=3F=22 + acquired); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 RevocationListener rl =3D new MyRevocationListener(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ipMutex.makeRevocable(rl); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 InterProcessMutex ipMutex2 =3D = new InterProcessMutex(client, =22/mpx-updates/guid123/swap=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 boolean a2 =3D ipMutex2.acquire= (3, TimeUnit.SECONDS); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(=22got the l= ock(swap)=3F=22 + a2); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(=22got the f= irst lock in this process=3F =22 + ipMutex.isAcquiredInThisProcess()); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // make a new client; see if it= can get the lock=21 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Curator=46ramework client2 =3D = Curator=46ramework=46actory.newClient(zookeeperConnectionString, retryPol= icy); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 client2.start(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 InterProcessMutex ipMutex1Retry= =3D new InterProcessMutex(client2, =22/mpx-updates/guid123/update=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 boolean a3 =3D ipMutex1Retry.ac= quire(3, TimeUnit.SECONDS); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(=22got the l= ock(retry/update) =3F=22 + a3); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(=22got the f= irst lock in this process=3F =22 + ipMutex1Retry.isAcquiredInThisProcess(= )); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Revoker.attemptRevoke(client2, = =22/mpx-updates/guid123/update=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 a3 =3D ipMutex1Retry.acquire(3,= TimeUnit.SECONDS); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(=22AGAIN: go= t the lock(retry/update) =3F=22 + a3); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =7D catch (Exception e) =7B =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // TODO Auto-generated catch bl= ock =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 e.printStackTrace(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =7D =C2=A0 =C2=A0 =7D =C2=A0 =C2=A0 public class MyRevocationListener implements RevocationList= ener =7B =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* (non-Javadoc) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* =40see org.apache.curator.framework.r= ecipes.locks.RevocationListener=23revocationRequested(java.lang.Object) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =40Override =C2=A0 =C2=A0 =C2=A0 =C2=A0 public void revocationRequested(InterProcessM= utex lock) =7B =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 //this seems to never be called= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Collection participantN= odes =3D null; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 try =7B =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.printl= n(=22revocation was requested....=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.printl= n(=22ick ick revocation requested....=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 participantNodes = =3D lock.getParticipantNodes(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 lock.release(); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.printl= n(=22revoked lock at path: =22 + participantNodes); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =7D catch (Exception e) =7B =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.printl= n(=22problem revoking lock with path: =22 + participantNodes + =22; it wa= s not revoked=22); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =7D =C2=A0 =C2=A0 =C2=A0 =C2=A0 =7D =C2=A0 =C2=A0 =7D =7D --542c1565_79e2a9e3_117 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline