On Tue, Jun 30, 2009 at 8:37 AM, Rowdy Rednose<rowdy.redn...@gmx.net> wrote: > > Would it be easy to implement an in-memory database in clojure that > allows concurrent access? > > It sounds pretty easy, as most of the features are already provided by > Clojure. I'm not sure though about the "locking granularity". > Of course you don't pessimistically lock in Clojure, but if you have a > relation that is "protected" by a Ref, then concurrently adding two > rows to that relation will make one of the two transaction replay, > although the added rows could be completely independent (unless there > are unique constraints, for example, which, now that I think about it, > are present in every real-world table in the form of primary keys).
You could wrap a Ref around every value, if you chose, to allow independent changes to different "rows" at the same time -- though this would not help when inserting rows. You could partition your key space somehow (perhaps by hash) to allow n groups of rows, and protect each of those with a Ref. This would allow insertions and deletions independently as long as the operations were being applied to different groups. I imagine there are other possible solutions as well... > Furthermore, if you have constraints that involve other relations, say > foreign key constraints, then the locking granularity gets even > coarser, spanning all relations involved, and thus affecting every > mutating access to any one of those relations. With either of the layouts I mentioned, this kind of multi-relation transaction ought to allow Clojure STM to really shine when compared to a more naive locking scheme. --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---