Search in sources :

Example 1 with DistTxEntryEvent

use of org.apache.geode.internal.cache.tx.DistTxEntryEvent in project geode by apache.

the class DistTXStateProxyImplOnCoordinator method getSecondariesAndReplicasForTxOps.

/**
   * creates a map of all secondaries(for PR) / replicas(for RR) to stubs to send commit message to
   * those
   */
private HashMap<DistributedMember, DistTXCoordinatorInterface> getSecondariesAndReplicasForTxOps() {
    final GemFireCacheImpl cache = GemFireCacheImpl.getExisting("getSecondariesAndReplicasForTxOps");
    InternalDistributedMember currentNode = cache.getInternalDistributedSystem().getDistributedMember();
    HashMap<DistributedMember, DistTXCoordinatorInterface> secondaryTarget2realDeals = new HashMap<>();
    for (Entry<DistributedMember, DistTXCoordinatorInterface> e : target2realDeals.entrySet()) {
        DistributedMember originalTarget = e.getKey();
        DistTXCoordinatorInterface distPeerTxStateStub = e.getValue();
        ArrayList<DistTxEntryEvent> primaryTxOps = distPeerTxStateStub.getPrimaryTransactionalOperations();
        for (DistTxEntryEvent dtop : primaryTxOps) {
            LocalRegion lr = dtop.getRegion();
            // replicas or secondaries
            Set<InternalDistributedMember> otherNodes = null;
            if (lr instanceof PartitionedRegion) {
                Set<InternalDistributedMember> allNodes = ((PartitionedRegion) dtop.getRegion()).getRegionAdvisor().getBucketOwners(dtop.getKeyInfo().getBucketId());
                allNodes.remove(originalTarget);
                otherNodes = allNodes;
            } else if (lr instanceof DistributedRegion) {
                otherNodes = ((DistributedRegion) lr).getCacheDistributionAdvisor().adviseInitializedReplicates();
                otherNodes.remove(originalTarget);
            }
            if (otherNodes != null) {
                for (InternalDistributedMember dm : otherNodes) {
                    // whether the target already exists due to other Tx op on the node
                    DistTXCoordinatorInterface existingDistPeerTXStateStub = target2realDeals.get(dm);
                    if (existingDistPeerTXStateStub == null) {
                        existingDistPeerTXStateStub = secondaryTarget2realDeals.get(dm);
                        if (existingDistPeerTXStateStub == null) {
                            DistTXCoordinatorInterface newTxStub = null;
                            if (currentNode.equals(dm)) {
                                // [DISTTX] TODO add a test case for this condition?
                                newTxStub = new DistTXStateOnCoordinator(this, false);
                            } else {
                                newTxStub = new DistPeerTXStateStub(this, dm, onBehalfOfClientMember);
                            }
                            newTxStub.addSecondaryTransactionalOperations(dtop);
                            secondaryTarget2realDeals.put(dm, newTxStub);
                        } else {
                            existingDistPeerTXStateStub.addSecondaryTransactionalOperations(dtop);
                        }
                    } else {
                        existingDistPeerTXStateStub.addSecondaryTransactionalOperations(dtop);
                    }
                }
            }
        }
    }
    return secondaryTarget2realDeals;
}
Also used : HashMap(java.util.HashMap) DistTxEntryEvent(org.apache.geode.internal.cache.tx.DistTxEntryEvent) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember)

Example 2 with DistTxEntryEvent

use of org.apache.geode.internal.cache.tx.DistTxEntryEvent in project geode by apache.

the class DistTXState method applyOpsOnRedundantCopy.

