Search in sources :

Example 1 with MetadataLockException

use of com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException in project kylo by Teradata.

the class JcrMetadataAccess method doCommit.

protected <R> R doCommit(Credentials creds, MetadataCommand<R> cmd, MetadataRollbackCommand rollbackCmd) throws RepositoryException, Exception {
    TransactionManager txnMgr = this.txnLookup.getTransactionManager();
    try {
        txnMgr.begin();
        R result = execute(creds, cmd);
        activeSession.get().session.save();
        checkinNodes();
        txnMgr.commit();
        performPostTransactionActions(true);
        return result;
    } catch (MetadataLockException | LockException e) {
        try {
            txnMgr.rollback();
        } catch (SystemException se) {
            log.error("Failed to rollback transaction as a result of lock acquisition failure", se);
        }
        activeSession.get().session.refresh(false);
        throw e;
    } catch (Exception e) {
        log.warn("Exception while execution a transactional operation - rolling back", e);
        try {
            txnMgr.rollback();
        } catch (SystemException se) {
            log.error("Failed to rollback transaction as a result of other transactional errors", se);
        }
        if (rollbackCmd != null) {
            try {
                rollbackCmd.execute(e);
            } catch (Exception rbe) {
                log.error("Failed to execution rollback command", rbe);
            }
        }
        activeSession.get().session.refresh(false);
        performPostTransactionActions(false);
        throw e;
    } finally {
        activeSession.get().session.logout();
    }
}
Also used : SystemException(javax.transaction.SystemException) LockException(javax.jcr.lock.LockException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) TransactionManager(javax.transaction.TransactionManager) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Example 2 with MetadataLockException

use of com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException in project kylo by Teradata.

the class JcrMetadataAccess method commit.

public <R> R commit(Credentials creds, MetadataCommand<R> cmd, MetadataRollbackCommand rollbackCmd) {
    ActiveSession active = activeSession.get();
    if (active == null) {
        try {
            activeSession.set(new ActiveSession(this.repository.login(creds)));
            try {
                Exception failException = null;
                while (failException == null) {
                    try {
                        return doCommit(creds, cmd, rollbackCmd);
                    } catch (MetadataLockException | LockException e) {
                        // If a lock acquisition failed then retry the command if the number of retries has not been exceeded.
                        if (activeSession.get().retriesRemaining > 0) {
                            activeSession.get().decrementRetry();
                            log.debug("Failed to aquire lock - retries remaining: {}", activeSession.get().retriesRemaining, e);
                            try {
                                Thread.sleep(activeSession.get().retryDelay);
                            } catch (InterruptedException ie) {
                            // Just continue.
                            }
                            // Start a new session before the retry.
                            activeSession.get().updateSession(this.repository.login(creds));
                        } else {
                            performPostTransactionActions(false);
                            failException = e;
                        }
                    } catch (Exception e) {
                        failException = e;
                    }
                }
                throw failException;
            } finally {
                activeSession.remove();
                postTransactionActions.remove();
                checkedOutNodes.remove();
            }
        } catch (RuntimeException e) {
            throw e;
        } catch (RepositoryException e) {
            throw new MetadataAccessException("Failure accessing the metadata store", e);
        } catch (Exception e) {
            throw new MetadataExecutionException(e);
        }
    } else {
        try {
            return cmd.execute();
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new MetadataExecutionException(e);
        }
    }
}
Also used : LockException(javax.jcr.lock.LockException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) RepositoryException(javax.jcr.RepositoryException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Aggregations

MetadataAccessException (com.thinkbiganalytics.metadata.api.MetadataAccessException)2 MetadataExecutionException (com.thinkbiganalytics.metadata.api.MetadataExecutionException)2 MetadataLockException (com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException)2 RepositoryException (javax.jcr.RepositoryException)2 LockException (javax.jcr.lock.LockException)2 NotSupportedException (javax.transaction.NotSupportedException)2 SystemException (javax.transaction.SystemException)2 TransactionManager (javax.transaction.TransactionManager)1