Author: gunther
Date: Thu Aug 8 04:07:25 2013
New Revision: 1511574
URL: http://svn.apache.org/r1511574
Log:
HIVE-4233: The TGT gotten from class 'CLIService' should be renewed on time (Thejas M Nair via Gunther Hagleitner)
Modified:
hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java
hive/trunk/shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java
hive/trunk/shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java
hive/trunk/shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java
Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java?rev=1511574&r1=1511573&r2=1511574&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java Thu Aug 8 04:07:25 2013
@@ -18,6 +18,7 @@
package org.apache.hadoop.hive.metastore;
+import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -28,26 +29,36 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.shims.ShimLoader;
import org.apache.thrift.TApplicationException;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.transport.TTransportException;
+/**
+ * RetryingMetaStoreClient. Creates a proxy for a IMetaStoreClient
+ * implementation and retries calls to it on failure.
+ * If the login user is authenticated using keytab, it relogins user before
+ * each call.
+ *
+ */
public class RetryingMetaStoreClient implements InvocationHandler {
private static final Log LOG = LogFactory.getLog(RetryingMetaStoreClient.class.getName());
private final IMetaStoreClient base;
- private final HiveConf hiveConf;
private final int retryLimit;
private final int retryDelaySeconds;
+
+
protected RetryingMetaStoreClient(HiveConf hiveConf, HiveMetaHookLoader hookLoader,
Class<? extends IMetaStoreClient> msClientClass) throws MetaException {
- this.hiveConf = hiveConf;
this.retryLimit = hiveConf.getIntVar(HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES);
this.retryDelaySeconds =
hiveConf.getIntVar(HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY);
+
+ reloginExpiringKeytabUser();
this.base = (IMetaStoreClient) MetaStoreUtils.newInstance(msClientClass, new Class[] {
HiveConf.class, HiveMetaHookLoader.class}, new Object[] {hiveConf, hookLoader});
}
@@ -71,6 +82,10 @@ public class RetryingMetaStoreClient imp
TException caughtException = null;
while (true) {
try {
+ reloginExpiringKeytabUser();
+ if(retriesMade > 0){
+ base.reconnect();
+ }
ret = method.invoke(base, args);
break;
} catch (UndeclaredThrowableException e) {
@@ -95,8 +110,27 @@ public class RetryingMetaStoreClient imp
LOG.warn("MetaStoreClient lost connection. Attempting to reconnect.",
caughtException);
Thread.sleep(retryDelaySeconds * 1000);
- base.reconnect();
}
return ret;
}
+
+ /**
+ * Relogin if login user is logged in using keytab
+ * Relogin is actually done by ugi code only if sufficient time has passed
+ * A no-op if kerberos security is not enabled
+ * @throws MetaException
+ */
+ private void reloginExpiringKeytabUser() throws MetaException {
+ if(!ShimLoader.getHadoopShims().isSecurityEnabled()){
+ return;
+ }
+ try {
+ ShimLoader.getHadoopShims().reLoginUserFromKeytab();
+ } catch (IOException e) {
+ String msg = "Error doing relogin using keytab " + e.getMessage();
+ LOG.error(msg, e);
+ throw new MetaException(msg);
+ }
+ }
+
}
Modified: hive/trunk/shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java
URL: http://svn.apache.org/viewvc/hive/trunk/shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java?rev=1511574&r1=1511573&r2=1511574&view=diff
==============================================================================
--- hive/trunk/shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java (original)
+++ hive/trunk/shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java Thu Aug 8 04:07:25 2013
@@ -71,6 +71,7 @@ import org.apache.hadoop.security.UserGr
import org.apache.hadoop.tools.HadoopArchives;
import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.util.ToolRunner;
+import org.apache.hadoop.util.VersionInfo;
/**
* Implemention of shims against Hadoop 0.20.0.
@@ -605,7 +606,17 @@ public class Hadoop20Shims implements Ha
@Override
public void loginUserFromKeytab(String principal, String keytabFile) throws IOException {
- throw new UnsupportedOperationException("Kerberos login is not supported in current hadoop version");
+ throwKerberosUnsupportedError();
+ }
+
+ @Override
+ public void reLoginUserFromKeytab() throws IOException{
+ throwKerberosUnsupportedError();
+ }
+
+ private void throwKerberosUnsupportedError() throws UnsupportedOperationException{
+ throw new UnsupportedOperationException("Kerberos login is not supported" +
+ " in this hadoop version (" + VersionInfo.getVersion() + ")");
}
@Override
Modified: hive/trunk/shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java
URL: http://svn.apache.org/viewvc/hive/trunk/shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java?rev=1511574&r1=1511573&r2=1511574&view=diff
==============================================================================
--- hive/trunk/shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java (original)
+++ hive/trunk/shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java Thu Aug 8 04:07:25 2013
@@ -583,6 +583,16 @@ public abstract class HadoopShimsSecure
}
@Override
+ public void reLoginUserFromKeytab() throws IOException{
+ UserGroupInformation ugi = UserGroupInformation.getLoginUser();
+ //checkTGT calls ugi.relogin only after checking if it is close to tgt expiry
+ //hadoop relogin is actually done only every x minutes (x=10 in hadoop 1.x)
+ if(ugi.isFromKeytab()){
+ ugi.checkTGTAndReloginFromKeytab();
+ }
+ }
+
+ @Override
abstract public JobTrackerState getJobTrackerState(ClusterStatus clusterStatus) throws Exception;
@Override
Modified: hive/trunk/shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java
URL: http://svn.apache.org/viewvc/hive/trunk/shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java?rev=1511574&r1=1511573&r2=1511574&view=diff
==============================================================================
--- hive/trunk/shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java (original)
+++ hive/trunk/shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java Thu Aug 8 04:07:25 2013
@@ -343,13 +343,20 @@ public interface HadoopShims {
public String getJobLauncherHttpAddress(Configuration conf);
- /**
- * Perform kerberos login using the given principal and keytab
- * @throws IOException
- */
+ /**
+ * Perform kerberos login using the given principal and keytab
+ * @throws IOException
+ */
public void loginUserFromKeytab(String principal, String keytabFile) throws IOException;
/**
+ * Perform kerberos re-login using the given principal and keytab, to renew
+ * the credentials
+ * @throws IOException
+ */
+ public void reLoginUserFromKeytab() throws IOException;
+
+ /**
* Move the directory/file to trash. In case of the symlinks or mount points, the file is
* moved to the trashbin in the actual volume of the path p being deleted
* @param fs