<commit_before>(ns jepsen.voltdb.single
  "Implements a table of single registers identified by id. Verifies
  linearizability over independent registers."
  (:require [jepsen [core         :as jepsen]
                    [control      :as c :refer [|]]
                    [checker      :as checker]
                    [client       :as client]
                    [generator    :as gen]
                    [independent  :as independent]
                    [nemesis      :as nemesis]
                    [os           :as os]
                    [tests        :as tests]]
            [jepsen.os.debian     :as debian]
            [jepsen.checker.timeline :as timeline]
            [jepsen.voltdb        :as voltdb]
            [knossos.model        :as model]
            [knossos.op           :as op]
            [clojure.string       :as str]
            [clojure.core.reducers :as r]
            [clojure.tools.logging :refer [info warn]]))

(defn client
  "A single-register client. Options:

      :strong-reads?                 Whether to perform normal or strong selects
      :procedure-call-timeout       How long in ms to wait for proc calls
      :connection-response-timeout  How long in ms to wait for connections"
  ([opts] (client nil opts))
  ([conn opts]
   (let [initialized? (promise)]
     (reify client/Client
       (setup! [_ test node]
         (let [conn (voltdb/connect
                      node (select-keys opts
                                        [:procedure-call-timeout
                                         :connection-response-timeout]))]
           (when (deliver initialized? true)
             (try
               (c/on node
                     ; Create table
                     (voltdb/sql-cmd! "CREATE TABLE registers (
                                      id          INTEGER UNIQUE NOT NULL,
                                      value       INTEGER NOT NULL,
                                      PRIMARY KEY (id)
                                      );
                                      PARTITION TABLE registers ON COLUMN id;")
                     (voltdb/sql-cmd! "CREATE PROCEDURE registers_cas
                                      PARTITION ON TABLE registers COLUMN id
                                      AS
                                      UPDATE registers SET value = ?
                                      WHERE id = ? AND value = ?;")
                     (voltdb/sql-cmd! "CREATE PROCEDURE FROM CLASS
                                      jepsen.procedures.SRegisterStrongRead;")
                     (voltdb/sql-cmd! "PARTITION PROCEDURE SRegisterStrongRead
                                      ON TABLE registers COLUMN id;")
                     (info node "table created"))
               (catch RuntimeException e
                 (voltdb/close! conn)
                 (throw e))))
           (client conn opts)))

       (invoke! [this test op]
         (try
           (let [id     (key (:value op))
                 value  (val (:value op))]
             (case (:f op)
               :read   (let [proc (if (:strong-reads? opts)
                                    "SRegisterStrongRead"
                                    "REGISTERS.select")
                             v (-> conn
                                   (voltdb/call! proc id)
                                   first
                                   :rows
                                   first
                                   :VALUE)]
                         (assoc op
                                :type :ok
                                :value (independent/tuple id v)))
               :write (do (voltdb/call! conn "REGISTERS.upsert" id value)
                          (assoc op :type :ok))
               :cas   (let [[v v'] value
                            res (-> conn
                                    (voltdb/call! "registers_cas" v' id v)
                                    first
                                    :rows
                                    first
                                    :modified_tuples)]
                        (assert (#{0 1} res))
                        (assoc op :type (if (zero? res) :fail :ok)))))
           (catch org.voltdb.client.NoConnectionsException e
             (Thread/sleep 1000)
             (assoc op :type :fail, :error :no-conns))<commit_msg>single: log what node a process uses<commit_after>(ns jepsen.voltdb.single
  "Implements a table of single registers identified by id. Verifies
  linearizability over independent registers."
  (:require [jepsen [core         :as jepsen]
                    [control      :as c :refer [|]]
                    [checker      :as checker]
                    [client       :as client]
                    [generator    :as gen]
                    [independent  :as independent]
                    [nemesis      :as nemesis]
                    [os           :as os]
                    [tests        :as tests]]
            [jepsen.os.debian     :as debian]
            [jepsen.checker.timeline :as timeline]
            [jepsen.voltdb        :as voltdb]
            [knossos.model        :as model]
            [knossos.op           :as op]
            [clojure.string       :as str]
            [clojure.core.reducers :as r]
            [clojure.tools.logging :refer [info warn]]))

(defn client
  "A single-register client. Options:

      :strong-reads?                 Whether to perform normal or strong selects
      :procedure-call-timeout       How long in ms to wait for proc calls
      :connection-response-timeout  How long in ms to wait for connections"
  ([opts] (client nil nil opts))
  ([conn node opts]
   (let [initialized? (promise)]
     (reify client/Client
       (setup! [_ test node]
         (let [conn (voltdb/connect
                      node (select-keys opts
                                        [:procedure-call-timeout
                                         :connection-response-timeout]))]
           (when (deliver initialized? true)
             (try
               (c/on node
                     ; Create table
                     (voltdb/sql-cmd! "CREATE TABLE registers (
                                      id          INTEGER UNIQUE NOT NULL,
                                      value       INTEGER NOT NULL,
                                      PRIMARY KEY (id)
                                      );
                                      PARTITION TABLE registers ON COLUMN id;")
                     (voltdb/sql-cmd! "CREATE PROCEDURE registers_cas
                                      PARTITION ON TABLE registers COLUMN id
                                      AS
                                      UPDATE registers SET value = ?
                                      WHERE id = ? AND value = ?;")
                     (voltdb/sql-cmd! "CREATE PROCEDURE FROM CLASS
                                      jepsen.procedures.SRegisterStrongRead;")
                     (voltdb/sql-cmd! "PARTITION PROCEDURE SRegisterStrongRead
                                      ON TABLE registers COLUMN id;")
                     (info node "table created"))
               (catch RuntimeException e
                 (voltdb/close! conn)
                 (throw e))))
           (client conn node opts)))

       (invoke! [this test op]
         (info "Process " (:process op) "using node" node)
         (try
           (let [id     (key (:value op))
                 value  (val (:value op))]
             (case (:f op)
               :read   (let [proc (if (:strong-reads? opts)
                                    "SRegisterStrongRead"
                                    "REGISTERS.select")
                             v (-> conn
                                   (voltdb/call! proc id)
                                   first
                                   :rows
                                   first
                                   :VALUE)]
                         (assoc op
                                :type :ok
                                :value (independent/tuple id v)))
               :write (do (voltdb/call! conn "REGISTERS.upsert" id value)
                          (assoc op :type :ok))
               :cas   (let [[v v'] value
                            res (-> conn
                                    (voltdb/call! "registers_cas" v' id v)
                                    first
                                    :rows
                                    first
                                    :modified_tuples)]
                        (assert (#{0 1} res))
                        (assoc op :type (if (zero? res) :fail :ok)))))
           (catch org.voltdb.client.NoConnectionsException e
             (Thread/sleep 1000)
             (assoc op :type :fail, :error :no-conns))
{'fraction_non_alphanumeric': 0.07768744354110207, 'fraction_numerical': 0.0013550135501355014, 'mean_word_length': 0.8808664259927798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3802333', 'n_tokens_mistral': 2161, 'n_tokens_neox': 2007, 'n_words': 609}