Author: chetanm
Date: Fri Nov 18 12:25:25 2016
New Revision: 1770372
URL: http://svn.apache.org/viewvc?rev=1770372&view=rev
Log:
OAK-4836 - Avoid excessive logging in case of corrupt index or mis-configured
index defnition
Update MBean to show failed index details
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTracker.java
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBean.java
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImpl.java
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTracker.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTracker.java?rev=1770372&r1=1770371&r2=1770372&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTracker.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTracker.java
Fri Nov 18 12:25:25 2016
@@ -107,6 +107,7 @@ class BadIndexTracker {
class BadIndexInfo {
final String path;
final int lastIndexerCycleCount = indexerCycleCount;
+ private final long createdTime =
TimeUnit.NANOSECONDS.toMillis(ticker.read());
private final Stopwatch created = Stopwatch.createStarted(ticker);
private final Stopwatch watch = Stopwatch.createStarted(ticker);
private String exception;
@@ -145,6 +146,14 @@ class BadIndexTracker {
return accessCount;
}
+ public String getException() {
+ return exception;
+ }
+
+ public long getCreatedTime() {
+ return createdTime;
+ }
+
private int getCycleCount() {
return indexerCycleCount - lastIndexerCycleCount;
}
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBean.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBean.java?rev=1770372&r1=1770371&r2=1770372&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBean.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBean.java
Fri Nov 18 12:25:25 2016
@@ -31,6 +31,10 @@ public interface LuceneIndexMBean {
TabularData getIndexStats() throws IOException;
+ TabularData getBadIndexStats();
+
+ boolean isFailing();
+
@Description("Determines the set of index paths upto given maxLevel. This
can be used to determine the value for" +
"[includedPaths]. For this to work you should have
[evaluatePathRestrictions] set to true in your index " +
"definition")
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImpl.java?rev=1770372&r1=1770371&r2=1770372&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexMBeanImpl.java
Fri Nov 18 12:25:25 2016
@@ -41,11 +41,9 @@ import javax.management.openmbean.Tabula
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.collect.TreeTraverser;
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
+import
org.apache.jackrabbit.oak.plugins.index.lucene.BadIndexTracker.BadIndexInfo;
import
org.apache.jackrabbit.oak.plugins.index.lucene.LucenePropertyIndex.PathStoredFieldVisitor;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
@@ -106,6 +104,32 @@ public class LuceneIndexMBeanImpl extend
}
@Override
+ public TabularData getBadIndexStats() {
+ TabularDataSupport tds;
+ try {
+ TabularType tt = new
TabularType(LuceneIndexMBeanImpl.class.getName(),
+ "Lucene Bad Index Stats", BadIndexStats.TYPE, new
String[]{"path"});
+ tds = new TabularDataSupport(tt);
+ Set<String> indexes =
indexTracker.getBadIndexTracker().getIndexPaths();
+ for (String path : indexes) {
+ BadIndexInfo info =
indexTracker.getBadIndexTracker().getInfo(path);
+ if (info != null){
+ BadIndexStats stats = new BadIndexStats(info);
+ tds.put(stats.toCompositeData());
+ }
+ }
+ } catch (OpenDataException e) {
+ throw new IllegalStateException(e);
+ }
+ return tds;
+ }
+
+ @Override
+ public boolean isFailing() {
+ return !indexTracker.getBadIndexTracker().getIndexPaths().isEmpty();
+ }
+
+ @Override
public String[] getIndexedPaths(String indexPath, int maxLevel, int
maxPathCount) throws IOException {
IndexNode indexNode = null;
try {
@@ -387,6 +411,64 @@ public class LuceneIndexMBeanImpl extend
}
}
+ private static class BadIndexStats {
+ static final String[] FIELD_NAMES = new String[]{
+ "path",
+ "stats",
+ "failingSince",
+ "exception"
+ };
+
+ static final String[] FIELD_DESCRIPTIONS = new String[]{
+ "Path",
+ "Failure stats",
+ "Failure start time",
+ "Exception"
+ };
+
+ @SuppressWarnings("rawtypes")
+ static final OpenType[] FIELD_TYPES = new OpenType[]{
+ SimpleType.STRING,
+ SimpleType.STRING,
+ SimpleType.STRING,
+ SimpleType.STRING,
+ };
+
+ static final CompositeType TYPE = createCompositeType();
+
+ static CompositeType createCompositeType() {
+ try {
+ return new CompositeType(
+ BadIndexStats.class.getName(),
+ "Composite data type for Lucene Bad Index statistics",
+ BadIndexStats.FIELD_NAMES,
+ BadIndexStats.FIELD_DESCRIPTIONS,
+ BadIndexStats.FIELD_TYPES);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private final BadIndexInfo info;
+
+ public BadIndexStats(BadIndexInfo info){
+ this.info = info;
+ }
+
+ CompositeDataSupport toCompositeData() {
+ Object[] values = new Object[]{
+ info.path,
+ info.getStats(),
+ String.format("%tc", info.getCreatedTime()),
+ info.getException(),
+ };
+ try {
+ return new CompositeDataSupport(TYPE, FIELD_NAMES, values);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
//~---------------------------------------------------------< Internal >
private static Directory getDirectory(IndexReader reader) {