Last active
August 29, 2015 14:09
-
-
Save jenschelkopf/5f0b12259e0c31cac8b7 to your computer and use it in GitHub Desktop.
FoundationDB CAS Register for Jepsen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:cas (timeout 5000 (assoc op :type :info :value :timed-out) | |
(let [cas (reify Function | |
(apply [this, tr] | |
(let [ | |
[value value'] (:value op) | |
key_var (byte-array (map byte key)) | |
old_value (.getLong (Tuple/fromBytes (.get (.get tr (byte-array (map byte key))))) 0) | |
new_value (.pack (Tuple/from (into-array [value'])))] | |
(if (= old_value value) | |
(do | |
(.set tr key_var new_value) | |
(assoc op :type :ok)) | |
(assoc op :type :fail)) | |
)))] | |
(try | |
(.run client cas) | |
(catch RuntimeException e | |
(assoc op :type :fail :value (.getMessage e)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment