Author: chetanm Date: Tue Oct 3 12:58:55 2017 New Revision: 1811003 URL: http://svn.apache.org/viewvc?rev=1811003&view=rev Log: OAK-6535 - Synchronous Lucene Property Indexes
Return the stats from cleanup run as return value instead of just boolean Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleaner.java jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleanerTest.java Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleaner.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleaner.java?rev=1811003&r1=1811002&r2=1811003&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleaner.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleaner.java Tue Oct 3 12:58:55 2017 @@ -32,7 +32,6 @@ import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableMap; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.commons.PathUtils; -import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfo; import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService; import org.apache.jackrabbit.oak.plugins.index.IndexPathService; import org.apache.jackrabbit.oak.plugins.index.IndexUtils; @@ -85,14 +84,16 @@ public class PropertyIndexCleaner implem * * @return true if the cleanup was attempted */ - public boolean performCleanup() throws CommitFailedException { + public CleanupStats performCleanup() throws CommitFailedException { + CleanupStats stats = new CleanupStats(); Stopwatch w = Stopwatch.createStarted(); Map<String, Long> asyncInfo = asyncIndexInfoService.getIndexedUptoPerLane(); if (lastAsyncInfo.equals(asyncInfo)) { log.debug("No change found in async state from last run {}. Skipping the run", asyncInfo); - return false; + return stats; } - CleanupStats stats = new CleanupStats(); + + stats.cleanupPerformed = true; List<String> syncIndexes = getSyncIndexPaths(); IndexInfo indexInfo = switchBucketsAndCollectIndexData(syncIndexes, asyncInfo, stats); @@ -106,7 +107,7 @@ public class PropertyIndexCleaner implem log.debug("Property index cleanup done in {}. {}", w, stats); } - return true; + return stats; } /** @@ -201,7 +202,7 @@ public class PropertyIndexCleaner implem bucket.remove(); } - stats.bucketCount = bucketPaths.size(); + stats.purgedBucketCount = bucketPaths.size(); merge(builder); } @@ -259,15 +260,16 @@ public class PropertyIndexCleaner implem final Map<String, Long> uniqueIndexPaths = new HashMap<>(); } - private static class CleanupStats { - int uniqueIndexEntryRemovalCount; - int bucketCount; - Set<String> purgedIndexPaths = new HashSet<>(); + public static class CleanupStats { + public int uniqueIndexEntryRemovalCount; + public int purgedBucketCount; + public Set<String> purgedIndexPaths = new HashSet<>(); + public boolean cleanupPerformed; @Override public String toString() { return String.format("Removed %d index buckets, %d unique index entries " + - "from indexes %s", bucketCount, uniqueIndexEntryRemovalCount, purgedIndexPaths); + "from indexes %s", purgedBucketCount, uniqueIndexEntryRemovalCount, purgedIndexPaths); } } } Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleanerTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleanerTest.java?rev=1811003&r1=1811002&r2=1811003&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleanerTest.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/PropertyIndexCleanerTest.java Tue Oct 3 12:58:55 2017 @@ -34,6 +34,7 @@ import org.apache.jackrabbit.oak.plugins import org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition; import org.apache.jackrabbit.oak.plugins.index.lucene.PropertyDefinition; import org.apache.jackrabbit.oak.plugins.index.lucene.PropertyUpdateCallback; +import org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyIndexCleaner.CleanupStats; import org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; import org.apache.jackrabbit.oak.plugins.memory.PropertyValues; @@ -115,7 +116,7 @@ public class PropertyIndexCleanerTest { //------------------------ Run 1 asyncService.addInfo("async", 1000); - assertTrue(cleaner.performCleanup()); + assertCleanUpPerformed(cleaner.performCleanup(), true); assertThat(query(indexPath, "foo", "bar"), containsInAnyOrder("/a")); @@ -128,14 +129,14 @@ public class PropertyIndexCleanerTest { //------------------------ Run 2 asyncService.addInfo("async", 2000); - assertTrue(cleaner.performCleanup()); + assertCleanUpPerformed(cleaner.performCleanup(), true); //Now /a would be part of removed bucket assertThat(query(indexPath, "foo", "bar"), containsInAnyOrder("/b")); //------------------------ Run 3 asyncService.addInfo("async", 3000); - assertTrue(cleaner.performCleanup()); + assertCleanUpPerformed(cleaner.performCleanup(), true); //With another run /b would also be removed assertThat(query(indexPath, "foo", "bar"), empty()); @@ -173,7 +174,7 @@ public class PropertyIndexCleanerTest { //------------------------ Run 1 asyncService.addInfo("async", 1200); - assertTrue(cleaner.performCleanup()); + assertCleanUpPerformed(cleaner.performCleanup(), true); // /a would be purged, /b would be retained as its created time 1150 is not older than 100 wrt // indexer time of 1200 @@ -193,7 +194,7 @@ public class PropertyIndexCleanerTest { //------------------------ Run 2 asyncService.addInfo("async", 1400); - assertTrue(cleaner.performCleanup()); + assertCleanUpPerformed(cleaner.performCleanup(), true); //Both entries would have been purged assertThat(query(indexPath, "foo", "bar"), empty()); @@ -219,10 +220,14 @@ public class PropertyIndexCleanerTest { //------------------------ Run 1 asyncService.addInfo("async", 1000); - assertTrue(cleaner.performCleanup()); + assertCleanUpPerformed(cleaner.performCleanup(), true); //Second run should not run - assertFalse(cleaner.performCleanup()); + assertCleanUpPerformed(cleaner.performCleanup(), false); + } + + private void assertCleanUpPerformed(CleanupStats stats, boolean expected) { + assertEquals(expected, stats.cleanupPerformed); } private void addIndex(String indexPath, IndexDefinitionBuilder defnb) throws CommitFailedException {