Search in sources :

Example 26 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class BucketRegion method createEventForPR.

@Retained
EntryEventImpl createEventForPR(EntryEventImpl sourceEvent) {
    EntryEventImpl e2 = new EntryEventImpl(sourceEvent);
    boolean returned = false;
    try {
        e2.setRegion(this.partitionedRegion);
        if (FORCE_LOCAL_LISTENERS_INVOCATION) {
            e2.setInvokePRCallbacks(true);
        } else {
            e2.setInvokePRCallbacks(sourceEvent.getInvokePRCallbacks());
        }
        DistributedMember dm = this.getDistributionManager().getDistributionManagerId();
        e2.setOriginRemote(!e2.getDistributedMember().equals(dm));
        returned = true;
        return e2;
    } finally {
        if (!returned) {
            e2.release();
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 27 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class AbstractRegionMap method createCBEvent.

/** create a callback event for applying a transactional change to the local cache */
@Retained
public static EntryEventImpl createCBEvent(final LocalRegion re, Operation op, Object key, Object newValue, TransactionId txId, TXRmtEvent txEvent, EventID eventId, Object aCallbackArgument, FilterRoutingInfo filterRoutingInfo, ClientProxyMembershipID bridgeContext, TXEntryState txEntryState, VersionTag versionTag, long tailKey) {
    DistributedMember originator = null;
    // txId should not be null even on localOrigin
    Assert.assertTrue(txId != null);
    originator = ((TXId) txId).getMemberId();
    LocalRegion eventRegion = re;
    if (eventRegion.isUsedForPartitionedRegionBucket()) {
        eventRegion = re.getPartitionedRegion();
    }
    @Retained EntryEventImpl retVal = EntryEventImpl.create(re, op, key, newValue, aCallbackArgument, txEntryState == null, originator);
    boolean returnedRetVal = false;
    try {
        if (bridgeContext != null) {
            retVal.setContext(bridgeContext);
        }
        if (eventRegion.generateEventID()) {
            retVal.setEventId(eventId);
        }
        if (versionTag != null) {
            retVal.setVersionTag(versionTag);
        }
        retVal.setTailKey(tailKey);
        FilterInfo localRouting = null;
        boolean computeFilterInfo = false;
        if (filterRoutingInfo == null) {
            computeFilterInfo = true;
        } else {
            localRouting = filterRoutingInfo.getLocalFilterInfo();
            if (localRouting != null) {
                // routing was computed in this VM but may need to perform local interest processing
                computeFilterInfo = !filterRoutingInfo.hasLocalInterestBeenComputed();
            } else {
                // routing was computed elsewhere and is in the "remote" routing table
                localRouting = filterRoutingInfo.getFilterInfo(re.getMyId());
            }
            if (localRouting != null) {
                if (!computeFilterInfo) {
                    retVal.setLocalFilterInfo(localRouting);
                }
            } else {
                computeFilterInfo = true;
            }
        }
        if (logger.isTraceEnabled()) {
            logger.trace("createCBEvent filterRouting={} computeFilterInfo={} local routing={}", filterRoutingInfo, computeFilterInfo, localRouting);
        }
        if (re.isUsedForPartitionedRegionBucket()) {
            BucketRegion bucket = (BucketRegion) re;
            if (BucketRegion.FORCE_LOCAL_LISTENERS_INVOCATION || bucket.getBucketAdvisor().isPrimary()) {
                retVal.setInvokePRCallbacks(true);
            } else {
                retVal.setInvokePRCallbacks(false);
            }
            if (computeFilterInfo) {
                if (bucket.getBucketAdvisor().isPrimary()) {
                    if (logger.isTraceEnabled()) {
                        logger.trace("createCBEvent computing routing for primary bucket");
                    }
                    FilterProfile fp = ((BucketRegion) re).getPartitionedRegion().getFilterProfile();
                    if (fp != null) {
                        FilterRoutingInfo fri = fp.getFilterRoutingInfoPart2(filterRoutingInfo, retVal);
                        if (fri != null) {
                            retVal.setLocalFilterInfo(fri.getLocalFilterInfo());
                        }
                    }
                }
            }
        } else if (computeFilterInfo) {
            // not a bucket
            if (logger.isTraceEnabled()) {
                logger.trace("createCBEvent computing routing for non-bucket");
            }
            FilterProfile fp = re.getFilterProfile();
            if (fp != null) {
                retVal.setLocalFilterInfo(fp.getLocalFilterRouting(retVal));
            }
        }
        retVal.setTransactionId(txId);
        returnedRetVal = true;
        return retVal;
    } finally {
        if (!returnedRetVal) {
            retVal.release();
        }
    }
}
Also used : Retained(org.apache.geode.internal.offheap.annotations.Retained) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 28 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class MemberFunctionExecutor method executeFunction.

@SuppressWarnings("unchecked")
private ResultCollector executeFunction(final Function function, ResultCollector resultCollector) {
    final DM dm = this.ds.getDistributionManager();
    final Set dest = new HashSet(this.members);
    if (dest.isEmpty()) {
        throw new FunctionException(LocalizedStrings.MemberFunctionExecutor_NO_MEMBER_FOUND_FOR_EXECUTING_FUNCTION_0.toLocalizedString(function.getId()));
    }
    validateExecution(function, dest);
    setExecutionNodes(dest);
    final InternalDistributedMember localVM = this.ds.getDistributionManager().getDistributionManagerId();
    final LocalResultCollector<?, ?> localRC = getLocalResultCollector(function, resultCollector);
    boolean remoteOnly = false;
    boolean localOnly = false;
    if (!dest.contains(localVM)) {
        remoteOnly = true;
    }
    if (dest.size() == 1 && dest.contains(localVM)) {
        localOnly = true;
    }
    final MemberFunctionResultSender resultSender = new MemberFunctionResultSender(dm, localRC, function, localOnly, remoteOnly, sender);
    if (dest.contains(localVM)) {
        // if member is local VM
        dest.remove(localVM);
        final FunctionContext context = new FunctionContextImpl(function.getId(), getArgumentsForMember(localVM.getId()), resultSender);
        boolean isTx = false;
        InternalCache cache = GemFireCacheImpl.getInstance();
        if (cache != null) {
            isTx = cache.getTxManager().getTXState() == null ? false : true;
        }
        executeFunctionOnLocalNode(function, context, resultSender, dm, isTx);
    }
    if (!dest.isEmpty()) {
        HashMap<InternalDistributedMember, Object> memberArgs = new HashMap<InternalDistributedMember, Object>();
        Iterator<DistributedMember> iter = dest.iterator();
        while (iter.hasNext()) {
            InternalDistributedMember recip = (InternalDistributedMember) iter.next();
            memberArgs.put(recip, getArgumentsForMember(recip.getId()));
        }
        Assert.assertTrue(memberArgs.size() == dest.size());
        MemberFunctionResultWaiter resultReciever = new MemberFunctionResultWaiter(this.ds, localRC, function, memberArgs, dest, resultSender);
        ResultCollector reply = resultReciever.getFunctionResultFrom(dest, function, this);
        return reply;
    }
    return localRC;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FunctionException(org.apache.geode.cache.execute.FunctionException) DM(org.apache.geode.distributed.internal.DM) InternalCache(org.apache.geode.internal.cache.InternalCache) FunctionContext(org.apache.geode.cache.execute.FunctionContext) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 29 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class MultiRegionFunctionExecutor method validateExecution.

@Override
public void validateExecution(Function function, Set targetMembers) {
    InternalCache cache = null;
    for (Region r : regions) {
        cache = (InternalCache) r.getCache();
        break;
    }
    if (cache != null && cache.getTxManager().getTXState() != null) {
        if (targetMembers.size() > 1) {
            throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_FUNCTION_ON_MORE_THAN_ONE_NODE.toLocalizedString());
        } else {
            assert targetMembers.size() == 1;
            DistributedMember funcTarget = (DistributedMember) targetMembers.iterator().next();
            DistributedMember target = cache.getTxManager().getTXState().getTarget();
            if (target == null) {
                cache.getTxManager().getTXState().setTarget(funcTarget);
            } else if (!target.equals(funcTarget)) {
                throw new TransactionDataNotColocatedException(LocalizedStrings.PartitionedRegion_TX_FUNCTION_EXECUTION_NOT_COLOCATED_0_1.toLocalizedString(target, funcTarget));
            }
        }
    }
    if (function.optimizeForWrite() && cache.getInternalResourceManager().getHeapMonitor().containsHeapCriticalMembers(targetMembers) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
        Set<InternalDistributedMember> hcm = cache.getResourceAdvisor().adviseCritialMembers();
        Set<DistributedMember> sm = SetUtils.intersection(hcm, targetMembers);
        throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), sm), sm);
    }
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 30 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class MultiRegionFunctionExecutor method executeFunction.

private ResultCollector executeFunction(final Function function, ResultCollector resultCollector) {
    InternalDistributedSystem ds = InternalDistributedSystem.getConnectedInstance();
    if (ds == null) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_DS_NOT_CREATED_OR_NOT_READY.toLocalizedString());
    }
    final DM dm = ds.getDistributionManager();
    final Map<InternalDistributedMember, Set<String>> memberToRegionMap = calculateMemberToRegionMap();
    final Set<InternalDistributedMember> dest = new HashSet<InternalDistributedMember>(memberToRegionMap.keySet());
    if (dest.isEmpty()) {
        throw new FunctionException(LocalizedStrings.MemberFunctionExecutor_NO_MEMBER_FOUND_FOR_EXECUTING_FUNCTION_0.toLocalizedString(function.getId()));
    }
    final InternalCache cache = GemFireCacheImpl.getInstance();
    if (function.optimizeForWrite() && cache != null && cache.getInternalResourceManager().getHeapMonitor().containsHeapCriticalMembers(dest) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
        Set<InternalDistributedMember> hcm = cache.getResourceAdvisor().adviseCritialMembers();
        Set<DistributedMember> sm = SetUtils.intersection(hcm, dest);
        throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), sm), sm);
    }
    setExecutionNodes(dest);
    final InternalDistributedMember localVM = cache.getMyId();
    final LocalResultCollector<?, ?> localResultCollector = getLocalResultCollector(function, resultCollector);
    boolean remoteOnly = false;
    boolean localOnly = false;
    if (!dest.contains(localVM)) {
        remoteOnly = true;
    }
    if (dest.size() == 1 && dest.contains(localVM)) {
        localOnly = true;
    }
    validateExecution(function, dest);
    final MemberFunctionResultSender resultSender = new MemberFunctionResultSender(dm, localResultCollector, function, localOnly, remoteOnly, null);
    if (dest.contains(localVM)) {
        // if member is local VM
        dest.remove(localVM);
        Set<String> regionPathSet = memberToRegionMap.get(localVM);
        Set<Region> regions = new HashSet<Region>();
        if (regionPathSet != null) {
            InternalCache cache1 = GemFireCacheImpl.getInstance();
            for (String regionPath : regionPathSet) {
                regions.add(cache1.getRegion(regionPath));
            }
        }
        final FunctionContextImpl context = new MultiRegionFunctionContextImpl(function.getId(), getArgumentsForMember(localVM.getId()), resultSender, regions, this.isReExecute);
        boolean isTx = cache.getTxManager().getTXState() == null ? false : true;
        executeFunctionOnLocalNode(function, context, resultSender, dm, isTx);
    }
    if (!dest.isEmpty()) {
        HashMap<InternalDistributedMember, Object> memberArgs = new HashMap<InternalDistributedMember, Object>();
        for (InternalDistributedMember recip : dest) {
            memberArgs.put(recip, getArgumentsForMember(recip.getId()));
        }
        Assert.assertTrue(memberArgs.size() == dest.size());
        MultiRegionFunctionResultWaiter waiter = new MultiRegionFunctionResultWaiter(ds, localResultCollector, function, dest, memberArgs, resultSender, memberToRegionMap);
        return waiter.getFunctionResultFrom(dest, function, this);
    }
    return localResultCollector;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) DM(org.apache.geode.distributed.internal.DM) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LowMemoryException(org.apache.geode.cache.LowMemoryException) HashSet(java.util.HashSet) FunctionException(org.apache.geode.cache.execute.FunctionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Aggregations

DistributedMember (org.apache.geode.distributed.DistributedMember)360 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)120 Test (org.junit.Test)109 HashSet (java.util.HashSet)83 InternalCache (org.apache.geode.internal.cache.InternalCache)83 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)82 ArrayList (java.util.ArrayList)64 VM (org.apache.geode.test.dunit.VM)60 CliCommand (org.springframework.shell.core.annotation.CliCommand)59 CliMetaData (org.apache.geode.management.cli.CliMetaData)57 Result (org.apache.geode.management.cli.Result)56 Set (java.util.Set)49 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)49 List (java.util.List)48 Cache (org.apache.geode.cache.Cache)47 Region (org.apache.geode.cache.Region)42 HashMap (java.util.HashMap)39 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)39 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)39 FunctionException (org.apache.geode.cache.execute.FunctionException)37