jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r911856 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
Date Fri, 19 Feb 2010 16:16:49 GMT
Author: jukka
Date: Fri Feb 19 16:16:49 2010
New Revision: 911856

URL: http://svn.apache.org/viewvc?rev=911856&view=rev
Log:
JCR-1440: NPE Thrown when two Cluster Nodes are hitting the same underlying database

Patch by Micah Whitacre

This needs more work (the solution reminds me of the double checked-locking antipattern),
but at least it solves the most pressing issue and doesn't seem to cause any notable risk
to other use cases.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=911856&r1=911855&r2=911856&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
Fri Feb 19 16:16:49 2010
@@ -290,6 +290,32 @@
      * {@inheritDoc}
      */
     public InternalVersion getVersion(NodeId id) {
+        InternalVersion v = getCachedVersion(id);
+
+        // If the version was not found, our cache may not have been
+        // synchronized with updates from another cluster node.  Reload the history
+        // to be sure we have the latest updates and try again.
+        if (v == null) {
+            try {
+                reload();
+            } catch (RepositoryException e) {
+
+                // We should add the checked exception to this method definition
+                // so we don't need to wrap it.
+                // Avoiding it for now to limit impact of this fix.
+                throw new RuntimeException(e);
+            }
+            v = getCachedVersion(id);
+        }
+
+        return v;
+    }
+
+    /**
+     * Returns the version from cache, or <code>null</code> if it is not
+     * present.
+     */
+    private InternalVersion getCachedVersion(NodeId id) {
         InternalVersion v = versionCache.get(id);
         if (v == null) {
             for (Name versionName : nameCache.keySet()) {



Mime
View raw message