Search in sources :

Example 21 with VersionedObjectList

use of org.apache.geode.internal.cache.tier.sockets.VersionedObjectList in project geode by apache.

the class PartitionedRegion method tryToSendOneRemoveAllMessage.

public VersionedObjectList tryToSendOneRemoveAllMessage(RemoveAllPRMessage prMsg, InternalDistributedMember currentTarget) throws DataLocationException {
    boolean putResult = false;
    VersionedObjectList versions = null;
    final boolean isLocal = (this.localMaxMemory > 0) && currentTarget.equals(getMyId());
    if (isLocal) {
        // local
        // It might throw retry exception when one key failed
        // InternalDS has to be set for each msg
        prMsg.initMessage(this, null, false, null);
        putResult = prMsg.doLocalRemoveAll(this, this.getDistributionManager().getDistributionManagerId(), true);
        versions = prMsg.getVersions();
    } else {
        RemoveAllPRMessage.RemoveAllResponse response = (RemoveAllPRMessage.RemoveAllResponse) prMsg.send(currentTarget, this);
        RemoveAllPRMessage.RemoveAllResult pr = null;
        if (response != null) {
            this.prStats.incPartitionMessagesSent();
            try {
                pr = response.waitForResult();
                putResult = pr.returnValue;
                versions = pr.versions;
            } catch (RegionDestroyedException rde) {
                if (logger.isDebugEnabled()) {
                    logger.debug("prMsg.send: caught RegionDestroyedException", rde);
                }
                throw new RegionDestroyedException(toString(), getFullPath());
            } catch (CacheException ce) {
                // Fix for bug 36014
                throw new PartitionedRegionDistributionException("prMsg.send on " + currentTarget + " failed", ce);
            }
        } else {
            // follow the same behavior of putRemotely()
            putResult = true;
        }
    }
    if (!putResult) {
        // retry exception when msg failed in waitForResult()
        ForceReattemptException fre = new ForceReattemptException("false result in PutAllMessage.send - retrying");
        fre.setHash(0);
        throw fre;
    }
    return versions;
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) RemoveAllPRMessage(org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException)

Example 22 with VersionedObjectList

use of org.apache.geode.internal.cache.tier.sockets.VersionedObjectList in project geode by apache.

the class ServerRegionProxy method getAll.

@Override
public VersionedObjectList getAll(List keys, Object callback) {
    recordTXOperation(ServerRegionOperation.GET_ALL, null, keys);
    int txID = TXManagerImpl.getCurrentTXUniqueId();
    VersionedObjectList result;
    if (this.pool.getPRSingleHopEnabled() && (txID == TXManagerImpl.NOTX)) {
        result = GetAllOp.execute(this.pool, this.region, keys, this.pool.getRetryAttempts(), callback);
    } else {
        result = GetAllOp.execute(this.pool, this.regionName, keys, callback);
    }
    if (result != null) {
        for (Iterator it = result.iterator(); it.hasNext(); ) {
            VersionedObjectList.Entry entry = it.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            boolean isOnServer = entry.isKeyNotOnServer();
            if (!isOnServer) {
                if (value instanceof Throwable) {
                    logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { value, key }), (Throwable) value);
                }
            }
        }
    }
    return result;
}
Also used : Iterator(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList.Iterator) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)

Example 23 with VersionedObjectList

use of org.apache.geode.internal.cache.tier.sockets.VersionedObjectList in project geode by apache.

the class SingleHopClientExecutor method submitGetAll.

