Search in sources :

Example 1 with InternalGemFireException

use of org.apache.geode.InternalGemFireException in project geode by apache.

the class DistributedCacheTestCase method setUpDistributedCacheTestCase.

/**
   * Creates the {@link Cache} and root region in each remote VM and, if createLocalCache, in this
   * VM.
   */
private final void setUpDistributedCacheTestCase(boolean createLocalCache) throws Exception {
    if (createLocalCache) {
        try {
            remoteCreateCache();
            assertTrue(cache != null);
        } catch (Exception ex) {
            String s = "While creating cache in this VM";
            throw new InternalGemFireException(s, ex);
        }
    } else {
        // make sure we have a connected DistributedSystem
        this.getSystem();
    }
    for (int h = 0; h < Host.getHostCount(); h++) {
        Host host = Host.getHost(h);
        for (int v = 0; v < host.getVMCount(); v++) {
            VM vm = host.getVM(v);
            vm.invoke(() -> this.remoteCreateCache());
        }
    }
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) CacheException(org.apache.geode.cache.CacheException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException)

Example 2 with InternalGemFireException

use of org.apache.geode.InternalGemFireException in project geode by apache.

the class ReplyProcessor21 method timeout.

/**
   * process a wait-timeout. Usually suspectThem would be used in the first timeout, followed by a
   * subsequent use of disconnectThem
   * 
   * @param suspectThem whether to ask the membership manager to suspect the unresponsive members
   * @param severeAlert whether to ask the membership manager to disconnect the unresponseive
   *        members
   */
