@Override protected synchronized TTransport connect(HiveConf conf) throws HiveSQLException, TTransportException { connectCount++; return super.connect(conf); } }
@Override public Object invoke(Object o, Method method, Object[] args) throws Throwable { int attempts = 0; while (true) { attempts++; InvocationResult invokeResult = invokeInternal(method, args); if (invokeResult.success) { return invokeResult.result; } // Error because of thrift client, we have to recreate base object connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_CONNECTION_RETRY_LIMIT)); if (attempts >= retryLimit) { LOG.error(method.getName() + " failed after " + attempts + " retries.", invokeResult.exception); throw invokeResult.exception; } LOG.warn("Last call ThriftCLIServiceClient." + method.getName() + " failed, attempts = " + attempts, invokeResult.exception); Thread.sleep(retryDelaySeconds * 1000); } }
public static CLIServiceClientWrapper newRetryingCLIServiceClient(HiveConf conf) throws HiveSQLException { RetryingThriftCLIServiceClient retryClient = new RetryingThriftCLIServiceClient(conf); TTransport tTransport = retryClient .connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_CONNECTION_RETRY_LIMIT)); ICLIService cliService = (ICLIService) Proxy.newProxyInstance(RetryingThriftCLIServiceClient.class.getClassLoader(), CLIServiceClient.class.getInterfaces(), retryClient); return new CLIServiceClientWrapper(cliService, tTransport, conf); }
@Override protected InvocationResult invokeInternal(Method method, Object[] args) throws Throwable { System.out.println("## Calling: " + method.getName() + ", " + callCount + "/" + getRetryLimit()); callCount++; return super.invokeInternal(method, args); }
@Override public CLIServiceClient getClient() throws LensException { if (!connected) { try { log.info("HiveDriver connecting to HiveServer @ {}:{}", conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST), conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT)); hs2Client = RetryingThriftCLIServiceClient.newRetryingCLIServiceClient(conf); log.info("HiveDriver connected to HiveServer @ {}:{}", conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST), conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT)); } catch (HiveSQLException e) { throw new LensException(e); } connected = true; } return hs2Client; }
@Override public CLIServiceClient getClient() throws LensException { if (!connected) { try { log.info("HiveDriver connecting to HiveServer @ {}:{}", conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST), conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT)); if (conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_AUTHENTICATION) .equals(HiveAuthFactory.AuthTypes.KERBEROS.toString())) { hs2Client = RetryingThriftCLIServiceClientSasl.newRetryingCLIServiceClient(conf); } else { hs2Client = RetryingThriftCLIServiceClient.newRetryingCLIServiceClient(conf); } log.info("HiveDriver connected to HiveServer @ {}:{}", conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST), conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT)); } catch (Exception e) { throw new LensException(e); } connected = true; } return hs2Client; }
@Override public Object invoke(Object o, Method method, Object[] args) throws Throwable { int attempts = 0; while (true) { attempts++; InvocationResult invokeResult = invokeInternal(method, args); if (invokeResult.success) { return invokeResult.result; } // Error because of thrift client, we have to recreate base object connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_CONNECTION_RETRY_LIMIT)); if (attempts >= retryLimit) { LOG.error(method.getName() + " failed after " + attempts + " retries.", invokeResult.exception); throw invokeResult.exception; } LOG.warn("Last call ThriftCLIServiceClient." + method.getName() + " failed, attempts = " + attempts, invokeResult.exception); Thread.sleep(retryDelaySeconds * 1000); } }
protected TTransport connectWithRetry(int retries) throws HiveSQLException { TTransportException exception = null; for (int i = 0 ; i < retries; i++) { try { return connect(conf); } catch (TTransportException e) { exception = e; LOG.warn("Connection attempt " + i, e); } try { Thread.sleep(retryDelaySeconds * 1000); } catch (InterruptedException e) { LOG.warn("Interrupted", e); } } throw new HiveSQLException("Unable to connect after " + retries + " retries", exception); }
public static CLIServiceClientWrapper newRetryingCLIServiceClient(HiveConf conf) throws HiveSQLException { RetryingThriftCLIServiceClient retryClient = new RetryingThriftCLIServiceClient(conf); TTransport tTransport = retryClient .connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_CONNECTION_RETRY_LIMIT)); ICLIService cliService = (ICLIService) Proxy.newProxyInstance(RetryingThriftCLIServiceClient.class.getClassLoader(), CLIServiceClient.class.getInterfaces(), retryClient); return new CLIServiceClientWrapper(cliService, tTransport, conf); }
protected TTransport connectWithRetry(int retries) throws HiveSQLException { TTransportException exception = null; for (int i = 0 ; i < retries; i++) { try { return connect(conf); } catch (TTransportException e) { exception = e; LOG.warn("Connection attempt " + i, e); } try { Thread.sleep(retryDelaySeconds * 1000); } catch (InterruptedException e) { LOG.warn("Interrupted", e); } } throw new HiveSQLException("Unable to connect after " + retries + " retries", exception); }