static Map<ServerLocation, Object> submitGetAll(Map<ServerLocation, HashSet> serverToFilterMap, List callableTasks, ClientMetadataService cms, LocalRegion region) {
    if (callableTasks != null && !callableTasks.isEmpty()) {
        Map<ServerLocation, Object> resultMap = new HashMap<ServerLocation, Object>();
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                List keys = ((GetAllOpImpl) task.getOperation()).getKeyList();
                ServerLocation server = task.getServer();
                try {
                    VersionedObjectList valuesFromServer = (VersionedObjectList) fut.get();
                    valuesFromServer.setKeys(keys);
                    for (VersionedObjectList.Iterator it = valuesFromServer.iterator(); it.hasNext(); ) {
                        VersionedObjectList.Entry entry = it.next();
                        Object key = entry.getKey();
                        Object value = entry.getValue();
                        if (!entry.isKeyNotOnServer()) {
                            if (value instanceof Throwable) {
                                logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { value, key }), (Throwable) value);
                            }
                        }
                    }
                    if (logger.isDebugEnabled()) {
                        logger.debug("GetAllOp#got result from {}: {}", server, valuesFromServer);
                    }
                    resultMap.put(server, valuesFromServer);
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof ServerOperationException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("GetAllOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        throw (ServerOperationException) ee.getCause();
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("GetAllOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return null;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData((LocalRegion) region, false);
                        resultMap.put(server, ee.getCause());
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            return resultMap;
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) InternalGemFireException(org.apache.geode.InternalGemFireException) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) GetAllOpImpl(org.apache.geode.cache.client.internal.GetAllOp.GetAllOpImpl) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) Iterator(java.util.Iterator) 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)

Example 24 with VersionedObjectList

use of org.apache.geode.internal.cache.tier.sockets.VersionedObjectList in project geode by apache.

the class SingleHopClientExecutor method submitBulkOp.

/**
   * execute bulk op (putAll or removeAll) on multiple PR servers, returning a map of the results.
   * Results are either a VersionedObjectList or a BulkOpPartialResultsException
   * 
   * @param callableTasks
   * @param cms
   * @param region
   * @param failedServers
   * @return the per-server results
   */
static Map<ServerLocation, Object> submitBulkOp(List callableTasks, ClientMetadataService cms, LocalRegion region, Map<ServerLocation, RuntimeException> failedServers) {
    if (callableTasks != null && !callableTasks.isEmpty()) {
        Map<ServerLocation, Object> resultMap = new HashMap<ServerLocation, Object>();
        boolean anyPartialResults = false;
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            RuntimeException rte = null;
            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 {
                    VersionedObjectList versions = (VersionedObjectList) fut.get();
                    if (logger.isDebugEnabled()) {
                        logger.debug("submitBulkOp#got result from {}:{}", server, versions);
                    }
                    resultMap.put(server, versions);
                } catch (InterruptedException e) {
                    InternalGemFireException ige = new InternalGemFireException(e);
                    // only to make this server as failed server, not to throw right now
                    failedServers.put(server, ige);
                    if (rte == null) {
                        rte = ige;
                    }
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof ServerOperationException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("submitBulkOp#ExecutionException from server {}", server, ee);
                        }
                        ServerOperationException soe = (ServerOperationException) ee.getCause();
                        // only to make this server as failed server, not to throw right now
                        failedServers.put(server, soe);
                        if (rte == null) {
                            rte = soe;
                        }
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("submitBulkOp#ExecutionException for server {}", server, ee);
                        }
                        cms = region.getCache().getClientMetadataService();
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        failedServers.put(server, (ServerConnectivityException) ee.getCause());
                    } else {
                        Throwable t = ee.getCause();
                        if (t instanceof PutAllPartialResultException) {
                            resultMap.put(server, t);
                            anyPartialResults = true;
                            failedServers.put(server, (PutAllPartialResultException) t);
                        } else {
                            RuntimeException other_rte = executionThrowable(ee.getCause());
                            failedServers.put(server, other_rte);
                            if (rte == null) {
                                rte = other_rte;
                            }
                        }
                    }
                }
            // catch
            }
            // so the partial results can be processed
            if (rte != null && !anyPartialResults) {
                throw rte;
            }
        }
        return resultMap;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) InternalGemFireException(org.apache.geode.InternalGemFireException) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) Iterator(java.util.Iterator) 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)

