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 ch...@apache.org on 2016/10/19 15:10:38 UTC
svn commit: r1765640 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/
main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/
test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/
Author: chetanm
Date: Wed Oct 19 15:10:37 2016
New Revision: 1765640
URL: http://svn.apache.org/viewvc?rev=1765640&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Add observation support for bundling config change detection
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java (with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandlerTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1765640&r1=1765639&r2=1765640&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Wed Oct 19 15:10:37 2016
@@ -85,7 +85,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.blob.MarkSweepGarbageCollector;
import org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob;
import org.apache.jackrabbit.oak.plugins.document.Branch.BranchCommit;
-import org.apache.jackrabbit.oak.plugins.document.bundlor.BundledTypesRegistry;
+import org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler;
import org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingHandler;
import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache;
import org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.DynamicBroadcastConfig;
@@ -114,7 +114,6 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
-import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.stats.Clock;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
@@ -419,6 +418,8 @@ public final class DocumentNodeStore
private final StatisticsProvider statisticsProvider;
+ private final BundlingConfigHandler bundlingConfigHandler = new BundlingConfigHandler();
+
public DocumentNodeStore(DocumentMK.Builder builder) {
this.blobStore = builder.getBlobStore();
this.statisticsProvider = builder.getStatisticsProvider();
@@ -574,8 +575,11 @@ public final class DocumentNodeStore
this.mbean = createMBean();
LOG.info("Initialized DocumentNodeStore with clusterNodeId: {} ({})", clusterId,
getClusterNodeInfoDisplayString());
+
+ bundlingConfigHandler.initialize(this, executor);
}
+
/**
* Recover _lastRev recovery if needed.
*
@@ -608,6 +612,13 @@ public final class DocumentNodeStore
// only dispose once
return;
}
+
+ try {
+ bundlingConfigHandler.close();
+ } catch (IOException e) {
+ LOG.warn("Error closing bundlingConfigHandler", bundlingConfigHandler);
+ }
+
// notify background threads waiting on isDisposed
synchronized (isDisposed) {
isDisposed.notifyAll();
@@ -1111,9 +1122,7 @@ public final class DocumentNodeStore
}
public BundlingHandler getBundlingHandler() {
- //TODO Move this to observor based
- NodeState registryState = NodeStateUtils.getNode(getRoot(), "/jcr:system/documentstore/bundlor");
- return new BundlingHandler(BundledTypesRegistry.from(registryState));
+ return bundlingConfigHandler.newBundlingHandler();
}
/**
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java?rev=1765640&r1=1765639&r2=1765640&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledTypesRegistry.java Wed Oct 19 15:10:37 2016
@@ -31,6 +31,7 @@ import com.google.common.collect.Sets;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -40,6 +41,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
public class BundledTypesRegistry {
+ public static BundledTypesRegistry NOOP = BundledTypesRegistry.from(EMPTY_NODE);
private final Map<String, DocumentBundlor> bundlors;
public BundledTypesRegistry(Map<String, DocumentBundlor> bundlors) {
@@ -66,6 +68,10 @@ public class BundledTypesRegistry {
return bundlors.get(getPrimaryTypeName(state));
}
+ Map<String, DocumentBundlor> getBundlors() {
+ return bundlors;
+ }
+
private static String getPrimaryTypeName(NodeState nodeState) {
PropertyState ps = nodeState.getProperty(JcrConstants.JCR_PRIMARYTYPE);
return (ps == null) ? JcrConstants.NT_BASE : ps.getValue(Type.NAME);
@@ -90,7 +96,9 @@ public class BundledTypesRegistry {
}
public TypeBuilder forType(String typeName){
- return new TypeBuilder(this, builder.child(typeName));
+ NodeBuilder child = builder.child(typeName);
+ child.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_OAK_UNSTRUCTURED, Type.NAME);
+ return new TypeBuilder(this, child);
}
public TypeBuilder forType(String typeName, String ... includes){
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java?rev=1765640&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java Wed Oct 19 15:10:37 2016
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.document.bundlor;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.concurrent.Executor;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.collect.Iterables;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.spi.commit.BackgroundObserver;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.DefaultEditor;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.spi.commit.EditorDiff;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.commit.Observable;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
+import org.apache.jackrabbit.oak.spi.commit.SubtreeEditor;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+
+public class BundlingConfigHandler implements Observer, Closeable {
+ private static final String CONFIG_PATH = "/jcr:system/documentstore/bundlor";
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private NodeState root = EMPTY_NODE;
+ private BackgroundObserver backgroundObserver;
+ private Closeable observerRegistration;
+
+ private volatile BundledTypesRegistry registry = BundledTypesRegistry.NOOP;
+
+ private Editor changeDetector = new SubtreeEditor(new DefaultEditor() {
+ @Override
+ public void leave(NodeState before, NodeState after) throws CommitFailedException {
+ recreateRegistry(after);
+ }
+ }, Iterables.toArray(PathUtils.elements(CONFIG_PATH), String.class));
+
+ @Override
+ public synchronized void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info) {
+ EditorDiff.process(changeDetector, this.root, root);
+ this.root = root;
+ }
+
+ public BundlingHandler newBundlingHandler() {
+ return new BundlingHandler(registry);
+ }
+
+ public void initialize(NodeStore nodeStore, Executor executor) {
+ registerObserver(nodeStore, executor);
+ }
+
+ @Override
+ public void close() throws IOException{
+ if (backgroundObserver != null){
+ observerRegistration.close();
+ backgroundObserver.close();
+ }
+ }
+
+ BundledTypesRegistry getRegistry() {
+ return registry;
+ }
+
+ private void recreateRegistry(NodeState nodeState) {
+ //TODO Any sanity checks
+ registry = BundledTypesRegistry.from(nodeState);
+ log.info("Refreshing the BundledTypesRegistry");
+ }
+
+ private void registerObserver(NodeStore nodeStore, Executor executor) {
+ if (nodeStore instanceof Observable) {
+ backgroundObserver = new BackgroundObserver(this, executor, 5);
+ observerRegistration = ((Observable) nodeStore).addObserver(backgroundObserver);
+ }
+ }
+
+}
+
+
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java?rev=1765640&r1=1765639&r2=1765640&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandler.java Wed Oct 19 15:10:37 2016
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.oak.commons
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.apache.jackrabbit.oak.spi.state.NodeState;
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.jackrabbit.oak.commons.PathUtils.ROOT_PATH;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
@@ -47,7 +48,7 @@ public class BundlingHandler {
}
private BundlingHandler(BundledTypesRegistry registry, BundlingContext ctx, String path, NodeState nodeState) {
- this.registry = registry;
+ this.registry = checkNotNull(registry);
this.path = path;
this.ctx = ctx;
this.nodeState = nodeState;
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandlerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandlerTest.java?rev=1765640&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandlerTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandlerTest.java Wed Oct 19 15:10:37 2016
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.document.bundlor;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.junit.Test;
+
+import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class BundlingConfigHandlerTest {
+ private BundlingConfigHandler configHandler = new BundlingConfigHandler();
+ private MemoryNodeStore nodeStore = new MemoryNodeStore();
+
+ @Test
+ public void defaultSetup() throws Exception{
+ assertNotNull(configHandler.getRegistry());
+ assertNotNull(configHandler.newBundlingHandler());
+
+ //Close should work without init also
+ configHandler.close();
+ }
+
+ @Test
+ public void detectRegistryUpdate() throws Exception{
+ configHandler.initialize(nodeStore, sameThreadExecutor());
+ addBundlorConfigForAsset();
+
+ BundledTypesRegistry registry = configHandler.getRegistry();
+ assertEquals(1, registry.getBundlors().size());
+ DocumentBundlor assetBundlor = registry.getBundlors().get("app:Asset");
+ assertNotNull(assetBundlor);
+ }
+
+ private void addBundlorConfigForAsset() throws CommitFailedException {
+ NodeBuilder builder = nodeStore.getRoot().builder();
+ NodeBuilder bundlor = builder.child("jcr:system").child("documentstore").child("bundlor");
+ bundlor.child("app:Asset").setProperty(DocumentBundlor.PROP_PATTERN, "metadata");
+ nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+ }
+
+}
\ No newline at end of file
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native