Skip to content

Commit

Permalink
Added random timeout for pessimistic locking append tests (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
qvad authored Nov 8, 2023
1 parent 2e7540c commit af65490
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions yugabyte/src/yugabyte/ysql/append.clj
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@

(defn append-primary!
"Writes a key based on primary key."
[geo-partitioning conn table row col v]
(let [r (c/execute! conn [(str "update " table
[locking geo-partitioning conn table row col v]
(let [_ (if (= :pessimistic locking)
(do
; Randomly evaluate SELECT FOR UPDATE with timeout in case of pessimistic locking
(c/query conn [(select-with-optional-lock locking col table) row])
(Thread/sleep (rand-int 2000)))
nil)
r (c/execute! conn [(str "update " table
" set " col " = CONCAT(" col ", ',', ?)" (geo-row-update geo-partitioning v) " "
"where k = ?") v row])]
(when (= [0] r)
Expand Down Expand Up @@ -132,7 +138,7 @@
(read-primary locking conn table row col)

:append
(append-primary! geo-partitioning conn table row col v))]))
(append-primary! locking geo-partitioning conn table row col v))]))

(defn create-geo-tablespace
[conn tablespace-name replica-placement]
Expand Down

0 comments on commit af65490

Please sign in to comment.