Skip to content

Commit f590d4a

Browse files
committedJul 10, 2020
jepsen.txn: add int-write-mops for finding internal writes
1 parent 556d305 commit f590d4a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎txn/src/jepsen/txn.clj

+25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
init-state
1717
history))
1818

19+
(defn op-mops
20+
"A lazy sequence of all [op mop] pairs from a history."
21+
[history]
22+
(mapcat (fn [op] (map (fn [mop] [op mop]) (:value op))) history))
23+
1924
(defn ext-reads
2025
"Given a transaction, returns a map of keys to values for its external reads:
2126
values that transaction observed which it did not write itself."
@@ -46,3 +51,23 @@
4651
(assoc! ext k v))
4752
(next txn)))
4853
(persistent! ext))))
54+
55+
(defn int-write-mops
56+
"Returns a map of keys to vectors of of all non-final write mops to that key."
57+
[txn]
58+
(loop [int (transient {})
59+
txn txn]
60+
(if (seq txn)
61+
(let [[f k v :as mop] (first txn)]
62+
(recur (if (= :r f)
63+
int
64+
(let [writes (get int k [])]
65+
(assoc! int k (conj writes mop))))
66+
(next txn)))
67+
; All done; trim final writes.
68+
(->> int
69+
persistent!
70+
(keep (fn [[k vs]]
71+
(when (< 1 (count vs))
72+
[k (subvec vs 0 (dec (count vs)))])))
73+
(into {})))))

0 commit comments

Comments
 (0)
Failed to load comments.