This is an automated email from the ASF dual-hosted git repository.
apolovtsev pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new e176800a88 IGNITE-22976 Remove CriticalWorkerWatchdog message
duplication (#4220)
e176800a88 is described below
commit e176800a88992097184b73367244df6f4c6d9709
Author: Alexander Polovtcev <[email protected]>
AuthorDate: Tue Aug 13 12:18:11 2024 +0300
IGNITE-22976 Remove CriticalWorkerWatchdog message duplication (#4220)
---
.../org/apache/ignite/lang/IgniteException.java | 47 ++++++++++++++++++----
.../ignite/internal/failure/FailureProcessor.java | 6 +--
modules/workers/build.gradle | 1 +
.../worker/ItCriticalWorkerMonitoringTest.java | 6 +--
.../internal/worker/CriticalWorkerWatchdog.java | 20 ++++-----
5 files changed, 57 insertions(+), 23 deletions(-)
diff --git
a/modules/api/src/main/java/org/apache/ignite/lang/IgniteException.java
b/modules/api/src/main/java/org/apache/ignite/lang/IgniteException.java
index 3c3fcd9eb5..ab5f5c61e4 100644
--- a/modules/api/src/main/java/org/apache/ignite/lang/IgniteException.java
+++ b/modules/api/src/main/java/org/apache/ignite/lang/IgniteException.java
@@ -49,7 +49,12 @@ public class IgniteException extends RuntimeException
implements TraceableExcept
*/
private final int code;
- /** Unique identifier of the exception that helps locate the error message
in a log file. */
+ /**
+ * Unique identifier of the exception that helps locate the error message
in a log file.
+ *
+ * <p>Not {@code final} because it gets accessed via reflection when
creating a copy.
+ */
+ @SuppressWarnings({"NonFinalFieldOfException", "FieldMayBeFinal"})
private UUID traceId;
/**
@@ -122,6 +127,17 @@ public class IgniteException extends RuntimeException
implements TraceableExcept
this(UUID.randomUUID(), code, message);
}
+ /**
+ * Creates an exception with the given error code and detailed message
with the ability to skip filling in the stacktrace.
+ *
+ * @param code Full error code.
+ * @param message Detailed message.
+ * @param writableStackTrace Whether or not the stack trace should be
writable.
+ */
+ public IgniteException(int code, String message, boolean
writableStackTrace) {
+ this(UUID.randomUUID(), code, message, null, true, writableStackTrace);
+ }
+
/**
* Creates an exception with the given trace ID, error code, and detailed
message.
*
@@ -130,11 +146,7 @@ public class IgniteException extends RuntimeException
implements TraceableExcept
* @param message Detailed message.
*/
public IgniteException(UUID traceId, int code, String message) {
- super(message);
-
- this.traceId = traceId;
- this.groupName = errorGroupByCode(code).name();
- this.code = code;
+ this(traceId, code, message, null);
}
/**
@@ -182,7 +194,28 @@ public class IgniteException extends RuntimeException
implements TraceableExcept
* @param cause Optional nested exception (can be {@code null}).
*/
public IgniteException(UUID traceId, int code, String message, @Nullable
Throwable cause) {
- super(message, cause);
+ this(traceId, code, message, cause, true, true);
+ }
+
+ /**
+ * Creates an exception with the given trace ID, error code, and detailed
message.
+ *
+ * @param traceId Unique identifier of this exception.
+ * @param code Full error code.
+ * @param message Detailed message.
+ * @param cause Optional nested exception (can be {@code null}).
+ * @param enableSuppression Whether or not suppression is enabled or
disabled.
+ * @param writableStackTrace Whether or not the stack trace should be
writable.
+ */
+ public IgniteException(
+ UUID traceId,
+ int code,
+ String message,
+ @Nullable Throwable cause,
+ boolean enableSuppression,
+ boolean writableStackTrace
+ ) {
+ super(message, cause, enableSuppression, writableStackTrace);
this.traceId = traceId;
this.groupName = errorGroupByCode(code).name();
diff --git
a/modules/failure-handler/src/main/java/org/apache/ignite/internal/failure/FailureProcessor.java
b/modules/failure-handler/src/main/java/org/apache/ignite/internal/failure/FailureProcessor.java
index 82fecc98cb..60be935d24 100644
---
a/modules/failure-handler/src/main/java/org/apache/ignite/internal/failure/FailureProcessor.java
+++
b/modules/failure-handler/src/main/java/org/apache/ignite/internal/failure/FailureProcessor.java
@@ -54,7 +54,7 @@ public class FailureProcessor implements IgniteComponent {
+ "Will be handled accordingly to configured handler [hnd={},
failureCtx={}]";
/** Ignored failure log message. */
- private static final String IGNORED_FAILURE_LOG_MSG = "Possible failure
suppressed accordingly to a configured handler "
+ private static final String IGNORED_FAILURE_LOG_MSG = "Possible failure
suppressed according to a configured handler "
+ "[hnd={}, failureCtx={}]";
/** Failure processor configuration. */
@@ -146,9 +146,9 @@ public class FailureProcessor implements IgniteComponent {
}
if (handler.ignoredFailureTypes().contains(failureCtx.type())) {
- LOG.warn(IGNORED_FAILURE_LOG_MSG, failureCtx.error(), handler,
failureCtx);
+ LOG.warn(IGNORED_FAILURE_LOG_MSG, failureCtx.error(), handler,
failureCtx.type());
} else {
- LOG.error(FAILURE_LOG_MSG, failureCtx.error(), handler,
failureCtx);
+ LOG.error(FAILURE_LOG_MSG, failureCtx.error(), handler,
failureCtx.type());
}
boolean invalidated = handler.onFailure(failureCtx);
diff --git a/modules/workers/build.gradle b/modules/workers/build.gradle
index 8d637a43c1..7bb8facb5b 100644
--- a/modules/workers/build.gradle
+++ b/modules/workers/build.gradle
@@ -46,6 +46,7 @@ dependencies {
integrationTestImplementation project(':ignite-table')
integrationTestImplementation project(':ignite-raft')
integrationTestImplementation project(':ignite-partition-replicator')
+ integrationTestImplementation project(':ignite-failure-handler')
integrationTestImplementation testFixtures(project(':ignite-runner'))
integrationTestImplementation testFixtures(project(':ignite-core'))
integrationTestImplementation libs.netty.transport
diff --git
a/modules/workers/src/integrationTest/java/org/apache/ignite/internal/worker/ItCriticalWorkerMonitoringTest.java
b/modules/workers/src/integrationTest/java/org/apache/ignite/internal/worker/ItCriticalWorkerMonitoringTest.java
index 7f6a235240..9d705e802f 100644
---
a/modules/workers/src/integrationTest/java/org/apache/ignite/internal/worker/ItCriticalWorkerMonitoringTest.java
+++
b/modules/workers/src/integrationTest/java/org/apache/ignite/internal/worker/ItCriticalWorkerMonitoringTest.java
@@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.failure.FailureProcessor;
import
org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessageGroup;
import
org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessagesFactory;
import
org.apache.ignite.internal.partition.replicator.network.raft.SnapshotMetaResponse;
@@ -33,9 +34,8 @@ import org.apache.logging.log4j.core.LogEvent;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-@SuppressWarnings("resource")
class ItCriticalWorkerMonitoringTest extends ClusterPerTestIntegrationTest {
- private final LogInspector watchdogLogInspector =
LogInspector.create(CriticalWorkerWatchdog.class, true);
+ private final LogInspector watchdogLogInspector =
LogInspector.create(FailureProcessor.class, true);
@Override
protected int initialNodes() {
@@ -75,7 +75,7 @@ class ItCriticalWorkerMonitoringTest extends
ClusterPerTestIntegrationTest {
private static boolean matchesWithDotall(LogEvent event, String regex) {
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
- return
pattern.matcher(event.getMessage().getFormattedMessage()).matches();
+ return pattern.matcher(event.getThrown().getMessage()).matches();
}
private static String criticalThreadDetectedRegex(String threadSignature) {
diff --git
a/modules/workers/src/main/java/org/apache/ignite/internal/worker/CriticalWorkerWatchdog.java
b/modules/workers/src/main/java/org/apache/ignite/internal/worker/CriticalWorkerWatchdog.java
index 1c9178d999..040e1232a9 100644
---
a/modules/workers/src/main/java/org/apache/ignite/internal/worker/CriticalWorkerWatchdog.java
+++
b/modules/workers/src/main/java/org/apache/ignite/internal/worker/CriticalWorkerWatchdog.java
@@ -139,18 +139,19 @@ public class CriticalWorkerWatchdog implements
CriticalWorkerRegistry, IgniteCom
for (ThreadInfo threadInfo : threadInfos) {
if (threadInfo != null) {
- String message = String.format(
- "A critical thread is blocked for %d ms that is more
than the allowed %d ms, it is %s",
- delayedThreadIdsToDelays.get(threadInfo.getThreadId()),
- maxAllowedLag,
- toString(threadInfo));
+ StringBuilder message = new StringBuilder()
+ .append("A critical thread is blocked for ")
+
.append(delayedThreadIdsToDelays.get(threadInfo.getThreadId()))
+ .append(" ms that is more than the allowed ")
+ .append(maxAllowedLag)
+ .append(" ms, it is ");
- LOG.error(message);
+ appendThreadInfo(message, threadInfo);
failureProcessor.process(
new FailureContext(
SYSTEM_WORKER_BLOCKED,
- new IgniteException(SYSTEM_WORKER_BLOCKED_ERR,
message)));
+ new IgniteException(SYSTEM_WORKER_BLOCKED_ERR,
message.toString(), false)));
}
}
}
@@ -181,12 +182,12 @@ public class CriticalWorkerWatchdog implements
CriticalWorkerRegistry, IgniteCom
return delayedThreadIdsToDelays;
}
- private static String toString(ThreadInfo threadInfo) {
+ private static void appendThreadInfo(StringBuilder sb, ThreadInfo
threadInfo) {
// This method is based on code taken from ThreadInfo#toString(). The
original method limits the depth of the
// stacktrace it includes in the string representation to just 8
frames, which is too few. Here, we
// removed this limitation and include the stack trace in its entirety.
- StringBuilder sb = new StringBuilder()
+ sb
.append('\"').append(threadInfo.getThreadName()).append('\"')
.append(threadInfo.isDaemon() ? " daemon" : "")
.append(" prio=").append(threadInfo.getPriority())
@@ -249,7 +250,6 @@ public class CriticalWorkerWatchdog implements
CriticalWorkerRegistry, IgniteCom
}
}
sb.append('\n');
- return sb.toString();
}
@Override