Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 93B8DD10E for ; Thu, 19 Jul 2012 22:21:01 +0000 (UTC) Received: (qmail 17182 invoked by uid 500); 19 Jul 2012 22:21:00 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 17154 invoked by uid 500); 19 Jul 2012 22:21:00 -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 17146 invoked by uid 99); 19 Jul 2012 22:21:00 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2012 22:21:00 +0000 Received: from localhost (HELO [192.168.1.7]) (127.0.0.1) (smtp-auth username rnewson, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2012 22:20:59 +0000 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1278) Subject: Re: Atomicity with _update handlers? From: Robert Newson In-Reply-To: Date: Thu, 19 Jul 2012 23:20:59 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <5FC64674-B32F-4B60-8EA0-E4F34480DC18@apache.org> References: To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1278) An update to a couchdb document is atomic, whether done directly or via = an update handler. An update handler can fail with a 409 just the same = as a direct update can. The only difference between the two update = methods is where the logic runs. The update handler is merely returning = the new document to couchdb, the actual update occurs after the function = has returned (and can fail). B. On 19 Jul 2012, at 22:09, Andrew Melo wrote: > Hello all, >=20 > The documentation is a bit unclear on this, but basically I was > wondering what sort of atomicity guarantees exist for _update > handlers. Suppose I have documents that look like this >=20 > { 'states' : [ { 'oldstate' : 'created', 'newstate' : 'new' } ] } >=20 > And an update handler that looks like this (probably not the exactly > right syntax) >=20 > function (doc, req) { > // check that the requested old state equals the previous new state > if doc.states[ len(doc.states) ]['newstate'] =3D=3D = req.query['oldstate'] { > // update the document, adding a new state to the end of = doc.states > } else { > // barf back to the user > } > } >=20 > Is there a guarantee that concurrent requests to the same instance > can't end up with a garbled ordering of states? >=20 > Thanks, > Andrew >=20 > --=20 > -- > Andrew Melo