Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java (revision 1777538) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java (working copy) @@ -490,7 +490,7 @@ beforeCheckpoint = null; callback.setCheckpoint(beforeCheckpoint); before = MISSING_NODE; - } else if (noVisibleChanges(state, root)) { + } else if (noVisibleChanges(state, root) && !switchOnSync) { log.debug( "[{}] No changes since last checkpoint; skipping the index update", name); @@ -611,11 +611,11 @@ } void cleanUpCheckpoints() { - log.debug("Cleaning up orphaned checkpoints"); + log.debug("[{}] Cleaning up orphaned checkpoints", name); Set keep = newHashSet(); String cp = indexStats.getReferenceCheckpoint(); if (cp == null) { - log.warn("No reference checkpoint set in index stats"); + log.warn("[{}] No reference checkpoint set in index stats", name); return; } keep.add(cp); @@ -639,8 +639,8 @@ && AsyncIndexUpdate.class.getSimpleName().equals(creator) && (created == null || ISO8601.parse(created).getTimeInMillis() + leaseTimeOut < current)) { if (store.release(checkpoint)) { - log.info("Removed orphaned checkpoint '{}' {}", - checkpoint, info); + log.info("[{}] Removed orphaned checkpoint '{}' {}", + name, checkpoint, info); } } } @@ -713,6 +713,12 @@ } } reindexedDefinitions.clear(); + if (store.release(afterCheckpoint)) { + builder.child(ASYNC).removeProperty(name); + builder.child(ASYNC).removeProperty(lastIndexedTo); + } else { + log.debug("[{}] Unable to release checkpoint {}", name, afterCheckpoint); + } } updatePostRunStatus = true; } Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java (revision 1777538) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/AsyncPropertyIndexTest.java (working copy) @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.plugins.index.property; import static com.google.common.collect.ImmutableSet.of; -import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM; import static org.apache.jackrabbit.JcrConstants.NT_BASE; import static org.apache.jackrabbit.oak.api.Type.STRINGS; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ASYNC_PROPERTY_NAME; @@ -25,10 +24,10 @@ import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_ASYNC_PROPERTY_NAME; import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefinition; -import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES; import static org.apache.jackrabbit.oak.spi.commit.CommitInfo.EMPTY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.Set; @@ -52,6 +51,7 @@ import org.junit.Test; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.common.collect.Sets; /** @@ -66,6 +66,7 @@ @Test public void testAsyncPropertyLookup() throws Exception { NodeStore store = new MemoryNodeStore(); + assertTrue(Iterables.isEmpty(store.checkpoints())); NodeBuilder builder = store.getRoot().builder(); @@ -101,8 +102,10 @@ // run async second time, there are no changes, should switch to sync async.run(); + async.close(); assertEquals(null, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME) .getChildNode("foo").getString(ASYNC_PROPERTY_NAME)); + assertTrue(Iterables.isEmpty(store.checkpoints())); // add content, it should be indexed synchronously builder = store.getRoot().builder(); @@ -127,4 +130,15 @@ : PropertyValues.newString(value))); } + @Test + public void testAsyncPropertyNoChanges() throws Exception { + NodeStore store = new MemoryNodeStore(); + assertTrue(Iterables.isEmpty(store.checkpoints())); + AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, + store, provider, true); + async.run(); + async.run(); + async.close(); + assertTrue(Iterables.isEmpty(store.checkpoints())); + } }