-
Notifications
You must be signed in to change notification settings - Fork 718
/
long_fork.clj
63 lines (57 loc) · 2.44 KB
/
long_fork.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(ns yugabyte.long-fork
"Looks for instances of long fork: a snapshot isolation violation involving
incompatible orders of writes to disparate objects"
(:refer-clojure :exclude [test])
(:require [clojure [pprint :refer [pprint]]]
[clojure.tools.logging :refer [info]]
[clojurewerkz.cassaforte [cql :as cql]
[query :as q]]
[jepsen [checker :as checker]
[generator :as gen]]
[jepsen.tests.long-fork :as lf]
[yugabyte [client :as c]]))
(def keyspace "jepsen")
(def table "long_fork")
(c/defclient CQLLongForkIndexClient keyspace []
(setup! [this test]
(c/create-transactional-table
conn table
(q/if-not-exists)
(q/column-definitions {:key :int
:key2 :int
:val :int
:primary-key [:key]}))
(c/create-index conn (str (c/statement->str
(q/create-index "long_forks"
(q/on-table table)
(q/and-column :key2)))
" INCLUDE (val)")))
(invoke! [this test op]
(let [txn (:value op)]
(c/with-errors op #{}
(case (:f op)
:read (let [ks (lf/op-read-keys op)
; Look up values by the value index
vs (->> (cql/select conn table
(q/columns :key2 :val)
(q/where [[:in :key2 ks]]))
(map (juxt :key2 :val))
(into (sorted-map)))
; Rewrite txn to use those values
txn' (reduce (fn [txn [f k _]]
; We already know these are all reads
(conj txn [f k (get vs k)]))
[]
txn)]
(assoc op :type :ok :value txn'))
:write (let [[[_ k v]] txn]
(do (cql/insert conn table
{:key k
:key2 k
:val v})
(assoc op :type :ok)))))))
(teardown! [this test]))
(defn workload
[opts]
(assoc (lf/workload 3)
:client (->CQLLongForkIndexClient)))