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 533D717B7E for ; Tue, 3 Feb 2015 11:13:33 +0000 (UTC) Received: (qmail 16396 invoked by uid 500); 3 Feb 2015 11:12:34 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 16349 invoked by uid 500); 3 Feb 2015 11:12:34 -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 15687 invoked by uid 99); 3 Feb 2015 11:12:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Feb 2015 11:12:33 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW X-Spam-Check-By: apache.org Received-SPF: unknown ~allinclude:_spf.google.com (athena.apache.org: encountered unrecognized mechanism during SPF processing of domain of jeff@greenqloud.com) Received: from [209.85.214.175] (HELO mail-ob0-f175.google.com) (209.85.214.175) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Feb 2015 11:12:29 +0000 Received: by mail-ob0-f175.google.com with SMTP id va2so9855315obc.6 for ; Tue, 03 Feb 2015 03:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greenqloud.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Dm7ODhZNjE9r2CdFylNwxuAOErXeizwTWVXlxwX7KGU=; b=gJwqza+c8Z3ztiF4bjOmKQ/c+vhqid1gJsVnjSnH/jAUBITeiLjEIAAPHUA89PrpFv klYT47lOzaKXKb9hoad5hxRf+d0uc/+hHBTbjBH0dQGBVyMrJWiUsll5kCAFpTJFreCp 8CqgUaW+YQ9lC3ZLsc2eoSuz9FDIBN0hmn6Es= 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:content-transfer-encoding; bh=Dm7ODhZNjE9r2CdFylNwxuAOErXeizwTWVXlxwX7KGU=; b=cl/T/+h7egGaFrEe5OZZSzy9ky00P26k2BpGfSpgWCM9w0uLNMGRaBbKEEKkkZUKgN 92oWuLIZ2bhRdtP6nlG2jt76lfjgExbDNKgBlhaSd+OK8BFBA84BrxgcEvl3g74Jo80y nEd3bTaP+BdlkWjw/DX2EmyaW6EiAv2pHe8mjtmxGBDon2S+x+7hIr/rY5b4o0debKpD m3EObIAB/qV9GWK2JKLYyy1G3WXzDm9UTos5wzJrcwIGiXyH8ogNVPJlJHLnp0TI0icE OiNFOdlRneTVsnrcJUIupH0UmANL0BAYv7aXn6WtBag8L4sthliGjt718PKNbLJVB8H5 6QLw== X-Gm-Message-State: ALoCoQnydyhhaiY/r83fEwcipUEbjHErVXfJ4hHsr9Xnm/Z+s9VvsHmj4P9Ut49nz7ZEicdL+fNa MIME-Version: 1.0 X-Received: by 10.60.103.116 with SMTP id fv20mr1241008oeb.3.1422961882997; Tue, 03 Feb 2015 03:11:22 -0800 (PST) Received: by 10.202.71.19 with HTTP; Tue, 3 Feb 2015 03:11:22 -0800 (PST) In-Reply-To: References: Date: Tue, 3 Feb 2015 11:11:22 +0000 Message-ID: Subject: Re: Database locking code From: Jeff Hair To: dev@cloudstack.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Hi, I've tried this and from our testing thus far it appears to do the job. In fact the synchronization code I wrote didn't really do the job (was storing a bunch of single-threaded ExecutorServices, one per user--but still noticed conflicts at the end). One concern I have though is the management server and running out of threads. Let's say 10 of these operations are submitted. They all get blocked and execute one at a time, per user. If enough users submit enough of these requests, what will happen to other requests that don't need to be locked? I assume we can configure the management server's thread pool size somewhere? Jeff On Thu, Jan 29, 2015 at 2:34 PM, Mike Tutkowski wrote: > Like this: > > GlobalLock lock =3D GlobalLock.getInternLock( > someStringYouMadeUpThatIsUniqueForThisPurpose); > > if (!lock.lock(timeoutInSeconds)) { > > s_logger.debug("Couldn't lock the db on the string " + > someStringYouMadeUpThatIsUniqueForThisPurpose); > > throw new CloudRuntimeException("Couldn't acquire DB lock= "); > > } > try { > > // do your work > > } > > finally { > > lock.unlock(); > > lock.releaseRef(); > > } > > On Thu, Jan 29, 2015 at 7:32 AM, Mike Tutkowski < > mike.tutkowski@solidfire.com> wrote: > >> I wrote that example code from memory, but now that I think about it, yo= u >> wouldn't call the lock method in the try block. >> >> Call lock and if you're successful, entry a try block to do your work an= d >> have a finally to unlock and release the lock. >> >> On Thu, Jan 29, 2015 at 7:27 AM, Mike Tutkowski < >> mike.tutkowski@solidfire.com> wrote: >> >>> 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 D= B >>> 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 >>>> >>> >>> >>> >>> -- >>> *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* >>> >> >> >> >> -- >> *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* >> > > > > -- > *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* --=20 Jeff Hair Core Systems Developer Tel: (+354) 415 0200 jeff@greenqloud.com www.greenqloud.com