Remove and forbid usage of Thread#getAllThreadGroups()

This method needs special permission and can cause all kinds of other problems
if we are creating lots of theads. Also the reason why we added this are fixed
long ago, no need to maintain this code.
This commit is contained in:
Simon Willnauer 2015-10-27 21:13:48 +01:00
parent 935a8fc3d4
commit 5fc1c8ba95
4 changed files with 17 additions and 57 deletions

View File

@ -326,28 +326,21 @@ public abstract class ESIntegTestCase extends ESTestCase {
protected final void beforeInternal() throws Exception {
assert Thread.getDefaultUncaughtExceptionHandler() instanceof ElasticsearchUncaughtExceptionHandler;
try {
final Scope currentClusterScope = getCurrentClusterScope();
switch (currentClusterScope) {
case SUITE:
assert SUITE_SEED != null : "Suite seed was not initialized";
currentCluster = buildAndPutCluster(currentClusterScope, SUITE_SEED);
break;
case TEST:
currentCluster = buildAndPutCluster(currentClusterScope, randomLong());
break;
default:
fail("Unknown Scope: [" + currentClusterScope + "]");
}
cluster().beforeTest(getRandom(), getPerTestTransportClientRatio());
cluster().wipe(excludeTemplates());
randomIndexTemplate();
} catch (OutOfMemoryError e) {
if (e.getMessage().contains("unable to create new native thread")) {
ESTestCase.printStackDump(logger);
}
throw e;
final Scope currentClusterScope = getCurrentClusterScope();
switch (currentClusterScope) {
case SUITE:
assert SUITE_SEED != null : "Suite seed was not initialized";
currentCluster = buildAndPutCluster(currentClusterScope, SUITE_SEED);
break;
case TEST:
currentCluster = buildAndPutCluster(currentClusterScope, randomLong());
break;
default:
fail("Unknown Scope: [" + currentClusterScope + "]");
}
cluster().beforeTest(getRandom(), getPerTestTransportClientRatio());
cluster().wipe(excludeTemplates());
randomIndexTemplate();
}
private void printTestMessage(String message) {

View File

@ -570,41 +570,11 @@ public abstract class ESTestCase extends LuceneTestCase {
if (e.getMessage() != null && ((EsRejectedExecutionException) e).isExecutorShutdown()) {
return; // ignore the EsRejectedExecutionException when a node shuts down
}
} else if (e instanceof OutOfMemoryError) {
if (e.getMessage() != null && e.getMessage().contains("unable to create new native thread")) {
printStackDump(logger);
}
}
parent.uncaughtException(t, e);
}
}
protected static final void printStackDump(ESLogger logger) {
// print stack traces if we can't create any native thread anymore
Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
logger.error(formatThreadStacks(allStackTraces));
}
/** Dump threads and their current stack trace. */
public static String formatThreadStacks(Map<Thread, StackTraceElement[]> threads) {
StringBuilder message = new StringBuilder();
int cnt = 1;
final Formatter f = new Formatter(message, Locale.ENGLISH);
for (Map.Entry<Thread, StackTraceElement[]> e : threads.entrySet()) {
if (e.getKey().isAlive()) {
f.format(Locale.ENGLISH, "\n %2d) %s", cnt++, threadName(e.getKey())).flush();
}
if (e.getValue().length == 0) {
message.append("\n at (empty stack)");
} else {
for (StackTraceElement ste : e.getValue()) {
message.append("\n at ").append(ste);
}
}
}
return message.toString();
}
private static String threadName(Thread t) {
return "Thread[" +
"id=" + t.getId() +

View File

@ -153,12 +153,6 @@ public abstract class TestCluster implements Iterable<Client>, Closeable {
assertAcked(client().admin().indices().prepareDelete(concreteIndices.toArray(String.class)));
}
}
} catch (AssertionError ae) {
// Try to see what threads are doing when we hit the "Delete index failed - not acked":
logger.info("dump all threads on AssertionError");
ESTestCase.printStackDump(logger);
logger.info("done dump all threads on AssertionError");
throw ae;
}
}
}

View File

@ -97,3 +97,6 @@ java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObj
@defaultMessage this should not have been added to lucene in the first place
org.apache.lucene.index.IndexReader#getCombinedCoreAndDeletesKey()
@defaultMessage this method needs special permission
java.lang.Thread#getAllStackTraces()