@Override public List<Long> replOpenTxn(String replPolicy, List<Long> srcTxnIds, String user) throws LockException { try { return getMS().replOpenTxn(replPolicy, srcTxnIds, user); } catch (TException e) { throw new LockException(e, ErrorMsg.METASTORE_COMMUNICATION_FAILED); } }
private long getTableWriteId( String dbName, String tableName, boolean allocateIfNotYet) throws LockException { String fullTableName = AcidUtils.getFullTableName(dbName, tableName); if (tableWriteIds.containsKey(fullTableName)) { return tableWriteIds.get(fullTableName); } else if (!allocateIfNotYet) { return 0; } try { long writeId = getMS().allocateTableWriteId(txnId, dbName, tableName); LOG.debug("Allocated write ID {} for {}.{}", writeId, dbName, tableName); tableWriteIds.put(fullTableName, writeId); return writeId; } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
private boolean heartbeatMaterializationRebuildLock(String dbName, String tableName, long txnId) throws LockException { try { return getMS().heartbeatLockMaterializationRebuild(dbName, tableName, txnId); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
public void replAllocateTableWriteIdsBatch(String dbName, String tableName, String replPolicy, List<TxnToWriteId> srcTxnToWriteIdList) throws LockException { try { getMS().replAllocateTableWriteIdsBatch(dbName, tableName, replPolicy, srcTxnToWriteIdList); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
public ShowLocksResponse getLocks(ShowLocksRequest showLocksRequest) throws LockException { try { return txnManager.getMS().showLocks(showLocksRequest); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
@Override public void replTableWriteIdState(String validWriteIdList, String dbName, String tableName, List<String> partNames) throws LockException { try { getMS().replTableWriteIdState(validWriteIdList, dbName, tableName, partNames); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
public ShowLocksResponse getLocks(ShowLocksRequest showLocksRequest) throws LockException { try { return txnManager.getMS().showLocks(showLocksRequest); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
@Override public ValidTxnWriteIdList getValidWriteIds(List<String> tableList, String validTxnList) throws LockException { assert isTxnOpen(); assert validTxnList != null && !validTxnList.isEmpty(); try { return TxnCommonUtils.createValidTxnWriteIdList( txnId, getMS().getValidWriteIds(tableList, validTxnList)); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
@Override public ValidTxnList getValidTxns() throws LockException { init(); try { return getMS().getValidTxns(txnId); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
/** * Used to make another attempt to acquire a lock (in Waiting state) * @param extLockId * @return result of the attempt * @throws LockException */ LockState checkLock(long extLockId) throws LockException { try { return txnManager.getMS().checkLock(extLockId).getState(); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
/** * Used to make another attempt to acquire a lock (in Waiting state) * @param extLockId * @return result of the attempt * @throws LockException */ LockState checkLock(long extLockId) throws LockException { try { return txnManager.getMS().checkLock(extLockId).getState(); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
@Override public ValidTxnList getValidTxns() throws LockException { assert isTxnOpen(); init(); try { return getMS().getValidTxns(txnId); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
@Override public void replRollbackTxn(String replPolicy, long srcTxnId) throws LockException { try { getMS().replRollbackTxn(srcTxnId, replPolicy); } catch (NoSuchTxnException e) { LOG.error("Metastore could not find " + JavaUtils.txnIdToString(srcTxnId)); throw new LockException(e, ErrorMsg.TXN_NO_SUCH_TRANSACTION, JavaUtils.txnIdToString(srcTxnId)); } catch (TxnAbortedException e) { LockException le = new LockException(e, ErrorMsg.TXN_ABORTED, JavaUtils.txnIdToString(srcTxnId), e.getMessage()); LOG.error(le.getMessage()); throw le; } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } }
@Override public LockResponse acquireMaterializationRebuildLock(String dbName, String tableName, long txnId) throws LockException { // Acquire lock LockResponse lockResponse; try { lockResponse = getMS().lockMaterializationRebuild(dbName, tableName, txnId); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } if (lockResponse.getState() == LockState.ACQUIRED) { // If lock response is ACQUIRED, we can create the heartbeater long initialDelay = 0L; long heartbeatInterval = getHeartbeatInterval(conf); assert heartbeatInterval > 0; MaterializationRebuildLockHeartbeater heartbeater = new MaterializationRebuildLockHeartbeater( this, dbName, tableName, queryId, txnId); ScheduledFuture<?> task = startHeartbeat(initialDelay, heartbeatInterval, heartbeater); heartbeater.task.set(task); LOG.debug("Started heartbeat for materialization rebuild lock for {} with delay/interval = {}/{} {} for query: {}", AcidUtils.getFullTableName(dbName, tableName), initialDelay, heartbeatInterval, TimeUnit.MILLISECONDS, queryId); } return lockResponse; }
@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(); } }
@VisibleForTesting long openTxn(Context ctx, String user, long delay) throws LockException { /*Q: why don't we lock the snapshot here??? Instead of having client make an explicit call whenever it chooses A: If we want to rely on locks for transaction scheduling we must get the snapshot after lock acquisition. Relying on locks is a pessimistic strategy which works better under high contention.*/ init(); getLockManager(); if(isTxnOpen()) { throw new LockException("Transaction already opened. " + JavaUtils.txnIdToString(txnId)); } try { txnId = getMS().openTxn(user); stmtId = 0; numStatements = 0; tableWriteIds.clear(); isExplicitTransaction = false; startTransactionCount = 0; LOG.info("Opened " + JavaUtils.txnIdToString(txnId)); ctx.setHeartbeater(startHeartbeat(delay)); return txnId; } catch (TException e) { throw new LockException(e, ErrorMsg.METASTORE_COMMUNICATION_FAILED); } }
@Override public void commitTxn() throws LockException { if (!isTxnOpen()) { throw new RuntimeException("Attempt to commit before opening a transaction"); } try { // do all new clear in clearLocksAndHB method to make sure that same code is there for replCommitTxn flow. clearLocksAndHB(); LOG.debug("Committing txn " + JavaUtils.txnIdToString(txnId)); getMS().commitTxn(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) { LockException le = new LockException(e, ErrorMsg.TXN_ABORTED, JavaUtils.txnIdToString(txnId), e.getMessage()); LOG.error(le.getMessage()); throw le; } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } finally { // do all new reset in resetTxnInfo method to make sure that same code is there for replCommitTxn flow. resetTxnInfo(); } } @Override
@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; statementId = -1; } }
@VisibleForTesting long openTxn(Context ctx, String user, long delay) throws LockException { //todo: why don't we lock the snapshot here??? Instead of having client make an explicit call //whenever it chooses init(); if(isTxnOpen()) { throw new LockException("Transaction already opened. " + JavaUtils.txnIdToString(txnId)); } try { txnId = getMS().openTxn(user); statementId = 0; LOG.debug("Opened " + JavaUtils.txnIdToString(txnId)); ctx.setHeartbeater(startHeartbeat(delay)); return txnId; } catch (TException e) { throw new LockException(e, ErrorMsg.METASTORE_COMMUNICATION_FAILED); } }
@Override public void replCommitTxn(CommitTxnRequest rqst) throws LockException { try { if (rqst.isSetReplLastIdInfo()) { if (!isTxnOpen()) { throw new RuntimeException("Attempt to commit before opening a transaction"); } // For transaction started internally by repl load command, heartbeat needs to be stopped. clearLocksAndHB(); } getMS().replCommitTxn(rqst); } catch (NoSuchTxnException e) { LOG.error("Metastore could not find " + JavaUtils.txnIdToString(rqst.getTxnid())); throw new LockException(e, ErrorMsg.TXN_NO_SUCH_TRANSACTION, JavaUtils.txnIdToString(rqst.getTxnid())); } catch (TxnAbortedException e) { LockException le = new LockException(e, ErrorMsg.TXN_ABORTED, JavaUtils.txnIdToString(rqst.getTxnid()), e.getMessage()); LOG.error(le.getMessage()); throw le; } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } finally { if (rqst.isSetReplLastIdInfo()) { // For transaction started internally by repl load command, needs to clear the txn info. resetTxnInfo(); } } }