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;
}
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;
}
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;
}
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;
}
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());
}
}
}
}
Aggregations