@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { Deadline.registerIfNot(socketTimeout); boolean isTimerStarted = Deadline.startTimer(method.getName()); try { return method.invoke(base, args); } finally { if (isTimerStarted) { Deadline.stopTimer(); } } } catch (UndeclaredThrowableException e) { throw e.getCause(); } catch (InvocationTargetException e) { throw e.getCause(); } }
@Override public void run() { Deadline.registerIfNot(timeout); try { Deadline.checkTimeout(); } catch (MetaException e) { failInThread("should not timeout", e); return; Deadline.stopTimer(); Deadline.checkTimeout(); } catch (MetaException e) { failInThread("should not timeout", e); return; Deadline.stopTimer(); Deadline.resetTimeout(resetTimeout); Deadline.checkTimeout(); failInThread("should timeout.", null); return; } catch (MetaException e) { if (e.getCause() instanceof DeadlineException) { Deadline.clear(); } else { failInThread("new MetaException failed.", e);
/** * register a Deadline threadlocal object to current thread. * @param timeout */ public static void registerIfNot(long timeout) { if (getCurrentDeadline() == null) { setCurrentDeadline(new Deadline(timeout)); } }
/** * Check whether the long running method timeout. * @throws MetaException when the method timeout */ public static void checkTimeout() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.check(); } else { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
ConfVars.CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); Deadline.registerIfNot(timeout); boolean isStarted = Deadline.startTimer(method.getName()); try { object = method.invoke(baseHandler, args); } finally { if (isStarted) { Deadline.stopTimer(); } else if (e.getCause().getCause() instanceof DeadlineException) { Deadline.clear(); LOG.error("Error happens in method " + method.getName() + ": " + ExceptionUtils.getStackTrace(e.getCause()));
private void updateTablePartitions(RawStore rawStore, String catName, String dbName, String tblName) { try { Deadline.startTimer("getPartitions"); List<Partition> partitions = rawStore.getPartitions(catName, dbName, tblName, Integer.MAX_VALUE); Deadline.stopTimer(); sharedCache.refreshPartitionsInCache(StringUtils.normalizeIdentifier(catName), StringUtils.normalizeIdentifier(dbName), StringUtils.normalizeIdentifier(tblName), partitions); } catch (MetaException | NoSuchObjectException e) { LOG.info("Updating CachedStore: unable to read partitions of table: " + tblName, e); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object ret = null; boolean isTimerStarted = false; try { try { if (!Deadline.isStarted()) { Deadline.startTimer(method.getName()); isTimerStarted = true; } } catch (MetaException e) { // Deadline was not registered yet. long timeout = HiveConf.getTimeVar(hiveConf, HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); Deadline.registerIfNot(timeout); Deadline.startTimer(method.getName()); isTimerStarted = true; } ret = method.invoke(base, args); if (isTimerStarted) { Deadline.stopTimer(); } } catch (UndeclaredThrowableException e) { throw e.getCause(); } catch (InvocationTargetException e) { throw e.getCause(); } return ret; }
private List<Partition> convertToParts(String catName, String dbName, String tblName, List<MPartition> mparts) throws MetaException { List<Partition> parts = new ArrayList<>(mparts.size()); for (MPartition mp : mparts) { parts.add(convertToPart(catName, dbName, tblName, mp)); Deadline.checkTimeout(); } return parts; }
private static void dropAllStoreObjects(RawStore store) throws MetaException, InvalidObjectException, InvalidInputException { try { Deadline.registerIfNot(100000); Deadline.startTimer("getPartition"); List<String> dbs = store.getAllDatabases(DEFAULT_CATALOG_NAME); for (int i = 0; i < dbs.size(); i++) { String db = dbs.get(i); List<String> tbls = store.getAllTables(DEFAULT_CATALOG_NAME, db); for (String tbl : tbls) { List<Partition> parts = store.getPartitions(DEFAULT_CATALOG_NAME, db, tbl, 100); for (Partition part : parts) { store.dropPartition(DEFAULT_CATALOG_NAME, db, tbl, part.getValues()); } store.dropTable(DEFAULT_CATALOG_NAME, db, tbl); } store.dropDatabase(DEFAULT_CATALOG_NAME, db); } } catch (NoSuchObjectException e) { } }
/** * end the time after a method is done. */ public static void stopTimer() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = -1; deadline.method = null; } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it firstly.")); } }
private void start() throws MetaException { Deadline.startTimer("test"); try { Thread.sleep(duration); } catch (InterruptedException e) { failInThread("Odd. Sleeping thread is interrupted.", e); } }
/** * Check whether the long running method timeout. * @throws DeadlineException when the method timeout */ public static void checkTimeout() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.check(); } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
/** * start the timer before a method is invoked. * @param method method to be invoked */ public static boolean startTimer(String method) throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline == null) { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } if (deadline.startTime != NO_DEADLINE) return false; deadline.method = method; do { deadline.startTime = System.nanoTime(); } while (deadline.startTime == NO_DEADLINE); return true; }
@Override public void onConfigChange(ConfigChangeEvent changeEvent) throws MetaException { if (changeEvent.getKey().equals(MetastoreConf.ConfVars.CLIENT_SOCKET_TIMEOUT.getVarname()) || changeEvent.getKey().equals(MetastoreConf.ConfVars.CLIENT_SOCKET_TIMEOUT.getHiveName())) { // TODO: this only applies to current thread, so it's not useful at all. Deadline.resetTimeout(MetastoreConf.convertTimeStr(changeEvent.getNewValue(), TimeUnit.SECONDS, TimeUnit.MILLISECONDS)); } } }
void update() { Deadline.registerIfNot(1000000); LOG.debug("CachedStore: updating cached objects"); try {
/** * remove the registered Deadline threadlocal object from current thread. */ public static void clear() { removeCurrentDeadline(); }
HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); Deadline.registerIfNot(timeout); baseHandler.setConf(getActiveConf()); Deadline.startTimer(method.getName()); Object object = method.invoke(baseHandler, args); Deadline.stopTimer(); return object; } else if (e.getCause().getCause() instanceof DeadlineException) { Deadline.clear(); LOG.error("Error happens in method " + method.getName() + ": " + ExceptionUtils.getStackTrace(e.getCause()));
List<String> colNames = MetaStoreUtils.getColumnNamesForTable(table); if ((partNames != null) && (partNames.size() > 0)) { Deadline.startTimer("getAggregareStatsForAllPartitions"); AggrStats aggrStatsAllPartitions = rawStore.get_aggr_stats_for(catName, dbName, tblName, partNames, colNames); Deadline.stopTimer(); Deadline.startTimer("getAggregareStatsForAllPartitionsExceptDefault"); AggrStats aggrStatsAllButDefaultPartition = rawStore.get_aggr_stats_for(catName, dbName, tblName, partNames, colNames); Deadline.stopTimer(); sharedCache.refreshAggregateStatsInCache(StringUtils.normalizeIdentifier(catName), StringUtils.normalizeIdentifier(dbName),
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object ret = null; boolean isTimerStarted = false; try { try { if (!Deadline.isStarted()) { Deadline.startTimer(method.getName()); isTimerStarted = true; } } catch (MetaException e) { // Deadline was not registered yet. long timeout = HiveConf.getTimeVar(hiveConf, HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); Deadline.registerIfNot(timeout); Deadline.startTimer(method.getName()); isTimerStarted = true; } ret = method.invoke(base, args); if (isTimerStarted) { Deadline.stopTimer(); } } catch (UndeclaredThrowableException e) { throw e.getCause(); } catch (InvocationTargetException e) { throw e.getCause(); } return ret; }
public void noopMethod() throws MetaException { Deadline.checkTimeout(); }