Return-Path: X-Original-To: apmail-curator-dev-archive@minotaur.apache.org Delivered-To: apmail-curator-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 942E8109AD for ; Tue, 10 Sep 2013 23:02:13 +0000 (UTC) Received: (qmail 32585 invoked by uid 500); 10 Sep 2013 23:02:13 -0000 Delivered-To: apmail-curator-dev-archive@curator.apache.org Received: (qmail 32552 invoked by uid 500); 10 Sep 2013 23:02:13 -0000 Mailing-List: contact dev-help@curator.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.incubator.apache.org Delivered-To: mailing list dev@curator.incubator.apache.org Received: (qmail 32544 invoked by uid 99); 10 Sep 2013 23:02:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Sep 2013 23:02:13 +0000 X-ASF-Spam-Status: No, hits=-2000.7 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 10 Sep 2013 23:02:12 +0000 Received: (qmail 31371 invoked by uid 99); 10 Sep 2013 23:01:52 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Sep 2013 23:01:52 +0000 Date: Tue, 10 Sep 2013 23:01:52 +0000 (UTC) From: "Jordan Zimmerman (JIRA)" To: dev@curator.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (CURATOR-54) No reliable way to cancel leadership in LeaderSelector when connection fails due to edge cases MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CURATOR-54?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jordan Zimmerman resolved CURATOR-54. ------------------------------------- Resolution: Fixed It was not possible to correctly handle connection state issues with the LeaderSelectorListener. There was an edge case where if the connection was lost before takeLeadership() was called, the thread would not be known and the existing sample code on how to handle stateChanged would not work. Introduced CancelLeadershipException to signal to the LeaderSelector instance that it should cancel the leadership. Also added a direct method of canceling leadership. > No reliable way to cancel leadership in LeaderSelector when connection fails due to edge cases > ---------------------------------------------------------------------------------------------- > > Key: CURATOR-54 > URL: https://issues.apache.org/jira/browse/CURATOR-54 > Project: Apache Curator > Issue Type: Bug > Components: Recipes > Affects Versions: 2.2.0-incubating > Reporter: Jordan Zimmerman > Assignee: Jordan Zimmerman > Fix For: 2.3.0-incubating > > > From a post to user@ > "Hi, > I'm fairly new with Zookeeper and Curator. I want to achieve a simple leader election process. > But, I ran into trouble implementing the interruption behavior. I could not find a reliable way to stop the leader (withdraw from leadership). > I think even the schoolbook example that Curator brings is flawed. > In leader.ExampleClient: > @Override > public void stateChanged(CuratorFramework client, ConnectionState newState) > { > // you MUST handle connection state changes. This WILL happen in production code. > if ( (newState == ConnectionState.LOST) || (newState == ConnectionState.SUSPENDED) ) > { > if ( ourThread != null ) > { > ourThread.interrupt(); > } > } > } > So in case of lost leadership, the ourThread thread is interrupted. However, ourThread is set in the 2nd line of the takeLeadership() method. Until then, it is null. > What happens if the connection is lost immediately after it is established, and ourThread stays null? Won't it be the case that the thread will go on, thinking that it is the leader, despite it being supposed to withdraw? > Thanks, > Arie" -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira