Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: updating error message in thread pool supplier #3001

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.connectors.resources;

import glide.api.logging.Logger;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.kqueue.KQueue;
import java.util.function.Supplier;
Expand Down Expand Up @@ -30,6 +31,13 @@ public static class Capabilities {
private final boolean isNIOAvailable;
}

/**
* String which accumulates with report of checking platform capabilities. Thrown with an
* exception if neither epoll/kqueue available. TODO: replace with logging Note: logging into
* files may be unavailable in AWS lambda.
*/
private static String debugInfo = "Detailed report of checking platform capabilities\n";

/** Detected platform (OS + JVM) capabilities. Not supposed to be changed in runtime. */
@Getter
private static final Capabilities capabilities =
Expand All @@ -38,32 +46,57 @@ public static class Capabilities {
/** Detect <em>kqueue</em> availability. */
private static boolean isKQueueAvailable() {
try {
debugInfo += "Checking KQUEUE...\n";
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
Class.forName("io.netty.channel.kqueue.KQueue");
return KQueue.isAvailable();
debugInfo += "KQUEUE class found\n";
var res = KQueue.isAvailable();
debugInfo += "KQUEUE is" + (res ? " " : " not") + " available\n";
if (!res) {
debugInfo += "Reason: " + KQueue.unavailabilityCause() + "\n";
}
return res;
} catch (ClassNotFoundException e) {
debugInfo += "Exception checking KQUEUE:\n" + e + "\n";
return false;
}
}

/** Detect <em>epoll</em> availability. */
private static boolean isEPollAvailable() {
try {
debugInfo += "Checking EPOLL...\n";
Class.forName("io.netty.channel.epoll.Epoll");
return Epoll.isAvailable();
debugInfo += "EPOLL class found\n";
var res = Epoll.isAvailable();
debugInfo += "EPOLL is" + (res ? " " : " not") + " available\n";
if (!res) {
debugInfo += "Reason: " + Epoll.unavailabilityCause() + "\n";
}
return res;
} catch (ClassNotFoundException e) {
debugInfo += "Exception checking EPOLL\n" + e + "\n";
return false;
}
}

public static Supplier<ThreadPoolResource> getThreadPoolResourceSupplier() {
if (Platform.getCapabilities().isKQueueAvailable()) {
if (capabilities.isKQueueAvailable()) {
return KQueuePoolResource::new;
}

if (Platform.getCapabilities().isEPollAvailable()) {
if (capabilities.isEPollAvailable()) {
return EpollResource::new;
}

// TODO support IO-Uring and NIO
throw new RuntimeException("Current platform supports no known thread pool resources");
String errorMessage =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this adequately describes the problem, and identifies some system information, is there an solution, fixes, or workarounds that the user might try to resolve the issue?

String.format(
"Cannot load Netty native components for the current os version and arch: %s %s %s.\n",
System.getProperty("os.name"),
System.getProperty("os.version"),
System.getProperty("os.arch"));

throw new RuntimeException(
errorMessage + (Logger.getLoggerLevel() == Logger.Level.DEBUG ? debugInfo : ""));
}
}
Loading