Example 25 with VersionedObjectList

use of org.apache.geode.internal.cache.tier.sockets.VersionedObjectList in project geode by apache.

the class PartitionedTXRegionStub method postPutAll.

/**
   * Create PutAllPRMsgs for each bucket, and send them.
   * 
   * @param putallO DistributedPutAllOperation object.
   */
public void postPutAll(DistributedPutAllOperation putallO, VersionedObjectList successfulPuts, LocalRegion r) throws TransactionException {
    if (r.getCache().isCacheAtShutdownAll()) {
        throw new CacheClosedException("Cache is shutting down");
    }
    PartitionedRegion pr = (PartitionedRegion) r;
    final long startTime = PartitionedRegionStats.startTime();
    // build all the msgs by bucketid
    HashMap prMsgMap = putallO.createPRMessages();
    PutAllPartialResult partialKeys = new PutAllPartialResult(putallO.putAllDataSize);
    // this is rebuilt by this method
    successfulPuts.clear();
    Iterator itor = prMsgMap.entrySet().iterator();
    while (itor.hasNext()) {
        Map.Entry mapEntry = (Map.Entry) itor.next();
        Integer bucketId = (Integer) mapEntry.getKey();
        PutAllPRMessage prMsg = (PutAllPRMessage) mapEntry.getValue();
        pr.checkReadiness();
        try {
            VersionedObjectList versions = sendMsgByBucket(bucketId, prMsg, pr);
            // prMsg.saveKeySet(partialKeys);
            partialKeys.addKeysAndVersions(versions);
            successfulPuts.addAll(versions);
        } catch (PutAllPartialResultException pre) {
            // sendMsgByBucket applied partial keys
            partialKeys.consolidate(pre.getResult());
        } catch (Exception ex) {
            // If failed at other exception
            @Released EntryEventImpl firstEvent = prMsg.getFirstEvent(pr);
            try {
                partialKeys.saveFailedKey(firstEvent.getKey(), ex);
            } finally {
                firstEvent.release();
            }
        }
    }
    pr.prStats.endPutAll(startTime);
    if (partialKeys.hasFailure()) {
        pr.getCache().getLoggerI18n().info(LocalizedStrings.Region_PutAll_Applied_PartialKeys_0_1, new Object[] { pr.getFullPath(), partialKeys });
        if (putallO.isBridgeOperation()) {
            if (partialKeys.getFailure() instanceof CancelException) {
                throw (CancelException) partialKeys.getFailure();
            } else {
                throw new PutAllPartialResultException(partialKeys);
            }
        } else {
            if (partialKeys.getFailure() instanceof RuntimeException) {
                throw (RuntimeException) partialKeys.getFailure();
            } else {
                throw new RuntimeException(partialKeys.getFailure());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) CacheClosedException(org.apache.geode.cache.CacheClosedException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CacheClosedException(org.apache.geode.cache.CacheClosedException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) CancelException(org.apache.geode.CancelException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) Entry(org.apache.geode.cache.Region.Entry) PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)37 HashMap (java.util.HashMap)13 Map (java.util.Map)12 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)12 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)12 CacheClosedException (org.apache.geode.cache.CacheClosedException)10 PutAllPartialResult (org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult)10 ArrayList (java.util.ArrayList)9 Iterator (java.util.Iterator)9 List (java.util.List)9 CancelException (org.apache.geode.CancelException)9 CacheException (org.apache.geode.cache.CacheException)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)9 IOException (java.io.IOException)8 PutAllPartialResultException (org.apache.geode.internal.cache.PutAllPartialResultException)8 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)8 Released (org.apache.geode.internal.offheap.annotations.Released)8 ExecutionException (java.util.concurrent.ExecutionException)7 InternalGemFireException (org.apache.geode.InternalGemFireException)7 CacheWriterException (org.apache.geode.cache.CacheWriterException)7