|
1 | 1 | (ns scalardb.db.postgres |
2 | | - (:require [clojure.tools.logging :refer [info]] |
| 2 | + (:require [clojure.tools.logging :refer [info warn]] |
3 | 3 | [jepsen |
4 | 4 | [control :as c] |
5 | 5 | [db :as db] |
6 | 6 | [util :refer [meh]]] |
7 | 7 | [jepsen.control.util :as cu] |
8 | | - [jepsen.os.debian :as debian])) |
| 8 | + [jepsen.os.debian :as debian] |
| 9 | + [jepsen.nemesis.combined :as jn] |
| 10 | + [scalardb.db-extend :as ext]) |
| 11 | + (:import (java.util Properties))) |
9 | 12 |
|
10 | 13 | (def ^:private ^:const DEFAULT_VERSION "15") |
11 | 14 | (def ^:private ^:const TIMEOUT_SEC 600) |
|
71 | 74 | (c/su (meh (c/exec :rm :-r (get-main-dir version)))) |
72 | 75 | (c/su (meh (c/exec :rm (get-log-path version))))) |
73 | 76 |
|
74 | | -(defn live-node? |
| 77 | +(defn- live-node? |
75 | 78 | [test] |
76 | 79 | (let [node (-> test :nodes first)] |
77 | 80 | (try |
|
81 | 84 | (info node "is down") |
82 | 85 | false)))) |
83 | 86 |
|
84 | | -(defn wait-for-recovery |
| 87 | +(defn- wait-for-recovery |
85 | 88 | "Wait for the node bootstrapping." |
86 | 89 | ([test] |
87 | 90 | (wait-for-recovery TIMEOUT_SEC INTERVAL_SEC test)) |
|
134 | 137 |
|
135 | 138 | db/LogFiles |
136 | 139 | (log-files [_ test _] [(get-log-path test)]))) |
| 140 | + |
| 141 | +(defrecord ExtPostgres [] |
| 142 | + ext/DbExtension |
| 143 | + (get-db-type [_] :postgres) |
| 144 | + (live-nodes [_ test] (live-node? test)) |
| 145 | + (wait-for-recovery [_ test] (wait-for-recovery test)) |
| 146 | + (create-table-opts [_ _] {}) |
| 147 | + (create-properties |
| 148 | + [_ test] |
| 149 | + (or (ext/load-config test) |
| 150 | + (let [node (-> test :nodes first)] |
| 151 | + ;; We have only one node in this test |
| 152 | + (->> (doto (Properties.) |
| 153 | + (.setProperty "scalar.db.storage" "jdbc") |
| 154 | + (.setProperty "scalar.db.contact_points" |
| 155 | + (str "jdbc:postgresql://" node ":5432/")) |
| 156 | + (.setProperty "scalar.db.username" "postgres") |
| 157 | + (.setProperty "scalar.db.password" "postgres")) |
| 158 | + (ext/set-common-properties test))))) |
| 159 | + (create-storage-properties [this test] (ext/create-properties this test))) |
| 160 | + |
| 161 | +(defn gen-db |
| 162 | + [faults admin] |
| 163 | + (when (seq admin) |
| 164 | + (warn "The admin operations are ignored:" admin)) |
| 165 | + [(ext/extend-db (db) (->ExtPostgres)) |
| 166 | + (jn/nemesis-package |
| 167 | + {:db db |
| 168 | + :interval 60 |
| 169 | + :faults faults |
| 170 | + :partition {:targets [:one]} |
| 171 | + :kill {:targets [:one]} |
| 172 | + :pause {:targets [:one]}}) |
| 173 | + 1]) |
0 commit comments