Author: reschke
Date: Wed May 30 13:11:22 2018
New Revision: 1832541

URL: http://svn.apache.org/viewvc?rev=1832541&view=rev
Log:
OAK-7471: add a config switch to disable locking

Modified:
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockDeprecation.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/JcrDescriptorsImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/WorkspaceImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1832541&r1=1832540&r2=1832541&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
 Wed May 30 13:11:22 2018
@@ -75,6 +75,8 @@ import javax.jcr.security.AccessControlE
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
+
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
@@ -82,6 +84,7 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.jcr.lock.LockDeprecation;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants;
@@ -378,6 +381,9 @@ public class NodeDelegate extends ItemDe
     }
 
     public boolean canAddMixin(String typeName) throws RepositoryException {
+        if (!LockDeprecation.isLockingSupported() && 
JcrConstants.MIX_LOCKABLE.equals(typeName)) {
+            return false;
+        }
         Tree type = 
sessionDelegate.getRoot().getTree(NODE_TYPES_PATH).getChild(typeName);
         if (type.exists()) {
             return !TreeUtil.getBoolean(type, JCR_IS_ABSTRACT)

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockDeprecation.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockDeprecation.java?rev=1832541&r1=1832540&r2=1832541&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockDeprecation.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockDeprecation.java
 Wed May 30 13:11:22 2018
@@ -21,6 +21,8 @@ import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import javax.jcr.UnsupportedRepositoryOperationException;
+
 import org.apache.jackrabbit.oak.jcr.session.NodeImpl;
 import org.apache.jackrabbit.oak.jcr.session.SessionImpl;
 import org.slf4j.Logger;
@@ -33,6 +35,9 @@ public class LockDeprecation {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(LockDeprecation.class);
 
+    private static final String LOCKSUPPORT = 
System.getProperty("oak.locksupport", "deprecated");
+    private static final boolean ISLOCKINGSUPPORTED = 
!("disabled".equals(LOCKSUPPORT));
+    
     private LockDeprecation() {
     }
 
@@ -44,18 +49,27 @@ public class LockDeprecation {
             new String[] { Thread.class.getName(), 
java.lang.reflect.Method.class.getName(), LockDeprecation.class.getName(),
                     LockManagerImpl.class.getName(), NodeImpl.class.getName(), 
SessionImpl.class.getName() }));
 
-    public static void logCall(String operation) {
-
-        boolean firstInvocation = NOTWARNEDYET.getAndSet(false);
+    public static void logCall(String operation) throws 
UnsupportedRepositoryOperationException {
 
-        if (firstInvocation) {
-            String explanation = "Support for JCR Locking is deprecated and 
will be disabled in a future version of Jackrabbit Oak (see OAK-6421 for 
further information)";
-            LOG.warn(explanation + " - " + createLogMessage(operation));
-        } else if (LOG.isTraceEnabled()) {
-            LOG.trace(createLogMessage(operation));
+        if (!ISLOCKINGSUPPORTED) {
+            throw new UnsupportedRepositoryOperationException(
+                    "Support for JCR Locking is disabled (see OAK-6421 for 
further information)");
+        } else {
+            boolean firstInvocation = NOTWARNEDYET.getAndSet(false);
+
+            if (firstInvocation) {
+                String explanation = "Support for JCR Locking is deprecated 
and will be disabled in a future version of Jackrabbit Oak (see OAK-6421 for 
further information)";
+                LOG.warn(explanation + " - " + createLogMessage(operation));
+            } else if (LOG.isTraceEnabled()) {
+                LOG.trace(createLogMessage(operation));
+            }
         }
     }
 
+    public final static boolean isLockingSupported() {
+        return ISLOCKINGSUPPORTED;
+    }
+
     private static String createLogMessage(String operation) {
         StackTraceElement elements[] = Thread.currentThread().getStackTrace();
         StringBuilder b = new StringBuilder();

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/JcrDescriptorsImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/JcrDescriptorsImpl.java?rev=1832541&r1=1832540&r2=1832541&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/JcrDescriptorsImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/JcrDescriptorsImpl.java
 Wed May 30 13:11:22 2018
@@ -20,6 +20,7 @@ import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 
 import org.apache.jackrabbit.oak.api.Descriptors;
+import org.apache.jackrabbit.oak.jcr.lock.LockDeprecation;
 import org.apache.jackrabbit.oak.spi.descriptors.GenericDescriptors;
 
 import static javax.jcr.Repository.OPTION_LOCKING_SUPPORTED;
@@ -37,7 +38,7 @@ public class JcrDescriptorsImpl extends
 
         // add the descriptors of the features that are provided by the JCR 
layer
         final Value trueValue = valueFactory.createValue(true);
-        put(OPTION_LOCKING_SUPPORTED, trueValue, true, true);
+        put(OPTION_LOCKING_SUPPORTED, 
valueFactory.createValue(LockDeprecation.isLockingSupported()), true, true);
         put(OPTION_XML_EXPORT_SUPPORTED, trueValue, true, true);
         put(OPTION_XML_IMPORT_SUPPORTED, trueValue, true, true);
    }

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java?rev=1832541&r1=1832540&r2=1832541&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
 Wed May 30 13:11:22 2018
@@ -1208,6 +1208,9 @@ public class NodeImpl<T extends NodeDele
 
     @Override
     public boolean isLocked() throws RepositoryException {
+        if (!LockDeprecation.isLockingSupported()) {
+            return false;
+        }
         return getLockManager().isLocked(getPath());
     }
 

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java?rev=1832541&r1=1832540&r2=1832541&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
 Wed May 30 13:11:22 2018
@@ -657,7 +657,8 @@ public class SessionImpl implements Jack
             if (!parent.isCheckedOut()) {
                 return false;
             }
-            if (parent.isLocked()) {
+            boolean hasLocking = 
sessionContext.getRepository().getDescriptorValue(Repository.OPTION_LOCKING_SUPPORTED).getBoolean();
+            if (hasLocking && parent.isLocked()) {
                 return false;
             }
 

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/WorkspaceImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/WorkspaceImpl.java?rev=1832541&r1=1832540&r2=1832541&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/WorkspaceImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/WorkspaceImpl.java
 Wed May 30 13:11:22 2018
@@ -44,6 +44,7 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.WorkspaceDelegate;
+import org.apache.jackrabbit.oak.jcr.lock.LockDeprecation;
 import org.apache.jackrabbit.oak.jcr.lock.LockManagerImpl;
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation;
@@ -197,7 +198,8 @@ public class WorkspaceImpl implements Ja
     }
 
     @Override
-    public LockManagerImpl getLockManager() {
+    public LockManagerImpl getLockManager() throws 
UnsupportedRepositoryOperationException {
+        LockDeprecation.logCall("get LockManager");
         return new LockManagerImpl(sessionContext);
     }
 

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=1832541&r1=1832540&r2=1832541&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
 Wed May 30 13:11:22 2018
@@ -49,6 +49,7 @@ import org.apache.jackrabbit.oak.jcr.del
 import org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionHistoryDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
+import org.apache.jackrabbit.oak.jcr.lock.LockDeprecation;
 import org.apache.jackrabbit.oak.jcr.lock.LockManagerImpl;
 import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation;
@@ -389,12 +390,15 @@ public class VersionManagerImpl implemen
     }
 
     private void checkNotLocked(String absPath) throws RepositoryException {
+        if (!LockDeprecation.isLockingSupported()) {
+            return;
+        }
         // TODO: avoid nested calls
         LockManagerImpl lockManager = 
sessionContext.getWorkspace().getLockManager();
         if (lockManager.isLocked(absPath)) {
             NodeDelegate node = 
sessionContext.getSessionDelegate().getNode(absPath);
             if (!lockManager.canUnlock(node)) {
-                throw new LockException("Node at " + absPath + " is locked");  
  
+                throw new LockException("Node at " + absPath + " is locked");
             }
         }
     }

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?rev=1832541&r1=1832540&r2=1832541&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
 Wed May 30 13:11:22 2018
@@ -31,6 +31,7 @@ import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.ItemExistsException;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
@@ -147,7 +148,8 @@ public class ImporterImpl implements Imp
         if (!vMgr.isCheckedOut(absPath)) {
             throw new VersionException("Target node is checked in.");
         }
-        if (importTargetTree.getStatus() != Tree.Status.NEW && 
wsp.getLockManager().isLocked(absPath)) {
+        boolean hasLocking = 
sessionContext.getRepository().getDescriptorValue(Repository.OPTION_LOCKING_SUPPORTED).getBoolean();
+        if (importTargetTree.getStatus() != Tree.Status.NEW && hasLocking && 
wsp.getLockManager().isLocked(absPath)) {
             throw new LockException("Target node is locked.");
         }
         effectiveNodeTypeProvider = wsp.getNodeTypeManager();


Reply via email to