Review Board 1.7.22


HIVE-4233- The TGT gotten from class 'CLIService' should be renewed on time

Review Request #11046 - Created May 10, 2013 and updated

Thejas Nair
HIVE-4233
Reviewers
hive
hive-git
HIVE-4233- The TGT gotten from class 'CLIService'  should be renewed on time
manually tested on secure hadoop cluster.
metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java
Revision 76b1989 New Change
[20] 15 lines
[+20]
16
 * limitations under the License.
16
 * limitations under the License.
17
 */
17
 */
18

    
   
18

   
19
package org.apache.hadoop.hive.metastore;
19
package org.apache.hadoop.hive.metastore;
20

    
   
20

   

    
   
21
import java.io.IOException;
21
import java.lang.reflect.InvocationHandler;
22
import java.lang.reflect.InvocationHandler;
22
import java.lang.reflect.InvocationTargetException;
23
import java.lang.reflect.InvocationTargetException;
23
import java.lang.reflect.Method;
24
import java.lang.reflect.Method;
24
import java.lang.reflect.Proxy;
25
import java.lang.reflect.Proxy;
25
import java.lang.reflect.UndeclaredThrowableException;
26
import java.lang.reflect.UndeclaredThrowableException;
26

    
   
27

   
27
import org.apache.commons.logging.Log;
28
import org.apache.commons.logging.Log;
28
import org.apache.commons.logging.LogFactory;
29
import org.apache.commons.logging.LogFactory;
29
import org.apache.hadoop.hive.conf.HiveConf;
30
import org.apache.hadoop.hive.conf.HiveConf;
30
import org.apache.hadoop.hive.metastore.api.MetaException;
31
import org.apache.hadoop.hive.metastore.api.MetaException;

    
   
32
import org.apache.hadoop.hive.shims.ShimLoader;
31
import org.apache.thrift.TApplicationException;
33
import org.apache.thrift.TApplicationException;
32
import org.apache.thrift.TException;
34
import org.apache.thrift.TException;
33
import org.apache.thrift.protocol.TProtocolException;
35
import org.apache.thrift.protocol.TProtocolException;
34
import org.apache.thrift.transport.TTransportException;
36
import org.apache.thrift.transport.TTransportException;
35

    
   
37

   

    
   
38
/**

    
   
39
 * RetryingMetaStoreClient. Creates a proxy for a IMetaStoreClient

    
   
40
 * implementation and retries calls to it on failure.

    
   
41
 * If the login user is authenticated using keytab, it relogins user before

    
   
42
 * each call.

    
   
43
 *

    
   
44
 */
36
public class RetryingMetaStoreClient implements InvocationHandler {
45
public class RetryingMetaStoreClient implements InvocationHandler {
37

    
   
46

   
38
  private static final Log LOG = LogFactory.getLog(RetryingMetaStoreClient.class.getName());
47
  private static final Log LOG = LogFactory.getLog(RetryingMetaStoreClient.class.getName());
39

    
   
48

   
40
  private final IMetaStoreClient base;
49
  private final IMetaStoreClient base;
41
  private final HiveConf hiveConf;

   
42
  private final int retryLimit;
50
  private final int retryLimit;
43
  private final int retryDelaySeconds;
51
  private final int retryDelaySeconds;
44

    
   
52

   

    
   
53

   

    
   
54

   
45
  protected RetryingMetaStoreClient(HiveConf hiveConf, HiveMetaHookLoader hookLoader,
55
  protected RetryingMetaStoreClient(HiveConf hiveConf, HiveMetaHookLoader hookLoader,
46
      Class<? extends IMetaStoreClient> msClientClass) throws MetaException {
56
      Class<? extends IMetaStoreClient> msClientClass) throws MetaException {
47
    this.hiveConf = hiveConf;

   
48
    this.retryLimit = hiveConf.getIntVar(HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES);
57
    this.retryLimit = hiveConf.getIntVar(HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES);
49
    this.retryDelaySeconds =
58
    this.retryDelaySeconds =
50
        hiveConf.getIntVar(HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY);
59
        hiveConf.getIntVar(HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY);

    
   
60

   

    
   
61
    reloginExpiringKeytabUser();
51
    this.base = (IMetaStoreClient) MetaStoreUtils.newInstance(msClientClass, new Class[] {
62
    this.base = (IMetaStoreClient) MetaStoreUtils.newInstance(msClientClass, new Class[] {
52
        HiveConf.class, HiveMetaHookLoader.class}, new Object[] {hiveConf, hookLoader});
63
        HiveConf.class, HiveMetaHookLoader.class}, new Object[] {hiveConf, hookLoader});
53
  }
64
  }
54

    
   
65

   
55
  public static IMetaStoreClient getProxy(HiveConf hiveConf, HiveMetaHookLoader hookLoader,
66
  public static IMetaStoreClient getProxy(HiveConf hiveConf, HiveMetaHookLoader hookLoader,
[+20] [20] 13 lines
[+20] public class RetryingMetaStoreClient implements InvocationHandler {
69
    Object ret = null;
80
    Object ret = null;
70
    int retriesMade = 0;
81
    int retriesMade = 0;
71
    TException caughtException = null;
82
    TException caughtException = null;
72
    while (true) {
83
    while (true) {
73
      try {
84
      try {

    
   
85
        reloginExpiringKeytabUser();

    
   
86
        if(retriesMade > 0){

    
   
87
          base.reconnect();

    
   
88
        }
74
        ret = method.invoke(base, args);
89
        ret = method.invoke(base, args);
75
        break;
90
        break;
76
      } catch (UndeclaredThrowableException e) {
91
      } catch (UndeclaredThrowableException e) {
77
        throw e.getCause();
92
        throw e.getCause();
78
      } catch (InvocationTargetException e) {
93
      } catch (InvocationTargetException e) {
[+20] [20] 14 lines
[+20] public class RetryingMetaStoreClient implements InvocationHandler {
93
      }
108
      }
94
      retriesMade++;
109
      retriesMade++;
95
      LOG.warn("MetaStoreClient lost connection. Attempting to reconnect.",
110
      LOG.warn("MetaStoreClient lost connection. Attempting to reconnect.",
96
          caughtException);
111
          caughtException);
97
      Thread.sleep(retryDelaySeconds * 1000);
112
      Thread.sleep(retryDelaySeconds * 1000);
98
      base.reconnect();

   
99
    }
113
    }
100
    return ret;
114
    return ret;
101
  }
115
  }

    
   
116

   

    
   
117
  /**

    
   
118
   * Relogin if login user is logged in using keytab

    
   
119
   * Relogin is actually done by ugi code only if sufficient time has passed

    
   
120
   * A no-op if kerberos security is not enabled

    
   
121
   * @throws MetaException

    
   
122
   */

    
   
123
  private void reloginExpiringKeytabUser() throws MetaException {

    
   
124
    if(!ShimLoader.getHadoopShims().isSecurityEnabled()){

    
   
125
      return;

    
   
126
    }

    
   
127
    try {

    
   
128
      ShimLoader.getHadoopShims().reLoginUserFromKeytab();

    
   
129
    } catch (IOException e) {

    
   
130
      String msg = "Error doing relogin using keytab " + e.getMessage();

    
   
131
      LOG.error(msg, e);

    
   
132
      throw new MetaException(msg);

    
   
133
    }

    
   
134
  }

    
   
135

   
102
}
136
}
shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java
Revision a837e33 New Change
 
shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java
Revision a649221 New Change
 
shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java
Revision 6a7da82 New Change
 
  1. metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java: Loading...
  2. shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java: Loading...
  3. shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java: Loading...
  4. shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java: Loading...