Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 14503 invoked from network); 12 Feb 2009 17:12:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Feb 2009 17:12:11 -0000 Received: (qmail 7488 invoked by uid 500); 12 Feb 2009 17:12:08 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 7458 invoked by uid 500); 12 Feb 2009 17:12:08 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 7447 invoked by uid 99); 12 Feb 2009 17:12:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Feb 2009 09:12:08 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of wmertens@cisco.com designates 144.254.15.119 as permitted sender) Received: from [144.254.15.119] (HELO av-tac-bru.cisco.com) (144.254.15.119) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Feb 2009 17:12:00 +0000 X-TACSUNS: Virus Scanned Received: from strange-brew.cisco.com (localhost [127.0.0.1]) by av-tac-bru.cisco.com (8.11.7p3+Sun/8.11.7) with ESMTP id n1CHBcZ00661 for ; Thu, 12 Feb 2009 18:11:38 +0100 (CET) Received: from dhcp-peg3-cl31144-254-5-143.cisco.com (dhcp-peg3-cl31144-254-5-143.cisco.com [144.254.5.143]) by strange-brew.cisco.com (8.11.7p3+Sun/8.11.7) with ESMTP id n1CHBct14880 for ; Thu, 12 Feb 2009 18:11:38 +0100 (CET) Message-Id: <7528BFCF-2533-4A6F-AE60-C6968E219F88@cisco.com> From: Wout Mertens To: user@couchdb.apache.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: reserving resources in Couch Date: Thu, 12 Feb 2009 18:11:34 +0100 X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org Ok, (no actual code yet, I don't have time to code right now :( ) I have a project currently using an RDBMS and I'd like to port it to CouchDB. One of the things I do is lock a table, choose a free resource from a query on a static table and the session list, assign the resource to a new session and unlock the table. How would I be able to do the same thing with CouchDB given that 2 sessions could start at the same time? I do have the advantage that simultaneous starters would contact the same CouchDB instance. I was thinking of using sums: make a view that calculates the sum of resources. A resource record would count as +1 and an in-use record would be -1. Then when you reserve a resource, you save the in-use record. After saving, look up the sum for the resource you reserved. If it's not equal to 0, then use a stable algorithm to determine who has to release the resource again. Would this close the race condition? Note that no documents are overwritten at reservation time, each reservation doubles as the event log. When the session clears up, the document that represents it is updated to release the resource. Does this work? Is there a better way to do it? Thanks, Wout.