jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1498995 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemImpl.java SessionImpl.java delegate/SessionDelegate.java delegate/SessionOperation.java version/VersionManagerImpl.java
Date Tue, 02 Jul 2013 16:13:16 GMT
Author: jukka
Date: Tue Jul  2 16:13:15 2013
New Revision: 1498995

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

Only check for staleness after there has been some transient or persisted update

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/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.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=1498995&r1=1498994&r2=1498995&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
Tue Jul  2 16:13:15 2013
@@ -67,10 +67,13 @@ 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>
{
@@ -81,6 +84,9 @@ abstract class ItemImpl<T extends ItemDe
     }
 
     protected abstract class ItemWriteOperation<U> extends SessionOperation<U>
{
+        protected ItemWriteOperation() {
+            super(true);
+        }
         @Override
         protected void checkPreconditions() throws RepositoryException {
             checkAlive();
@@ -274,9 +280,13 @@ abstract class ItemImpl<T extends ItemDe
      * @throws RepositoryException if this item has been rendered invalid for some reason
      * or the associated session has been logged out.
      */
-    void checkAlive() throws RepositoryException {
+    synchronized void checkAlive() throws RepositoryException {
         sessionDelegate.checkAlive();
-        dlg.checkNotStale();
+        long count = sessionDelegate.getUpdateCount();
+        if (updateCount != count) {
+            dlg.checkNotStale();
+            updateCount = count;
+        }
     }
 
     void checkProtected() throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1498995&r1=1498994&r2=1498995&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Tue Jul  2 16:13:15 2013
@@ -92,15 +92,26 @@ public class SessionImpl implements Jack
         }
     }
 
-    private abstract class CheckedSessionOperation<T> extends SessionOperation<T>
{
+    private abstract class ReadOperation<T> extends SessionOperation<T> {
         @Override
         protected void checkPreconditions() throws RepositoryException {
             sd.checkAlive();
         }
     }
 
+    private abstract class WriteOperation<T> extends SessionOperation<T> {
+        @Override
+        protected void checkPreconditions() throws RepositoryException {
+            sd.checkAlive();
+        }
+        @Override
+        public boolean isUpdate() {
+            return true;
+        }
+    }
+
     @CheckForNull
-    private <T> T perform(@Nonnull CheckedSessionOperation<T> op) throws RepositoryException
{
+    private <T> T perform(@Nonnull SessionOperation<T> op) throws RepositoryException
{
         return sd.perform(op);
     }
 
@@ -146,7 +157,7 @@ public class SessionImpl implements Jack
      */
     @CheckForNull
     public Node getNodeOrNull(final String absPath) throws RepositoryException {
-        return perform(new CheckedSessionOperation<Node>() {
+        return perform(new ReadOperation<Node>() {
             @Override
             public Node perform() throws RepositoryException {
                 return sessionContext.createNodeOrNull(sd.getNode(getOakPathOrThrow(absPath)));
@@ -167,7 +178,7 @@ public class SessionImpl implements Jack
         if (absPath.equals("/")) {
             return null;
         } else {
-            return perform(new CheckedSessionOperation<Property>() {
+            return perform(new ReadOperation<Property>() {
                 @Override
                 public Property perform() throws RepositoryException {
                     return createPropertyOrNull(sd.getProperty(getOakPathOrThrow(absPath)));
@@ -187,7 +198,7 @@ public class SessionImpl implements Jack
      */
     @CheckForNull
     public Item getItemOrNull(final String absPath) throws RepositoryException {
-        return perform(new CheckedSessionOperation<Item>() {
+        return perform(new ReadOperation<Item>() {
             @Override
             public Item perform() throws RepositoryException {
                 return getItemInternal(getOakPathOrThrow(absPath));
@@ -243,7 +254,7 @@ public class SessionImpl implements Jack
     @Override
     @Nonnull
     public Node getRootNode() throws RepositoryException {
-        return perform(new CheckedSessionOperation<Node>() {
+        return perform(new ReadOperation<Node>() {
             @Override
             protected Node perform() throws AccessDeniedException, RepositoryException {
                 NodeDelegate nd = sd.getRootNode();
@@ -271,7 +282,7 @@ public class SessionImpl implements Jack
 
     @Nonnull
     private Node getNodeById(final String id) throws RepositoryException {
-        return perform(new CheckedSessionOperation<Node>() {
+        return perform(new ReadOperation<Node>() {
             @Override
             public Node perform() throws ItemNotFoundException, RepositoryException {
                 NodeDelegate nd = sd.getNodeByIdentifier(id);
@@ -325,7 +336,7 @@ public class SessionImpl implements Jack
 
     @Override
     public void move(final String srcAbsPath, final String destAbsPath) throws RepositoryException
{
-        sd.perform(new CheckedSessionOperation<Void>() {
+        sd.perform(new WriteOperation<Void>() {
             @Override
             protected void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
@@ -347,7 +358,7 @@ public class SessionImpl implements Jack
 
     @Override
     public void removeItem(final String absPath) throws RepositoryException {
-        perform(new CheckedSessionOperation<Void>() {
+        perform(new WriteOperation<Void>() {
             @Override
             protected Void perform() throws RepositoryException {
                 String oakPath = getOakPathOrThrowNotFound(absPath);
@@ -365,7 +376,7 @@ public class SessionImpl implements Jack
 
     @Override
     public void save() throws RepositoryException {
-        perform(new CheckedSessionOperation<Void>() {
+        perform(new WriteOperation<Void>() {
             @Override
             protected Void perform() throws RepositoryException {
                 sd.save();
@@ -377,7 +388,7 @@ public class SessionImpl implements Jack
 
     @Override
     public void refresh(final boolean keepChanges) throws RepositoryException {
-        perform(new CheckedSessionOperation<Void>() {
+        perform(new WriteOperation<Void>() {
             @Override
             protected Void perform() throws RepositoryException {
                 sd.refresh(keepChanges);
@@ -548,7 +559,7 @@ public class SessionImpl implements Jack
 
     @Override
     public boolean hasPermission(final String absPath, final String actions) throws RepositoryException
{
-        return perform(new CheckedSessionOperation<Boolean>() {
+        return perform(new ReadOperation<Boolean>() {
             @Override
             protected Boolean perform() throws RepositoryException {
                 String oakPath = getOakPathOrThrow(absPath);

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=1498995&r1=1498994&r2=1498995&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
Tue Jul  2 16:13:15 2013
@@ -64,6 +64,7 @@ public class SessionDelegate {
 
     private boolean isAlive = true;
     private int sessionOpCount;
+    private long updateCount = 0;
 
     private long lastAccessed = System.currentTimeMillis();
 
@@ -73,7 +74,7 @@ public class SessionDelegate {
         this.idManager = new IdentifierManager(root);
     }
 
-    public void refreshAtNextAccess() {
+    public synchronized void refreshAtNextAccess() {
         lastAccessed = -1;
     }
 
@@ -96,6 +97,7 @@ public class SessionDelegate {
             long now = System.currentTimeMillis();
             if (now > lastAccessed + AUTO_REFRESH_INTERVAL) {
                 refresh(true);
+                updateCount++;
             }
             lastAccessed = now;
 
@@ -106,6 +108,9 @@ public class SessionDelegate {
             return sessionOperation.perform();
         } finally {
             sessionOpCount--;
+            if (sessionOperation.isUpdate()) {
+                updateCount++;
+            }
         }
     }
 
@@ -134,6 +139,14 @@ public class SessionDelegate {
         }
     }
 
+    /**
+     * @return session update counter
+     */
+    public long getUpdateCount() {
+        return updateCount;
+    }
+
+
     @Nonnull
     public AuthInfo getAuthInfo() {
         return contentSession.getAuthInfo();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java?rev=1498995&r1=1498994&r2=1498995&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java
Tue Jul  2 16:13:15 2013
@@ -24,6 +24,26 @@ import javax.jcr.RepositoryException;
  * A {@code SessionOperation} provides an execution context for executing session scoped
operations.
  */
 public abstract class SessionOperation<T> {
+
+    private final boolean update;
+
+    protected SessionOperation(boolean update) {
+        this.update = update;
+    }
+
+    protected SessionOperation() {
+        this(false);
+    }
+
+    /**
+     * Returns {@code true} if this operation updates the the transient
+     * @return
+     */
+    public boolean isUpdate() {
+        return update;
+    }
+
     protected void checkPreconditions() throws RepositoryException {}
     protected abstract T perform() throws RepositoryException;
+
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java?rev=1498995&r1=1498994&r2=1498995&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
Tue Jul  2 16:13:15 2013
@@ -81,7 +81,7 @@ public class VersionManagerImpl implemen
                         final boolean removeExisting)
             throws RepositoryException {
         final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        sessionDelegate.perform(new SessionOperation<Void>(true) {
             @Override
             public Void perform() throws RepositoryException {
                 String oakPath = getOakPathOrThrowNotFound(absPath);
@@ -169,7 +169,7 @@ public class VersionManagerImpl implemen
             throw new VersionException("Restore of root version not possible");
         }
         final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        sessionDelegate.perform(new SessionOperation<Void>(true) {
             @Override
             public Void perform() throws RepositoryException {
                 // check for pending changes
@@ -332,7 +332,7 @@ public class VersionManagerImpl implemen
     @Override
     public void checkout(final String absPath) throws RepositoryException {
         final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        sessionDelegate.perform(new SessionOperation<Void>(true) {
             @Override
             public Void perform() throws RepositoryException {
                 String oakPath = getOakPathOrThrowNotFound(absPath);
@@ -350,7 +350,7 @@ public class VersionManagerImpl implemen
     @Override
     public Version checkin(final String absPath) throws RepositoryException {
         final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
-        return sessionDelegate.perform(new SessionOperation<Version>() {
+        return sessionDelegate.perform(new SessionOperation<Version>(true) {
             @Override
             public Version perform() throws RepositoryException {
                 String oakPath = getOakPathOrThrowNotFound(absPath);



Mime
View raw message