couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Transaction_model_use_cases" by AnthonyTowns
Date Mon, 21 Sep 2009 03:07:28 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "Transaction_model_use_cases" page has been changed by AnthonyTowns:
http://wiki.apache.org/couchdb/Transaction_model_use_cases?action=diff&rev1=27&rev2=28

  
  '''''The proper way to do this is treat CouchDB as a ledger, with each line item as a new
document. Then to do a transfer a single document that shows the money subtracted from account
A and added to account B. To get the balance of an account, create a view of transactions
by account and use a reduction to add up all the transactions for each account.'''''
  
+ == Harder example involving money ==
+ 
+ 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 >= $80 (query view)
+  2. Check Balance of A >= $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 problem...
+ 
+ I guess writing the transfer function as:
+ 
+  1. Tentatively transfer AMOUNT from ACCOUNT to DESTINATION (add new document, marked tentative)
+  2. Wait for document to have been replicated to all other hosts
+  3. Determine balance of ACCOUNT (query view)
+  4. If balance >= 0: remove tentative mark from transaction
+  5. Otherwise: delete transaction
+ 
+ might be feasible, but getting the right semantics for the second step seems hard.
  
  == Users, groups and relationships ==
  

Mime
View raw message