Author: jukka
Date: Wed Jul 24 11:27:53 2013
New Revision: 1506503

URL: http://svn.apache.org/r1506503
Log:
OAK-663: oak-jcr performance optimization

Keep the update counter local to the delegate layer. Avoid unnecessary 
checkAlive() calls.

Modified:
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ItemDelegate.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1506503&r1=1506502&r2=1506503&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
 Wed Jul 24 11:27:53 2013
@@ -67,19 +67,16 @@ abstract class ItemImpl<T extends ItemDe
     protected final T dlg;
     protected final SessionDelegate sessionDelegate;
 
-    private long updateCount;
-
     protected ItemImpl(T itemDelegate, SessionContext sessionContext) {
         this.sessionContext = sessionContext;
         this.dlg = itemDelegate;
         this.sessionDelegate = sessionContext.getSessionDelegate();
-        this.updateCount = sessionDelegate.getUpdateCount();
     }
 
     protected abstract class ItemReadOperation<U> extends SessionOperation<U> {
         @Override
         protected void checkPreconditions() throws RepositoryException {
-            checkAlive();
+            dlg.checkAlive();
         }
     }
 
@@ -89,7 +86,7 @@ abstract class ItemImpl<T extends ItemDe
         }
         @Override
         protected void checkPreconditions() throws RepositoryException {
-            checkAlive();
+            dlg.checkAlive();
             checkProtected();
         }
     }
@@ -274,21 +271,6 @@ abstract class ItemImpl<T extends ItemDe
 
     //-----------------------------------------------------------< internal 
>---
 
-    /**
-     * Performs a sanity check on this item and the associated session.
-     *
-     * @throws RepositoryException if this item has been rendered invalid for 
some reason
-     * or the associated session has been logged out.
-     */
-    synchronized void checkAlive() throws RepositoryException {
-        sessionDelegate.checkAlive();
-        long count = sessionDelegate.getUpdateCount();
-        if (updateCount != count) {
-            dlg.checkNotStale();
-            updateCount = count;
-        }
-    }
-
     void checkProtected() throws RepositoryException {
         if (dlg.isProtected()) {
             throw new ConstraintViolationException("Item is protected.");

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1506503&r1=1506502&r2=1506503&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
 Wed Jul 24 11:27:53 2013
@@ -181,12 +181,8 @@ public class NodeImpl<T extends NodeDele
         });
     }
 
-    /**
-     * @see Item#accept(javax.jcr.ItemVisitor)
-     */
     @Override
     public void accept(ItemVisitor visitor) throws RepositoryException {
-        checkAlive();
         visitor.visit(this);
     }
 
@@ -933,7 +929,7 @@ public class NodeImpl<T extends NodeDele
     @Override
     @Nonnull
     public String getCorrespondingNodePath(String workspaceName) throws 
RepositoryException {
-        checkAlive();
+        // TODO: use perform()
         checkValidWorkspace(workspaceName);
         throw new UnsupportedRepositoryOperationException("TODO: 
Node.getCorrespondingNodePath");
     }
@@ -941,7 +937,7 @@ public class NodeImpl<T extends NodeDele
 
     @Override
     public void update(String srcWorkspace) throws RepositoryException {
-        checkAlive();
+        // TODO: use perform()
         checkValidWorkspace(srcWorkspace);
 
         // check for pending changes

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1506503&r1=1506502&r2=1506503&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
 Wed Jul 24 11:27:53 2013
@@ -112,7 +112,6 @@ public class PropertyImpl extends ItemIm
 
     @Override
     public void accept(ItemVisitor visitor) throws RepositoryException {
-        checkAlive();
         visitor.visit(this);
     }
 

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ItemDelegate.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ItemDelegate.java?rev=1506503&r1=1506502&r2=1506503&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ItemDelegate.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ItemDelegate.java
 Wed Jul 24 11:27:53 2013
@@ -22,6 +22,7 @@ import static com.google.common.base.Pre
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.api.Tree.Status;
 
@@ -32,8 +33,36 @@ public abstract class ItemDelegate {
 
     protected final SessionDelegate sessionDelegate;
 
+    /**
+     * The session update count. Used to avoid the overhead of extra
+     * {@link #exists()} calls every time this item is accessed.
+     *
+     * @see #checkAlive()
+     */
+    private long updateCount;
+
     ItemDelegate(SessionDelegate sessionDelegate) {
         this.sessionDelegate = checkNotNull(sessionDelegate);
+        this.updateCount  = sessionDelegate.getUpdateCount();
+    }
+
+    /**
+     * Performs a sanity check on this item and the associated session.
+     *
+     * @throws RepositoryException if this item has been rendered invalid
+     *                             for some reason or the associated session
+     *                             has been logged out
+     */
+    public synchronized void checkAlive() throws RepositoryException {
+        sessionDelegate.checkAlive();
+        long sessionCount = sessionDelegate.getUpdateCount();
+        if (updateCount != sessionCount) {
+            if (!exists()) {
+                throw new InvalidItemStateException(
+                        "This item does not exist anymore");
+            }
+            updateCount = sessionCount;
+        }
     }
 
     /**
@@ -73,10 +102,4 @@ public abstract class ItemDelegate {
      */
     public abstract boolean exists();
 
-    public void checkNotStale() throws InvalidItemStateException {
-        if (!exists()) {
-            throw new InvalidItemStateException("stale");
-        }
-    }
-
 }

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1506503&r1=1506502&r2=1506503&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
 Wed Jul 24 11:27:53 2013
@@ -160,7 +160,6 @@ public class SessionDelegate {
         return updateCount;
     }
 
-
     @Nonnull
     public AuthInfo getAuthInfo() {
         return contentSession.getAuthInfo();


Reply via email to