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 AF0DD10955 for ; Thu, 12 Sep 2013 07:09:58 +0000 (UTC) Received: (qmail 53905 invoked by uid 500); 12 Sep 2013 07:09:58 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 53313 invoked by uid 500); 12 Sep 2013 07:09:50 -0000 Mailing-List: contact user-help@curator.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@curator.incubator.apache.org Delivered-To: mailing list user@curator.incubator.apache.org Received: (qmail 53303 invoked by uid 99); 12 Sep 2013 07:09:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Sep 2013 07:09:49 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of azilberstein@salesforce.com designates 209.85.212.169 as permitted sender) Received: from [209.85.212.169] (HELO mail-wi0-f169.google.com) (209.85.212.169) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Sep 2013 07:09:43 +0000 Received: by mail-wi0-f169.google.com with SMTP id hj3so2950496wib.4 for ; Thu, 12 Sep 2013 00:09:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=3ofYyYA1AOApX5WWcfDOOw6GvgWd7EYbdK6xri5T7Hc=; b=eL0YZfPUOzsleFmdE9raB4b4xNCs3sdlAEownc8s5ZxSNz/mOhsyQIpxU77KNn2s9L pChL8ZXyOTQt3W8kJ4Gyej+gvSAWHPygCVRN/wWWb7vlxepRR+1qA8uOa+O0ZKWp691s dP5OKbiFIAguNacpQff/IwrO86uMQx9CtWmmVT2T/eVx3z/Us5LzHu6kFS+BzyMe6clq yPN+q+qgKY33d28ZF1nLixvP+7phvVBKMXwVwAbD8lZAZW12gPYRQSt8S9ag6I/PtVDp sUK3IzKPRW+d3HeIGERolkTDWpjxyyVuwWBGBRyxZFFN+9JYY0SAshGOh6YaZADDye4u f0xQ== X-Gm-Message-State: ALoCoQm3CkubQHMLGYlBO65/SIB1vB0vWW26UsDJDT98CT0uguHQfButk7+hL0w9eMKx5QVb8r/d MIME-Version: 1.0 X-Received: by 10.194.175.133 with SMTP id ca5mr4739191wjc.19.1378969762871; Thu, 12 Sep 2013 00:09:22 -0700 (PDT) Received: by 10.216.63.207 with HTTP; Thu, 12 Sep 2013 00:09:22 -0700 (PDT) In-Reply-To: References: Date: Thu, 12 Sep 2013 10:09:22 +0300 Message-ID: Subject: Re: Atomically setting a node's data while having leadership From: Arie Zilberstein To: user@curator.incubator.apache.org Content-Type: multipart/alternative; boundary=089e01493c5adf46c604e62a6ad1 X-Virus-Checked: Checked by ClamAV on apache.org --089e01493c5adf46c604e62a6ad1 Content-Type: text/plain; charset=ISO-8859-1 Yes, currently the path of the leader lock is pretty much inaccessible to the user of the LeaderSelector (It's "hidden" in LeaderSelector.mutex.threadData...). I think it would be a good addition to the library since some operations must be done while making sure leadership is held. For example if your leader just completed doing a bunch of work but lost leadership before updating the ZooKeeper-stored shared state variable, then it should not be allowed to update this variable (since another process may have acquired leadership and already started working on the same bunch). Thanks, Arie On Wed, Sep 11, 2013 at 7:09 PM, Jordan Zimmerman < jordan@jordanzimmerman.com> wrote: > I think it could be done with a transaction. i.e. > > client.inTransaction() > .check().forPath("/leader/path/...") > .and() > .setData().forPath("/some/other/path...", data) > .and() > .commit() > > So, we'd need to either expose the path/name of the leader's lock ZNode or > make this a method of LeaderSelector (and other lock-oriented recipes). > > -JZ > > On Sep 11, 2013, at 3:40 AM, Arie Zilberstein > wrote: > > > Hi, > > > > I wonder if it is possible to achieve the following behavior: Assume a > leader election scenario where a certain process has been elected as leader > and its takeLeadership() method was called. Inside that method the process > wishes to perform a Zookeeper operation, e.g., to set data in a node. But, > the leader may receive a message saying to relinquish leadership > immediately at any point in time. So the question is, is it possible to set > this data while making sure that we're still the leader? > > Can Curator support this sort of an atomic "test-and-set" operation? > > > > Thanks, > > Arie > > --089e01493c5adf46c604e62a6ad1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Yes, currently the path of the leader lock is pretty much = inaccessible to the user of the LeaderSelector (It's "hidden"= in LeaderSelector.mutex.threadData...).

I think it woul= d be a good addition to the library since some operations must be done whil= e making sure leadership is held. For example if your leader just completed= doing a bunch of work but lost leadership before updating the ZooKeeper-st= ored shared state variable, then it should not be allowed to update this va= riable (since another process may have acquired leadership and already star= ted working on the same bunch).

Thanks,
Arie


On Wed, Sep 11, 2013 at 7:09 PM, J= ordan Zimmerman <jordan@jordanzimmerman.com> wrote:=
I think it could be done with a transaction.= i.e.

=A0 =A0 =A0 =A0 =A0 =A0 client.inTransaction()
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .check().forPath("/leader/path/...&quo= t;)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .and()
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .setData().forPath("/some/other/path..= .", data)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .and()
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .commit()

So, we'd need to either expose the path/name of the leader's lock Z= Node or make this a method of LeaderSelector (and other lock-oriented recip= es).

-JZ

On Sep 11, 2013, at 3:40 AM, Ar= ie Zilberstein <azilberst= ein@salesforce.com> wrote:

> Hi,
>
> I wonder if it is possible to achieve the following behavior: Assume a= leader election scenario where a certain process has been elected as leade= r and its takeLeadership() method was called. Inside that method the proces= s wishes to perform a Zookeeper operation, e.g., to set data in a node. But= , the leader may receive a message saying to relinquish leadership immediat= ely at any point in time. So the question is, is it possible to set this da= ta while making sure that we're still the leader?
> Can Curator support this sort of an atomic "test-and-set" op= eration?
>
> Thanks,
> Arie


--089e01493c5adf46c604e62a6ad1--