jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dürig <mdue...@apache.org>
Subject [jr3 microkernel] Write skew
Date Wed, 30 Nov 2011 12:38:42 GMT


As documented earlier [1] new Mircokernel based JCR implementations will 
most likely introduce snapshot isolation for sessions. While I think 
this is a good thing in general, it also introduces potentially 
troublesome write skew: application level constraints might hold locally 
(i.e. per session) but might fail globally. That is, in order to enforce 
some constraints, applications might need to implement explicit cross 
session synchronization mechanisms instead of being able to rely on 
session isolation. The following test case demonstrates the issue.

  * Trans-session isolation differs from Jackrabbit 2.
  * Snapshot isolation can result in write skew as this
  * test demonstrates: the check method enforces an
  * application logic constraint which says that the sum
  * of the properties p1 and p2 must not be negative. While
  * session1 and session2 each enforce this constraint before
  * saving, the constraint might not hold globally as can be
  * seen in session3.
public void testSessionIsolation() throws RepositoryException {
     Repository repository = getRepository();

     Session session0 = repository.login();
     Node testNode = session0.getNode("/").addNode("testNode");
     testNode.setProperty("p1", 1);
     testNode.setProperty("p2", 1);

     Session session1 = repository.login();
     Session session2 = repository.login();

     session1.getNode("/testNode").setProperty("p1", -1);

     session2.getNode("/testNode").setProperty("p2", -1);
     check(session2);  // Throws on JR2 but not on JR3

     Session session3 = repository.login();
     check(session3);  // Throws on JR3

private static void check(Session session) throws RepositoryException {
     if (session.getNode("/testNode").getProperty("p1").getLong() +
         session.getNode("/testNode").getProperty("p2").getLong() < 0) {
           fail("p1 + p2 < 0");



View raw message