Return-Path: Delivered-To: apmail-zookeeper-user-archive@www.apache.org Received: (qmail 48638 invoked from network); 15 Jan 2011 16:15:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Jan 2011 16:15:03 -0000 Received: (qmail 75280 invoked by uid 500); 15 Jan 2011 16:15:03 -0000 Delivered-To: apmail-zookeeper-user-archive@zookeeper.apache.org Received: (qmail 75066 invoked by uid 500); 15 Jan 2011 16:15:01 -0000 Mailing-List: contact user-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@zookeeper.apache.org Delivered-To: mailing list user@zookeeper.apache.org Received: (qmail 75048 invoked by uid 99); 15 Jan 2011 16:15:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Jan 2011 16:14:59 +0000 X-ASF-Spam-Status: No, hits=1.5 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,HTML_OBFUSCATE_05_10,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of scottfines@gmail.com designates 209.85.215.170 as permitted sender) Received: from [209.85.215.170] (HELO mail-ey0-f170.google.com) (209.85.215.170) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Jan 2011 16:14:55 +0000 Received: by eyf5 with SMTP id 5so2686294eyf.15 for ; Sat, 15 Jan 2011 08:14:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=EuCtPur1l/cQwazzH0B+CeJRxxizd1LZryT8Lzi84F0=; b=QLzc27ZGJ+3aBibq9o8fLtj3ePQ/pOgDCcZRFHQvHqddl/u+/v+lti7h7ArQVD5UTv JedAWEeQlypgTkmZza6tghpfEiwp1gTgBeamG1jdi5YZaMOw4jKY5852p9fzb1sPRFue Kc2vOi1nJzzBEfLlAPJV5rteChSNuBwPsR3CU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=QE/ndy7cZsJEpT/oTzdfiHF++pL8c6dNtKbPqGAz+zRppRFi5L/32Bt9EjoRn/W6su KAFkhkLMk3jgXNPNt4GDuVfbwSzTx3Ph/nHRSVXKTOsY4FfKt+P6oDJbKdTGsWiUrJ2L IKsIfXGvLRs8MX0De2SOdQ+hljWGrKirwtsQc= MIME-Version: 1.0 Received: by 10.14.22.80 with SMTP id s56mr1565429ees.6.1295108071468; Sat, 15 Jan 2011 08:14:31 -0800 (PST) Received: by 10.14.29.9 with HTTP; Sat, 15 Jan 2011 08:14:31 -0800 (PST) Date: Sat, 15 Jan 2011 10:14:31 -0600 Message-ID: Subject: Atomic Compare-and-swap like operations From: Scott Fines To: user@zookeeper.apache.org Content-Type: multipart/alternative; boundary=90e6ba6154b68bb0920499e4d821 --90e6ba6154b68bb0920499e4d821 Content-Type: text/plain; charset=ISO-8859-1 Hello All, So I've been working on an implementation of a BlockingQueue for Menagerie (shameless plug!), and I keep running into complications because of some compound actions, so I thought I would bring it up to the community at large. To fully implement a java.util.concurrent.BlockingQueue, you need to implement a take() operation that blocks until an entry is added, then get the data for that entry and delete it. Unfortunately, the ZooKeeper API makes getting data from a znode a distinct, separate action from a delete operation which isn't atomic. Thus, in order to perform a take, I have to first grab a distributed Lock on the head node, just because a delete-and-get operation is not atomic. This seems very much like excessive locking that could be easily circumvented with an atomic get-and-delete operation. It seems like it would be a very powerful option to be able to have a "delete-and-return" operation that atomically deletes a znode, and returns the bytes that were previously stored in that znode. Is there a particular reason why this was not chosen as the behavior of the API? In most of the other generic compare-and-swap operations (put-if-absent and set-if-matches), there is already a mechanism in place, or one can relatively easily be implemented, but this seems like an odd oversight. I saw that ZooKeeper-965 could potentially address this in the future, but it seems like API overkill for something like this. --90e6ba6154b68bb0920499e4d821--