This is an automated email from the ASF dual-hosted git repository.
guohao1225 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 94a8fbe41 RATIS-1917. Print Epoll.unavailabilityCause() only once.
(#949)
94a8fbe41 is described below
commit 94a8fbe419157b449a1fa534fe1fd2b970d09587
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Mon Oct 23 18:51:09 2023 -0700
RATIS-1917. Print Epoll.unavailabilityCause() only once. (#949)
* RATIS-1917. Print Epoll.unavailabilityCause() only once.
---
.../java/org/apache/ratis/netty/NettyUtils.java | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyUtils.java
b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyUtils.java
index 2b643d7c9..8cce291af 100644
--- a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyUtils.java
+++ b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyUtils.java
@@ -40,19 +40,37 @@ import org.slf4j.LoggerFactory;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
public interface NettyUtils {
Logger LOG = LoggerFactory.getLogger(NettyUtils.class);
+ class Print {
+ private static final AtomicBoolean PRINTED_EPOLL_UNAVAILABILITY_CAUSE =
new AtomicBoolean();
+
+ private Print() {}
+
+ static void epollUnavailability(String message) {
+ if (!LOG.isWarnEnabled()) {
+ return;
+ }
+ if (PRINTED_EPOLL_UNAVAILABILITY_CAUSE.compareAndSet(false, true)) {
+ LOG.warn(message, new IllegalStateException("Epoll is unavailable.",
Epoll.unavailabilityCause()));
+ } else {
+ LOG.warn(message);
+ }
+ }
+ }
+
static EventLoopGroup newEventLoopGroup(String name, int size, boolean
useEpoll) {
if (useEpoll) {
if (Epoll.isAvailable()) {
LOG.info("Create EpollEventLoopGroup for {}; Thread size is {}.",
name, size);
return new EpollEventLoopGroup(size,
ConcurrentUtils.newThreadFactory(name + "-"));
} else {
- LOG.warn("Failed to create EpollEventLoopGroup for " + name + "; fall
back on NioEventLoopGroup.",
- Epoll.unavailabilityCause());
+ Print.epollUnavailability("Failed to create EpollEventLoopGroup for "
+ name
+ + "; fall back on NioEventLoopGroup.");
}
}
return new NioEventLoopGroup(size, ConcurrentUtils.newThreadFactory(name +
"-"));