diff --git a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index 43657e7430..df30f29af8 100644 --- a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -70,7 +70,6 @@ import org.apache.hadoop.hive.metastore.utils.JavaUtils; import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils; import org.apache.hadoop.hive.metastore.utils.SecurityUtils; -import org.apache.hadoop.hive.metastore.utils.LogUtils; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.StringUtils; @@ -134,7 +133,7 @@ private Map currentMetaVars; - private static final AtomicInteger connCount = new AtomicInteger(0); + private final AtomicInteger connCount = new AtomicInteger(0); // for thrift connects private int retries = 5; @@ -429,8 +428,8 @@ public boolean isCompatibleWith(Configuration conf) { String newVar = MetastoreConf.getAsString(conf, oneVar); if (oldVar == null || (oneVar.isCaseSensitive() ? !oldVar.equals(newVar) : !oldVar.equalsIgnoreCase(newVar))) { - LOG.info("Mestastore configuration " + oneVar.toString() + - " changed from " + oldVar + " to " + newVar); + LOG.info("Mestastore configuration {} changed from {} to {}", + oneVar, oldVar, newVar); compatible = false; } } @@ -446,8 +445,8 @@ public void setHiveAddedJars(String addedJars) { public void reconnect() throws MetaException { if (localMetaStore) { // For direct DB connections we don't yet support reestablishing connections. - throw new MetaException("For direct MetaStore DB connections, we don't support retries" + - " at the client level."); + throw new MetaException("Retries for direct MetaStore DB connections " + + "are not supported by this client"); } else { close(); @@ -582,10 +581,13 @@ private void open() throws MetaException { // Create an SSL socket and connect transport = SecurityUtils.getSSLSocket(store.getHost(), store.getPort(), clientSocketTimeout, trustStorePath, trustStorePassword); - LOG.debug("Opened an SSL connection to metastore, current connections: " + connCount.incrementAndGet()); + final int newCount = connCount.incrementAndGet(); + LOG.debug( + "Opened an SSL connection to metastore, current connections: {}", + newCount); if (LOG.isTraceEnabled()) { - LOG.trace("", new LogUtils.StackTraceLogger("METASTORE SSL CONNECTION TRACE - open - " + - System.identityHashCode(this))); + LOG.trace("METASTORE SSL CONNECTION TRACE - open [{}]", + System.identityHashCode(this), new Exception()); } } catch (IOException e) { throw new IllegalArgumentException(e); @@ -621,7 +623,7 @@ private void open() throws MetaException { transport = MetaStorePlainSaslHelper.getPlainTransport(userName, passwd, transport); } catch (IOException sasle) { // IOException covers SaslException - LOG.error("Couldn't create client transport", sasle); + LOG.error("Could not create client transport", sasle); throw new MetaException(sasle.toString()); } } else if (useSasl) { @@ -654,7 +656,7 @@ private void open() throws MetaException { transport, MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL)); } } catch (IOException ioe) { - LOG.error("Couldn't create client transport", ioe); + LOG.error("Failed to create client transport", ioe); throw new MetaException(ioe.toString()); } } else { @@ -673,21 +675,23 @@ private void open() throws MetaException { try { if (!transport.isOpen()) { transport.open(); - LOG.info("Opened a connection to metastore, URI (" + store + ") current connections: " + connCount.incrementAndGet()); + final int newCount = connCount.incrementAndGet(); + LOG.info("Opened a connection to metastore, URI ({}) " + + "current connections: {}", store, newCount); if (LOG.isTraceEnabled()) { - LOG.trace("", new LogUtils.StackTraceLogger("METASTORE CONNECTION TRACE - open - " + - System.identityHashCode(this))); + LOG.trace("METASTORE CONNECTION TRACE - open [{}]", + System.identityHashCode(this), new Exception()); } } isConnected = true; } catch (TTransportException e) { tte = e; - if (LOG.isDebugEnabled()) { - LOG.warn("Failed to connect to the MetaStore Server URI (" + store + ")", e); - } else { - // Don't print full exception trace if DEBUG is not on. - LOG.warn("Failed to connect to the MetaStore Server URI (" + store + ")"); - } + LOG.warn("Failed to connect to the MetaStore Server URI ({})", + store); + + // Include stack trace in DEBUG logging + LOG.debug("Failed to connect to the MetaStore Server URI ({})", + store, e); } if (isConnected && !useSasl && !usePasswordAuth && @@ -740,8 +744,6 @@ private void open() throws MetaException { } snapshotActiveConf(); - - LOG.info("Connected to metastore."); } private void snapshotActiveConf() { @@ -771,10 +773,12 @@ public void close() { // just in case, we make this call. if ((transport != null) && transport.isOpen()) { transport.close(); - LOG.info("Closed a connection to metastore, current connections: " + connCount.decrementAndGet()); + final int newCount = connCount.incrementAndGet(); + LOG.info("Closed a connection to metastore, current connections: {}", + newCount); if (LOG.isTraceEnabled()) { - LOG.trace("", new LogUtils.StackTraceLogger("METASTORE CONNECTION TRACE - close - " + - System.identityHashCode(this))); + LOG.trace("METASTORE CONNECTION TRACE - close [{}]", + System.identityHashCode(this), new Exception()); } } } @@ -1920,7 +1924,7 @@ public boolean listPartitionsByExpr(String catName, String db_name, String tbl_n throw te; } throw new IncompatibleMetastoreException( - "Metastore doesn't support listPartitionsByExpr: " + te.getMessage()); + "Metastore does not support listPartitionsByExpr: " + te.getMessage()); } r.setPartitions(FilterUtils.filterPartitionsIfEnabled(isClientFilterEnabled, filterHook, r.getPartitions())); diff --git a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/LogUtils.java b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/LogUtils.java index c93da380e3..26daeaed56 100644 --- a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/LogUtils.java +++ b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/LogUtils.java @@ -46,15 +46,6 @@ } } - /** - * This is an exception that can be passed to logger just for printing the stacktrace. - */ - public static class StackTraceLogger extends Exception { - public StackTraceLogger(final String msg) { - super(msg); - } - } - /** * Initialize log4j. *