handle async errors in a way that doesn't hide details

This commit is contained in:
Jonathan Shook 2023-09-08 18:42:02 -05:00
parent 5cf0fbcaec
commit 675667eaa6
4 changed files with 134 additions and 6 deletions

View File

@ -36,9 +36,7 @@ import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
// TODO: add statement filtering
@ -121,9 +119,15 @@ public abstract class Cqld4CqlOp implements CycleOp<List<Row>>, VariableCapture,
try {
return rowsStage.toCompletableFuture().get(300, TimeUnit.SECONDS);
} catch (Exception e) {
if (e instanceof RuntimeException re) throw re;
throw new RuntimeException(e);
} catch (ExecutionException exe) {
Throwable ee = exe.getCause();
if (ee instanceof RuntimeException re) {
throw re;
} else throw new NBExecutionException(exe);
} catch (InterruptedException ie) {
throw new NBInterruptedException(ie);
} catch (TimeoutException e) {
throw new NBTimeoutException(e);
} finally {
processors.flush();
metrics.recordFetchedPages(fetchedPages);

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.adapter.cqld4.optypes;
import java.util.concurrent.ExecutionException;
public class NBExecutionException extends RuntimeException {
private final ExecutionException exception;
public NBExecutionException(ExecutionException e) {
this.exception = e;
}
@Override
public String getMessage() {
return "Wrapped Exception: " + exception.getMessage();
}
@Override
public StackTraceElement[] getStackTrace() {
return exception.getStackTrace();
}
@Override
public synchronized Throwable getCause() {
return exception.getCause();
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.adapter.cqld4.optypes;
public class NBInterruptedException extends RuntimeException {
private final InterruptedException exception;
public NBInterruptedException(InterruptedException e) {
this.exception = e;
}
@Override
public String getMessage() {
return "Wrapped Exception: " + exception.getMessage();
}
@Override
public StackTraceElement[] getStackTrace() {
return exception.getStackTrace();
}
@Override
public synchronized Throwable getCause() {
return exception.getCause();
}
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.adapter.cqld4.optypes;
import java.util.concurrent.TimeoutException;
public class NBTimeoutException extends RuntimeException {
private final TimeoutException exception;
public NBTimeoutException(TimeoutException e) {
this.exception = e;
}
@Override
public String getMessage() {
return "Wrapped Exception: " + exception.getMessage();
}
@Override
public StackTraceElement[] getStackTrace() {
return exception.getStackTrace();
}
@Override
public synchronized Throwable getCause() {
return exception.getCause();
}
}