LUCENE-10088: allow per-class override in HandleLimitFS. Bump the limit a bit for nightlies in TestIndexWriterMergePolicy. (#424)

This commit is contained in:
Dawid Weiss 2021-11-04 08:31:28 +01:00 committed by GitHub
parent 1ae6b2a6b9
commit adec73dd28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 9 deletions

View File

@ -28,12 +28,14 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.StringField; import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.mockfile.HandleLimitFS;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
@HandleLimitFS.MaxOpenHandles(limit = HandleLimitFS.MaxOpenHandles.MAX_OPEN_FILES * 2)
public class TestIndexWriterMergePolicy extends LuceneTestCase { public class TestIndexWriterMergePolicy extends LuceneTestCase {
// Test the normal case // Test the normal case
@ -772,9 +774,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
if (random().nextBoolean()) { if (random().nextBoolean()) {
writer.commit(); writer.commit();
} }
try (DirectoryReader open = try (DirectoryReader delegate = DirectoryReader.open(directory);
new SoftDeletesDirectoryReaderWrapper( DirectoryReader open =
DirectoryReader.open(directory), "___soft_deletes")) { new SoftDeletesDirectoryReaderWrapper(delegate, "___soft_deletes")) {
assertEquals( assertEquals(
1, 1,
new IndexSearcher(open) new IndexSearcher(open)

View File

@ -17,16 +17,38 @@
package org.apache.lucene.mockfile; package org.apache.lucene.mockfile;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.file.FileSystem; import java.nio.file.FileSystem;
import java.nio.file.FileSystemException; import java.nio.file.FileSystemException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** FileSystem that throws exception if file handles in use exceeds a specified limit */ /**
* FileSystem that throws exception if file handles in use exceeds a specified limit.
*
* @see MaxOpenHandles
*/
public class HandleLimitFS extends HandleTrackingFS { public class HandleLimitFS extends HandleTrackingFS {
final int limit; final int limit;
final AtomicInteger count = new AtomicInteger(); final AtomicInteger count = new AtomicInteger();
/** An annotation */
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public static @interface MaxOpenHandles {
// TODO: can we make the default even lower?
public static final int MAX_OPEN_FILES = 2048;
int limit();
}
/** /**
* Create a new instance, limiting the maximum number of open files to {@code limit} * Create a new instance, limiting the maximum number of open files to {@code limit}
* *

View File

@ -100,10 +100,6 @@ final class TestRuleTemporaryFilesCleanup extends TestRuleAdapter {
javaTempDir = initializeJavaTempDir(); javaTempDir = initializeJavaTempDir();
} }
// os/config-independent limit for too many open files
// TODO: can we make this lower?
private static final int MAX_OPEN_FILES = 2048;
private boolean allowed(Set<String> avoid, Class<? extends FileSystemProvider> clazz) { private boolean allowed(Set<String> avoid, Class<? extends FileSystemProvider> clazz) {
if (avoid.contains("*") || avoid.contains(clazz.getSimpleName())) { if (avoid.contains("*") || avoid.contains(clazz.getSimpleName())) {
return false; return false;
@ -152,7 +148,11 @@ final class TestRuleTemporaryFilesCleanup extends TestRuleAdapter {
fs = new LeakFS(fs).getFileSystem(null); fs = new LeakFS(fs).getFileSystem(null);
} }
if (allowed(avoid, HandleLimitFS.class)) { if (allowed(avoid, HandleLimitFS.class)) {
fs = new HandleLimitFS(fs, MAX_OPEN_FILES).getFileSystem(null); int limit = HandleLimitFS.MaxOpenHandles.MAX_OPEN_FILES;
if (targetClass.isAnnotationPresent(HandleLimitFS.MaxOpenHandles.class)) {
limit = targetClass.getAnnotation(HandleLimitFS.MaxOpenHandles.class).limit();
}
fs = new HandleLimitFS(fs, limit).getFileSystem(null);
} }
// windows is currently slow // windows is currently slow
if (random.nextInt(10) == 0) { if (random.nextInt(10) == 0) {