3333import com .hotels .bdp .waggledance .client .compatibility .HiveCompatibleThriftHiveMetastoreIfaceFactory ;
3434import com .hotels .hcommon .hive .metastore .exception .MetastoreUnavailableException ;
3535
36-
3736public class DefaultMetaStoreClientFactory implements MetaStoreClientFactory {
3837
3938 static final Class <?>[] INTERFACES = new Class <?>[] { CloseableThriftHiveMetastoreIface .class };
@@ -48,9 +47,9 @@ private static class ReconnectingMetastoreClientInvocationHandler implements Inv
4847 private HiveUgiArgs cachedUgi = null ;
4948
5049 private ReconnectingMetastoreClientInvocationHandler (
51- String name ,
52- int maxRetries ,
53- AbstractThriftMetastoreClientManager base ) {
50+ String name ,
51+ int maxRetries ,
52+ AbstractThriftMetastoreClientManager base ) {
5453 this .name = name ;
5554 this .maxRetries = maxRetries ;
5655 this .base = base ;
@@ -81,8 +80,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
8180 cachedUgi = new HiveUgiArgs (user , groups );
8281 if (base .isOpen ()) {
8382 log
84- .info ("calling #set_ugi (on already open client) for user '{}', on metastore {}" , cachedUgi .getUser (),
85- name );
83+ .info ("calling #set_ugi (on already open client) for user '{}', on metastore {}" , cachedUgi .getUser (),
84+ name );
8685 return doRealCall (method , args , attempt );
8786 } else {
8887 // delay call until we get the next non set_ugi call, this helps doing unnecessary calls to Federated
@@ -107,21 +106,25 @@ private Object doRealCall(Method method, Object[] args, int attempt) throws Ille
107106 base .reconnect (cachedUgi );
108107 continue ;
109108 }
110- throw new MetastoreUnavailableException ("Client " + name + " is not available" , realException );
109+ log .debug ("Client " + name + " is not available" );
110+ throw realException ;
111111 }
112112 throw realException ;
113113 }
114114 } while (++attempt <= maxRetries );
115115 throw new RuntimeException ("Unreachable code" );
116116 }
117117
118+ /**
119+ * Decides whether a method should be retried. Only 'get' methods are retried. Alters/creates methods are not
120+ * retried as there are cases where this is not idempotent. TODO Potentially in the future we should remove the
121+ * whole retry mechanic and just leave that up to the caller/client.
122+ */
118123 private boolean shouldRetry (Method method ) {
119- switch (method .getName ()) {
120- case "shutdown" :
121- return false ;
122- default :
123- return true ;
124+ if (method .getName ().startsWith ("get" )) {
125+ return true ;
124126 }
127+ return false ;
125128 }
126129
127130 private void reconnectIfDisconnected () {
@@ -143,10 +146,10 @@ private void reconnectIfDisconnected() {
143146 */
144147 @ Override
145148 public CloseableThriftHiveMetastoreIface newInstance (
146- HiveConf hiveConf ,
147- String name ,
148- int reconnectionRetries ,
149- int connectionTimeout ) {
149+ HiveConf hiveConf ,
150+ String name ,
151+ int reconnectionRetries ,
152+ int connectionTimeout ) {
150153 boolean useSasl = hiveConf .getBoolVar (ConfVars .METASTORE_USE_THRIFT_SASL );
151154 HiveCompatibleThriftHiveMetastoreIfaceFactory factory = new HiveCompatibleThriftHiveMetastoreIfaceFactory ();
152155 AbstractThriftMetastoreClientManager base = null ;
@@ -160,13 +163,13 @@ public CloseableThriftHiveMetastoreIface newInstance(
160163
161164 @ VisibleForTesting
162165 CloseableThriftHiveMetastoreIface newInstance (
163- String name ,
164- int reconnectionRetries ,
165- AbstractThriftMetastoreClientManager base ) {
166+ String name ,
167+ int reconnectionRetries ,
168+ AbstractThriftMetastoreClientManager base ) {
166169 ReconnectingMetastoreClientInvocationHandler reconnectingHandler = new ReconnectingMetastoreClientInvocationHandler (
167170 name , reconnectionRetries , base );
168- return (CloseableThriftHiveMetastoreIface ) Proxy . newProxyInstance ( getClass (). getClassLoader (),
169- INTERFACES , reconnectingHandler );
171+ return (CloseableThriftHiveMetastoreIface ) Proxy
172+ . newProxyInstance ( getClass (). getClassLoader (), INTERFACES , reconnectingHandler );
170173 }
171174
172- }
175+ }
0 commit comments