protected boolean applyOpsOnRedundantCopy(DistributedMember sender, ArrayList<DistTxEntryEvent> secondaryTransactionalOperations) {
    boolean returnValue = true;
    try {
        boolean result = true;
        // Start TxState Update During PreCommit phase
        setUpdatingTxStateDuringPreCommit(true);
        if (logger.isDebugEnabled()) {
            logger.debug("DistTXState.applyOpOnRedundantCopy: size of " + "secondaryTransactionalOperations = {}", secondaryTransactionalOperations.size());
        }
        /*
       * Handle Put Operations meant for secondary.
       * 
       * @see org.apache.geode.internal.cache.partitioned.PutMessage.
       * operateOnPartitionedRegion(DistributionManager, PartitionedRegion, long)
       * 
       * [DISTTX] TODO need to handle other operations
       */
        for (DistTxEntryEvent dtop : secondaryTransactionalOperations) {
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXState.applyOpOnRedundantCopy: processing dist " + "tx operation {}", dtop);
            }
            dtop.setDistributedMember(sender);
            dtop.setOriginRemote(false);
            /*
         * [DISTTX} TODO handle call back argument version tag and other settings in PutMessage
         */
            String failureReason = null;
            try {
                if (dtop.getKeyInfo().isDistKeyInfo()) {
                    dtop.getKeyInfo().setCheckPrimary(false);
                } else {
                    dtop.setKeyInfo(new DistTxKeyInfo(dtop.getKeyInfo()));
                    dtop.getKeyInfo().setCheckPrimary(false);
                }
                // apply the op
                result = applyIndividualOp(dtop);
                if (!result) {
                    // make sure the region hasn't gone away
                    dtop.getRegion().checkReadiness();
                }
            } catch (CacheWriterException cwe) {
                result = false;
                failureReason = "CacheWriterException";
            } catch (PrimaryBucketException pbe) {
                result = false;
                failureReason = "PrimaryBucketException";
            } catch (InvalidDeltaException ide) {
                result = false;
                failureReason = "InvalidDeltaException";
            } catch (DataLocationException e) {
                result = false;
                failureReason = "DataLocationException";
            }
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXState.applyOpOnRedundantCopy {} ##op {},  " + "##region {}, ##key {}", (result ? " sucessfully applied op " : " failed to apply op due to " + failureReason), dtop.getOperation(), dtop.getRegion().getName(), dtop.getKey());
            }
            if (!result) {
                returnValue = false;
                break;
            }
        }
    } finally {
        // End TxState Update During PreCommit phase
        setUpdatingTxStateDuringPreCommit(false);
    }
    return returnValue;
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) DistTxEntryEvent(org.apache.geode.internal.cache.tx.DistTxEntryEvent) DistTxKeyInfo(org.apache.geode.internal.cache.tx.DistTxKeyInfo) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 3 with DistTxEntryEvent

use of org.apache.geode.internal.cache.tx.DistTxEntryEvent in project geode by apache.

the class DistTXStateOnCoordinator method postRemoveAll.

public void postRemoveAll(DistributedRemoveAllOperation removeAllOp, VersionedObjectList successfulOps, LocalRegion region) {
    super.postRemoveAll(removeAllOp, successfulOps, region);
    // TODO DISTTX: event is never released
    EntryEventImpl event = EntryEventImpl.createRemoveAllEvent(removeAllOp, region, removeAllOp.getBaseEvent().getKey());
    event.setEventId(removeAllOp.getBaseEvent().getEventId());
    DistTxEntryEvent dtop = new DistTxEntryEvent(event);
    dtop.setRemoveAllOperation(removeAllOp);
    addPrimaryTransactionalOperations(dtop);
}
Also used : DistTxEntryEvent(org.apache.geode.internal.cache.tx.DistTxEntryEvent)

Example 4 with DistTxEntryEvent

use of org.apache.geode.internal.cache.tx.DistTxEntryEvent in project geode by apache.

the class DistTXStateOnCoordinator method invalidateOnRemote.

/*
   * (non-Javadoc)
   * 
   * @see org.apache.geode.internal.cache.InternalDataView#invalidateOnRemote
   * (org.apache.geode.internal.cache.EntryEventImpl, boolean, boolean)
   */
public void invalidateOnRemote(EntryEventImpl event, boolean invokeCallbacks, boolean forceNewEntry) throws DataLocationException {
    // logger.debug("DistTXStateOnCoordinator.invalidateOnRemote", new Throwable());
    super.invalidateExistingEntry(event, invokeCallbacks, forceNewEntry);
    addPrimaryTransactionalOperations(new DistTxEntryEvent(event));
}
Also used : DistTxEntryEvent(org.apache.geode.internal.cache.tx.DistTxEntryEvent)

Example 5 with DistTxEntryEvent

use of org.apache.geode.internal.cache.tx.DistTxEntryEvent in project geode by apache.

the class DistPeerTXStateStub method postRemoveAll.

public void postRemoveAll(DistributedRemoveAllOperation removeAllOp, VersionedObjectList successfulOps, LocalRegion region) {
    super.postRemoveAll(removeAllOp, successfulOps, region);
    // TODO DISTTX: event is never released
    EntryEventImpl event = EntryEventImpl.createRemoveAllEvent(removeAllOp, region, removeAllOp.getBaseEvent().getKey());
    event.setEventId(removeAllOp.getBaseEvent().getEventId());
    DistTxEntryEvent dtop = new DistTxEntryEvent(event);
    dtop.setRemoveAllOperation(removeAllOp);
    this.primaryTransactionalOperations.add(dtop);
}
Also used : DistTxEntryEvent(org.apache.geode.internal.cache.tx.DistTxEntryEvent)

Aggregations

DistTxEntryEvent (org.apache.geode.internal.cache.tx.DistTxEntryEvent)15 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 DistTxKeyInfo (org.apache.geode.internal.cache.tx.DistTxKeyInfo)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Test (org.junit.Test)1