jhrotko commented on code in PR #16780: URL: https://github.com/apache/iceberg/pull/16780#discussion_r3493753280
########## core/src/main/java/org/apache/iceberg/util/CommitRetryExceptions.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.util; + +import static org.apache.iceberg.TableProperties.COMMIT_NUM_RETRIES; +import static org.apache.iceberg.TableProperties.COMMIT_TOTAL_RETRY_TIME_MS; + +import org.apache.iceberg.RetryableValidationException; +import org.apache.iceberg.exceptions.CommitFailedException; + +/** Internal helper for converting exhausted commit retries into user-facing commit exceptions. */ +public class CommitRetryExceptions { + static final String RETRYABLE_VALIDATION_FAILURE_PREFIX = "Validation failed, please retry:"; Review Comment: Good point. I extracted the commit failure message prefixes into `CommitFailureMessages`, and now both `CatalogHandlers` and `CommitRetryExceptions` use that helper. I also routed requirement failure messages through the same helper so that prefix does not drift either. ########## core/src/main/java/org/apache/iceberg/util/CommitRetryExceptions.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.util; + +import static org.apache.iceberg.TableProperties.COMMIT_NUM_RETRIES; +import static org.apache.iceberg.TableProperties.COMMIT_TOTAL_RETRY_TIME_MS; + +import org.apache.iceberg.RetryableValidationException; +import org.apache.iceberg.exceptions.CommitFailedException; + +/** Internal helper for converting exhausted commit retries into user-facing commit exceptions. */ +public class CommitRetryExceptions { + static final String RETRYABLE_VALIDATION_FAILURE_PREFIX = "Validation failed, please retry:"; + private static final String REST_RETRYABLE_VALIDATION_FAILURE_PREFIX = + "Commit failed: " + RETRYABLE_VALIDATION_FAILURE_PREFIX; + private static final String REQUIREMENT_FAILURE_PREFIX = "Requirement failed:"; + private static final String REST_REQUIREMENT_FAILURE_PREFIX = + "Commit failed: " + REQUIREMENT_FAILURE_PREFIX; + + private CommitRetryExceptions() {} + + public static CommitFailedException retryExhaustedException( + Exception cause, Tasks.RetryExhaustionReason reason) { + if (shouldKeepOriginalCommitFailure(cause)) { + return (CommitFailedException) cause; + } + + return new CommitFailedException( + cause, "Commit failed after exhausting retries. %s", retryExhaustionMessage(reason)); + } + + public static boolean isRetryableValidationCommitFailure(Exception cause) { + return cause instanceof CommitFailedException + && cause.getCause() instanceof RetryableValidationException; + } + + // Keep specific commit failures as the primary error instead of replacing them with retry tuning. + private static boolean shouldKeepOriginalCommitFailure(Exception cause) { + return cause instanceof CommitFailedException + && (cause.getCause() instanceof RetryableValidationException Review Comment: Good catch. Updated `shouldKeepOriginalCommitFailure` to reuse `isRetryableValidationCommitFailure(cause)`, so the typed cause check lives in one place. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
