Search in sources :

Example 26 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class GlobalTransaction method expireGTX.

/**
   * A timer task cleaup method. This is called when Transaction timeout occurs. On timeout the
   * transaction is rolled back and the thread removed from thread-Transaction Map.
   */
void expireGTX() {
    if (timedOut)
        // this method is only called by a single thread so this is safe
        return;
    timedOut = true;
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    try {
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.GlobalTransaction_TRANSACTION_0_HAS_TIMED_OUT, this);
        TransactionManagerImpl.getTransactionManager().removeTranxnMappings(transactions);
        setStatus(Status.STATUS_NO_TRANSACTION);
    } catch (Exception e) {
        if (writer.severeEnabled())
            writer.severe(LocalizedStrings.GlobalTransaction_GLOBATRANSACTION_EXPIREGTX_ERROR_OCCURRED_WHILE_REMOVING_TRANSACTIONAL_MAPPINGS_0, e, e);
    }
}
Also used : LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException)

Example 27 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class GlobalTransaction method enlistResource.

/**
   * Enlist the specified XAResource with this transaction. Currently only one Resource Manager is
   * being supported. enlistResource checks if there is no XAResource, then enlists the current
   * XAResource. For subsequent XAResources, it checks if is the same Resource Manager. If it is,
   * then the XAResources are addded, else an exception is thrown
   * 
   * Concurrency: The order of acquiring lock will be lock on "this" followed by lock on
   * resourceMap. It is possible that in some functions of this class both the locks are not needed
   * , but if the two are acquired then the realitive order will always be"this" followed by
   * resourceMap.
   * 
   * @param xaRes XAResource to be enlisted
   * @return true, if resource was enlisted successfully, otherwise false.
   * @throws SystemException - Thrown if the transaction manager encounters an unexpected error
   *         condition.
   * @throws IllegalStateException - Thrown if the transaction in the target object is in the
   *         prepared state or the transaction is inactive.
   * @throws RollbackException - Thrown to indicate that the transaction has been marked for
   *         rollback only.
   * 
   * @see javax.transaction.Transaction#enlistResource(javax.transaction.xa.XAResource)
   */
public boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException, SystemException {
    XAResource xar = null;
    try {
        synchronized (this) {
            if (status == Status.STATUS_MARKED_ROLLBACK) {
                String exception = "GlobalTransaction::enlistResource::Cannot enlist resource as the transaction has been marked for rollback";
                LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
                if (VERBOSE)
                    writer.fine(exception);
                throw new RollbackException(exception);
            } else if (status != Status.STATUS_ACTIVE) {
                String exception = LocalizedStrings.GlobalTransaction_GLOBALTRANSACTION_ENLISTRESOURCE_CANNOT_ENLIST_A_RESOURCE_TO_A_TRANSACTION_WHICH_IS_NOT_ACTIVE.toLocalizedString();
                LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
                if (VERBOSE)
                    writer.fine(exception);
                throw new IllegalStateException(exception);
            }
            if (resourceMap.isEmpty()) {
                xaRes.start(xid, XAResource.TMNOFLAGS);
                int delay = (int) ((expirationTime - System.currentTimeMillis()) / 1000);
                try {
                    if (!DISABLE_TRANSACTION_TIMEOUT_SETTING) {
                        xaRes.setTransactionTimeout(delay);
                    }
                } catch (XAException xe) {
                    String exception = LocalizedStrings.GlobalTransaction_GLOBALTRANSACTION_ENLISTRESOURCE_EXCEPTION_OCCURRED_IN_TRYING_TO_SET_XARESOURCE_TIMEOUT_DUE_TO_0_ERROR_CODE_1.toLocalizedString(new Object[] { xe, Integer.valueOf(xe.errorCode) });
                    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
                    if (VERBOSE)
                        writer.fine(exception);
                    throw new SystemException(exception);
                }
                resourceMap.put(xaRes, Boolean.TRUE);
            } else {
                synchronized (this.resourceMap) {
                    Iterator iterator = resourceMap.keySet().iterator();
                    xar = (XAResource) iterator.next();
                }
                if (!xar.isSameRM(xaRes)) {
                    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
                    if (writer.severeEnabled())
                        writer.severe(LocalizedStrings.GlobalTransaction_GLOBALTRANSACTIONENLISTRESOURCEONLY_ONE_RESOUCE_MANAGER_SUPPORTED);
                    throw new SystemException(LocalizedStrings.GlobalTransaction_GLOBALTRANSACTIONENLISTRESOURCEONLY_ONE_RESOUCE_MANAGER_SUPPORTED.toLocalizedString());
                } else {
                    xaRes.start(xid, XAResource.TMJOIN);
                    resourceMap.put(xaRes, Boolean.TRUE);
                }
            }
        }
    } catch (Exception e) {
        String addon = (e instanceof XAException ? ("Error Code =" + ((XAException) e).errorCode) : "");
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (VERBOSE)
            writer.fine(LocalizedStrings.GLOBALTRANSACTION__ENLISTRESOURCE__ERROR_WHILE_ENLISTING_XARESOURCE_0_1.toLocalizedString(new Object[] { e, addon }), e);
        SystemException sysEx = new SystemException(LocalizedStrings.GLOBALTRANSACTION__ENLISTRESOURCE__ERROR_WHILE_ENLISTING_XARESOURCE_0_1.toLocalizedString(new Object[] { e, addon }));
        sysEx.initCause(e);
        throw sysEx;
    }
    return true;
}
Also used : LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException)

