jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1404945 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemDelegate.java ItemImpl.java SessionDelegate.java
Date Fri, 02 Nov 2012 12:26:43 GMT
Author: mduerig
Date: Fri Nov  2 12:26:42 2012
New Revision: 1404945

URL: http://svn.apache.org/viewvc?rev=1404945&view=rev
Log:
 OAK-418: Reduce/avoid re-resolving the underlying tree instances on every access in Item/Property/NodeDelegate
 Revision counter to avoid unnecessary re-resolving the underlying tree location for items
where nothing has changed.

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
    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/SessionDelegate.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java?rev=1404945&r1=1404944&r2=1404945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
Fri Nov  2 12:26:42 2012
@@ -38,9 +38,17 @@ public abstract class ItemDelegate {
     /** The underlying {@link org.apache.jackrabbit.oak.api.TreeLocation} of this item. */
     private TreeLocation location;
 
+    /**
+     * Revision on which this item is based. The underlying state of the item
+     * is re-resolved whenever the revision of the session does not match this
+     * revision.
+     */
+    private int revision;
+
     ItemDelegate(SessionDelegate sessionDelegate, TreeLocation location) {
         this.sessionDelegate = checkNotNull(sessionDelegate);
         this.location = checkNotNull(location);
+        this.revision = sessionDelegate.getRevision();
     }
 
     /**
@@ -76,7 +84,8 @@ public abstract class ItemDelegate {
      * @return  {@code true} iff stale
      */
     public boolean isStale() {
-        return getLocationOrNull() == NullLocation.INSTANCE;
+        Status status = getLocationOrNull().getStatus();
+        return status == Status.REMOVED || status == null;
     }
 
     /**
@@ -125,12 +134,15 @@ public abstract class ItemDelegate {
 
     /**
      * The underlying {@link org.apache.jackrabbit.oak.api.TreeLocation} of this item.
+     * The location is only re-resolved when the revision of this item does not match
+     * the revision of the session.
      * @return  tree location of the underlying item or {@code null} if stale.
      */
     @CheckForNull
     private synchronized TreeLocation getLocationOrNull() {
-        if (location != NullLocation.INSTANCE) {
+        if (location != NullLocation.INSTANCE && sessionDelegate.getRevision() !=
revision) {
             location = sessionDelegate.getLocation(location.getPath());
+            revision = sessionDelegate.getRevision();
         }
         return location;
     }

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=1404945&r1=1404944&r2=1404945&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
Fri Nov  2 12:26:42 2012
@@ -73,6 +73,7 @@ abstract class ItemImpl<T extends ItemDe
     @Override
     @Nonnull
     public String getPath() throws RepositoryException {
+        checkStatus();
         return sessionDelegate.perform(new SessionOperation<String>() {
             @Override
             public String perform() throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1404945&r1=1404944&r2=1404945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Fri Nov  2 12:26:42 2012
@@ -81,6 +81,7 @@ public class SessionDelegate {
     private PrivilegeManager privilegeManager;
     private boolean isAlive = true;
     private int sessionOpCount;
+    private int revision;
 
     SessionDelegate(
             Repository repository, ScheduledExecutorService executor,
@@ -133,6 +134,16 @@ public class SessionDelegate {
                 (sessionOpCount <= 1 && observationManager != null &&
observationManager.hasEvents());
     }
 
+    /**
+     * Revision of this session. The revision is incremented each time a session is refreshed
or saved.
+     * This allows items to determine whether they need to re-resolve their underlying state
when the
+     * revision on which an item is based does not match the revision of the session any
more.
+     * @return  the current revision of this session
+     */
+    int getRevision() {
+        return revision;
+    }
+
     public boolean isAlive() {
         return isAlive;
     }
@@ -229,6 +240,7 @@ public class SessionDelegate {
     public void save() throws RepositoryException {
         try {
             root.commit();
+            revision++;
         } catch (CommitFailedException e) {
             e.throwRepositoryException();
         }
@@ -240,6 +252,7 @@ public class SessionDelegate {
         } else {
             root.refresh();
         }
+        revision++;
         // TODO: improve
         if (privilegeManager != null && privilegeManager instanceof PrivilegeManagerImpl)
{
             ((PrivilegeManagerImpl) privilegeManager).refresh();



Mime
View raw message