Author: chetanm
Date: Fri Jul 28 06:03:44 2017
New Revision: 1803247
URL: http://svn.apache.org/viewvc?rev=1803247&view=rev
Log:
OAK-6500 - NRTIndex leaks file handles due to unclosed IndexReader
Refactor code to allow customizing creation of NRTCachingDirectory.
Later it would be used to force use of SimpleDirectory for simulating
file handle leakage
Added:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTDirectoryFactory.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndex.java
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndexFactory.java
Added:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTDirectoryFactory.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTDirectoryFactory.java?rev=1803247&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTDirectoryFactory.java
(added)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTDirectoryFactory.java
Fri Jul 28 06:03:44 2017
@@ -0,0 +1,31 @@
+/*
+ * 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.lucene.hybrid;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition;
+import org.apache.lucene.store.Directory;
+
+interface NRTDirectoryFactory {
+
+ Directory createNRTDir(IndexDefinition definition, File indexDir) throws
IOException;
+}
Propchange:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTDirectoryFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndex.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndex.java?rev=1803247&r1=1803246&r2=1803247&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndex.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndex.java
Fri Jul 28 06:03:44 2017
@@ -75,6 +75,7 @@ public class NRTIndex implements Closeab
private final TimerStats refreshTimer;
private final HistogramStats sizeHisto;
private final TimerStats.Context openTime;
+ private final NRTDirectoryFactory directoryFactory;
private NRTIndex previous;
@@ -88,12 +89,13 @@ public class NRTIndex implements Closeab
public NRTIndex(IndexDefinition definition, IndexCopier indexCopier,
IndexUpdateListener refreshPolicy, @Nullable NRTIndex
previous,
- StatisticsProvider statisticsProvider) {
+ StatisticsProvider statisticsProvider, NRTDirectoryFactory
directoryFactory) {
this.definition = definition;
this.indexCopier = indexCopier;
this.refreshPolicy = refreshPolicy;
this.previous = previous;
this.statisticsProvider = statisticsProvider;
+ this.directoryFactory = directoryFactory;
this.refreshTimer =
statisticsProvider.getTimer(metricName("REFRESH_TIME"),
StatsOptions.METRICS_ONLY);
this.sizeHisto = statisticsProvider.getHistogram(metricName("SIZE"),
StatsOptions.METRICS_ONLY);
@@ -222,9 +224,7 @@ public class NRTIndex implements Closeab
private synchronized NRTIndexWriter createWriter() throws IOException {
String dirName = generateDirName();
indexDir = indexCopier.getIndexDir(definition,
definition.getIndexPath(), dirName);
- Directory fsdir = FSDirectory.open(indexDir);
- //TODO make these configurable
- directory = new NRTCachingDirectory(fsdir, 1, 1);
+ directory = directoryFactory.createNRTDir(definition, indexDir);
IndexWriterConfig config =
IndexWriterUtils.getIndexWriterConfig(definition, false);
//TODO Explore following for optimizing indexing speed
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndexFactory.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndexFactory.java?rev=1803247&r1=1803246&r2=1803247&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndexFactory.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/NRTIndexFactory.java
Fri Jul 28 06:03:44 2017
@@ -20,6 +20,7 @@
package org.apache.jackrabbit.oak.plugins.index.lucene.hybrid;
import java.io.Closeable;
+import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -32,6 +33,9 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition;
import org.apache.jackrabbit.oak.stats.Clock;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.NRTCachingDirectory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,6 +56,7 @@ public class NRTIndexFactory implements
private final Clock clock;
private final long refreshDeltaInSecs;
private final StatisticsProvider statisticsProvider;
+ private NRTDirectoryFactory directoryFactory =
DefaultNRTDirFactory.INSTANCE;
public NRTIndexFactory(IndexCopier indexCopier, StatisticsProvider
statisticsProvider) {
this(indexCopier, Clock.SIMPLE, REFRESH_DELTA_IN_SECS,
statisticsProvider);
@@ -75,7 +80,7 @@ public class NRTIndexFactory implements
}
String indexPath = definition.getIndexPath();
NRTIndex current = new NRTIndex(definition, indexCopier,
getRefreshPolicy(definition),
- getPrevious(indexPath), statisticsProvider);
+ getPrevious(indexPath), statisticsProvider, directoryFactory);
indexes.put(indexPath, current);
closeLast(indexPath);
return current;
@@ -93,6 +98,10 @@ public class NRTIndexFactory implements
return indexes.get(path);
}
+ public void setDirectoryFactory(NRTDirectoryFactory directoryFactory) {
+ this.directoryFactory = directoryFactory;
+ }
+
private void closeLast(String indexPath) {
List<NRTIndex> existing = indexes.get(indexPath);
if (existing.size() <= MAX_INDEX_COUNT){
@@ -122,4 +131,15 @@ public class NRTIndexFactory implements
}
return new TimedRefreshPolicy(clock, TimeUnit.SECONDS,
refreshDeltaInSecs);
}
+
+ private enum DefaultNRTDirFactory implements NRTDirectoryFactory {
+ INSTANCE;
+
+ @Override
+ public Directory createNRTDir(IndexDefinition definition, File
indexDir) throws IOException {
+ Directory fsdir = FSDirectory.open(indexDir);
+ //TODO make these configurable
+ return new NRTCachingDirectory(fsdir, 1, 1);
+ }
+ }
}