This is an automated email from the ASF dual-hosted git repository.
mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 97172bf77c [ASTERIXDB-3319][COMP][RT] Throw external error in COPY TO
97172bf77c is described below
commit 97172bf77c8f81041421b22ec5667b346dacd79c
Author: Wail Alkowaileet <[email protected]>
AuthorDate: Wed Nov 22 13:57:58 2023 -0800
[ASTERIXDB-3319][COMP][RT] Throw external error in COPY TO
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
Whenever we face an S3 misconfiguration (wrong region),
we throw internal error. Instead, we should report the
error as received from S3 SDK.
Change-Id: I21d9d4c91bdee50b86ab1bf6b2b06f23cf376a29
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17979
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Wail Alkowaileet <[email protected]>
Reviewed-by: Murtadha Hubail <[email protected]>
Tested-by: Wail Alkowaileet <[email protected]>
---
.../writer/AbstractCloudExternalFileWriter.java | 41 +++++++++++++++++++---
.../asterix/cloud/writer/S3ExternalFileWriter.java | 7 ++++
.../cloud/writer/S3ExternalFileWriterFactory.java | 7 ++--
3 files changed, 48 insertions(+), 7 deletions(-)
diff --git
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriter.java
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriter.java
index fb8150b6e6..73a0aeb3f2 100644
---
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriter.java
+++
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/AbstractCloudExternalFileWriter.java
@@ -18,6 +18,8 @@
*/
package org.apache.asterix.cloud.writer;
+import static org.apache.hyracks.api.util.ExceptionUtils.getMessageOrToString;
+
import org.apache.asterix.cloud.CloudOutputStream;
import org.apache.asterix.cloud.CloudResettableInputStream;
import org.apache.asterix.cloud.IWriteBufferProvider;
@@ -91,26 +93,55 @@ abstract class AbstractCloudExternalFileWriter implements
IExternalFileWriter {
@Override
public final void write(IValueReference value) throws HyracksDataException
{
- printer.print(value);
+ try {
+ printer.print(value);
+ } catch (HyracksDataException e) {
+ throw e;
+ } catch (Exception e) {
+ if (isSdkException(e)) {
+ throw
RuntimeDataException.create(ErrorCode.EXTERNAL_SOURCE_ERROR, e,
getMessageOrToString(e));
+ }
+ throw e;
+ }
}
@Override
public final void abort() throws HyracksDataException {
- if (bufferedWriter != null) {
- bufferedWriter.abort();
+ try {
+ if (bufferedWriter != null) {
+ bufferedWriter.abort();
+ }
+ printer.close();
+ } catch (HyracksDataException e) {
+ throw e;
+ } catch (Exception e) {
+ if (isSdkException(e)) {
+ throw
RuntimeDataException.create(ErrorCode.EXTERNAL_SOURCE_ERROR, e,
getMessageOrToString(e));
+ }
+ throw e;
}
- printer.close();
}
@Override
public final void close() throws HyracksDataException {
- printer.close();
+ try {
+ printer.close();
+ } catch (HyracksDataException e) {
+ throw e;
+ } catch (Exception e) {
+ if (isSdkException(e)) {
+ throw
RuntimeDataException.create(ErrorCode.EXTERNAL_SOURCE_ERROR, e,
getMessageOrToString(e));
+ }
+ throw e;
+ }
}
abstract String getAdapterName();
abstract int getPathMaxLengthInBytes();
+ abstract boolean isSdkException(Exception e);
+
private boolean checkAndWarnExceedingMaxLength(String fullPath) {
boolean exceeding = isExceedingMaxLength(fullPath,
getPathMaxLengthInBytes());
if (exceeding && warningCollector.shouldWarn()) {
diff --git
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriter.java
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriter.java
index 648dda5662..e896c05d41 100644
---
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriter.java
+++
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriter.java
@@ -24,6 +24,8 @@ import org.apache.asterix.runtime.writer.IExternalFilePrinter;
import org.apache.hyracks.api.exceptions.IWarningCollector;
import org.apache.hyracks.api.exceptions.SourceLocation;
+import software.amazon.awssdk.core.exception.SdkException;
+
final class S3ExternalFileWriter extends AbstractCloudExternalFileWriter {
static int MAX_LENGTH_IN_BYTES = 1024;
@@ -41,4 +43,9 @@ final class S3ExternalFileWriter extends
AbstractCloudExternalFileWriter {
int getPathMaxLengthInBytes() {
return MAX_LENGTH_IN_BYTES;
}
+
+ @Override
+ boolean isSdkException(Exception e) {
+ return e instanceof SdkException;
+ }
}
diff --git
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
index 508225db1e..5036fc8c07 100644
---
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
+++
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/writer/S3ExternalFileWriterFactory.java
@@ -19,6 +19,7 @@
package org.apache.asterix.cloud.writer;
import static
org.apache.asterix.cloud.writer.AbstractCloudExternalFileWriter.isExceedingMaxLength;
+import static org.apache.hyracks.api.util.ExceptionUtils.getMessageOrToString;
import java.io.IOException;
import java.util.Collections;
@@ -51,6 +52,7 @@ import org.apache.hyracks.data.std.primitive.LongPointable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
public final class S3ExternalFileWriterFactory implements
IExternalFileWriterFactory {
@@ -126,12 +128,13 @@ public final class S3ExternalFileWriterFactory implements
IExternalFileWriterFac
doValidate(testClient, bucket);
} catch (IOException e) {
if (e.getCause() instanceof NoSuchBucketException) {
- throw new
CompilationException(ErrorCode.EXTERNAL_SOURCE_CONTAINER_NOT_FOUND, bucket);
+ throw
CompilationException.create(ErrorCode.EXTERNAL_SOURCE_CONTAINER_NOT_FOUND,
bucket);
} else {
- LOGGER.error(e);
throw
CompilationException.create(ErrorCode.EXTERNAL_SOURCE_ERROR,
ExceptionUtils.getMessageOrToString(e));
}
+ } catch (SdkException e) {
+ throw CompilationException.create(ErrorCode.EXTERNAL_SOURCE_ERROR,
e, getMessageOrToString(e));
}
}