Skip to content

Commit

Permalink
txn: add reads and writes, require dom-top.
Browse files Browse the repository at this point in the history
  • Loading branch information
aphyr committed Apr 3, 2023
1 parent 7a59089 commit 7a38680
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions txn/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
:test-selectors {:default (fn [m] (not (or (:perf m))))
:all (fn [m] true)
:perf :perf}
:dependencies [[dom-top "1.0.8"]]
:profiles {:dev {:dependencies [[org.clojure/clojure "1.10.1"]
[criterium "0.4.5"]]}})
27 changes: 26 additions & 1 deletion txn/src/jepsen/txn.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns jepsen.txn
"Manipulates transactions. Transactions are represented as a sequence of
micro-operations (mops for short).")
micro-operations (mops for short)."
(:require [dom-top.core :refer [loopr]]))

(defn reduce-mops
"Takes a history of operations, where each operation op has a :value which is
Expand All @@ -21,6 +22,30 @@
[history]
(mapcat (fn [op] (map (fn [mop] [op mop]) (:value op))) history))

(defn reads
"Given a transaction, returns a map of keys to sets of all values that
transaction read."
[txn]
(loopr [reads (transient {})]
[[f k v] txn]
(if (= :r f)
(let [vs (get reads k #{})]
(recur (assoc! reads k (conj vs v))))
(recur reads))
(persistent! reads)))

(defn writes
"Given a transaction, returns a map of keys to sets of all values that
transaction wrote."
[txn]
(loopr [writes (transient {})]
[[f k v] txn]
(if (= :w f)
(let [vs (get writes k #{})]
(recur (assoc! writes k (conj vs v))))
(recur writes))
(persistent! writes)))

(defn ext-reads
"Given a transaction, returns a map of keys to values for its external reads:
values that transaction observed which it did not write itself."
Expand Down

0 comments on commit 7a38680

Please sign in to comment.