public static void dropAllStoreObjects(RawStore store) throws MetaException, InvalidObjectException, InvalidInputException { try { Deadline.registerIfNot(100000); List<Function> funcs = store.getAllFunctions(); for (Function func : funcs) { store.dropFunction(func.getDbName(), func.getFunctionName()); } List<String> dbs = store.getAllDatabases(); for (int i = 0; i < dbs.size(); i++) { String db = dbs.get(i); List<String> tbls = store.getAllTables(db); for (String tbl : tbls) { Deadline.startTimer("getPartition"); List<Partition> parts = store.getPartitions(db, tbl, 100); for (Partition part : parts) { store.dropPartition(db, tbl, part.getValues()); } store.dropTable(db, tbl); } store.dropDatabase(db); } List<String> roles = store.listRoleNames(); for (String role : roles) { store.removeRole(role); } } catch (NoSuchObjectException 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.")); } }
/** 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.")); } }
/** * start the timer before a method is invoked. * * @param method */ public static void startTimer(String method) throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = System.currentTimeMillis(); deadline.method = method; } else { throw newMetaException( new DeadlineException( "The threadlocal Deadline is null," + " please register it firstly.")); } }
/** * reset the timeout value of this timer. * * @param timeout */ public static void resetTimeout(long timeout) throws MetaException { if (timeout <= 0) { throw newMetaException( new DeadlineException( "The reset timeout value should be " + "larger than 0: " + timeout)); } Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.timeout = timeout; } else { throw newMetaException( new DeadlineException( "The threadlocal Deadline is null," + " please register it firstly.")); } }
/** Tests partition operations */ @Test public void testPartitionOps() throws MetaException, InvalidObjectException, NoSuchObjectException, InvalidInputException { Database db1 = new Database(DB1, "description", "locationurl", null); objectStore.createDatabase(db1); StorageDescriptor sd = new StorageDescriptor( null, "location", null, null, false, 0, new SerDeInfo("SerDeName", "serializationLib", null), null, null, null); HashMap<String, String> tableParams = new HashMap<String, String>(); tableParams.put("EXTERNAL", "false"); FieldSchema partitionKey1 = new FieldSchema("Country", "String", ""); FieldSchema partitionKey2 = new FieldSchema("State", "String", ""); Table tbl1 = new Table( TABLE1, DB1, "owner", 1, 2, 3, sd, Arrays.asList(partitionKey1, partitionKey2), tableParams, "viewOriginalText", "viewExpandedText", "MANAGED_TABLE"); objectStore.createTable(tbl1); HashMap<String, String> partitionParams = new HashMap<String, String>(); partitionParams.put("PARTITION_LEVEL_PRIVILEGE", "true"); List<String> value1 = Arrays.asList("US", "CA"); Partition part1 = new Partition(value1, DB1, TABLE1, 111, 111, sd, partitionParams); objectStore.addPartition(part1); List<String> value2 = Arrays.asList("US", "MA"); Partition part2 = new Partition(value2, DB1, TABLE1, 222, 222, sd, partitionParams); objectStore.addPartition(part2); Deadline.startTimer("getPartition"); List<Partition> partitions = objectStore.getPartitions(DB1, TABLE1, 10); Assert.assertEquals(2, partitions.size()); Assert.assertEquals(111, partitions.get(0).getCreateTime()); Assert.assertEquals(222, partitions.get(1).getCreateTime()); objectStore.dropPartition(DB1, TABLE1, value1); partitions = objectStore.getPartitions(DB1, TABLE1, 10); Assert.assertEquals(1, partitions.size()); Assert.assertEquals(222, partitions.get(0).getCreateTime()); objectStore.dropPartition(DB1, TABLE1, value2); objectStore.dropTable(DB1, TABLE1); objectStore.dropDatabase(DB1); }
@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(); } }
public Result invokeInternal(final Object proxy, final Method method, final Object[] args) throws Throwable { boolean gotNewConnectUrl = false; boolean reloadConf = HiveConf.getBoolVar(origConf, HiveConf.ConfVars.HMSHANDLERFORCERELOADCONF); long retryInterval = HiveConf.getTimeVar(origConf, HiveConf.ConfVars.HMSHANDLERINTERVAL, TimeUnit.MILLISECONDS); int retryLimit = HiveConf.getIntVar(origConf, HiveConf.ConfVars.HMSHANDLERATTEMPTS); long timeout = HiveConf.getTimeVar( origConf, HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); Deadline.registerIfNot(timeout); if (reloadConf) { MetaStoreInit.updateConnectionURL(origConf, getActiveConf(), null, metaStoreInitData); } int retryCount = 0; Throwable caughtException = null; while (true) { try { if (reloadConf || gotNewConnectUrl) { baseHandler.setConf(getActiveConf()); } Object object = null; boolean isStarted = Deadline.startTimer(method.getName()); try { object = method.invoke(baseHandler, args); } finally { if (isStarted) { Deadline.stopTimer(); } } return new Result(object, retryCount); } catch (javax.jdo.JDOException e) { caughtException = e; } catch (UndeclaredThrowableException e) { if (e.getCause() != null) { if (e.getCause() instanceof javax.jdo.JDOException) { // Due to reflection, the jdo exception is wrapped in // invocationTargetException caughtException = e.getCause(); } else if (e.getCause() instanceof MetaException && e.getCause().getCause() != null && e.getCause().getCause() instanceof javax.jdo.JDOException) { // The JDOException may be wrapped further in a MetaException caughtException = e.getCause().getCause(); } else { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } } else { LOG.error(ExceptionUtils.getStackTrace(e)); throw e; } } catch (InvocationTargetException e) { if (e.getCause() instanceof javax.jdo.JDOException) { // Due to reflection, the jdo exception is wrapped in // invocationTargetException caughtException = e.getCause(); } else if (e.getCause() instanceof NoSuchObjectException || e.getTargetException().getCause() instanceof NoSuchObjectException) { String methodName = method.getName(); if (!methodName.startsWith("get_database") && !methodName.startsWith("get_table") && !methodName.startsWith("get_partition") && !methodName.startsWith("get_function")) { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); } throw e.getCause(); } else if (e.getCause() instanceof MetaException && e.getCause().getCause() != null) { if (e.getCause().getCause() instanceof javax.jdo.JDOException || e.getCause().getCause() instanceof NucleusException) { // The JDOException or the Nucleus Exception may be wrapped further in a MetaException caughtException = e.getCause().getCause(); } else if (e.getCause().getCause() instanceof DeadlineException) { // The Deadline Exception needs no retry and be thrown immediately. Deadline.clear(); LOG.error( "Error happens in method " + method.getName() + ": " + ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } else { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } } else { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } } if (retryCount >= retryLimit) { LOG.error("HMSHandler Fatal error: " + ExceptionUtils.getStackTrace(caughtException)); // Since returning exceptions with a nested "cause" can be a problem in // Thrift, we are stuffing the stack trace into the message itself. throw new MetaException(ExceptionUtils.getStackTrace(caughtException)); } assert (retryInterval >= 0); retryCount++; LOG.error( String.format( "Retrying HMSHandler after %d ms (attempt %d of %d)", retryInterval, retryCount, retryLimit) + " with error: " + ExceptionUtils.getStackTrace(caughtException)); Thread.sleep(retryInterval); // If we have a connection error, the JDO connection URL hook might // provide us with a new URL to access the datastore. String lastUrl = MetaStoreInit.getConnectionURL(getActiveConf()); gotNewConnectUrl = MetaStoreInit.updateConnectionURL(origConf, getActiveConf(), lastUrl, metaStoreInitData); } }