You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2017/05/25 08:53:22 UTC
svn commit: r1796137 - in /jackrabbit/oak/trunk/oak-store-composite/src:
main/java/org/apache/jackrabbit/oak/composite/
test/java/org/apache/jackrabbit/oak/composite/
Author: tomekr
Date: Thu May 25 08:53:21 2017
New Revision: 1796137
URL: http://svn.apache.org/viewvc?rev=1796137&view=rev
Log:
OAK-6256: Prevent creating the across-mounts references
By default, the cross-mount references should be just logged. Added
a property to configure this behaviour.
Modified:
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidator.java
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorProvider.java
jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorTest.java
Modified: jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidator.java?rev=1796137&r1=1796136&r2=1796137&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidator.java (original)
+++ jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidator.java Thu May 25 08:53:21 2017
@@ -31,6 +31,8 @@ import org.apache.jackrabbit.oak.spi.mou
import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
import org.apache.jackrabbit.oak.spi.query.Filter;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Map;
@@ -46,6 +48,8 @@ import static org.apache.jackrabbit.oak.
public class CrossMountReferenceValidator extends DefaultValidator {
+ private final Logger LOG = LoggerFactory.getLogger(CrossMountReferenceValidator.class);
+
private static final Filter EMPTY_FILTER = new FilterImpl(null, null, new QueryEngineSettings());
/** Parent editor, or {@code null} if this is the root editor. */
@@ -69,6 +73,8 @@ public class CrossMountReferenceValidato
private final Set<IndexStoreStrategy> uuidStores;
+ private final boolean failOnDetection;
+
private CrossMountReferenceValidator(CrossMountReferenceValidator parent, String name) {
this.name = name;
this.parent = parent;
@@ -78,9 +84,10 @@ public class CrossMountReferenceValidato
this.newReferences = parent.newReferences;
this.uuidDefinition = parent.uuidDefinition;
this.uuidStores = parent.uuidStores;
+ this.failOnDetection = parent.failOnDetection;
}
- public CrossMountReferenceValidator(NodeState root, MountInfoProvider mip) {
+ public CrossMountReferenceValidator(NodeState root, MountInfoProvider mip, boolean failOnDetection) {
this.name = null;
this.parent = null;
this.path = "/";
@@ -89,6 +96,7 @@ public class CrossMountReferenceValidato
this.newReferences = ArrayListMultimap.create();
this.uuidDefinition = root.getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("uuid");
this.uuidStores = Multiplexers.getStrategies(true, mip, uuidDefinition, INDEX_CONTENT_NODE_NAME);
+ this.failOnDetection = failOnDetection;
}
@Override
@@ -106,16 +114,19 @@ public class CrossMountReferenceValidato
String uuid = e.getKey();
String passivePath = getPathByUuid(uuid);
if (passivePath == null) {
- throw new CommitFailedException(INTEGRITY, 1,
- "Can't find path for the uuid: " + uuid);
+ LOG.warn("Can't find path for the UUID {}", uuid);
}
Mount m1 = mip.getMountByPath(passivePath);
for (String activePath : e.getValue()) {
Mount m2 = mip.getMountByPath(activePath);
if (!m1.equals(m2)) {
- throw new CommitFailedException(INTEGRITY, 1,
- "Unable to reference the node [" + passivePath + "] from node [" + activePath + "]. Referencing across the mounts is not allowed.");
+ if (failOnDetection) {
+ throw new CommitFailedException(INTEGRITY, 1,
+ "Unable to reference the node [" + passivePath + "] from node [" + activePath + "]. Referencing across the mounts is not allowed.");
+ } else {
+ LOG.warn("Detected a cross-mount reference: {} -> {}", activePath, passivePath);
+ }
}
}
}
Modified: jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorProvider.java?rev=1796137&r1=1796136&r2=1796137&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorProvider.java (original)
+++ jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorProvider.java Thu May 25 08:53:21 2017
@@ -36,16 +36,29 @@ import org.apache.jackrabbit.oak.spi.sta
@Service({ValidatorProvider.class, EditorProvider.class})
public class CrossMountReferenceValidatorProvider extends ValidatorProvider {
+ @Property(
+ boolValue = true,
+ label = "Fail when detecting commits cross-mount references",
+ description = "Commits will fail if set to true when detecting cross-mount references. If set to false the commit information is only logged."
+ )
+ private static final String PROP_FAIL_ON_DETECTION = "failOnDetection";
+ private boolean failOnDetection;
+
@Reference
private MountInfoProvider mountInfoProvider = Mounts.defaultMountInfoProvider();
@Override
protected Validator getRootValidator(NodeState before, NodeState after, CommitInfo info) {
- return new CrossMountReferenceValidator(after, mountInfoProvider);
+ return new CrossMountReferenceValidator(after, mountInfoProvider, failOnDetection);
}
CrossMountReferenceValidatorProvider with(MountInfoProvider mountInfoProvider) {
this.mountInfoProvider = mountInfoProvider;
return this;
}
+
+ CrossMountReferenceValidatorProvider withFailOnDetection(boolean failOnDetection) {
+ this.failOnDetection = failOnDetection;
+ return this;
+ }
}
Modified: jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorTest.java?rev=1796137&r1=1796136&r2=1796137&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorTest.java (original)
+++ jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CrossMountReferenceValidatorTest.java Thu May 25 08:53:21 2017
@@ -54,7 +54,7 @@ public class CrossMountReferenceValidato
new IndexUpdateProvider(new CompositeIndexEditorProvider(
new PropertyIndexEditorProvider().with(mip),
new ReferenceEditorProvider().with(mip))),
- new CrossMountReferenceValidatorProvider().with(mip)));
+ new CrossMountReferenceValidatorProvider().with(mip).withFailOnDetection(true)));
}
@Test