Repository: phoenix Updated Branches: refs/heads/master 5016a52e7 -> 61250b5ca
PHOENIX-4941 Handle TableExistsException when wrapped under RemoteException for SYSTEM.MUTEX table Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/61250b5c Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/61250b5c Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/61250b5c Branch: refs/heads/master Commit: 61250b5ca0abdaf0ed2ddb74bc576e41b6219b10 Parents: 5016a52 Author: Ankit Singhal <[email protected]> Authored: Tue Oct 2 12:09:28 2018 -0700 Committer: Ankit Singhal <[email protected]> Committed: Tue Oct 2 12:09:28 2018 -0700 ---------------------------------------------------------------------- .../query/ConnectionQueryServicesImpl.java | 47 +++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/61250b5c/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index 6e27f2a..daecf1f 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -72,6 +72,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Types; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -2600,22 +2601,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement boolean foundAccessDeniedException = false; // when running spark/map reduce jobs the ADE might be wrapped // in a RemoteException - for (Throwable t : Throwables.getCausalChain(e)) { - if (t instanceof AccessDeniedException - || (t instanceof RemoteException - && ((RemoteException) t).getClassName() - .equals(AccessDeniedException.class - .getName()))) { - foundAccessDeniedException = true; - break; - } - } - if (foundAccessDeniedException) { + if (inspectIfAnyExceptionInChain(e, Collections.singletonList(AccessDeniedException.class))) { // Pass logger.warn("Could not check for Phoenix SYSTEM tables, assuming they exist and are properly configured"); checkClientServerCompatibility(SchemaUtil.getPhysicalName(SYSTEM_CATALOG_NAME_BYTES, getProps()).getName()); success = true; - } else if (!Iterables.isEmpty(Iterables.filter(Throwables.getCausalChain(e), NamespaceNotFoundException.class))) { + } else if (inspectIfAnyExceptionInChain(e, Collections.singletonList(NamespaceNotFoundException.class))) { // This exception is only possible if SYSTEM namespace mapping is enabled and SYSTEM namespace is missing // It implies that SYSTEM tables are not created and hence we shouldn't provide a connection AccessDeniedException ade = new AccessDeniedException("Insufficient permissions to create SYSTEM namespace and SYSTEM Tables"); @@ -2712,15 +2703,39 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement .setTimeToLive(TTL_FOR_MUTEX).build()) .build(); admin.createTable(tableDesc); - } catch (IOException e) { - if(!Iterables.isEmpty(Iterables.filter(Throwables.getCausalChain(e), AccessDeniedException.class)) || - !Iterables.isEmpty(Iterables.filter(Throwables.getCausalChain(e), org.apache.hadoop.hbase.TableNotFoundException.class))) { - // Ignore + } + catch (IOException e) { + if (inspectIfAnyExceptionInChain(e, Arrays.<Class<? extends IOException>> asList( + AccessDeniedException.class, org.apache.hadoop.hbase.TableExistsException.class))) { + // Ignore TableExistsException as another client might beat us during upgrade. + // Ignore AccessDeniedException, as it may be possible underpriviliged user trying to use the connection + // which doesn't required upgrade. + logger.debug("Ignoring exception while creating mutex table during connection initialization: " + + Throwables.getStackTraceAsString(e)); } else { throw e; } } } + + private boolean inspectIfAnyExceptionInChain(Throwable io, List<Class<? extends IOException>> ioList) { + boolean exceptionToIgnore = false; + for (Throwable t : Throwables.getCausalChain(io)) { + for (Class<? extends IOException> exception : ioList) { + exceptionToIgnore |= isExceptionInstanceOf(t, exception); + } + if (exceptionToIgnore) { + break; + } + + } + return exceptionToIgnore; + } + + private boolean isExceptionInstanceOf(Throwable io, Class<? extends IOException> exception) { + return exception.isInstance(io) || (io instanceof RemoteException + && (((RemoteException)io).getClassName().equals(exception.getName()))); + } List<TableName> getSystemTableNamesInDefaultNamespace(Admin admin) throws IOException { return Lists.newArrayList(admin.listTableNames(Pattern.compile(QueryConstants.SYSTEM_SCHEMA_NAME + "\\..*"))); // TODO: replace to pattern
