Search in sources :

Example 11 with LowMemoryException

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

the class LocalRegion method basicPutAll.

// TODO: refactor basicPutAll
public VersionedObjectList basicPutAll(final Map<?, ?> map, final DistributedPutAllOperation putAllOp, final Map<Object, VersionTag> retryVersions) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final EntryEventImpl event = putAllOp.getBaseEvent();
    EventID eventId = event.getEventId();
    if (eventId == null && generateEventID()) {
        // We need to "reserve" the eventIds for the entries in map here
        event.reserveNewEventId(this.cache.getDistributedSystem(), map.size());
        eventId = event.getEventId();
    }
    verifyPutAllMap(map);
    VersionedObjectList proxyResult = null;
    boolean partialResult = false;
    RuntimeException runtimeException = null;
    if (hasServerProxy()) {
        // send message to bridge server
        if (isTX()) {
            TXStateProxyImpl txState = (TXStateProxyImpl) this.cache.getTxManager().getTXState();
            txState.getRealDeal(null, this);
        }
        try {
            proxyResult = getServerProxy().putAll(map, eventId, !event.isGenerateCallbacks(), event.getCallbackArgument());
            if (isDebugEnabled) {
                logger.debug("PutAll received response from server: {}", proxyResult);
            }
        } catch (PutAllPartialResultException e) {
            // adjust the map to only add succeeded entries, then apply the adjustedMap
            proxyResult = e.getSucceededKeysAndVersions();
            partialResult = true;
            if (isDebugEnabled) {
                logger.debug("putAll in client encountered a PutAllPartialResultException:{}{}. Adjusted keys are: {}", e.getMessage(), getLineSeparator(), proxyResult.getKeys());
            }
            Throwable txException = e.getFailure();
            while (txException != null) {
                if (txException instanceof TransactionException) {
                    runtimeException = (RuntimeException) txException;
                    break;
                }
                txException = txException.getCause();
            }
            if (runtimeException == null) {
                // for cache close
                runtimeException = getCancelCriterion().generateCancelledException(e.getFailure());
                if (runtimeException == null) {
                    runtimeException = new ServerOperationException(LocalizedStrings.Region_PutAll_Applied_PartialKeys_At_Server_0.toLocalizedString(getFullPath()), e.getFailure());
                }
            }
        }
    }
    final VersionedObjectList succeeded = new VersionedObjectList(map.size(), true, this.concurrencyChecksEnabled);
    // if this is a transactional putAll, we will not have version information as it is only
    // generated at commit
    // so treat transactional putAll as if the server is not versioned
    final boolean serverIsVersioned = proxyResult != null && proxyResult.regionIsVersioned() && !isTX() && this.dataPolicy != DataPolicy.EMPTY;
    if (!serverIsVersioned && !partialResult) {
        // we don't need server information if it isn't versioned or if the region is empty
        proxyResult = null;
    }
    lockRVVForBulkOp();
    try {
        try {
            int size = proxyResult == null ? map.size() : proxyResult.size();
            if (isDebugEnabled) {
                logger.debug("size of put result is {} maps is {} proxyResult is {}", size, map, proxyResult);
            }
            final PutAllPartialResult partialKeys = new PutAllPartialResult(size);
            final Iterator iterator;
            final boolean isVersionedResults;
            if (proxyResult != null) {
                iterator = proxyResult.iterator();
                isVersionedResults = true;
            } else {
                iterator = map.entrySet().iterator();
                isVersionedResults = false;
            }
            // TODO: refactor this mess
            Runnable task = new Runnable() {

                @Override
                public void run() {
                    int offset = 0;
                    VersionTagHolder tagHolder = new VersionTagHolder();
                    while (iterator.hasNext()) {
                        stopper.checkCancelInProgress(null);
                        Map.Entry mapEntry = (Map.Entry) iterator.next();
                        Object key = mapEntry.getKey();
                        VersionTag versionTag = null;
                        tagHolder.setVersionTag(null);
                        final Object value;
                        boolean overwritten = false;
                        if (isVersionedResults) {
                            versionTag = ((VersionedObjectList.Entry) mapEntry).getVersionTag();
                            value = map.get(key);
                            if (isDebugEnabled) {
                                logger.debug("putAll key {} -> {} version={}", key, value, versionTag);
                            }
                            if (versionTag == null && serverIsVersioned && concurrencyChecksEnabled && dataPolicy.withStorage()) {
                                // entry since we don't know what its state should be (but the server should)
                                if (isDebugEnabled) {
                                    logger.debug("server returned no version information for {}", key);
                                }
                                localDestroyNoCallbacks(key);
                                // to be consistent we need to fetch the current entry
                                get(key, event.getCallbackArgument(), false, null);
                                overwritten = true;
                            }
                        } else {
                            value = mapEntry.getValue();
                            if (isDebugEnabled) {
                                logger.debug("putAll {} -> {}", key, value);
                            }
                        }
                        try {
                            if (serverIsVersioned) {
                                if (isDebugEnabled) {
                                    logger.debug("associating version tag with {} version={}", key, versionTag);
                                }
                                // If we have received a version tag from a server, add it to the event
                                tagHolder.setVersionTag(versionTag);
                                tagHolder.setFromServer(true);
                            } else if (retryVersions != null && retryVersions.containsKey(key)) {
                                // If this is a retried event, and we have a version tag for the retry,
                                // add it to the event.
                                tagHolder.setVersionTag(retryVersions.get(key));
                            }
                            if (!overwritten) {
                                basicEntryPutAll(key, value, putAllOp, offset, tagHolder);
                            }
                            // now we must check again since the cache may have closed during
                            // distribution (causing this process to not receive and queue the
                            // event for clients
                            stopper.checkCancelInProgress(null);
                            succeeded.addKeyAndVersion(key, tagHolder.getVersionTag());
                        } catch (Exception ex) {
                            if (isDebugEnabled) {
                                logger.debug("PutAll operation encountered exception for key {}", key, ex);
                            }
                            partialKeys.saveFailedKey(key, ex);
                        }
                        offset++;
                    }
                }
            };
            syncBulkOp(task, eventId);
            if (partialKeys.hasFailure()) {
                // Bug 51725: Now succeeded contains an order key list, may be missing the version tags.
                // Save reference of succeeded into partialKeys. The succeeded may be modified by
                // postPutAll() to fill in the version tags.
                partialKeys.setSucceededKeysAndVersions(succeeded);
                logger.info(LocalizedMessage.create(LocalizedStrings.Region_PutAll_Applied_PartialKeys_0_1, new Object[] { getFullPath(), partialKeys }));
                if (isDebugEnabled) {
                    logger.debug(partialKeys.detailString());
                }
                if (runtimeException == null) {
                    // if received exception from server first, ignore local exception
                    if (putAllOp.isBridgeOperation()) {
                        if (partialKeys.getFailure() instanceof CancelException) {
                            runtimeException = (RuntimeException) partialKeys.getFailure();
                        } else if (partialKeys.getFailure() instanceof LowMemoryException) {
                            // fix for #43589
                            throw partialKeys.getFailure();
                        } else {
                            runtimeException = new PutAllPartialResultException(partialKeys);
                            if (isDebugEnabled) {
                                logger.debug("basicPutAll:" + partialKeys.detailString());
                            }
                        }
                    } else {
                        throw partialKeys.getFailure();
                    }
                }
            }
        } catch (LowMemoryException lme) {
            throw lme;
        } catch (RuntimeException ex) {
            runtimeException = ex;
        } catch (Exception ex) {
            runtimeException = new RuntimeException(ex);
        } finally {
            putAllOp.getBaseEvent().release();
            putAllOp.freeOffHeapResources();
        }
        getDataView().postPutAll(putAllOp, succeeded, this);
    } finally {
        unlockRVVForBulkOp();
    }
    if (runtimeException != null) {
        throw runtimeException;
    }
    return succeeded;
}
Also used : VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) Endpoint(org.apache.geode.cache.client.internal.Endpoint) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException) LRUEntry(org.apache.geode.internal.cache.lru.LRUEntry) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) TransactionException(org.apache.geode.cache.TransactionException) Iterator(java.util.Iterator) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) StoredObject(org.apache.geode.internal.offheap.StoredObject) CancelException(org.apache.geode.CancelException) Map(java.util.Map) IndexMap(org.apache.geode.internal.cache.persistence.query.IndexMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashMap(java.util.HashMap) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 12 with LowMemoryException

use of org.apache.geode.cache.LowMemoryException 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 13 with LowMemoryException

use of org.apache.geode.cache.LowMemoryException 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)

