From 6fb836c25e6cb31972ca24dc3f9739e7660d620e Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 23 Jun 2012 18:35:42 +0200 Subject: [PATCH] better thread naming --- .../elasticsearch/bootstrap/Bootstrap.java | 2 +- .../client/transport/TransportClient.java | 2 +- .../org/elasticsearch/common/Unicode.java | 2 +- .../common/netty/NettyStaticSetup.java | 37 ++++++ .../common/thread/ThreadNameDeterminer.java | 61 --------- .../common/thread/ThreadRenamingRunnable.java | 122 ------------------ .../common/util/concurrent/EsExecutors.java | 50 ++++--- .../concurrent}/LoggingRunnable.java | 2 +- .../concurrent}/ThreadLocals.java | 2 +- .../http/netty/NettyHttpServerTransport.java | 11 +- .../index/field/data/FieldData.java | 2 +- .../data/bytes/MultiValueByteFieldData.java | 2 +- .../data/bytes/SingleValueByteFieldData.java | 2 +- .../doubles/MultiValueDoubleFieldData.java | 2 +- .../doubles/SingleValueDoubleFieldData.java | 2 +- .../data/floats/MultiValueFloatFieldData.java | 2 +- .../floats/SingleValueFloatFieldData.java | 2 +- .../data/ints/MultiValueIntFieldData.java | 2 +- .../data/ints/SingleValueIntFieldData.java | 2 +- .../index/field/data/longs/LongFieldData.java | 2 +- .../data/longs/MultiValueLongFieldData.java | 2 +- .../data/longs/SingleValueLongFieldData.java | 2 +- .../data/shorts/MultiValueShortFieldData.java | 2 +- .../shorts/SingleValueShortFieldData.java | 2 +- .../strings/MultiValueStringFieldData.java | 2 +- .../strings/SingleValueStringFieldData.java | 2 +- .../index/mapper/geo/GeoPointFieldData.java | 2 +- .../geo/MultiValueGeoPointFieldData.java | 2 +- .../geo/SingleValueGeoPointFieldData.java | 2 +- .../ConcurrentMergeSchedulerProvider.java | 3 +- .../node/internal/InternalNode.java | 2 +- .../rest/StringRestResponse.java | 2 +- .../rest/XContentRestResponse.java | 2 +- .../elasticsearch/search/dfs/DfsPhase.java | 2 +- .../terms/longs/TermsLongFacetCollector.java | 2 +- .../strings/TermsStringFacetCollector.java | 2 +- .../search/internal/InternalSearchHits.java | 2 +- .../elasticsearch/threadpool/ThreadPool.java | 4 +- .../transport/netty/NettyTransport.java | 10 +- .../util/concurrent/EsExecutorsTests.java | 4 +- 40 files changed, 100 insertions(+), 264 deletions(-) create mode 100644 src/main/java/org/elasticsearch/common/netty/NettyStaticSetup.java delete mode 100644 src/main/java/org/elasticsearch/common/thread/ThreadNameDeterminer.java delete mode 100644 src/main/java/org/elasticsearch/common/thread/ThreadRenamingRunnable.java rename src/main/java/org/elasticsearch/common/{thread => util/concurrent}/LoggingRunnable.java (96%) rename src/main/java/org/elasticsearch/common/{thread => util/concurrent}/ThreadLocals.java (99%) diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 3ab8f368b34..f3768dbf8f8 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -224,7 +224,7 @@ public class Bootstrap { // bail out } } - }, "es[keepAlive]"); + }, "elasticsearch[keepAlive]"); keepAliveThread.setDaemon(false); keepAliveThread.start(); } catch (Throwable e) { diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 1082f9ed43e..21472577c54 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -57,8 +57,8 @@ import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; -import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.monitor.MonitorService; diff --git a/src/main/java/org/elasticsearch/common/Unicode.java b/src/main/java/org/elasticsearch/common/Unicode.java index 800149d20fa..a11d5a94331 100644 --- a/src/main/java/org/elasticsearch/common/Unicode.java +++ b/src/main/java/org/elasticsearch/common/Unicode.java @@ -20,7 +20,7 @@ package org.elasticsearch.common; import org.apache.lucene.util.UnicodeUtil; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import java.util.Arrays; diff --git a/src/main/java/org/elasticsearch/common/netty/NettyStaticSetup.java b/src/main/java/org/elasticsearch/common/netty/NettyStaticSetup.java new file mode 100644 index 00000000000..7fb91662f02 --- /dev/null +++ b/src/main/java/org/elasticsearch/common/netty/NettyStaticSetup.java @@ -0,0 +1,37 @@ +package org.elasticsearch.common.netty; + +import org.elasticsearch.transport.netty.NettyInternalESLoggerFactory; +import org.jboss.netty.logging.InternalLogger; +import org.jboss.netty.logging.InternalLoggerFactory; +import org.jboss.netty.util.ThreadNameDeterminer; +import org.jboss.netty.util.ThreadRenamingRunnable; + +/** + */ +public class NettyStaticSetup { + + private static EsThreadNameDeterminer ES_THREAD_NAME_DETERMINER = new EsThreadNameDeterminer(); + + public static class EsThreadNameDeterminer implements ThreadNameDeterminer { + @Override + public String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception { + // we control the thread name with a context, so use both + return currentThreadName + "{" + proposedThreadName + "}"; + } + } + + static { + InternalLoggerFactory.setDefaultFactory(new NettyInternalESLoggerFactory() { + @Override + public InternalLogger newInstance(String name) { + return super.newInstance(name.replace("org.jboss.netty.", "netty.").replace("org.jboss.netty.", "netty.")); + } + }); + + ThreadRenamingRunnable.setThreadNameDeterminer(ES_THREAD_NAME_DETERMINER); + } + + public static void setup() { + + } +} diff --git a/src/main/java/org/elasticsearch/common/thread/ThreadNameDeterminer.java b/src/main/java/org/elasticsearch/common/thread/ThreadNameDeterminer.java deleted file mode 100644 index a5a2668e621..00000000000 --- a/src/main/java/org/elasticsearch/common/thread/ThreadNameDeterminer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.thread; - -/** - * Overrides the thread name proposed by {@link ThreadRenamingRunnable}. - * - * - */ -public interface ThreadNameDeterminer { - - /** - * {@link ThreadNameDeterminer} that accepts the proposed thread name - * as is. - */ - ThreadNameDeterminer PROPOSED = new ThreadNameDeterminer() { - public String determineThreadName(String currentThreadName, - String proposedThreadName) throws Exception { - return proposedThreadName; - } - }; - - /** - * {@link ThreadNameDeterminer} that rejects the proposed thread name and - * retains the current one. - */ - ThreadNameDeterminer CURRENT = new ThreadNameDeterminer() { - public String determineThreadName(String currentThreadName, - String proposedThreadName) throws Exception { - return null; - } - }; - - /** - * Overrides the thread name proposed by {@link ThreadRenamingRunnable}. - * - * @param currentThreadName the current thread name - * @param proposedThreadName the proposed new thread name - * @return the actual new thread name. - * If {@code null} is returned, the proposed thread name is - * discarded (i.e. no rename). - */ - String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception; -} diff --git a/src/main/java/org/elasticsearch/common/thread/ThreadRenamingRunnable.java b/src/main/java/org/elasticsearch/common/thread/ThreadRenamingRunnable.java deleted file mode 100644 index 11b8014d748..00000000000 --- a/src/main/java/org/elasticsearch/common/thread/ThreadRenamingRunnable.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.thread; - -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; - -/** - * A {@link Runnable} that changes the current thread name and reverts it back - * when its execution ends. To change the default thread names set by Netty, - * use {@link #setThreadNameDeterminer(ThreadNameDeterminer)}. - * - * - */ -public class ThreadRenamingRunnable implements Runnable { - - private static final ESLogger logger = Loggers.getLogger(ThreadRenamingRunnable.class); - - private static volatile ThreadNameDeterminer threadNameDeterminer = - ThreadNameDeterminer.PROPOSED; - - /** - * Returns the {@link ThreadNameDeterminer} which overrides the proposed - * new thread name. - */ - public static ThreadNameDeterminer getThreadNameDeterminer() { - return threadNameDeterminer; - } - - /** - * Sets the {@link ThreadNameDeterminer} which overrides the proposed new - * thread name. Please note that the specified {@link ThreadNameDeterminer} - * affects only new {@link ThreadRenamingRunnable}s; the existing instances - * are not affected at all. Therefore, you should make sure to call this - * method at the earliest possible point (i.e. before any Netty worker - * thread starts) for consistent thread naming. Otherwise, you might see - * the default thread names and the new names appear at the same time in - * the full thread dump. - */ - public static void setThreadNameDeterminer(ThreadNameDeterminer threadNameDeterminer) { - if (threadNameDeterminer == null) { - throw new NullPointerException("threadNameDeterminer"); - } - ThreadRenamingRunnable.threadNameDeterminer = threadNameDeterminer; - } - - private final Runnable runnable; - private final String proposedThreadName; - - /** - * Creates a new instance which wraps the specified {@code runnable} - * and changes the thread name to the specified thread name when the - * specified {@code runnable} is running. - */ - public ThreadRenamingRunnable(Runnable runnable, String proposedThreadName) { - if (runnable == null) { - throw new NullPointerException("runnable"); - } - if (proposedThreadName == null) { - throw new NullPointerException("proposedThreadName"); - } - this.runnable = runnable; - this.proposedThreadName = proposedThreadName; - } - - public void run() { - final Thread currentThread = Thread.currentThread(); - final String oldThreadName = currentThread.getName(); - final String newThreadName = getNewThreadName(oldThreadName); - - // Change the thread name before starting the actual runnable. - boolean renamed = false; - if (!oldThreadName.equals(newThreadName)) { - try { - currentThread.setName(newThreadName); - renamed = true; - } catch (SecurityException e) { - logger.debug("Failed to rename a thread due to security restriction.", e); - } - } - - // Run the actual runnable and revert the name back when it ends. - try { - runnable.run(); - } finally { - if (renamed) { - // Revert the name back if the current thread was renamed. - // We do not check the exception here because we know it works. - currentThread.setName(oldThreadName); - } - } - } - - private String getNewThreadName(String currentThreadName) { - String newThreadName = null; - - try { - newThreadName = getThreadNameDeterminer().determineThreadName(currentThreadName, proposedThreadName); - } catch (Throwable t) { - logger.warn("Failed to determine the thread name", t); - } - - return newThreadName == null ? currentThreadName : newThreadName; - } -} diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java b/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java index 4f10fea7681..e6b69f18efc 100644 --- a/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java +++ b/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java @@ -23,6 +23,7 @@ import jsr166y.LinkedTransferQueue; import org.elasticsearch.common.settings.Settings; import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; /** * @@ -56,44 +57,37 @@ public class EsExecutors { } else { name = "elasticsearch[" + name + "]"; } - return name + namePrefix; + return name + "[" + namePrefix + "]"; } public static ThreadFactory daemonThreadFactory(Settings settings, String namePrefix) { return daemonThreadFactory(threadName(settings, namePrefix)); } - /** - * A priority based thread factory, for all Thread priority constants: - * Thread.MIN_PRIORITY, Thread.NORM_PRIORITY, Thread.MAX_PRIORITY; - *

- * This factory is used instead of Executers.DefaultThreadFactory to allow - * manipulation of priority and thread owner name. - * - * @param namePrefix a name prefix for this thread - * @return a thread factory based on given priority. - */ public static ThreadFactory daemonThreadFactory(String namePrefix) { - final ThreadFactory f = java.util.concurrent.Executors.defaultThreadFactory(); - final String o = namePrefix + "-"; + return new EsThreadFactory(namePrefix); + } - return new ThreadFactory() { - public Thread newThread(Runnable r) { - Thread t = f.newThread(r); + static class EsThreadFactory implements ThreadFactory { + final ThreadGroup group; + final AtomicInteger threadNumber = new AtomicInteger(1); + final String namePrefix; - /* - * Thread name: owner-pool-N-thread-M, where N is the sequence - * number of this factory, and M is the sequence number of the - * thread created by this factory. - */ - t.setName(o + t.getName()); + public EsThreadFactory(String namePrefix) { + this.namePrefix = namePrefix; + SecurityManager s = System.getSecurityManager(); + group = (s != null) ? s.getThreadGroup() : + Thread.currentThread().getThreadGroup(); + } - /* override default definition t.setDaemon(false); */ - t.setDaemon(true); - - return t; - } - }; + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(group, r, + namePrefix + "[T#" + threadNumber.getAndIncrement() + "]", + 0); + t.setDaemon(true); + return t; + } } /** diff --git a/src/main/java/org/elasticsearch/common/thread/LoggingRunnable.java b/src/main/java/org/elasticsearch/common/util/concurrent/LoggingRunnable.java similarity index 96% rename from src/main/java/org/elasticsearch/common/thread/LoggingRunnable.java rename to src/main/java/org/elasticsearch/common/util/concurrent/LoggingRunnable.java index 3b30391862b..d3aea059929 100644 --- a/src/main/java/org/elasticsearch/common/thread/LoggingRunnable.java +++ b/src/main/java/org/elasticsearch/common/util/concurrent/LoggingRunnable.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.common.thread; +package org.elasticsearch.common.util.concurrent; import org.elasticsearch.common.logging.ESLogger; diff --git a/src/main/java/org/elasticsearch/common/thread/ThreadLocals.java b/src/main/java/org/elasticsearch/common/util/concurrent/ThreadLocals.java similarity index 99% rename from src/main/java/org/elasticsearch/common/thread/ThreadLocals.java rename to src/main/java/org/elasticsearch/common/util/concurrent/ThreadLocals.java index e0dd365a81e..9a886b612db 100644 --- a/src/main/java/org/elasticsearch/common/thread/ThreadLocals.java +++ b/src/main/java/org/elasticsearch/common/util/concurrent/ThreadLocals.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.common.thread; +package org.elasticsearch.common.util.concurrent; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java b/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java index 6808676644b..28af592ae89 100644 --- a/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java +++ b/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java @@ -22,6 +22,7 @@ package org.elasticsearch.http.netty; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.netty.NettyStaticSetup; import org.elasticsearch.common.netty.OpenChannelsHandler; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.network.NetworkUtils; @@ -35,15 +36,12 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.http.*; import org.elasticsearch.http.HttpRequest; import org.elasticsearch.transport.BindTransportException; -import org.elasticsearch.transport.netty.NettyInternalESLoggerFactory; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.*; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory; import org.jboss.netty.handler.codec.http.*; import org.jboss.netty.handler.timeout.ReadTimeoutException; -import org.jboss.netty.logging.InternalLogger; -import org.jboss.netty.logging.InternalLoggerFactory; import java.io.IOException; import java.net.InetAddress; @@ -60,12 +58,7 @@ import static org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadF public class NettyHttpServerTransport extends AbstractLifecycleComponent implements HttpServerTransport { static { - InternalLoggerFactory.setDefaultFactory(new NettyInternalESLoggerFactory() { - @Override - public InternalLogger newInstance(String name) { - return super.newInstance(name.replace("org.jboss.netty.", "netty.").replace("org.jboss.netty.", "netty.")); - } - }); + NettyStaticSetup.setup(); } private final NetworkService networkService; diff --git a/src/main/java/org/elasticsearch/index/field/data/FieldData.java b/src/main/java/org/elasticsearch/index/field/data/FieldData.java index 337e47c76a8..3a200f59a71 100644 --- a/src/main/java/org/elasticsearch/index/field/data/FieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/FieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data; import org.apache.lucene.index.IndexReader; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import java.io.IOException; diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java b/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java index 8728342d410..f72b0d003e6 100644 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.bytes; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java b/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java index 85a7d2234df..8d3cf2581d8 100644 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.bytes; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java b/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java index 8e60c57fa34..373464ce621 100644 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.doubles; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; /** * diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java b/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java index 5c4dcaf7f7a..f79f1748b93 100644 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.doubles; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; /** * diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java b/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java index b08facd8fb8..1da88e1f501 100644 --- a/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.floats; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java b/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java index 80276769182..36eded25658 100644 --- a/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.floats; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java b/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java index 6751d480280..7c28608d6ad 100644 --- a/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.ints; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java b/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java index e23bd19bd50..50ece5f3397 100644 --- a/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.ints; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldData.java b/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldData.java index 3d8e337df7d..c5127bd3dfd 100644 --- a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldData.java @@ -23,7 +23,7 @@ import gnu.trove.list.array.TLongArrayList; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.FieldCache; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.NumericFieldData; import org.elasticsearch.index.field.data.support.FieldDataLoader; diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java b/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java index d72caf81227..0a9619d7e2a 100644 --- a/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.longs; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.joda.time.DateTimeZone; import org.joda.time.MutableDateTime; diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java b/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java index f29faa3aeee..2b0beaf0d54 100644 --- a/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.longs; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.joda.time.DateTimeZone; import org.joda.time.MutableDateTime; diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java b/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java index 3bad20c9800..6ce48478582 100644 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.shorts; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java b/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java index 4e349a7d1e9..6a9f0791675 100644 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.field.data.shorts; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; /** diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/MultiValueStringFieldData.java b/src/main/java/org/elasticsearch/index/field/data/strings/MultiValueStringFieldData.java index 50c86bbd411..020a17e612e 100644 --- a/src/main/java/org/elasticsearch/index/field/data/strings/MultiValueStringFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/strings/MultiValueStringFieldData.java @@ -21,7 +21,7 @@ package org.elasticsearch.index.field.data.strings; import org.elasticsearch.common.RamUsage; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; /** * diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/SingleValueStringFieldData.java b/src/main/java/org/elasticsearch/index/field/data/strings/SingleValueStringFieldData.java index fe17a1600cb..bc325cc1329 100644 --- a/src/main/java/org/elasticsearch/index/field/data/strings/SingleValueStringFieldData.java +++ b/src/main/java/org/elasticsearch/index/field/data/strings/SingleValueStringFieldData.java @@ -21,7 +21,7 @@ package org.elasticsearch.index.field.data.strings; import org.elasticsearch.common.RamUsage; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; /** * diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldData.java b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldData.java index 43e7c4e98d8..2b7cc774815 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldData.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldData.java @@ -22,8 +22,8 @@ package org.elasticsearch.index.mapper.geo; import gnu.trove.list.array.TDoubleArrayList; import org.apache.lucene.index.IndexReader; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.unit.DistanceUnit; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.support.FieldDataLoader; diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/MultiValueGeoPointFieldData.java b/src/main/java/org/elasticsearch/index/mapper/geo/MultiValueGeoPointFieldData.java index a011dd3fbad..bb2879e72c8 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/MultiValueGeoPointFieldData.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/MultiValueGeoPointFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.mapper.geo; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.search.geo.GeoHashUtils; diff --git a/src/main/java/org/elasticsearch/index/mapper/geo/SingleValueGeoPointFieldData.java b/src/main/java/org/elasticsearch/index/mapper/geo/SingleValueGeoPointFieldData.java index 8a734399f57..dff1d70f955 100644 --- a/src/main/java/org/elasticsearch/index/mapper/geo/SingleValueGeoPointFieldData.java +++ b/src/main/java/org/elasticsearch/index/mapper/geo/SingleValueGeoPointFieldData.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.mapper.geo; import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.field.data.doubles.DoubleFieldData; import org.elasticsearch.index.search.geo.GeoHashUtils; diff --git a/src/main/java/org/elasticsearch/index/merge/scheduler/ConcurrentMergeSchedulerProvider.java b/src/main/java/org/elasticsearch/index/merge/scheduler/ConcurrentMergeSchedulerProvider.java index 3a5de07697b..f976c4ed0e9 100644 --- a/src/main/java/org/elasticsearch/index/merge/scheduler/ConcurrentMergeSchedulerProvider.java +++ b/src/main/java/org/elasticsearch/index/merge/scheduler/ConcurrentMergeSchedulerProvider.java @@ -24,6 +24,7 @@ import org.apache.lucene.store.AlreadyClosedException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.index.merge.MergeStats; import org.elasticsearch.index.merge.policy.EnableMergePolicy; import org.elasticsearch.index.settings.IndexSettings; @@ -111,7 +112,7 @@ public class ConcurrentMergeSchedulerProvider extends AbstractIndexShardComponen @Override protected MergeThread getMergeThread(IndexWriter writer, MergePolicy.OneMerge merge) throws IOException { MergeThread thread = super.getMergeThread(writer, merge); - thread.setName("[" + shardId.index().name() + "][" + shardId.id() + "]: " + thread.getName()); + thread.setName(EsExecutors.threadName(provider.indexSettings(), "[" + shardId.index().name() + "][" + shardId.id() + "]: " + thread.getName())); return thread; } diff --git a/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/src/main/java/org/elasticsearch/node/internal/InternalNode.java index a98f54510b6..7bc7aae745d 100644 --- a/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -46,7 +46,7 @@ import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoveryService; import org.elasticsearch.env.Environment; diff --git a/src/main/java/org/elasticsearch/rest/StringRestResponse.java b/src/main/java/org/elasticsearch/rest/StringRestResponse.java index f517bd65a3e..7f2a2454783 100644 --- a/src/main/java/org/elasticsearch/rest/StringRestResponse.java +++ b/src/main/java/org/elasticsearch/rest/StringRestResponse.java @@ -20,7 +20,7 @@ package org.elasticsearch.rest; import org.apache.lucene.util.UnicodeUtil; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; /** * diff --git a/src/main/java/org/elasticsearch/rest/XContentRestResponse.java b/src/main/java/org/elasticsearch/rest/XContentRestResponse.java index 7bbfe19f3f0..d64bd04ee42 100644 --- a/src/main/java/org/elasticsearch/rest/XContentRestResponse.java +++ b/src/main/java/org/elasticsearch/rest/XContentRestResponse.java @@ -20,7 +20,7 @@ package org.elasticsearch.rest; import org.apache.lucene.util.UnicodeUtil; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; diff --git a/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java b/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java index 34615bed346..b0378653b98 100644 --- a/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java +++ b/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java @@ -22,7 +22,7 @@ package org.elasticsearch.search.dfs; import com.google.common.collect.ImmutableMap; import gnu.trove.set.hash.THashSet; import org.apache.lucene.index.Term; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.internal.SearchContext; diff --git a/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetCollector.java b/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetCollector.java index e68a873465a..475059c1ebe 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetCollector.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetCollector.java @@ -29,7 +29,7 @@ import org.apache.lucene.search.Scorer; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.collect.BoundedTreeSet; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.longs.LongFieldData; diff --git a/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringFacetCollector.java b/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringFacetCollector.java index 681a68e43a9..0caf691f723 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringFacetCollector.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringFacetCollector.java @@ -27,7 +27,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Scorer; import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.collect.BoundedTreeSet; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.FieldDataType; diff --git a/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java b/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java index d7acede5405..1e5bd887408 100644 --- a/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java +++ b/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java @@ -23,7 +23,7 @@ import com.google.common.collect.Iterators; import gnu.trove.map.hash.TIntObjectHashMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.thread.ThreadLocals; +import org.elasticsearch.common.util.concurrent.ThreadLocals; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.search.SearchHit; diff --git a/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 6518779e441..a79d3fe92fb 100644 --- a/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -104,7 +104,7 @@ public class ThreadPool extends AbstractComponent { executors.put(Names.SNAPSHOT, build(Names.SNAPSHOT, "scaling", groupSettings.get(Names.SNAPSHOT), settingsBuilder().put("keep_alive", "5m").put("size", 5).build())); executors.put(Names.SAME, new ExecutorHolder(MoreExecutors.sameThreadExecutor(), new Info(Names.SAME, "same"))); this.executors = ImmutableMap.copyOf(executors); - this.scheduler = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, EsExecutors.daemonThreadFactory(settings, "[scheduler]")); + this.scheduler = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, EsExecutors.daemonThreadFactory(settings, "scheduler")); this.scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); this.scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); @@ -216,7 +216,7 @@ public class ThreadPool extends AbstractComponent { settings = ImmutableSettings.Builder.EMPTY_SETTINGS; } String type = settings.get("type", defaultType); - ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(this.settings, "[" + name + "]"); + ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(this.settings, name); if ("same".equals(type)) { logger.debug("creating thread_pool [{}], type [{}]", name, type); return new ExecutorHolder(MoreExecutors.sameThreadExecutor(), new Info(name, type)); diff --git a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index 8bd017ddde5..cc00b375593 100644 --- a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.CachedStreamOutput; import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.netty.NettyStaticSetup; import org.elasticsearch.common.netty.OpenChannelsHandler; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.network.NetworkUtils; @@ -51,8 +52,6 @@ import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory; -import org.jboss.netty.logging.InternalLogger; -import org.jboss.netty.logging.InternalLoggerFactory; import java.io.IOException; import java.net.InetAddress; @@ -81,12 +80,7 @@ import static org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadF public class NettyTransport extends AbstractLifecycleComponent implements Transport { static { - InternalLoggerFactory.setDefaultFactory(new NettyInternalESLoggerFactory() { - @Override - public InternalLogger newInstance(String name) { - return super.newInstance(name.replace("org.jboss.netty.", "netty.").replace("org.jboss.netty.", "netty.")); - } - }); + NettyStaticSetup.setup(); } private final NetworkService networkService; diff --git a/src/test/java/org/elasticsearch/test/unit/common/util/concurrent/EsExecutorsTests.java b/src/test/java/org/elasticsearch/test/unit/common/util/concurrent/EsExecutorsTests.java index 3023595f449..1ca931904f2 100644 --- a/src/test/java/org/elasticsearch/test/unit/common/util/concurrent/EsExecutorsTests.java +++ b/src/test/java/org/elasticsearch/test/unit/common/util/concurrent/EsExecutorsTests.java @@ -20,10 +20,10 @@ package org.elasticsearch.test.unit.common.util.concurrent; import org.elasticsearch.common.util.concurrent.EsExecutors; +import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.util.concurrent.ThreadBarrier; import org.testng.annotations.Test; -import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -161,7 +161,7 @@ public class EsExecutorsTests { } }); assertThat("Should have thrown RejectedExecutionException", false, equalTo(true)); - } catch (RejectedExecutionException e) { + } catch (EsRejectedExecutionException e) { //caught expected exception }