Search in sources :

Example 1 with DistTxThinEntryState

use of org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState 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 2 with DistTxThinEntryState

use of org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState 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 3 with DistTxThinEntryState

use of org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState in project geode by apache.

the class TXRegionState method populateDistTxEntryStateList.

public boolean populateDistTxEntryStateList(ArrayList<DistTxThinEntryState> entryStateList) {
    String regionFullPath = this.getRegion().getFullPath();
    try {
        if (!this.entryMods.isEmpty()) {
            // [DISTTX] TODO Sort this first
            for (Entry<Object, TXEntryState> em : this.entryMods.entrySet()) {
                Object mKey = em.getKey();
                TXEntryState txes = em.getValue();
                DistTxThinEntryState thinEntryState = txes.getDistTxEntryStates();
                entryStateList.add(thinEntryState);
                if (logger.isDebugEnabled()) {
                    logger.debug("TXRegionState.populateDistTxEntryStateList Added " + thinEntryState + " for key=" + mKey + " ,op=" + txes.opToString() + " ,region=" + regionFullPath);
                }
            }
        }
        return true;
    } catch (RegionDestroyedException ex) {
    // region was destroyed out from under us; after conflict checking
    // passed. So act as if the region destroy happened right after the
    // commit. We act this way by doing nothing; including distribution
    // of this region's commit data.
    } catch (CancelException ex) {
    // cache was closed out from under us; after conflict checking
    // passed. So do nothing.
    }
    if (logger.isDebugEnabled()) {
        logger.debug("TXRegionState.populateDistTxEntryStateList Got exception for region " + regionFullPath);
    }
    return false;
}
Also used : CancelException(org.apache.geode.CancelException) DistTxThinEntryState(org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)

Example 4 with DistTxThinEntryState

use of org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState in project geode by apache.

the class TXRegionState method setDistTxEntryStates.

public void setDistTxEntryStates(ArrayList<DistTxThinEntryState> entryEventList) {
    String regionFullPath = this.getRegion().getFullPath();
    int entryModsSize = this.entryMods.size();
    int entryEventListSize = entryEventList.size();
    if (entryModsSize != entryEventListSize) {
        throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("entry size of " + entryModsSize + " for region " + regionFullPath, entryEventListSize));
    }
    int index = 0;
    // [DISTTX] TODO Sort this first
    for (Entry<Object, TXEntryState> em : this.entryMods.entrySet()) {
        Object mKey = em.getKey();
        TXEntryState txes = em.getValue();
        DistTxThinEntryState thinEntryState = entryEventList.get(index++);
        txes.setDistTxEntryStates(thinEntryState);
        if (logger.isDebugEnabled()) {
            logger.debug("TxRegionState.setDistTxEntryStates Added " + thinEntryState + " for key=" + mKey + " ,op=" + txes.opToString() + " ,region=" + regionFullPath);
        }
    }
}
Also used : DistTxThinEntryState(org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)

Aggregations

DistTxThinEntryState (org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)4 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 CancelException (org.apache.geode.CancelException)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DM (org.apache.geode.distributed.internal.DM)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 DistTxPrecommitResponse (org.apache.geode.internal.cache.DistTXPrecommitMessage.DistTxPrecommitResponse)1