Skip to content

Commit

Permalink
Change/Fix to also snapshot and rollback post commit actions
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Jun 10, 2023
1 parent 970c7e7 commit 975fdaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/kcas/kcas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,13 @@ module Xt = struct
and gt = rollback casn gt_mark gt in
CASN { loc; state; lt; gt; awaiters = [] })

type 'x snap = cass
type 'x snap = cass * Action.t

let snapshot ~xt = xt.cass
let rollback ~xt snap = xt.cass <- rollback xt.casn snap xt.cass
let snapshot ~xt = (xt.cass, xt.post_commit)

let rollback ~xt (snap, post_commit) =
xt.cass <- rollback xt.casn snap xt.cass;
xt.post_commit <- post_commit

let rec first ~xt tx = function
| [] -> tx ~xt
Expand Down
8 changes: 8 additions & 0 deletions test/kcas/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,29 @@ let test_rollback () =
let n_permanent = Random.int n_locs in
let n_rollbacks = Random.int n_locs in

let expected = ref false in
let unexpected = ref false in

let tx ~xt =
in_place_shuffle locs;
for i = 0 to n_permanent - 1 do
Xt.incr ~xt locs.(i)
done;
Xt.post_commit ~xt (fun () -> expected := true);

let snap = Xt.snapshot ~xt in
in_place_shuffle locs;
for i = 0 to n_rollbacks - 1 do
Xt.incr ~xt locs.(i)
done;
Xt.post_commit ~xt (fun () -> unexpected := true);
Xt.rollback ~xt snap
in
Xt.commit { tx };

assert !expected;
assert (not !unexpected);

accum := n_permanent + !accum
done;

Expand Down

0 comments on commit 975fdaf

Please sign in to comment.