From commits-return-3144-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Mon Sep 21 03:07:53 2009 Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 1557 invoked from network); 21 Sep 2009 03:07:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Sep 2009 03:07:53 -0000 Received: (qmail 86756 invoked by uid 500); 21 Sep 2009 03:07:53 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 86657 invoked by uid 500); 21 Sep 2009 03:07:52 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 86648 invoked by uid 500); 21 Sep 2009 03:07:52 -0000 Delivered-To: apmail-incubator-couchdb-commits@incubator.apache.org Received: (qmail 86636 invoked by uid 99); 21 Sep 2009 03:07:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Sep 2009 03:07:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Sep 2009 03:07:49 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 6B3D0118C4; Mon, 21 Sep 2009 03:07:28 +0000 (GMT) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Mon, 21 Sep 2009 03:07:28 -0000 Message-ID: <20090921030728.742.8005@eos.apache.org> Subject: =?utf-8?q?=5BCouchdb_Wiki=5D_Update_of_=22Transaction=5Fmodel=5Fuse=5Fcas?= =?utf-8?q?es=22_by_AnthonyTowns?= X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for c= hange notification. The "Transaction_model_use_cases" page has been changed by AnthonyTowns: http://wiki.apache.org/couchdb/Transaction_model_use_cases?action=3Ddiff&re= v1=3D27&rev2=3D28 = '''''The proper way to do this is treat CouchDB as a ledger, with each li= ne item as a new document. Then to do a transfer a single document that sho= ws the money subtracted from account A and added to account B. To get the b= alance of an account, create a view of transactions by account and use a re= duction to add up all the transactions for each account.''''' = + =3D=3D Harder example involving money =3D=3D + = + Documents store a transaction log -- from account, recipient account and = amount transfered. A view exists to give a balance for each account. At all= times, every accounts' balance should be greater-or-equal to zero. Balance= of account A is $100. Two transactions proposed, "Transfer $80 from A to B= ", and "Transfer $60 from + A to C": + = + 1. Check Balance of A >=3D $80 (query view) + 2. Check Balance of A >=3D $60 (query view) + 3. Transfer $80 from A to B (add new document) + 4. Transfer $60 from A to C (add new document) + 5. Check Balance of A --> -$40 (query view) + = + No explicit conflicts even appear in this case to alert you to the proble= m... + = + I guess writing the transfer function as: + = + 1. Tentatively transfer AMOUNT from ACCOUNT to DESTINATION (add new docu= ment, marked tentative) + 2. Wait for document to have been replicated to all other hosts + 3. Determine balance of ACCOUNT (query view) + 4. If balance >=3D 0: remove tentative mark from transaction + 5. Otherwise: delete transaction + = + might be feasible, but getting the right semantics for the second step se= ems hard. = =3D=3D Users, groups and relationships =3D=3D =20