private void timeout(boolean suspectThem, boolean severeAlert) {
    if (!this.processTimeout())
        return;
    Set activeMembers = getDistributionManagerIds();
    // an alert that will show up in the console
    long timeout = getAckWaitThreshold();
    final Object[] msgArgs = new Object[] { Long.valueOf(timeout + (severeAlert ? getSevereAlertThreshold() : 0)), this, getDistributionManager().getId(), activeMembers };
    final StringId msg = LocalizedStrings.ReplyProcessor21_0_SEC_HAVE_ELAPSED_WHILE_WAITING_FOR_REPLIES_1_ON_2_WHOSE_CURRENT_MEMBERSHIP_LIST_IS_3;
    if (severeAlert) {
        logger.fatal(LocalizedMessage.create(msg, msgArgs));
    } else {
        logger.warn(LocalizedMessage.create(msg, msgArgs));
    }
    msgArgs[3] = "(omitted)";
    Breadcrumbs.setProblem(msg, msgArgs);
    // Increment the stat
    getDistributionManager().getStats().incReplyTimeouts();
    final Set suspectMembers;
    if (suspectThem || severeAlert) {
        suspectMembers = new HashSet();
    } else {
        suspectMembers = null;
    }
    synchronized (this.members) {
        for (int i = 0; i < this.members.length; i++) {
            if (this.members[i] != null) {
                if (!activeMembers.contains(this.members[i])) {
                    logger.warn(LocalizedMessage.create(LocalizedStrings.ReplyProcessor21_VIEW_NO_LONGER_HAS_0_AS_AN_ACTIVE_MEMBER_SO_WE_WILL_NO_LONGER_WAIT_FOR_IT, this.members[i]));
                    memberDeparted(this.members[i], false);
                } else {
                    if (suspectMembers != null) {
                        suspectMembers.add(this.members[i]);
                    }
                }
            }
        }
    }
    if (THROW_EXCEPTION_ON_TIMEOUT) {
        // init the cause to be a TimeoutException so catchers can determine cause
        TimeoutException cause = new TimeoutException(LocalizedStrings.TIMED_OUT_WAITING_FOR_ACKS.toLocalizedString());
        throw new InternalGemFireException(LocalizedStrings.ReplyProcessor21_0_SEC_HAVE_ELAPSED_WHILE_WAITING_FOR_REPLIES_1_ON_2_WHOSE_CURRENT_MEMBERSHIP_LIST_IS_3.toLocalizedString(msgArgs), cause);
    } else if (suspectThem) {
        if (suspectMembers != null && suspectMembers.size() > 0) {
            getDistributionManager().getMembershipManager().suspectMembers(suspectMembers, "Failed to respond within ack-wait-threshold");
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringId(org.apache.geode.i18n.StringId) InternalGemFireException(org.apache.geode.InternalGemFireException) HashSet(java.util.HashSet) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 3 with InternalGemFireException

use of org.apache.geode.InternalGemFireException in project geode by apache.

the class AbstractLRURegionMap method evictEntry.

/**
   * Evicts the given entry from the cache. Returns the total number of bytes evicted. 1. For action
   * local destroy, returns size(key + value) 2. For action evict to disk, returns size(value)
   * 
   * @return number of bytes evicted, zero if no eviction took place
   */
protected int evictEntry(LRUEntry entry, LRUStatistics stats) throws RegionClearedException {
    EvictionAction action = _getCCHelper().getEvictionAction();
    LocalRegion region = _getOwner();
    if (action.isLocalDestroy()) {
        int size = entry.getEntrySize();
        if (region.evictDestroy(entry)) {
            return size;
        } else {
            return 0;
        }
    } else if (action.isOverflowToDisk()) {
        Assert.assertTrue(entry instanceof DiskEntry);
        int change = 0;
        synchronized (entry) {
            if (entry.isInUseByTransaction()) {
                entry.unsetEvicted();
                if (logger.isTraceEnabled(LogMarker.LRU)) {
                    logger.trace(LogMarker.LRU, "No eviction of transactional entry for key={}", entry.getKey());
                }
                return 0;
            }
            // Do the following check while synchronized to fix bug 31761
            Token entryVal = entry.getValueAsToken();
            if (entryVal == null) {
                if (logger.isTraceEnabled(LogMarker.LRU)) {
                    logger.trace(LogMarker.LRU, "no need to evict already evicted key={}", entry.getKey());
                }
                return 0;
            }
            if (Token.isInvalidOrRemoved(entryVal)) {
                // and the destroyed token needs to stay in memory
                if (logger.isTraceEnabled(LogMarker.LRU)) {
                    logger.trace(LogMarker.LRU, "no need to evict {} token for key={}", entryVal, entry.getKey());
                }
                return 0;
            }
            entry.setEvicted();
            change = DiskEntry.Helper.overflowToDisk((DiskEntry) entry, region, _getCCHelper());
        }
        boolean result = change < 0;
        if (result) {
            if (_getOwner() instanceof BucketRegion) {
                BucketRegion bucketRegion = (BucketRegion) _getOwner();
                bucketRegion.updateCounter(change);
                // if(bucketRegion.getBucketAdvisor().isPrimary()){
                stats.updateCounter(change);
            // }
            } else {
                stats.updateCounter(change);
            }
        } else {
            if (logger.isTraceEnabled(LogMarker.LRU)) {
                logger.trace(LogMarker.LRU, "no need to evict token for key={} because moving its value to disk resulted in a net change of {} bytes.", entry.getKey(), change);
            }
        }
        return change * -1;
    } else {
        throw new InternalGemFireException(LocalizedStrings.AbstractLRURegionMap_UNKNOWN_EVICTION_ACTION_0.toLocalizedString(action));
    }
}
Also used : EvictionAction(org.apache.geode.cache.EvictionAction) InternalGemFireException(org.apache.geode.InternalGemFireException)

Example 4 with InternalGemFireException

use of org.apache.geode.InternalGemFireException in project geode by apache.

the class EventID method getMembershipId.

/**
   * Convert a ClientProxyMembershipID distribted member ID array into one usable by EventIDs
   * 
   * @param client the client's ID
   * @return a byte array that may be used in EventID formation
   */
public static byte[] getMembershipId(ClientProxyMembershipID client) {
    try {
        HeapDataOutputStream hdos = new HeapDataOutputStream(256, Version.CURRENT);
        ((InternalDistributedMember) client.getDistributedMember()).writeEssentialData(hdos);
        return hdos.toByteArray();
    } catch (IOException ioe) {
        throw new InternalGemFireException(LocalizedStrings.ClientProxyMembershipID_UNABLE_TO_SERIALIZE_IDENTITY.toLocalizedString(), ioe);
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalGemFireException(org.apache.geode.InternalGemFireException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) IOException(java.io.IOException)

Example 5 with InternalGemFireException

use of org.apache.geode.InternalGemFireException in project geode by apache.

the class SingleHopClientExecutor method submitAllHA.

static boolean submitAllHA(List callableTasks, LocalRegion region, boolean isHA, ResultCollector rc, Set<String> failedNodes) {
    ClientMetadataService cms = region.getCache().getClientMetadataService();
    boolean reexecute = false;
    if (callableTasks != null && !callableTasks.isEmpty()) {
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            GemFireException functionExecutionException = null;
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            final boolean isDebugEnabled = logger.isDebugEnabled();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                ServerLocation server = task.getServer();
                try {
                    fut.get();
                    if (isDebugEnabled) {
                        logger.debug("ExecuteRegionFunctionSingleHopOp#got result from {}", server);
                    }
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof InternalFunctionInvocationTargetException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.InternalFunctionInvocationTargetException : Caused by :{}", ee.getCause());
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        reexecute = true;
                        failedNodes.addAll(((InternalFunctionInvocationTargetException) ee.getCause()).getFailedNodeSet());
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            rc.clearResults();
                        } else {
                            if (ee.getCause().getCause() != null) {
                                functionExecutionException = new FunctionInvocationTargetException(ee.getCause().getCause());
                            } else {
                                functionExecutionException = new FunctionInvocationTargetException(new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString()));
                            }
                        }
                    } else if (ee.getCause() instanceof FunctionException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.FunctionException : Caused by :{}", ee.getCause());
                        }
                        FunctionException fe = (FunctionException) ee.getCause();
                        if (isHA) {
                            throw fe;
                        } else {
                            functionExecutionException = fe;
                        }
                    } else if (ee.getCause() instanceof ServerOperationException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        ServerOperationException soe = (ServerOperationException) ee.getCause();
                        if (isHA) {
                            throw soe;
                        } else {
                            functionExecutionException = soe;
                        }
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            reexecute = true;
                            rc.clearResults();
                        } else {
                            functionExecutionException = (ServerConnectivityException) ee.getCause();
                        }
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            if (functionExecutionException != null) {
                throw functionExecutionException;
            }
        }
    }
    return reexecute;
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InternalGemFireException(org.apache.geode.InternalGemFireException) GemFireException(org.apache.geode.GemFireException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Future(java.util.concurrent.Future) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

InternalGemFireException (org.apache.geode.InternalGemFireException)46 IOException (java.io.IOException)12 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)8 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)8 ExecutionException (java.util.concurrent.ExecutionException)7 UnknownHostException (java.net.UnknownHostException)6 Future (java.util.concurrent.Future)6 Method (java.lang.reflect.Method)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 CacheException (org.apache.geode.cache.CacheException)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)4 NoSuchElementException (java.util.NoSuchElementException)3 Set (java.util.Set)3 ExecutorService (java.util.concurrent.ExecutorService)3