Brian, I imagine you are asking this in relation to your blog engine?

I came up with solution, that is, if you don't mind writing the
persistent data fresh every time.

http://paste.lisp.org/display/77987

Basically, I added a watch to the *comment* ref, which set the *db*
ref to the new state of the *comment* ref.  I wrote a test that hits
it with 10 current threads (that each add 10 comments) and then
validate that both refs are the same at the end (I borrowed the code
from Rich's example on the concurrency page).

This is my first real dive into the concurrency aspect of Clojure, and
just wanted to play around, but maybe this could give you other
ideas.  Maybe you could write to a file, and then every so often
commit the contents of the file to the db?  Like a buffer of commits
or something that is persisted to disk.  Meh, I'm just throwing up
ideas, good luck to ya.

On Apr 3, 5:02 am, Brian Carper <briancar...@gmail.com> wrote:
> Is there a safe way to keep the data in a Clojure ref and the data in
> a table in an external (e.g. mysql) database in sync, given concurrent
> creates/updates/deletes from within Clojure?
>
> I can't do a DB update from within a dosync because of retries.  If I
> send-off an agent for the DB update from within a dosync, it won't
> happen until after the dosync is done, and then if the DB update
> throws an exception, it'll be too late to rollback the ref and they'll
> be out of sync.  If I do the DB update and ref update separately,
> there's the potential for race conditions if things happen in between.
>
> Is manual locking the only way?
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to