Example 28 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class GlobalTransaction method resume.

/**
   * resume the current transaction by activating all the XAResources associated with the current
   * transaction
   */
public void resume() throws SystemException {
    XAResource xar = null;
    synchronized (this.resourceMap) {
        Iterator iterator = resourceMap.entrySet().iterator();
        Map.Entry entry;
        Boolean isActive = Boolean.FALSE;
        while (iterator.hasNext()) {
            entry = (Map.Entry) iterator.next();
            xar = (XAResource) entry.getKey();
            isActive = (Boolean) entry.getValue();
            if (!isActive.booleanValue())
                try {
                    xar.start(xid, XAResource.TMRESUME);
                    entry.setValue(Boolean.TRUE);
                } catch (Exception e) {
                    String exception = LocalizedStrings.GlobalTransaction_GLOBATRANSACTION_RESUME_RESUME_NOT_SUCCESFUL_DUE_TO_0.toLocalizedString(e);
                    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
                    if (VERBOSE)
                        writer.fine(exception, e);
                    throw new SystemException(exception);
                }
        }
    }
}
Also used : LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException)

Example 29 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class TransactionManagerImpl method setTransactionTimeout.

/**
   * not supported
   * 
   * @see javax.transaction.TransactionManager#setTransactionTimeout(int)
   */
public void setTransactionTimeout(int seconds) throws SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    GlobalTransaction gtx = getGlobalTransaction();
    if (gtx == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_SETTRANSACTIONTIMEOUT_NO_GLOBAL_TRANSACTION_EXISTS.toLocalizedString();
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (VERBOSE)
            writer.fine(exception);
        throw new SystemException(exception);
    }
    long newExpiry = gtx.setTransactionTimeoutForXARes(seconds);
    if (newExpiry > 0) {
        // long expirationTime = System.currentTimeMillis() + (seconds * 1000);
        gtxSet.remove(gtx);
        // Asif :Lets blindly remove the current gtx from the TreeMap &
        // Add only if status is neither Rolledback, Unknown , committed or no
        // transaction or GTX not
        // expired, which gurantees that the client thread will be returning &
        // cleaning up .so we
        // don't add it
        int status = gtx.getStatus();
        if (status != Status.STATUS_NO_TRANSACTION && status != Status.STATUS_COMMITTED && status != Status.STATUS_ROLLEDBACK && !gtx.isExpired()) {
            // Asif : Take a lock on GTX while setting the new Transaction timeout
            // value,
            // so that cleaner thread sees the new value immediately else due to
            // volatility issue
            // we may have inconsistent values of time out
            boolean toAdd = false;
            synchronized (gtx) {
                if (!gtx.isExpired()) {
                    gtx.setTimeoutValue(newExpiry);
                    toAdd = true;
                }
            }
            // of it.
            if (toAdd) {
                synchronized (gtxSet) {
                    gtxSet.add(gtx);
                    if (gtxSet.first() == gtx) {
                        gtxSet.notify();
                    }
                }
            }
        } else {
            String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_SETTRANSACTIONTIMEOUT_TRANSACTION_HAS_EITHER_EXPIRED_OR_ROLLEDBACK_OR_COMITTED.toLocalizedString();
            LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
            if (VERBOSE)
                writer.fine(exception);
            throw new SystemException(exception);
        }
    }
}
Also used : SystemException(javax.transaction.SystemException) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n)

Example 30 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class TransactionImpl method setTransactionTimeout.

/**
   * not supported
   */
public void setTransactionTimeout(int seconds) throws SystemException {
    String exception = LocalizedStrings.TransactionImpl_SETTRANSACTIONTIMEOUT_IS_NOT_SUPPORTED.toLocalizedString();
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.fineEnabled())
        writer.fine(exception);
    throw new SystemException(exception);
}
Also used : LogWriterI18n(org.apache.geode.i18n.LogWriterI18n)

Aggregations

LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)38 SystemException (javax.transaction.SystemException)11 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)8 HeuristicMixedException (javax.transaction.HeuristicMixedException)4 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)4 InvalidTransactionException (javax.transaction.InvalidTransactionException)4 NotSupportedException (javax.transaction.NotSupportedException)4 RollbackException (javax.transaction.RollbackException)4 CancelException (org.apache.geode.CancelException)4 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)4 Transaction (javax.transaction.Transaction)3 Region (org.apache.geode.cache.Region)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 CommitConflictException (org.apache.geode.cache.CommitConflictException)2 CommitIncompleteException (org.apache.geode.cache.CommitIncompleteException)2 Struct (org.apache.geode.cache.query.Struct)2 ClientHealthStats (org.apache.geode.internal.admin.remote.ClientHealthStats)2