Search in sources :

Example 1 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class DistTXStateProxyImplOnCoordinator method doCommit.

/*
   * [DISTTX] TODO - Handle result TXMessage
   */
private boolean doCommit() {
    boolean finalResult = true;
    final GemFireCacheImpl cache = GemFireCacheImpl.getExisting("Applying Dist TX Commit");
    final DM dm = cache.getDistributionManager();
    // Create Tx Participants
    Set<DistributedMember> txRemoteParticpants = getTxRemoteParticpants(dm);
    // create processor and commit message
    DistTXCommitMessage.DistTxCommitReplyProcessor processor = new DistTXCommitMessage.DistTxCommitReplyProcessor(this.getTxId(), dm, txRemoteParticpants, target2realDeals);
    // TODO [DISTTX} whats ack threshold?
    processor.enableSevereAlertProcessing();
    final DistTXCommitMessage commitMsg = new DistTXCommitMessage(this.getTxId(), this.onBehalfOfClientMember, processor);
    // send commit message to remote nodes
    ArrayList<ArrayList<DistTxThinEntryState>> entryEventList = new ArrayList<>();
    TreeSet<String> sortedRegionName = new TreeSet<>();
    for (DistributedMember remoteNode : txRemoteParticpants) {
        DistTXCoordinatorInterface remoteTXStateStub = target2realDeals.get(remoteNode);
        if (remoteTXStateStub.isTxState()) {
            throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistPeerTXStateStub", remoteTXStateStub.getClass().getSimpleName()));
        }
        try {
            populateEntryEventList(remoteNode, entryEventList, sortedRegionName);
            commitMsg.setEntryStateList(entryEventList);
            remoteTXStateStub.setCommitMessage(commitMsg, dm);
            remoteTXStateStub.commit();
        } finally {
            remoteTXStateStub.setCommitMessage(null, null);
            remoteTXStateStub.finalCleanup();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("DistTXStateProxyImplOnCoordinator.doCommit Sent Message target = " + remoteNode + " ,sortedRegions=" + sortedRegionName + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txEntryEventMap=" + printEntryEventMap(this.txEntryEventMap));
        }
    }
    // Do commit on local node
    DistTXCoordinatorInterface localTXState = target2realDeals.get(dm.getId());
    if (localTXState != null) {
        if (!localTXState.isTxState()) {
            throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateOnCoordinator", localTXState.getClass().getSimpleName()));
        }
        populateEntryEventList(dm.getId(), entryEventList, sortedRegionName);
        ((DistTXStateOnCoordinator) localTXState).setDistTxEntryStates(entryEventList);
        localTXState.commit();
        TXCommitMessage localResultMsg = localTXState.getCommitMessage();
        if (logger.isDebugEnabled()) {
            logger.debug("DistTXStateProxyImplOnCoordinator.doCommit local = " + dm.getId() + " ,sortedRegions=" + sortedRegionName + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txEntryEventMap=" + printEntryEventMap(this.txEntryEventMap) + " ,result= " + (localResultMsg != null) + " ,finalResult-old= " + finalResult);
        }
        finalResult = finalResult && (localResultMsg != null);
    }
    /*
     * [DISTTX] TODO Any test hooks
     */
    // if (internalAfterIndividualSend != null) {
    // internalAfterIndividualSend.run();
    // }
    /*
     * [DISTTX] TODO see how to handle exception
     */
    /*
     * [DISTTX] TODO Any test hooks
     */
    // if (internalAfterIndividualCommitProcess != null) {
    // // Testing callback
    // internalAfterIndividualCommitProcess.run();
    // }
    {
        // Wait for results
        dm.getCancelCriterion().checkCancelInProgress(null);
        processor.waitForPrecommitCompletion();
        // [DISTTX} TODO Handle stats
        dm.getStats().incCommitWaits();
        Map<DistributedMember, TXCommitMessage> remoteResults = processor.getCommitResponseMap();
        for (Entry<DistributedMember, TXCommitMessage> e : remoteResults.entrySet()) {
            DistributedMember target = e.getKey();
            TXCommitMessage remoteResultMsg = e.getValue();
            if (logger.isDebugEnabled()) {
                // TODO - make this trace level
                logger.debug("DistTXStateProxyImplOnCoordinator.doCommit got results from target = " + target + " ,result= " + (remoteResultMsg != null) + " ,finalResult-old= " + finalResult);
            }
            finalResult = finalResult && remoteResultMsg != null;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("DistTXStateProxyImplOnCoordinator.doCommit finalResult= " + finalResult);
    }
    return finalResult;
}
Also used : ArrayList(java.util.ArrayList) DM(org.apache.geode.distributed.internal.DM) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) Entry(java.util.Map.Entry) TreeSet(java.util.TreeSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 2 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class DistTXStateProxyImplOnCoordinator method doPrecommit.

private boolean doPrecommit() {
    boolean finalResult = true;
    final GemFireCacheImpl cache = GemFireCacheImpl.getExisting("Applying Dist TX Precommit");
    final DM dm = cache.getDistributionManager();
    Set<DistributedMember> txRemoteParticpants = getTxRemoteParticpants(dm);
    // create processor and precommit message
    DistTXPrecommitMessage.DistTxPrecommitReplyProcessor processor = new DistTXPrecommitMessage.DistTxPrecommitReplyProcessor(this.getTxId(), dm, txRemoteParticpants, target2realDeals);
    // TODO [DISTTX} whats ack threshold?
    processor.enableSevereAlertProcessing();
    final DistTXPrecommitMessage precommitMsg = new DistTXPrecommitMessage(this.getTxId(), this.onBehalfOfClientMember, processor);
    // send precommit message to remote nodes
    for (DistributedMember remoteNode : txRemoteParticpants) {
        DistTXCoordinatorInterface remoteTXStateStub = target2realDeals.get(remoteNode);
        if (remoteTXStateStub.isTxState()) {
            throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistPeerTXStateStub", remoteTXStateStub.getClass().getSimpleName()));
        }
        try {
            remoteTXStateStub.setPrecommitMessage(precommitMsg, dm);
            remoteTXStateStub.precommit();
        } finally {
            remoteTXStateStub.setPrecommitMessage(null, null);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit Sent Message to target = " + remoteNode);
        }
    }
    // Do precommit on local node
    TreeSet<String> sortedRegionName = new TreeSet<>();
    DistTXCoordinatorInterface localTXState = target2realDeals.get(dm.getId());
    if (localTXState != null) {
        if (!localTXState.isTxState()) {
            throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateOnCoordinator", localTXState.getClass().getSimpleName()));
        }
        localTXState.precommit();
        boolean localResult = localTXState.getPreCommitResponse();
        TreeMap<String, ArrayList<DistTxThinEntryState>> entryStateSortedMap = new TreeMap<String, ArrayList<DistTxThinEntryState>>();
        ArrayList<ArrayList<DistTxThinEntryState>> entryEventList = null;
        if (localResult) {
            localResult = ((DistTXStateOnCoordinator) localTXState).populateDistTxEntryStateList(entryStateSortedMap);
            if (localResult) {
                entryEventList = new ArrayList<ArrayList<DistTxThinEntryState>>(entryStateSortedMap.values());
                populateEntryEventMap(dm.getId(), entryEventList, sortedRegionName);
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit local = " + dm.getId() + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txRegionVersionsMap=" + printEntryEventMap(this.txEntryEventMap) + " ,result= " + localResult + " ,finalResult-old= " + finalResult);
        }
        finalResult = finalResult && localResult;
    }
    /*
     * [DISTTX] TODO Any test hooks
     */
    // if (internalAfterIndividualSend != null) {
    // internalAfterIndividualSend.run();
    // }
    /*
     * [DISTTX] TODO see how to handle exception
     */
    /*
     * [DISTTX] TODO Any test hooks
     */
    // if (internalAfterIndividualCommitProcess != null) {
    // // Testing callback
    // internalAfterIndividualCommitProcess.run();
    // }
    {
        // Wait for results
        dm.getCancelCriterion().checkCancelInProgress(null);
        processor.waitForPrecommitCompletion();
        // [DISTTX} TODO Handle stats
        // dm.getStats().incCommitWaits();
        Map<DistributedMember, DistTxPrecommitResponse> remoteResults = processor.getCommitResponseMap();
        for (Entry<DistributedMember, DistTxPrecommitResponse> e : remoteResults.entrySet()) {
            DistributedMember target = e.getKey();
            DistTxPrecommitResponse remoteResponse = e.getValue();
            ArrayList<ArrayList<DistTxThinEntryState>> entryEventList = remoteResponse.getDistTxEntryEventList();
            populateEntryEventMap(target, entryEventList, sortedRegionName);
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit got reply from target = " + target + " ,sortedRegions" + sortedRegionName + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txEntryEventMap=" + printEntryEventMap(this.txEntryEventMap) + " ,result= " + remoteResponse.getCommitState() + " ,finalResult-old= " + finalResult);
            }
            finalResult = finalResult && remoteResponse.getCommitState();
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit finalResult= " + finalResult);
    }
    return finalResult;
}
Also used : ArrayList(java.util.ArrayList) DM(org.apache.geode.distributed.internal.DM) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) DistTxPrecommitResponse(org.apache.geode.internal.cache.DistTXPrecommitMessage.DistTxPrecommitResponse) TreeSet(java.util.TreeSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) DistTxThinEntryState(org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)

Example 3 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class DistTXState method precommit.

/*
   * (non-Javadoc)
   * 
   * @see org.apache.geode.internal.cache.TXStateInterface#commit()
   * 
   * Take Locks Does conflict check on primary ([DISTTX] TODO on primary only) Invoke TxWriter
   */
@Override
public void precommit() throws CommitConflictException, UnsupportedOperationInTransactionException {
    if (logger.isDebugEnabled()) {
        logger.debug("DistTXState.precommit transaction {} is closed {} ", getTransactionId(), this.closed, new Throwable());
    }
    if (this.closed) {
        return;
    }
    synchronized (this.completionGuard) {
        this.completionStarted = true;
    }
    if (onBehalfOfRemoteStub && !proxy.isCommitOnBehalfOfRemoteStub()) {
        throw new UnsupportedOperationInTransactionException(LocalizedStrings.TXState_CANNOT_COMMIT_REMOTED_TRANSACTION.toLocalizedString());
    }
    cleanupNonDirtyRegions();
    /*
     * Lock buckets so they can't be rebalanced then perform the conflict check to fix #43489
     */
    try {
        lockBucketRegions();
    } catch (PrimaryBucketException pbe) {
        // not sure what to do here yet
        RuntimeException re = new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString());
        re.initCause(pbe);
        throw re;
    }
    if (this.locks == null) {
        reserveAndCheck();
    }
    // For internal testing
    if (this.internalAfterConflictCheck != null) {
        this.internalAfterConflictCheck.run();
    }
    updateRegionVersions();
    generateTailKeysForParallelDispatcherEvents();
    /*
     * If there is a TransactionWriter plugged in, we need to to give it an opportunity to abort the
     * transaction.
     */
    TransactionWriter writer = this.proxy.getTxMgr().getWriter();
    if (!firedWriter && writer != null) {
        try {
            firedWriter = true;
            writer.beforeCommit(getEvent());
        } catch (TransactionWriterException twe) {
            cleanup();
            throw new CommitConflictException(twe);
        } catch (VirtualMachineError err) {
            // cleanup(); this allocates objects so I don't think we can do it -
            // that leaves the TX open, but we are poison pilling so we should be
            // ok??
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            // rollback the transaction!
            cleanup();
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            throw new CommitConflictException(t);
        }
    }
}
Also used : CommitConflictException(org.apache.geode.cache.CommitConflictException) TransactionWriter(org.apache.geode.cache.TransactionWriter) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 4 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class DistTXCommitMessage method operateOnTx.

@Override
protected boolean operateOnTx(TXId txId, DistributionManager dm) throws RemoteOperationException {
    if (logger.isDebugEnabled()) {
        logger.debug("DistTXCommitMessage.operateOnTx: Tx {}", txId);
    }
    InternalCache cache = GemFireCacheImpl.getInstance();
    TXManagerImpl txMgr = cache.getTXMgr();
    final TXStateProxy txStateProxy = txMgr.getTXState();
    TXCommitMessage cmsg = null;
    try {
        // do the actual commit, only if it was not done before
        if (txMgr.isHostedTxRecentlyCompleted(txId)) {
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXCommitMessage.operateOnTx: found a previously committed transaction:{}", txId);
            }
            cmsg = txMgr.getRecentlyCompletedMessage(txId);
            if (txMgr.isExceptionToken(cmsg)) {
                throw txMgr.getExceptionForToken(cmsg, txId);
            }
        } else {
            // that don't start remote TX) then ignore
            if (txStateProxy != null) {
                /*
           * [DISTTX] TODO See how other exceptions are caught and send on wire, than throwing?
           * 
           * This can be spared since it will be programming bug
           */
                if (!txStateProxy.isDistTx() || txStateProxy.isCreatedOnDistTxCoordinator()) {
                    throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateProxyImplOnDatanode", txStateProxy.getClass().getSimpleName()));
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("DistTXCommitMessage.operateOnTx Commiting {} " + " incoming entryEventList:{} coming from {} ", txId, DistTXStateProxyImplOnCoordinator.printEntryEventList(this.entryStateList), this.getSender().getId());
                }
                // Set Member's ID to all entry states
                String memberID = this.getSender().getId();
                for (ArrayList<DistTxThinEntryState> esList : this.entryStateList) {
                    for (DistTxThinEntryState es : esList) {
                        es.setMemberID(memberID);
                    }
                }
                ((DistTXStateProxyImplOnDatanode) txStateProxy).populateDistTxEntryStates(this.entryStateList);
                txStateProxy.setCommitOnBehalfOfRemoteStub(true);
                txMgr.commit();
                cmsg = txStateProxy.getCommitMessage();
            }
        }
    } finally {
        txMgr.removeHostedTXState(txId);
    }
    DistTXCommitReplyMessage.send(getSender(), getProcessorId(), cmsg, getReplySender(dm));
    /*
     * return false so there isn't another reply
     */
    return false;
}
Also used : UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) DistTxThinEntryState(org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)

Example 5 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class TXStateStub method destroyExistingEntry.

/*
   * (non-Javadoc)
   * 
   * @see
   * org.apache.geode.internal.cache.TXStateInterface#destroyExistingEntry(org.apache.geode.internal
   * .cache.EntryEventImpl, boolean, java.lang.Object)
   */
public void destroyExistingEntry(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) throws EntryNotFoundException {
    if (event.getOperation().isLocal()) {
        throw new UnsupportedOperationInTransactionException(LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
    }
    TXRegionStub rs = getTXRegionStub(event.getRegion());
    rs.destroyExistingEntry(event, cacheWrite, expectedOldValue);
}
Also used : TXRegionStub(org.apache.geode.internal.cache.tx.TXRegionStub) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException)

Aggregations

UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)17 Region (org.apache.geode.cache.Region)7 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)6 Test (org.junit.Test)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 ArrayList (java.util.ArrayList)4 CommitConflictException (org.apache.geode.cache.CommitConflictException)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 TreeMap (java.util.TreeMap)3 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)3 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)3 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)3 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 DM (org.apache.geode.distributed.internal.DM)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 AbstractRegion (org.apache.geode.internal.cache.AbstractRegion)3