Skip to content

Commit

Permalink
Serializing arguments bug fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyDidenko committed Mar 18, 2010
1 parent 3e06216 commit b09fa88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
23 changes: 15 additions & 8 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ The disadvantage of the pattern is that your data structures must fit in memory

Snapshotting is not yet implemented. It can solve another pattern problem - growing startup time.

In comparison with Prevayler, this library does not block the reads, because it relies on Clojure STM. However it blocks the writes as Prevayler, because currently there is no way to reliably get/ generate a transaction id without locking.
In comparison with Prevayler, this library does not block the reads, because it relies on Clojure STM. However it blocks the writes as Prevayler. To avoid this, atoms can be used to generate a transaction id without locking, but that will make reading and backup logic much more complex.

I think it's possible to modify Clojure STM to return a global transaction id. Then locking inside the library can be omitted and writes will not be blocking each other.

Probably it's not as important now, when the most of today computers have <=8 cores and the typical usage pattern is that there are an order of magnitude more reads than writes.
Probably blocking of writes is not important now, when the most of today computers have <=8 cores and the typical usage pattern is that there are an order of magnitude more reads than writes.

Usage examples:

Expand All @@ -28,6 +26,7 @@ Usage examples:

(def refx (ref 0))
(def refy (ref 0))
(def refs (ref {}))

(defn tr-fn [x y]
(do
Expand All @@ -43,21 +42,26 @@ Usage examples:
(ref-set refx (inc @refx))
(ref-set refy (inc @refy)) )

(defn tr-set-s [new-s]
(ref-set refs new-s) )

(init-db)
(apply-transaction tr-fn 1 2)
(apply-transaction tr-fn 10 20)
(apply-transaction tr-fn-swap)
(apply-transaction tr-inc)
[refx refy]
(apply-transaction tr-set-s {:a :bb "key" #{"val1" :val2}})
[refx refy refs]

[#<Ref@5bb966: 23> #<Ref@1e903d5: 12>]
[#<Ref@5976c2: 23> #<Ref@183e7de: 12> #<Ref@112e7f7: {:a :bb, "key" #{:val2 "val1"}}>]

2. the second run

(use 'persister)

(def refx (ref 0))
(def refy (ref 0))
(def refs (ref {}))

(defn tr-fn [x y]
(do
Expand All @@ -73,10 +77,13 @@ Usage examples:
(ref-set refx (inc @refx))
(ref-set refy (inc @refy)) )

(defn tr-set-s [new-s]
(ref-set refs new-s) )

(init-db)
[refx refy]
[refx refy refs]

[#<Ref@5bb966: 23> #<Ref@1e903d5: 12>]
[#<Ref@10fe2b9: 23> #<Ref@1ee148b: 12> #<Ref@186d484: {:a :bb, "key" #{:val2 "val1"}}>]


Note that journaled functions must be accessible in the current namespace when you replay transactions.
Expand Down
8 changes: 4 additions & 4 deletions persister.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Basics:
See README.
WARNING! Do not use atoms inside transaction handlers.
WARNING! Do not use atoms inside transaction handlers.
Atom actions are not rollbacked in a failing dosync block.
Apply-transaction macro uses a smart buffer,
Expand Down Expand Up @@ -124,7 +124,7 @@ Notes:

(defn serialized-transaction
[transaction-id & transaction-params]
(str "(" (str-join " " transaction-params) ") ;" transaction-id) )
(str "(" (str-join " " (map pr-str transaction-params)) ") ;" transaction-id) )

(declare try-flushing-smart-buffer)

Expand Down Expand Up @@ -293,8 +293,8 @@ Notes:

(deftest test-serialized-transaction
(is (=
"(transaction param) ;1"
(serialized-transaction 1 "transaction" "param") )))
"(5 \"param\") ;1"
(serialized-transaction 1 5 "param") )))

(deftest test-make-str-join-n
(let [str-join-dosync (make-str-join-n 3 "(" "-" ")")]
Expand Down

0 comments on commit b09fa88

Please sign in to comment.