Skip to content

Rewrite operations of a client in register workload to SQL #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ligurio opened this issue Oct 1, 2020 · 0 comments
Closed

Rewrite operations of a client in register workload to SQL #31

ligurio opened this issue Oct 1, 2020 · 0 comments
Assignees

Comments

@ligurio
Copy link
Member

ligurio commented Oct 1, 2020

register was a first experience in a jepsen testing it contains two operations (write and read) written using Lua.
Although both can be implemented using SQL.

https://github.com/tarantool/jepsen.tarantool/blob/master/src/tarantool/register.clj

  (invoke! [this test op]
     (case (:f op)
       :read (assoc op
                    :type  :ok
                    :value (cl/read-v-by-k conn 1))
       :write (do (let [con (cl/open (jepsen/primary test) test)]
                   (cl/write-v-by-k con 1 (:value op)))
                   (assoc op :type :ok))
       :cas (let [[old new] (:value op)
                  con (cl/open (jepsen/primary test) test)]
                  (assoc op :type (if (cl/compare-and-set con 1 old new)
                                   :ok
                                   :fail)))))

  (teardown! [this test])
      ;(j/execute! conn ["DROP TABLE jepsen"]))

https://github.com/tarantool/jepsen.tarantool/blob/master/src/tarantool/client.clj

(defn read-v-by-k
  "Reads the current value of a key."
  [conn k]
  (first (vals (first (j/execute! conn ["SELECT _READ(?, 'JEPSEN')" k])))))

(defn write-v-by-k
  "Writes the current value of a key."
  [conn k v]
  (j/execute! conn ["SELECT _WRITE(?, ?, 'JEPSEN')"
                    k v]))

(defn compare-and-set
  [conn id old new]
  (first (vals (first (j/execute! conn ["SELECT _CAS(?, ?, ?, 'JEPSEN')"
                                        id old new])))))

https://github.com/tarantool/jepsen.tarantool/blob/master/resources/tarantool/jepsen.lua

--[[ Function implements an WRITE operation, which takes a key and value
and sets the key to the value if and only if the key is already exists, and
insert value if it is absent.
Example: SELECT _WRITE(1, 3, 'JEPSEN')
]]
box.schema.func.create('_WRITE',
   {language = 'LUA',
    returns = 'integer',
    body = [[function (id, value, table)
             box.space[table]:upsert({id, value}, {{'=', 1, 1}, {'=', 2, value}})
             return value
             end]],
    is_sandboxed = false,
    param_list = {'integer', 'integer', 'string'},
    exports = {'LUA', 'SQL'},
    is_deterministic = true})

--[[ Function implements an READ operation, which takes a key and returns a
value.
Example: SELECT _READ(1, 'JEPSEN')
]]
box.schema.func.create('_READ',
   {language = 'LUA',
    returns = 'integer',
    body = [[function (id, table)
             box.begin()
             local tuple = box.space[table]:get{id}
             if tuple then
                 return tuple[2]
             end
             box.commit()
             return nil
             end]],
    is_sandboxed = false,
    param_list = {'integer', "string"},
    exports = {'LUA', 'SQL'},
    is_deterministic = true})
@ligurio ligurio self-assigned this Oct 1, 2020
ligurio added a commit that referenced this issue Oct 1, 2020
ligurio added a commit that referenced this issue Oct 1, 2020
- converted READ opeartion to an SQL command
- converted WRITE operation to a custom SQL command UPSERT
- added teardown with table remove

Closes #31
ligurio added a commit that referenced this issue Oct 1, 2020
- converted READ opeartion to an SQL command
- converted WRITE operation to a custom SQL command UPSERT
- added teardown with table remove

Closes #31
ligurio added a commit that referenced this issue Oct 1, 2020
- replace READ operation by a seq of SQL commands
- replace WRITE operation by a Lua routine with UPSERT
- added teardown with table remove

Closes #31
ligurio added a commit that referenced this issue Oct 1, 2020
- replace READ operation by a seq of SQL commands
- replace WRITE operation by a Lua routine with UPSERT
- manage table in client's setup and teardown

Closes #31
ligurio added a commit that referenced this issue Oct 2, 2020
- replace READ operation by a seq of SQL commands
- replace WRITE operation by a Lua routine with native UPSERT
  and use it as an SQL command
- manage table in client's setup and teardown

Closes #31
ligurio added a commit that referenced this issue Oct 2, 2020
- replace READ operation by a sequence of SQL commands
- replace WRITE operation by a Lua routine with native UPSERT
  and use it as an SQL command
- manage table in client's setup and teardown

Closes #31
@ligurio ligurio closed this as completed in 3214905 Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant