Return-Path: X-Original-To: apmail-cloudstack-dev-archive@www.apache.org Delivered-To: apmail-cloudstack-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1AEED17EB6 for ; Thu, 29 Jan 2015 14:29:19 +0000 (UTC) Received: (qmail 3093 invoked by uid 500); 29 Jan 2015 14:29:19 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 3051 invoked by uid 500); 29 Jan 2015 14:29:19 -0000 Mailing-List: contact dev-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 dev@cloudstack.apache.org Received: (qmail 3040 invoked by uid 99); 29 Jan 2015 14:29:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jan 2015 14:29:18 +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 (athena.apache.org: domain of mike.tutkowski@solidfire.com designates 209.85.218.44 as permitted sender) Received: from [209.85.218.44] (HELO mail-oi0-f44.google.com) (209.85.218.44) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jan 2015 14:29:14 +0000 Received: by mail-oi0-f44.google.com with SMTP id a3so27000097oib.3 for ; Thu, 29 Jan 2015 06:27:23 -0800 (PST) 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=H5z0oKOd85Sn/9ezbLYTlR4rOK6Tjyg8towMhMEucCI=; b=OQQSmNHdtIvNgo3BjRy82a4ejhuNJfdR/asJ/YQRhr5lsjCSbjnFDSpBemXpJ+6b8D 3mse2On9z1tGlzAh99Ehu1poit1hom0abIPE7f7EOHBe6aKG+02zWKdVPmzIMUaS0m9P MTBOoIj36ofUew11UFY3V5noAfXDFW1xZaXdEiSJWSPNEll7XdQmnKdxNo05gk8fo5zD GboIfKuvMh+O7/eySIXVpaPlPN/qe2POcoiubmZReD1TMzyUEW2akSJIDqCaeMOurbTH 5JdLctqJeXYVbq7XhOsi6sLtAZQI6kd/6h84XkRTUcOs0F1HDhKpXQWjIcZ9+zDUXJR8 o1Sg== X-Gm-Message-State: ALoCoQntwzb+b1IXkR/L8U18wnbVTVuVhmmQ5Pqv6f87yp+UHFDGLI9J0BaINfDOc+jT+ogCf7qt MIME-Version: 1.0 X-Received: by 10.182.126.74 with SMTP id mw10mr495366obb.57.1422541643601; Thu, 29 Jan 2015 06:27:23 -0800 (PST) Received: by 10.182.131.136 with HTTP; Thu, 29 Jan 2015 06:27:23 -0800 (PST) In-Reply-To: References: Date: Thu, 29 Jan 2015 07:27:23 -0700 Message-ID: Subject: Re: Database locking code From: Mike Tutkowski To: "dev@cloudstack.apache.org" Content-Type: multipart/alternative; boundary=e89a8fb1f4a8586d6d050dcb495d X-Virus-Checked: Checked by ClamAV on apache.org --e89a8fb1f4a8586d6d050dcb495d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Does this work for you? GlobalLock lock =3D GlobalLock.getInternLock( someStringYouMadeUpThatIsUniqueForThisPurpose); try { if (!lock.lock(timeoutInSeconds)) { s_logger.debug("Couldn't lock the db on the string " + someStringYouMadeUpThatIsUniqueForThisPurpose); throw new CloudRuntimeException("Couldn't acquire DB lock"); } // do your work } finally { lock.unlock(); lock.releaseRef(); } On Thu, Jan 29, 2015 at 3:32 AM, Jeff Hair wrote: > I have some code I've added to CloudStack that I am currently > synchronizing on in the traditional manner (synchronized block, > ExecutorService, etc). I'm currently running a single instance of > CloudStack so I don't have to deal with clustering. > > I've read the Data Access Layer documentation and am wondering if the > database locks are the actual appropriate solution rather than what > I'm doing. > > Basically my issue is that I need to lock access to an IP address > reserved to the account and perform some long operations on it. I also > need to guarantee that no other IPs on the account are manipulated > while performing this task. Synchronization accomplishes this because > I can force the IP operations through an ExecutorService, but I'm > really looking for a better solution that will also work with > clustered management servers. > > Thanks, > > Jeff > --=20 *Mike Tutkowski* *Senior CloudStack Developer, SolidFire Inc.* e: mike.tutkowski@solidfire.com o: 303.746.7302 Advancing the way the world uses the cloud *=E2=84=A2* --e89a8fb1f4a8586d6d050dcb495d--