2023-04-19 12:14:22 +00:00
|
|
|
(ns jepsen.garage.reg
|
|
|
|
(:require [clojure.tools.logging :refer :all]
|
|
|
|
[clojure.string :as str]
|
2023-10-20 10:13:11 +00:00
|
|
|
[clojure.set :as set]
|
2023-04-19 12:14:22 +00:00
|
|
|
[jepsen [checker :as checker]
|
|
|
|
[cli :as cli]
|
|
|
|
[client :as client]
|
|
|
|
[control :as c]
|
|
|
|
[db :as db]
|
|
|
|
[generator :as gen]
|
|
|
|
[independent :as independent]
|
|
|
|
[nemesis :as nemesis]
|
2023-10-19 12:34:19 +00:00
|
|
|
[util :as util]
|
2023-04-19 12:14:22 +00:00
|
|
|
[tests :as tests]]
|
|
|
|
[jepsen.checker.timeline :as timeline]
|
|
|
|
[jepsen.control.util :as cu]
|
|
|
|
[jepsen.os.debian :as debian]
|
2023-10-18 14:30:45 +00:00
|
|
|
[jepsen.garage.daemon :as grg]
|
|
|
|
[jepsen.garage.s3api :as s3]
|
2023-04-19 12:14:22 +00:00
|
|
|
[knossos.model :as model]
|
|
|
|
[slingshot.slingshot :refer [try+]]))
|
|
|
|
|
|
|
|
(defn op-get [_ _] {:type :invoke, :f :read, :value nil})
|
2023-10-20 10:13:11 +00:00
|
|
|
(defn op-put [_ _] {:type :invoke, :f :write, :value (str (rand-int 99))})
|
2023-04-19 12:14:22 +00:00
|
|
|
(defn op-del [_ _] {:type :invoke, :f :write, :value nil})
|
|
|
|
|
|
|
|
(defrecord RegClient [creds]
|
|
|
|
client/Client
|
|
|
|
(open! [this test node]
|
2023-10-19 12:34:19 +00:00
|
|
|
(assoc this :creds (grg/creds node)))
|
2023-04-19 12:14:22 +00:00
|
|
|
(setup! [this test])
|
|
|
|
(invoke! [this test op]
|
2023-10-25 09:41:34 +00:00
|
|
|
(try+
|
|
|
|
(let [[k v] (:value op)]
|
|
|
|
(case (:f op)
|
|
|
|
:read
|
|
|
|
(util/timeout
|
|
|
|
10000
|
|
|
|
(assoc op :type :fail, :error ::timeout)
|
|
|
|
(let [value (s3/get (:creds this) k)]
|
|
|
|
(assoc op :type :ok, :value (independent/tuple k value))))
|
|
|
|
:write
|
|
|
|
(util/timeout
|
|
|
|
10000
|
|
|
|
(assoc op :type :info, :error ::timeout)
|
|
|
|
(do
|
|
|
|
(s3/put (:creds this) k v)
|
|
|
|
(assoc op :type :ok)))))
|
|
|
|
(catch (re-find #"Unavailable" (.getMessage %)) ex
|
|
|
|
(assoc op :type :info, :error ::unavailable))
|
|
|
|
(catch (re-find #"Broken pipe" (.getMessage %)) ex
|
|
|
|
(assoc op :type :info, :error ::broken-pipe))
|
|
|
|
(catch (re-find #"Connection refused" (.getMessage %)) ex
|
|
|
|
(assoc op :type :info, :error ::connection-refused))))
|
2023-04-19 12:14:22 +00:00
|
|
|
(teardown! [this test])
|
|
|
|
(close! [this test]))
|
|
|
|
|
2023-10-20 10:13:11 +00:00
|
|
|
(defn reg-read-after-write
|
|
|
|
"Read-after-Write checker for register operations"
|
|
|
|
[]
|
|
|
|
(reify checker/Checker
|
|
|
|
(check [this test history opts]
|
|
|
|
(let [init {:put-values {-1 nil}
|
|
|
|
:put-done #{-1}
|
|
|
|
:put-in-progress {}
|
|
|
|
:read-can-contain {}
|
|
|
|
:bad-reads #{}}
|
|
|
|
final (reduce
|
|
|
|
(fn [state op]
|
|
|
|
(let [current-values (set/union
|
|
|
|
(set (map (fn [idx] (get (:put-values state) idx)) (:put-done state)))
|
|
|
|
(set (map (fn [[_ [idx _]]] (get (:put-values state) idx)) (:put-in-progress state))))
|
|
|
|
read-can-contain (reduce
|
|
|
|
(fn [rcc [idx v]] (assoc rcc idx (set/union current-values v)))
|
|
|
|
{} (:read-can-contain state))]
|
|
|
|
(info "--------")
|
|
|
|
(info "state: " state)
|
|
|
|
(info "current-values: " current-values)
|
|
|
|
(info "read-can-contain: " read-can-contain)
|
|
|
|
(info "op: " op)
|
|
|
|
(case [(:type op) (:f op)]
|
|
|
|
([:invoke :write])
|
|
|
|
(assoc state
|
|
|
|
:read-can-contain read-can-contain
|
|
|
|
:put-values (assoc (:put-values state) (:index op) (:value op))
|
|
|
|
:put-in-progress (assoc (:put-in-progress state) (:process op) [(:index op) (:put-done state)]))
|
|
|
|
([:ok :write])
|
|
|
|
(let [[index overwrites] (get (:put-in-progress state) (:process op))]
|
|
|
|
(assoc state
|
|
|
|
:read-can-contain read-can-contain
|
|
|
|
:put-in-progress (dissoc (:put-in-progress state) (:process op))
|
|
|
|
:put-done
|
|
|
|
(conj
|
|
|
|
(set/difference (:put-done state) overwrites)
|
|
|
|
index)))
|
|
|
|
([:invoke :read])
|
|
|
|
(assoc state
|
|
|
|
:read-can-contain (assoc read-can-contain (:process op) current-values))
|
|
|
|
([:ok :read])
|
|
|
|
(let [this-read-can-contain (get read-can-contain (:process op))
|
|
|
|
bad-reads (if (contains? this-read-can-contain (:value op))
|
|
|
|
(:bad-reads state)
|
|
|
|
(conj (:bad-reads state) [(:process op) (:index op) (:value op) this-read-can-contain]))]
|
|
|
|
(info "this-read-can-contain: " this-read-can-contain)
|
|
|
|
(assoc state
|
|
|
|
:read-can-contain (dissoc read-can-contain (:process op))
|
|
|
|
:bad-reads bad-reads))
|
|
|
|
state)))
|
|
|
|
init history)
|
|
|
|
valid? (empty? (:bad-reads final))]
|
|
|
|
(assoc final :valid? valid?)))))
|
|
|
|
|
2023-10-20 10:56:45 +00:00
|
|
|
(defn workload-common
|
|
|
|
"Common parts of workload"
|
2023-04-19 12:14:22 +00:00
|
|
|
[opts]
|
2023-10-19 12:34:19 +00:00
|
|
|
{:client (RegClient. nil)
|
2023-04-19 13:27:26 +00:00
|
|
|
:generator (independent/concurrent-generator
|
2023-10-19 12:34:19 +00:00
|
|
|
10
|
|
|
|
(range)
|
2023-04-19 13:27:26 +00:00
|
|
|
(fn [k]
|
|
|
|
(->>
|
2023-10-20 13:00:10 +00:00
|
|
|
(gen/mix [op-get op-put op-del])
|
2023-04-19 13:27:26 +00:00
|
|
|
(gen/limit (:ops-per-key opts)))))})
|
2023-04-19 12:14:22 +00:00
|
|
|
|
2023-10-20 10:56:45 +00:00
|
|
|
(defn workload1
|
|
|
|
"Tests linearizable reads and writes"
|
|
|
|
[opts]
|
|
|
|
(assoc (workload-common opts)
|
|
|
|
:checker (independent/checker
|
|
|
|
(checker/compose
|
|
|
|
{:linear (checker/linearizable
|
|
|
|
{:model (model/register)
|
|
|
|
:algorithm :linear})
|
|
|
|
:timeline (timeline/html)}))))
|
2023-04-19 12:14:22 +00:00
|
|
|
|
2023-10-20 10:56:45 +00:00
|
|
|
(defn workload2
|
|
|
|
"Tests CRDT reads and writes"
|
|
|
|
[opts]
|
|
|
|
(assoc (workload-common opts)
|
|
|
|
:checker (independent/checker
|
|
|
|
(checker/compose
|
|
|
|
{:reg-read-after-write (reg-read-after-write)
|
|
|
|
:timeline (timeline/html)}))))
|