From d8f891232be2268b357864482e4e29f1c6d0e5b2 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Fri, 2 Sep 2022 09:12:32 -0700 Subject: [PATCH 1/3] Core: Add CommitStateUnknownException handling to REST. --- .../exceptions/ServiceFailureException.java | 2 +- .../ServiceUnavailableException.java | 35 +++++++++++++++++++ .../apache/iceberg/rest/ErrorHandlers.java | 12 +++++-- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java diff --git a/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java b/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java index b3395f80fca7..63a480a4d72c 100644 --- a/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java +++ b/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java @@ -21,7 +21,7 @@ import com.google.errorprone.annotations.FormatMethod; /** Exception thrown on HTTP 5XX Server Error. */ -public class ServiceFailureException extends RuntimeException { +public class ServiceFailureException extends RESTException { @FormatMethod public ServiceFailureException(String message, Object... args) { super(String.format(message, args)); diff --git a/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java b/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java new file mode 100644 index 000000000000..1e7f842d804a --- /dev/null +++ b/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.iceberg.exceptions; + +import com.google.errorprone.annotations.FormatMethod; + +/** Exception thrown on HTTP 503: service is unavailable */ +public class ServiceUnavailableException extends RESTException { + @FormatMethod + public ServiceUnavailableException(String message, Object... args) { + super(String.format(message, args)); + } + + @FormatMethod + public ServiceUnavailableException(Throwable cause, String message, Object... args) { + super(String.format(message, args), cause); + } +} diff --git a/core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java b/core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java index 6ef080e5f173..b800106ce179 100644 --- a/core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java +++ b/core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java @@ -22,12 +22,14 @@ import org.apache.iceberg.exceptions.AlreadyExistsException; import org.apache.iceberg.exceptions.BadRequestException; import org.apache.iceberg.exceptions.CommitFailedException; +import org.apache.iceberg.exceptions.CommitStateUnknownException; import org.apache.iceberg.exceptions.ForbiddenException; import org.apache.iceberg.exceptions.NoSuchNamespaceException; import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.iceberg.exceptions.NotAuthorizedException; import org.apache.iceberg.exceptions.RESTException; import org.apache.iceberg.exceptions.ServiceFailureException; +import org.apache.iceberg.exceptions.ServiceUnavailableException; import org.apache.iceberg.rest.responses.ErrorResponse; /** @@ -57,6 +59,10 @@ private static Consumer baseCommitErrorHandler() { throw new NoSuchTableException("%s", error.message()); case 409: throw new CommitFailedException("Commit failed: %s", error.message()); + case 500: + case 504: + throw new CommitStateUnknownException( + new ServiceFailureException("Service failed: %s: %s", error.code(), error.message())); } }; } @@ -113,10 +119,12 @@ public static Consumer defaultErrorHandler() { case 405: case 406: break; - case 501: - throw new UnsupportedOperationException(error.message()); case 500: throw new ServiceFailureException("Server error: %s: %s", error.type(), error.message()); + case 501: + throw new UnsupportedOperationException(error.message()); + case 503: + throw new ServiceUnavailableException("Service unavailable: %s", error.message()); } throw new RESTException("Unable to process: %s", error.message()); From b8da0d86dd33101556e3728579d90ae9ec9e0cbc Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Fri, 2 Sep 2022 09:31:02 -0700 Subject: [PATCH 2/3] Pass format and args through in exception constructors. --- .../apache/iceberg/exceptions/ServiceFailureException.java | 4 ++-- .../iceberg/exceptions/ServiceUnavailableException.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java b/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java index 63a480a4d72c..0d1e42b8c49d 100644 --- a/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java +++ b/api/src/main/java/org/apache/iceberg/exceptions/ServiceFailureException.java @@ -24,11 +24,11 @@ public class ServiceFailureException extends RESTException { @FormatMethod public ServiceFailureException(String message, Object... args) { - super(String.format(message, args)); + super(message, args); } @FormatMethod public ServiceFailureException(Throwable cause, String message, Object... args) { - super(String.format(message, args), cause); + super(cause, message, args); } } diff --git a/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java b/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java index 1e7f842d804a..74877214accd 100644 --- a/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java +++ b/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java @@ -25,11 +25,11 @@ public class ServiceUnavailableException extends RESTException { @FormatMethod public ServiceUnavailableException(String message, Object... args) { - super(String.format(message, args)); + super(message, args); } @FormatMethod public ServiceUnavailableException(Throwable cause, String message, Object... args) { - super(String.format(message, args), cause); + super(cause, message, args); } } From b34629174f6b137f1b6e6266f47223826d7c5399 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Fri, 2 Sep 2022 09:48:31 -0700 Subject: [PATCH 3/3] Fix spotless. --- .../apache/iceberg/exceptions/ServiceUnavailableException.java | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java b/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java index 74877214accd..df75473c5bd3 100644 --- a/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java +++ b/api/src/main/java/org/apache/iceberg/exceptions/ServiceUnavailableException.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.iceberg.exceptions; import com.google.errorprone.annotations.FormatMethod;