simhadri-g commented on code in PR #4629: URL: https://github.com/apache/hive/pull/4629#discussion_r1321592215
########## ql/src/java/org/apache/hadoop/hive/ql/reexec/ReExecuteOnWriteConflictPlugin.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.hadoop.hive.ql.reexec; + +import com.google.common.base.Throwables; +import org.apache.hadoop.hive.ql.Driver; +import org.apache.hadoop.hive.ql.hooks.ExecuteWithHookContext; +import org.apache.hadoop.hive.ql.hooks.HookContext; +import org.apache.hadoop.hive.ql.plan.mapper.PlanMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.regex.Pattern; + +public class ReExecuteOnWriteConflictPlugin implements IReExecutionPlugin { + private static final Logger LOG = LoggerFactory.getLogger(ReExecuteOnWriteConflictPlugin.class); + private boolean retryPossible; + + private final Pattern writeConflictErrorPattern = Pattern.compile("^Found.*conflicting.*files(.*)"); + private final String validationException = "org.apache.iceberg.exceptions.ValidationException"; + + class LocalHook implements ExecuteWithHookContext { + @Override + public void run(HookContext hookContext) throws Exception { + if (hookContext.getHookType() == HookContext.HookType.ON_FAILURE_HOOK) { + Throwable exception = hookContext.getException(); + + if (exception != null && exception.getMessage() != null) { + + Throwable cause = Throwables.getRootCause(exception); + if (cause.getClass().getName().equals(validationException) && + cause.getMessage().matches(writeConflictErrorPattern.pattern())) { + retryPossible = true; + LOG.info("Retrying query due to write conflict."); + } + LOG.info("Got exception message: {} retryPossible: {}", exception.getMessage(), retryPossible); + } + } + } + } + + @Override + public void initialize(Driver driver) { + driver.getHookRunner().addOnFailureHook(new ReExecuteOnWriteConflictPlugin.LocalHook()); + } + + @Override + public boolean shouldReExecute(int executionNum) { + return retryPossible; + } + + @Override + public boolean shouldReExecuteAfterCompile(int executionNum, PlanMapper oldPlanMapper, PlanMapper newPlanMapper) { + return retryPossible; + } + Review Comment: ok ########## ql/src/java/org/apache/hadoop/hive/ql/reexec/ReExecuteOnWriteConflictPlugin.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.hadoop.hive.ql.reexec; + +import com.google.common.base.Throwables; +import org.apache.hadoop.hive.ql.Driver; +import org.apache.hadoop.hive.ql.hooks.ExecuteWithHookContext; +import org.apache.hadoop.hive.ql.hooks.HookContext; +import org.apache.hadoop.hive.ql.plan.mapper.PlanMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.regex.Pattern; + +public class ReExecuteOnWriteConflictPlugin implements IReExecutionPlugin { + private static final Logger LOG = LoggerFactory.getLogger(ReExecuteOnWriteConflictPlugin.class); + private boolean retryPossible; + + private final Pattern writeConflictErrorPattern = Pattern.compile("^Found.*conflicting.*files(.*)"); + private final String validationException = "org.apache.iceberg.exceptions.ValidationException"; + + class LocalHook implements ExecuteWithHookContext { + @Override + public void run(HookContext hookContext) throws Exception { + if (hookContext.getHookType() == HookContext.HookType.ON_FAILURE_HOOK) { + Throwable exception = hookContext.getException(); + + if (exception != null && exception.getMessage() != null) { + + Throwable cause = Throwables.getRootCause(exception); Review Comment: done -- 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]
