Author: alexparvulescu Date: Tue Apr 8 10:35:18 2014 New Revision: 1585680
URL: http://svn.apache.org/r1585680 Log: OAK-1684 Non-blocking reindexing doesn't save the initial checkpoint Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindex.java (with props) jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindexMBean.java (with props) jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/package-info.java (with props) Modified: jackrabbit/oak/trunk/oak-core/pom.xml jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryManagementMBean.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/management/RepositoryManager.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java Modified: jackrabbit/oak/trunk/oak-core/pom.xml URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/pom.xml?rev=1585680&r1=1585679&r2=1585680&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/pom.xml (original) +++ jackrabbit/oak/trunk/oak-core/pom.xml Tue Apr 8 10:35:18 2014 @@ -58,6 +58,7 @@ org.apache.jackrabbit.oak.plugins.index.aggregate, org.apache.jackrabbit.oak.plugins.index.nodetype, org.apache.jackrabbit.oak.plugins.index.property, + org.apache.jackrabbit.oak.plugins.index.property.jmx, org.apache.jackrabbit.oak.plugins.index.reference, org.apache.jackrabbit.oak.plugins.itemsave, org.apache.jackrabbit.oak.plugins.lock, Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1585680&r1=1585679&r2=1585680&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Tue Apr 8 10:35:18 2014 @@ -62,6 +62,8 @@ import org.apache.jackrabbit.oak.plugins import org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider; import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider; import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider; +import org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindex; +import org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindexMBean; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; import org.apache.jackrabbit.oak.query.QueryEngineSettings; import org.apache.jackrabbit.oak.spi.commit.CommitHook; @@ -508,6 +510,12 @@ public class Oak { scheduleWithFixedDelay(whiteboard, task, 5, true); registerMBean(whiteboard, IndexStatsMBean.class, task.getIndexStats(), IndexStatsMBean.TYPE, name); + + PropertyIndexAsyncReindex asyncPI = new PropertyIndexAsyncReindex( + new AsyncIndexUpdate("async-reindex", store, indexEditors, + true), executor); + registerMBean(whiteboard, PropertyIndexAsyncReindexMBean.class, + asyncPI, PropertyIndexAsyncReindexMBean.TYPE, name); } registerMBean(whiteboard, QueryEngineSettingsMBean.class, Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryManagementMBean.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryManagementMBean.java?rev=1585680&r1=1585679&r2=1585680&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryManagementMBean.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryManagementMBean.java Tue Apr 8 10:35:18 2014 @@ -175,4 +175,23 @@ public interface RepositoryManagementMBe @CheckForNull String checkpoint(long lifetime); + /** + * Initiate a reindex operation for the property indexes marked for + * reindexing + * + * @return the status of the operation right after it was initiated + */ + @Nonnull + CompositeData startPropertyIndexAsyncReindex(); + + /** + * Asynchronous Property Index reindexing status + * + * @return the status of the ongoing operation or if none the terminal + * status of the last operation or <em>Status not available</em> if + * none. + */ + @Nonnull + CompositeData getPropertyIndexAsyncReindexStatus(); + } Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/management/RepositoryManager.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/management/RepositoryManager.java?rev=1585680&r1=1585679&r2=1585680&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/management/RepositoryManager.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/management/RepositoryManager.java Tue Apr 8 10:35:18 2014 @@ -35,6 +35,7 @@ import com.google.common.base.Function; import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean; import org.apache.jackrabbit.oak.plugins.backup.FileStoreBackupRestoreMBean; import org.apache.jackrabbit.oak.plugins.blob.BlobGCMBean; +import org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindexMBean; import org.apache.jackrabbit.oak.spi.state.RevisionGCMBean; import org.apache.jackrabbit.oak.spi.whiteboard.Tracker; import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard; @@ -181,4 +182,30 @@ public class RepositoryManager implement : null; } + @Override + public CompositeData startPropertyIndexAsyncReindex() { + return execute(PropertyIndexAsyncReindexMBean.class, + new Function<PropertyIndexAsyncReindexMBean, Status>() { + @Nonnull + @Override + public Status apply(PropertyIndexAsyncReindexMBean reindexer) { + return fromCompositeData(reindexer + .startPropertyIndexAsyncReindex()); + } + }).toCompositeData(); + } + + @Override + public CompositeData getPropertyIndexAsyncReindexStatus() { + return execute(PropertyIndexAsyncReindexMBean.class, + new Function<PropertyIndexAsyncReindexMBean, Status>() { + @Nonnull + @Override + public Status apply(PropertyIndexAsyncReindexMBean reindexer) { + return fromCompositeData(reindexer + .getPropertyIndexAsyncReindexStatus()); + } + }).toCompositeData(); + } + } Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java?rev=1585680&r1=1585679&r2=1585680&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java Tue Apr 8 10:35:18 2014 @@ -126,7 +126,7 @@ public class AsyncIndexUpdate implements public void indexUpdate() throws CommitFailedException { if (!dirty) { dirty = true; - preAsyncRun(store, name, indexStats); + preAsyncRun(store, name); } } @@ -161,6 +161,7 @@ public class AsyncIndexUpdate implements } AsyncUpdateCallback callback = new AsyncUpdateCallback(); + preAsyncRunStatsStats(indexStats); IndexUpdate indexUpdate = new IndexUpdate(provider, name, after, builder, callback); @@ -170,7 +171,7 @@ public class AsyncIndexUpdate implements if (callback.dirty) { async.setProperty(name, checkpoint); try { - store.merge(builder, newCommitHook(name, state, indexStats), + store.merge(builder, newCommitHook(name, state), CommitInfo.EMPTY); } catch (CommitFailedException e) { if (e != CONCURRENT_UPDATE) { @@ -180,8 +181,10 @@ public class AsyncIndexUpdate implements if (switchOnSync) { reindexedDefinitions.addAll(indexUpdate .getReindexedDefinitions()); + } else { + postAsyncRunStatsStatus(indexStats); } - } else if (switchOnSync && !reindexedDefinitions.isEmpty()) { + } else if (switchOnSync) { log.debug("No changes detected after diff, will try to switch to synchronous updates on " + reindexedDefinitions); async.setProperty(name, checkpoint); @@ -198,9 +201,10 @@ public class AsyncIndexUpdate implements } try { - store.merge(builder, newCommitHook(name, state, indexStats), + store.merge(builder, newCommitHook(name, state), CommitInfo.EMPTY); reindexedDefinitions.clear(); + postAsyncRunStatsStatus(indexStats); } catch (CommitFailedException e) { if (e != CONCURRENT_UPDATE) { exception = e; @@ -223,8 +227,7 @@ public class AsyncIndexUpdate implements } private static CommitHook newCommitHook(final String name, - final PropertyState state, final AsyncIndexStats indexStats) - throws CommitFailedException { + final PropertyState state) throws CommitFailedException { return new CommitHook() { @Override @Nonnull @@ -234,7 +237,7 @@ public class AsyncIndexUpdate implements PropertyState stateAfterRebase = before.getChildNode(ASYNC) .getProperty(name); if (Objects.equal(state, stateAfterRebase)) { - return postAsyncRunStatus(after.builder(), indexStats, name) + return postAsyncRunNodeStatus(after.builder(), name) .getNodeState(); } else { throw CONCURRENT_UPDATE; @@ -243,10 +246,9 @@ public class AsyncIndexUpdate implements }; } - private static void preAsyncRun(NodeStore store, String name, - AsyncIndexStats stats) throws CommitFailedException { + private static void preAsyncRun(NodeStore store, String name) throws CommitFailedException { NodeBuilder builder = store.getRoot().builder(); - preAsyncRunStatus(builder, stats, name); + preAsyncRunNodeStatus(builder, name); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); } @@ -278,20 +280,21 @@ public class AsyncIndexUpdate implements return false; } - private static void preAsyncRunStatus(NodeBuilder builder, - AsyncIndexStats stats, String name) { + private static void preAsyncRunNodeStatus(NodeBuilder builder, String name) { String now = now(); - stats.start(now); builder.getChildNode(INDEX_DEFINITIONS_NAME) .setProperty(name + "-status", STATUS_RUNNING) .setProperty(name + "-start", now, Type.DATE) .removeProperty(name + "-done"); } - private static NodeBuilder postAsyncRunStatus(NodeBuilder builder, - AsyncIndexStats stats, String name) { + private static void preAsyncRunStatsStats(AsyncIndexStats stats) { + stats.start(now()); + } + + private static NodeBuilder postAsyncRunNodeStatus(NodeBuilder builder, + String name) { String now = now(); - stats.done(now); builder.getChildNode(INDEX_DEFINITIONS_NAME) .setProperty(name + "-status", STATUS_DONE) .setProperty(name + "-done", now, Type.DATE) @@ -299,6 +302,10 @@ public class AsyncIndexUpdate implements return builder; } + private static void postAsyncRunStatsStatus(AsyncIndexStats stats) { + stats.done(now()); + } + private static String now() { return ISO8601.format(Calendar.getInstance()); } @@ -307,6 +314,10 @@ public class AsyncIndexUpdate implements return indexStats; } + public boolean isFinished() { + return indexStats.getStatus() == STATUS_DONE; + } + private static final class AsyncIndexStats implements IndexStatsMBean { private String start = ""; @@ -339,6 +350,12 @@ public class AsyncIndexUpdate implements public String getStatus() { return status; } + + @Override + public String toString() { + return "AsyncIndexStats [start=" + start + ", done=" + done + + ", status=" + status + "]"; + } } } Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindex.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindex.java?rev=1585680&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindex.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindex.java Tue Apr 8 10:35:18 2014 @@ -0,0 +1,85 @@ +/* + * 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.index.property.jmx; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.System.nanoTime; +import static org.apache.jackrabbit.oak.management.ManagementOperation.done; + +import java.util.concurrent.Callable; +import java.util.concurrent.Executor; + +import javax.annotation.Nonnull; +import javax.management.openmbean.CompositeData; + +import org.apache.jackrabbit.oak.management.ManagementOperation; +import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate; + +/** + * Default implementation of {@link PropertyIndexAsyncReindexMBean} based on a + * {@code Runnable}. + */ +public class PropertyIndexAsyncReindex implements + PropertyIndexAsyncReindexMBean { + + public static final String OP_NAME = "Property index asynchronous reindex"; + + private final AsyncIndexUpdate async; + private final Executor executor; + + private ManagementOperation arOp = done(OP_NAME, 0); + + /** + * @param gc + * Revision garbage collector + * @param executor + * executor for running the garbage collection task + */ + public PropertyIndexAsyncReindex(@Nonnull AsyncIndexUpdate async, + @Nonnull Executor executor) { + this.async = checkNotNull(async); + this.executor = checkNotNull(executor); + } + + @Nonnull + @Override + public CompositeData startPropertyIndexAsyncReindex() { + if (arOp.isDone()) { + arOp = new ManagementOperation(OP_NAME, new Callable<Long>() { + @Override + public Long call() throws Exception { + long t0 = nanoTime(); + boolean done = false; + while (!done) { + async.run(); + done = async.isFinished(); + } + return nanoTime() - t0; + } + }); + executor.execute(arOp); + } + return getPropertyIndexAsyncReindexStatus(); + } + + @Nonnull + @Override + public CompositeData getPropertyIndexAsyncReindexStatus() { + return arOp.getStatus().toCompositeData(); + } +} Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindex.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindexMBean.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindexMBean.java?rev=1585680&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindexMBean.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindexMBean.java Tue Apr 8 10:35:18 2014 @@ -0,0 +1,52 @@ +/* + * 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.index.property.jmx; + +import javax.annotation.Nonnull; +import javax.management.openmbean.CompositeData; + +/** + * MBean for starting and monitoring the progress of asynchronous reindexing of + * the property index + * + * @see org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean + */ +public interface PropertyIndexAsyncReindexMBean { + + String TYPE = "PropertyIndexAsyncReindex"; + + /** + * Initiate a reindex operation for the property indexes marked for + * reindexing + * + * @return the status of the operation right after it was initiated + */ + @Nonnull + CompositeData startPropertyIndexAsyncReindex(); + + /** + * Asynchronous Property Index reindexing status + * + * @return the status of the ongoing operation or if none the terminal + * status of the last operation or <em>Status not available</em> if + * none. + */ + @Nonnull + CompositeData getPropertyIndexAsyncReindexStatus(); + +} Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/PropertyIndexAsyncReindexMBean.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/package-info.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/package-info.java?rev=1585680&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/package-info.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/package-info.java Tue Apr 8 10:35:18 2014 @@ -0,0 +1,22 @@ +/* + * 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. + */ +@Version("0.21.0") +@Export(optional = "provide:=true") +package org.apache.jackrabbit.oak.plugins.index.property.jmx; + +import aQute.bnd.annotation.Version; +import aQute.bnd.annotation.Export; \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/jmx/package-info.java ------------------------------------------------------------------------------ svn:mime-type = text/plain