jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r792211 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SessionImpl.java cluster/ClusterNode.java
Date Wed, 08 Jul 2009 16:24:22 GMT
Author: jukka
Date: Wed Jul  8 16:24:21 2009
New Revision: 792211

URL: http://svn.apache.org/viewvc?rev=792211&view=rev
Log:
JCR-1753: Allow means force a Repository to synchronize with the cluster

Synchronize with the cluster whenever Session.refresh(boolean) is called, unless the "org.apache.jackrabbit.disableClusterSyncOnRefresh"
attribute is set.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=792211&r1=792210&r2=792211&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Wed Jul  8 16:24:21 2009
@@ -65,6 +65,8 @@
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.commons.AbstractSession;
 import org.apache.jackrabbit.core.RepositoryImpl.WorkspaceInfo;
+import org.apache.jackrabbit.core.cluster.ClusterException;
+import org.apache.jackrabbit.core.cluster.ClusterNode;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.data.GarbageCollector;
 import org.apache.jackrabbit.core.lock.LockManager;
@@ -111,6 +113,19 @@
 public class SessionImpl extends AbstractSession
         implements JackrabbitSession, NamespaceResolver, NamePathResolver, IdentifierResolver,
Dumpable {
 
+    /**
+     * Name of the session attribute that controls whether the
+     * {@link #refresh(boolean)} method will cause the repository to
+     * synchronize itself to changes in other cluster nodes. This cluster
+     * synchronization is enabled by default, unless an attribute with this
+     * name is set (any non-null value) for this session.
+     *
+     * @since Apache Jackrabbit 1.6
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1753">JCR-1753</a>
+     */
+    public static final String DISABLE_CLUSTER_SYNC_ON_REFRESH =
+        "org.apache.jackrabbit.disableClusterSyncOnRefresh";
+
     private static Logger log = LoggerFactory.getLogger(SessionImpl.class);
 
     /**
@@ -915,6 +930,17 @@
         // check sanity of this session
         sanityCheck();
 
+        // JCR-1753: Ensure that we are up to date with cluster changes
+        ClusterNode cluster = rep.getClusterNode();
+        if (cluster != null && clusterSyncOnRefresh()) {
+            try {
+                cluster.sync();
+            } catch (ClusterException e) {
+                throw new RepositoryException(
+                        "Unable to synchronize with the cluster", e);
+            }
+        }
+
         if (!keepChanges) {
             // optimization
             itemStateMgr.disposeAllTransientItemStates();
@@ -924,6 +950,22 @@
     }
 
     /**
+     * Checks whether the {@link #refresh(boolean)} method should cause
+     * cluster synchronization.
+     * <p>
+     * Subclasses can override this method to implement alternative
+     * rules on when cluster synchronization should be done.
+     *
+     * @return <code>true</code> if the {@link #DISABLE_CLUSTER_SYNC_ON_REFRESH}
+     *         attribute is <em>not</em> set, <code>false</code>
otherwise
+     * @since Apache Jackrabbit 1.6
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1753">JCR-1753</a>
+     */
+    protected boolean clusterSyncOnRefresh() {
+        return getAttribute(DISABLE_CLUSTER_SYNC_ON_REFRESH) == null;
+    }
+
+    /**
      * {@inheritDoc}
      */
     public boolean hasPendingChanges() throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=792211&r1=792210&r2=792211&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Wed Jul  8 16:24:21 2009
@@ -132,6 +132,15 @@
     private final Latch stopLatch = new Latch();
 
     /**
+     * Sync counter, used to avoid repeated sync() calls from piling up.
+     * Only updated within the critical section guarded by {@link #syncLock}.
+     *
+     * @since Apache Jackrabbit 1.6
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1753">JCR-1753</a>
+     */
+    private volatile int syncCount = 0;
+
+    /**
      * Status flag, one of {@link #NONE}, {@link #STARTED} or {@link #STOPPED}.
      */
     private int status;
@@ -304,6 +313,8 @@
      * @throws ClusterException if an error occurs
      */
     public void sync() throws ClusterException {
+        int count = syncCount;
+
         try {
             syncLock.acquire();
         } catch (InterruptedException e) {
@@ -312,7 +323,12 @@
         }
 
         try {
-            journal.sync();
+            // JCR-1753: Only synchronize if no other thread already did so
+            // while we were waiting to acquire the syncLock.
+            if (count == syncCount) {
+                journal.sync();
+                syncCount++;
+            }
         } catch (JournalException e) {
             throw new ClusterException(e.getMessage(), e.getCause());
         } finally {



Mime
View raw message