This is an automated email from the ASF dual-hosted git repository.
dlmarion pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new 40c99ccc48 Disable metrics for thread pools when metrics disabled
(#5605)
40c99ccc48 is described below
commit 40c99ccc48b1fb176e162d8861f3856472773022
Author: Dave Marion <[email protected]>
AuthorDate: Mon Jun 2 13:26:02 2025 -0400
Disable metrics for thread pools when metrics disabled (#5605)
Metrics were being registered and emitted for thread
pools regardless of the metrics property setting. Added
a mechanism to disable metrics collection for thread
pools when the property is false.
Co-authored-by: Keith Turner <[email protected]>
---
.../DefaultContextClassLoaderFactory.java | 2 +-
.../accumulo/core/clientImpl/ClientContext.java | 14 ++++++------
.../accumulo/core/util/threads/ThreadPools.java | 25 ++++++++++++++++++++--
.../accumulo/server/metrics/MetricsInfoImpl.java | 1 +
4 files changed, 32 insertions(+), 10 deletions(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/classloader/DefaultContextClassLoaderFactory.java
b/core/src/main/java/org/apache/accumulo/core/classloader/DefaultContextClassLoaderFactory.java
index cc829a908e..1bd5fcb670 100644
---
a/core/src/main/java/org/apache/accumulo/core/classloader/DefaultContextClassLoaderFactory.java
+++
b/core/src/main/java/org/apache/accumulo/core/classloader/DefaultContextClassLoaderFactory.java
@@ -74,7 +74,7 @@ public class DefaultContextClassLoaderFactory implements
ContextClassLoaderFacto
private static void startCleanupThread(final AccumuloConfiguration conf,
final Supplier<Map<String,String>> contextConfigSupplier) {
ScheduledFuture<?> future =
- ((ScheduledThreadPoolExecutor) ThreadPools.getClientThreadPools((t, e)
-> {
+ ((ScheduledThreadPoolExecutor) ThreadPools.getClientThreadPools(conf,
(t, e) -> {
LOG.error("context classloader cleanup thread has failed.", e);
}).createExecutorService(conf, Property.GENERAL_THREADPOOL_SIZE,
false))
.scheduleWithFixedDelay(Threads.createNamedRunnable(className +
"-cleanup", () -> {
diff --git
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
index c9e714f74c..2b154c0519 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
@@ -153,7 +153,7 @@ public class ClientContext implements AccumuloClient {
@SuppressWarnings("deprecation")
private org.apache.accumulo.core.client.admin.ReplicationOperations
replicationops = null;
private final SingletonReservation singletonReservation;
- private final ThreadPools clientThreadPools;
+ private final Supplier<ThreadPools> clientThreadPools;
private ThreadPoolExecutor cleanupThreadPool;
private ThreadPoolExecutor scannerReadaheadPool;
@@ -238,15 +238,15 @@ public class ClientContext implements AccumuloClient {
this.tableops = new TableOperationsImpl(this);
this.namespaceops = new NamespaceOperationsImpl(this, tableops);
if (ueh == Threads.UEH) {
- clientThreadPools = ThreadPools.getServerThreadPools();
+ clientThreadPools = () -> ThreadPools.getServerThreadPools();
} else {
// Provide a default UEH that just logs the error
if (ueh == null) {
- clientThreadPools = ThreadPools.getClientThreadPools((t, e) -> {
+ clientThreadPools = () ->
ThreadPools.getClientThreadPools(getConfiguration(), (t, e) -> {
log.error("Caught an Exception in client background thread: {}.
Thread is dead.", t, e);
});
} else {
- clientThreadPools = ThreadPools.getClientThreadPools(ueh);
+ clientThreadPools = () ->
ThreadPools.getClientThreadPools(getConfiguration(), ueh);
}
}
}
@@ -260,7 +260,7 @@ public class ClientContext implements AccumuloClient {
submitScannerReadAheadTask(Callable<List<KeyValue>> c) {
ensureOpen();
if (scannerReadaheadPool == null) {
- scannerReadaheadPool =
clientThreadPools.getPoolBuilder(SCANNER_READ_AHEAD_POOL)
+ scannerReadaheadPool =
clientThreadPools.get().getPoolBuilder(SCANNER_READ_AHEAD_POOL)
.numCoreThreads(0).numMaxThreads(Integer.MAX_VALUE).withTimeOut(3L,
SECONDS)
.withQueue(new SynchronousQueue<>()).build();
}
@@ -270,7 +270,7 @@ public class ClientContext implements AccumuloClient {
public synchronized void executeCleanupTask(Runnable r) {
ensureOpen();
if (cleanupThreadPool == null) {
- cleanupThreadPool =
clientThreadPools.getPoolBuilder(CONDITIONAL_WRITER_CLEANUP_POOL)
+ cleanupThreadPool =
clientThreadPools.get().getPoolBuilder(CONDITIONAL_WRITER_CLEANUP_POOL)
.numCoreThreads(1).withTimeOut(3L, SECONDS).build();
}
this.cleanupThreadPool.execute(r);
@@ -281,7 +281,7 @@ public class ClientContext implements AccumuloClient {
*/
public ThreadPools threadPools() {
ensureOpen();
- return clientThreadPools;
+ return clientThreadPools.get();
}
/**
diff --git
a/core/src/main/java/org/apache/accumulo/core/util/threads/ThreadPools.java
b/core/src/main/java/org/apache/accumulo/core/util/threads/ThreadPools.java
index b30505c1fc..e0c8873198 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/threads/ThreadPools.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/threads/ThreadPools.java
@@ -58,6 +58,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.IntSupplier;
@@ -99,9 +100,14 @@ public class ThreadPools {
return SERVER_INSTANCE;
}
- public static final ThreadPools
getClientThreadPools(UncaughtExceptionHandler ueh) {
+ public static final ThreadPools getClientThreadPools(AccumuloConfiguration
conf,
+ UncaughtExceptionHandler ueh) {
ThreadPools clientPools = new ThreadPools(ueh);
- clientPools.setMeterRegistry(Metrics.globalRegistry);
+ if (conf.getBoolean(Property.GENERAL_MICROMETER_ENABLED) == false) {
+ clientPools.disableThreadPoolMetrics();
+ } else {
+ clientPools.setMeterRegistry(Metrics.globalRegistry);
+ }
return clientPools;
}
@@ -718,10 +724,14 @@ public class ThreadPools {
return result;
}
+ private final AtomicBoolean metricsEnabled = new AtomicBoolean(true);
private final AtomicReference<MeterRegistry> registry = new
AtomicReference<>();
private final List<ExecutorServiceMetrics> earlyExecutorServices = new
ArrayList<>();
private void addExecutorServiceMetrics(ExecutorService executor, String
name) {
+ if (!metricsEnabled.get()) {
+ return;
+ }
ExecutorServiceMetrics esm = new ExecutorServiceMetrics(executor, name,
List.of());
synchronized (earlyExecutorServices) {
MeterRegistry r = registry.get();
@@ -743,4 +753,15 @@ public class ThreadPools {
}
}
+ /**
+ * Called by MetricsInfoImpl.init on the server side if metrics are
disabled. ClientContext calls
+ * {@code #getClientThreadPools(AccumuloConfiguration,
UncaughtExceptionHandler)} above.
+ */
+ public void disableThreadPoolMetrics() {
+ metricsEnabled.set(false);
+ synchronized (earlyExecutorServices) {
+ earlyExecutorServices.clear();
+ }
+ }
+
}
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
index 1249d901c0..b8434828a6 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
@@ -119,6 +119,7 @@ public class MetricsInfoImpl implements MetricsInfo {
Objects.requireNonNull(tags);
if (!metricsEnabled) {
+ ThreadPools.getServerThreadPools().disableThreadPoolMetrics();
LOG.info("Metrics not initialized, metrics are disabled.");
return;
}