Skip to content
Permalink
Browse files
[NO ISSUE][MISC] Fix unwrap(), consolidate exception utils
- ExceptionUtils.unwrap() is supposed to return only instances of IFormattedException,
  but due to a bug was returning the first non-IFormattedException nested exception

Change-Id: Ib26371609d9e1fcd1ff434b8ece04b6d96e4e2f4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11563
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
Reviewed-by: Till Westmann <tillw@apache.org>
  • Loading branch information
mblow committed May 21, 2021
1 parent 3b6982c commit 080a53e6b6f6f6ddcbf649d1b84453de2fad12f1
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 98 deletions.
@@ -36,7 +36,6 @@
import org.apache.asterix.common.api.IRequestReference;
import org.apache.asterix.common.config.GlobalConfig;
import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.common.exceptions.RuntimeDataException;
import org.apache.asterix.common.messaging.api.INCMessageBroker;
import org.apache.asterix.common.messaging.api.MessageFuture;
@@ -46,6 +45,7 @@
import org.apache.asterix.translator.SessionOutput;
import org.apache.hyracks.api.application.INCServiceContext;
import org.apache.hyracks.api.exceptions.Warning;
import org.apache.hyracks.api.util.ExceptionUtils;
import org.apache.hyracks.http.api.IChannelClosedHandler;
import org.apache.hyracks.http.api.IServletRequest;
import org.apache.hyracks.http.server.HttpServer;
@@ -76,7 +76,6 @@
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.common.exceptions.CompilationException;
import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.common.exceptions.MetadataException;
import org.apache.asterix.common.exceptions.RuntimeDataException;
import org.apache.asterix.common.exceptions.WarningCollector;
@@ -3576,7 +3575,7 @@ private static void createAndRunJob(IHyracksClientConnection hcc, EnumSet<JobFla
printer.print(jobId);
}
} catch (Exception e) {
if (ExceptionUtils.getRootCause(e) instanceof InterruptedException) {
if (org.apache.hyracks.api.util.ExceptionUtils.getRootCause(e) instanceof InterruptedException) {
Thread.currentThread().interrupt();
throw new RuntimeDataException(ErrorCode.REQUEST_CANCELLED, clientRequest.getId());
}
@@ -34,7 +34,6 @@
import org.apache.asterix.app.active.ActiveNotificationHandler;
import org.apache.asterix.common.api.IMetadataLockManager;
import org.apache.asterix.common.dataflow.ICcApplicationContext;
import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.common.metadata.DataverseName;
import org.apache.asterix.common.transactions.TxnId;
import org.apache.asterix.common.utils.JobUtils;
@@ -182,7 +181,7 @@ private static void runWithRetryAfterInterrupt(Work work) throws Exception {
work.run();
done = true;
} catch (Exception e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
Throwable rootCause = org.apache.hyracks.api.util.ExceptionUtils.getRootCause(e);
if (rootCause instanceof java.lang.InterruptedException) {
interruptedException = (InterruptedException) rootCause;
// clear the interrupted state from the thread
@@ -33,7 +33,6 @@
import java.util.concurrent.Future;
import java.util.function.Predicate;

import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.common.utils.Servlets;
import org.apache.asterix.test.runtime.SqlppExecutionWithCancellationTest;
import org.apache.asterix.testframework.context.TestCaseContext;
@@ -43,6 +42,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.hyracks.api.util.ExceptionUtils;
import org.junit.Assert;

public class CancellationTestExecutor extends TestExecutor {
@@ -29,7 +29,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.common.utils.Servlets;
import org.apache.asterix.testframework.context.TestCaseContext;
import org.apache.asterix.testframework.xml.ComparisonEnum;
@@ -38,6 +37,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.hyracks.api.util.ExceptionUtils;
import org.apache.logging.log4j.Level;
import org.junit.Assert;

@@ -20,9 +20,9 @@

import java.util.Collection;

import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.test.common.CancellationTestExecutor;
import org.apache.asterix.testframework.context.TestCaseContext;
import org.apache.hyracks.api.util.ExceptionUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -31,7 +31,6 @@
import org.apache.asterix.common.config.TransactionProperties;
import org.apache.asterix.common.dataflow.DatasetLocalResource;
import org.apache.asterix.common.exceptions.ACIDException;
import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.common.transactions.DatasetId;
import org.apache.asterix.common.transactions.ILockManager;
import org.apache.asterix.common.transactions.ILogManager;
@@ -113,7 +112,7 @@ public void interruptedLogPageSwitch() throws Exception {
logManager.log(logRecord);
}
} catch (ACIDException e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
Throwable rootCause = org.apache.hyracks.api.util.ExceptionUtils.getRootCause(e);
if (rootCause instanceof java.lang.InterruptedException) {
interrupted.set(true);
}

This file was deleted.

@@ -26,7 +26,6 @@
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.asterix.common.exceptions.ExceptionUtils;
import org.apache.asterix.external.dataflow.AbstractFeedDataFlowController;
import org.apache.asterix.external.util.FeedLogManager;
import org.apache.asterix.external.util.FileSystemWatcher;
@@ -129,7 +128,7 @@ public boolean handleException(Throwable th) {
if (in == null) {
return false;
}
Throwable root = ExceptionUtils.getRootCause(th);
Throwable root = org.apache.hyracks.api.util.ExceptionUtils.getRootCause(th);
if (root instanceof HyracksDataException) {
HyracksDataException r = (HyracksDataException) root;
boolean advance = false;
@@ -23,9 +23,11 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;

import org.apache.hyracks.api.exceptions.ErrorCode;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.exceptions.IFormattedException;
import org.apache.hyracks.util.ThrowingFunction;

import com.google.common.util.concurrent.UncheckedExecutionException;
@@ -158,4 +160,41 @@ public static <K, V> V computeIfAbsent(Map<K, V> map, K key, ThrowingFunction<K,
throw HyracksDataException.create(e.getCause());
}
}

// Gets the error message for the root cause of a given Throwable instance.
public static String getErrorMessage(Throwable th) {
Throwable cause = getRootCause(th);
return cause.getMessage();
}

/**
* Determines whether supplied exception contains a matching cause in its hierarchy, or is itself a match
*/
public static boolean matchingCause(Throwable e, Predicate<Throwable> test) {
Throwable current = e;
Throwable cause = e.getCause();
while (cause != null && cause != current) {
if (test.test(cause)) {
return true;
}
Throwable nextCause = current.getCause();
current = cause;
cause = nextCause;
}
return test.test(e);
}

/**
* Unwraps enclosed exceptions until a non-product exception is found, otherwise returns the root production
* exception
*/
public static Throwable unwrap(Throwable e) {
Throwable current = e;
Throwable cause = e.getCause();
while (cause != current && cause instanceof IFormattedException) {
current = cause;
cause = current.getCause();
}
return current;
}
}

0 comments on commit 080a53e

Please sign in to comment.