Example 14 with LowMemoryException

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

the class MemberFunctionExecutor method validateExecution.

@Override
public void validateExecution(final Function function, final Set dest) {
    final InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && cache.getTxManager().getTXState() != null) {
        if (dest.size() > 1) {
            throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_FUNCTION_ON_MORE_THAN_ONE_NODE.toLocalizedString());
        } else {
            assert dest.size() == 1;
            DistributedMember funcTarget = (DistributedMember) dest.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.toLocalizedString());
            }
        }
    }
    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(new Object[] { 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) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 15 with LowMemoryException

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

the class DistributedRegionFunctionExecutor method validateExecution.

/*
   * (non-Javadoc)
   * 
   * @see
   * org.apache.geode.internal.cache.execute.AbstractExecution#validateExecution(org.apache.geode.
   * cache.execute.Function, java.util.Set)
   */
@Override
public void validateExecution(Function function, Set targetMembers) {
    InternalCache cache = region.getGemFireCache();
    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 (!MemoryThresholds.isLowMemoryExceptionDisabled() && function.optimizeForWrite()) {
        try {
            region.checkIfAboveThreshold(null);
        } catch (LowMemoryException ignore) {
            Set<DistributedMember> htrm = region.getMemoryThresholdReachedMembers();
            throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), htrm), htrm);
        }
    }
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) Set(java.util.Set) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Aggregations

LowMemoryException (org.apache.geode.cache.LowMemoryException)23 DistributedMember (org.apache.geode.distributed.DistributedMember)16 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 FunctionException (org.apache.geode.cache.execute.FunctionException)12 Set (java.util.Set)9 CacheException (org.apache.geode.cache.CacheException)8 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)8 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)8 InternalCache (org.apache.geode.internal.cache.InternalCache)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 HashSet (java.util.HashSet)7 Host (org.apache.geode.test.dunit.Host)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7 VM (org.apache.geode.test.dunit.VM)7 TransactionException (org.apache.geode.cache.TransactionException)6 IgnoredException (org.apache.geode.test.dunit.IgnoredException)6 IOException (java.io.IOException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashMap (java.util.HashMap)4 AttributesFactory (org.apache.geode.cache.AttributesFactory)4