private void clearLocksAndHB() throws LockException { lockMgr.clearLocalLockRecords(); stopHeartbeat(); }
public ShowLocksResponse getLocks() throws LockException { return getLocks(new ShowLocksRequest()); }
/** * we don't expect multiple threads to call this method concurrently but {@link #lockMgr} will * be read by a different threads than one writing it, thus it's {@code volatile} */ @Override public HiveLockManager getLockManager() throws LockException { init(); if (lockMgr == null) { lockMgr = new DbLockManager(conf, this); } return lockMgr; }
long startRetry = System.currentTimeMillis(); while (res.getState() == LockState.WAITING && numRetries++ < maxNumWaits) { backoff(); res = txnManager.getMS().checkLock(res.getLockid()); unlock(hl);//remove the locks in Waiting state LockException le = new LockException(null, ErrorMsg.LOCK_ACQUIRE_TIMEDOUT, lock.toString(), Long.toString(retryDuration), res.toString()); if(conf.getBoolVar(HiveConf.ConfVars.TXN_MGR_DUMP_LOCK_STATE_ON_ACQUIRE_TIMEOUT)) { showLocksNewFormat(le.getMessage());
private void testLockExpiration(HiveTxnManager txnMgr, int numLocksBefore, boolean shouldExpire) throws Exception { DbLockManager lockManager = (DbLockManager)txnMgr.getLockManager(); ShowLocksResponse resp = lockManager.getLocks(); Assert.assertEquals("Wrong number of locks before expire", numLocksBefore, resp.getLocks().size()); Thread.sleep(HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_TXN_TIMEOUT, TimeUnit.MILLISECONDS)); runReaper(); resp = lockManager.getLocks(); if (shouldExpire) { Assert.assertEquals("Expected all locks to expire", 0, resp.getLocks().size()); lockManager.clearLocalLockRecords(); } else { Assert.assertEquals("No lock should expire because there is heartbeating", numLocksBefore, resp.getLocks().size()); } }
@Override public void close() throws LockException { for (HiveLock lock : locks) { unlock(lock); } locks.clear(); }
@Override protected void destruct() { try { stopHeartbeat(); if (shutdownRunner != null) { ShutdownHookManager.removeShutdownHook(shutdownRunner); } if (isTxnOpen()) rollbackTxn(); if (lockMgr != null) lockMgr.close(); } catch (Exception e) { LOG.error("Caught exception " + e.getClass().getName() + " with message <" + e.getMessage() + ">, swallowing as there is nothing we can do with it."); // Not much we can do about it here. } }
LockState lockState = lockMgr.lock(rqstBuilder.build(), queryId, isBlocking, locks); ctx.setHiveLocks(locks); return lockState;
backoff(); res = client.checkLock(res.getLockid());
@Override public void releaseLocks(List<HiveLock> hiveLocks) throws LockException { if (lockMgr != null) { stopHeartbeat(); lockMgr.releaseLocks(hiveLocks); } }
long startRetry = System.currentTimeMillis(); while (res.getState() == LockState.WAITING && numRetries++ < maxNumWaits) { backoff(); res = txnManager.getMS().checkLock(res.getLockid()); unlock(hl);//remove the locks in Waiting state LockException le = new LockException(null, ErrorMsg.LOCK_ACQUIRE_TIMEDOUT, lock.toString(), Long.toString(retryDuration), res.toString()); if(conf.getBoolVar(HiveConf.ConfVars.TXN_MGR_DUMP_LOCK_STATE_ON_ACQUIRE_TIMEOUT)) { showLocksNewFormat(le.getMessage());
@Override public void close() throws LockException { for (HiveLock lock : locks) { unlock(lock); } locks.clear(); }
@Override protected void destruct() { try { stopHeartbeat(); if (shutdownRunner != null) { ShutdownHookManager.removeShutdownHook(shutdownRunner); } if (isTxnOpen()) rollbackTxn(); if (lockMgr != null) lockMgr.close(); } catch (Exception e) { LOG.error("Caught exception " + e.getClass().getName() + " with message <" + e.getMessage() + ">, swallowing as there is nothing we can do with it."); // Not much we can do about it here. } }
LockState lockState = lockMgr.lock(rqstBuilder.build(), queryId, isBlocking, locks); ctx.setHiveLocks(locks); return lockState;
@Override public void releaseLocks(List<HiveLock> hiveLocks) throws LockException { if (lockMgr != null) { stopHeartbeat(); lockMgr.releaseLocks(hiveLocks); } }
private void showLocksNewFormat(String preamble) throws LockException { ShowLocksResponse rsp = getLocks(); // write the results in the file ByteArrayOutputStream baos = new ByteArrayOutputStream(1024*2); DataOutputStream os = new DataOutputStream(baos); try { DDLTask.dumpLockInfo(os, rsp); os.flush(); LOG.info(baos.toString()); } catch(IOException ex) { LOG.error("Dumping lock info for " + preamble + " failed: " + ex.getMessage(), ex); } } /**
@Override public void rollbackTxn() throws LockException { if (!isTxnOpen()) { throw new RuntimeException("Attempt to rollback before opening a transaction"); } try { lockMgr.clearLocalLockRecords(); stopHeartbeat(); LOG.debug("Rolling back " + JavaUtils.txnIdToString(txnId)); getMS().rollbackTxn(txnId); } catch (NoSuchTxnException e) { LOG.error("Metastore could not find " + JavaUtils.txnIdToString(txnId)); throw new LockException(e, ErrorMsg.TXN_NO_SUCH_TRANSACTION, JavaUtils.txnIdToString(txnId)); } catch(TxnAbortedException e) { throw new LockException(e, ErrorMsg.TXN_ABORTED, JavaUtils.txnIdToString(txnId)); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } finally { txnId = 0; stmtId = -1; numStatements = 0; tableWriteIds.clear(); } }
@Override public void releaseLocks(List<HiveLock> hiveLocks) { LOG.info("releaseLocks: " + hiveLocks); for (HiveLock lock : hiveLocks) { try { unlock(lock); } catch (LockException e) { // Not sure why this method doesn't throw any exceptions, // but since the interface doesn't allow it we'll just swallow them and // move on. //This OK-ish since releaseLocks() is only called for RO/AC queries; it //would be really bad to eat exceptions here for write operations } } }
/** * we don't expect multiple thread to call this method concurrently but {@link #lockMgr} will * be read by a different threads that one writing it, thus it's {@code volatile} */ @Override public HiveLockManager getLockManager() throws LockException { init(); if (lockMgr == null) { lockMgr = new DbLockManager(conf, this); } return lockMgr; }
@Override protected void destruct() { try { if (txnId > 0) rollbackTxn(); if (lockMgr != null) lockMgr.close(); } catch (Exception e) { LOG.error("Caught exception " + e.getClass().getName() + " with message <" + e.getMessage() + ">, swallowing as there is nothing we can do with it."); // Not much we can do about it here. } }