Skip to content

Instantly share code, notes, and snippets.

@galderz
Created November 12, 2013 11:54
Show Gist options
  • Save galderz/9ba22e47116906a750d7 to your computer and use it in GitHub Desktop.
Save galderz/9ba22e47116906a750d7 to your computer and use it in GitHub Desktop.
With RC and no WSC:
tm(0).begin();
cache(0).put(k, "v1");
final Transaction tx1 = tm(0).suspend();
//another tx working on the same keys
tm(0).begin();
cache(0).put(k, "v2");
tm(0).commit();
assert cache(0).get(k).equals("v2");
assert cache(1).get(k).equals("v2");
tm(0).resume(tx1);
tm(0).commit();
assert cache(0).get(k).equals("v1");
assert cache(1).get(k).equals("v1");
With RR and WSC:
tm(0).begin();
cache(0).put(k, "v1");
final Transaction tx1 = tm(0).suspend();
//another tx working on the same keys
tm(0).begin();
cache(0).put(k, "v2");
tm(0).commit();
assert cache(0).get(k).equals("v2");
assert cache(1).get(k).equals("v2");
tm(0).resume(tx1);
try {
tm(0).commit();
fail("Should have rolledback with write skew failure");
} catch (RollbackException e) {
// Write skew fails
assert cache(0).get(k).equals("v2");
assert cache(1).get(k).equals("v2");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment