On Mon, Nov 23, 2009 at 4:34 PM, Sergey Didenko <sergey.dide...@gmail.com>wrote:
> Hi, > > Andre, Danny's first approach is about "syncing" only on the root > object, so that every piece of data is behind one deref: > > (def root (ref {:persons [ ... no other refs here... ])) > > This approach is simpler to code but can lead to a lot of retried > transactions under heavy concurrent load, as I understand. > > What about making all derefs that you need inside one transaction? > There are words somewhere in docs that you need dosync if you perform > a few reads that must be consistent. I think this is what you need. I'm starting to think that for some tasks Clojure could use a concept of "row locking" with maps. It would mean having a map-of-refs type that was integrated with the STM, so multiple updates whose keys didn't collide could occur concurrently. It *might* be possible to do this using commute and update-in, with a ref wrapping the whole map. The tricky thing is you want the update-ins to commute if the keys are not the same, but not if they are. Perhaps we need a "conditional commute" that takes two extra arguments, a value to test and a binary predicate. Then it could be done with (conditional-commute key = map update-in [key] val-transform-fn). The idea here being, in this case, that if two of these were done in overlapping transactions, the first arguments would be compared using the second argument. If the result was true one transaction would be retried, if false the operations would commute. (If the second arguments to the two conditional-commutes differed the transaction would be retried.) I think adding "conditional commute" would require changes to core, however. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en