use of org.apache.geode.cache.client.ServerOperationException in project geode by apache.
the class DestroyOp method execute.
/**
* Does a region entry destroy on a server using connections from the given pool to communicate
* with the server.
*
* @param pool the pool to use to communicate with the server.
* @param region the region to do the entry destroy on
* @param key the entry key to do the destroy on
* @param event the event for this destroy operation
* @param callbackArg an optional callback arg to pass to any cache callbacks
*/
public static Object execute(ExecutablePool pool, LocalRegion region, Object key, Object expectedOldValue, Operation operation, EntryEventImpl event, Object callbackArg, boolean prSingleHopEnabled) {
if (logger.isDebugEnabled()) {
logger.debug("Preparing DestroyOp for {} operation={}", key, operation);
}
DestroyOpImpl op = new DestroyOpImpl(region, key, expectedOldValue, operation, event, callbackArg, prSingleHopEnabled);
if (prSingleHopEnabled) {
ClientMetadataService cms = region.getCache().getClientMetadataService();
ServerLocation server = cms.getBucketServerLocation(region, Operation.DESTROY, key, null, callbackArg);
if (server != null) {
try {
PoolImpl poolImpl = (PoolImpl) pool;
boolean onlyUseExistingCnx = ((poolImpl.getMaxConnections() != -1 && poolImpl.getConnectionCount() >= poolImpl.getMaxConnections()) ? true : false);
op.setAllowDuplicateMetadataRefresh(!onlyUseExistingCnx);
return pool.executeOn(server, op, true, onlyUseExistingCnx);
} catch (AllConnectionsInUseException e) {
} catch (ServerConnectivityException e) {
if (e instanceof ServerOperationException) {
// fixed 44656
throw e;
}
cms.removeBucketServerLocation(server);
}
}
}
return pool.execute(op);
}
use of org.apache.geode.cache.client.ServerOperationException 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.cache.client.ServerOperationException 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.cache.client.ServerOperationException in project geode by apache.
the class OpExecutorImplJUnitTest method testExecuteOn.
@Test
public void testExecuteOn() throws Exception {
OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, 3, 10, false, cancelCriterion, null);
ServerLocation server = new ServerLocation("localhost", -1);
Object result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
return "hello";
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
assertEquals("hello", result);
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(0, invalidateConnections);
assertEquals(0, serverCrashes);
reset();
try {
result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
throw new SocketTimeoutException();
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
fail("Should have got an exception");
} catch (ServerConnectivityException expected) {
// do nothing
}
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(1, invalidateConnections);
assertEquals(0, serverCrashes);
reset();
try {
result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
throw new ServerOperationException("Something didn't work");
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
fail("Should have got an exception");
} catch (ServerOperationException expected) {
// do nothing
}
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(0, invalidateConnections);
assertEquals(0, serverCrashes);
reset();
{
final String expectedEx = "java.lang.Exception";
final String addExpected = "<ExpectedException action=add>" + expectedEx + "</ExpectedException>";
final String removeExpected = "<ExpectedException action=remove>" + expectedEx + "</ExpectedException>";
logger.info(addExpected);
try {
result = exec.executeOn(server, new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
throw new Exception("Something didn't work");
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
});
fail("Should have got an exception");
} catch (ServerConnectivityException expected) {
// do nothing
} finally {
logger.info(removeExpected);
}
}
assertEquals(1, borrows);
assertEquals(1, returns);
assertEquals(1, invalidateConnections);
assertEquals(1, serverCrashes);
}
use of org.apache.geode.cache.client.ServerOperationException in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testRegisterInterestNoDataStores.
@Test
public void testRegisterInterestNoDataStores() {
// Closing the client may log a warning on the server
IgnoredException.addIgnoredException("Connection reset");
IgnoredException.addIgnoredException("SocketTimeoutException");
IgnoredException.addIgnoredException("ServerConnectivityException");
IgnoredException.addIgnoredException("Socket Closed");
IgnoredException.addIgnoredException("Unexpected IOException");
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final Integer serverPort = (Integer) vm0.invoke(new SerializableCallable("create per") {
public Object call() {
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(0);
paf.setLocalMaxMemory(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PARTITION);
cache.createRegion(PR_REGION_NAME, af.create());
CacheServer server = cache.addCacheServer();
server.setPort(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
server.setNotifyBySubscription(true);
try {
server.start();
} catch (IOException e) {
throw new RuntimeException(e);
}
return server.getPort();
}
});
vm1.invoke(new SerializableRunnable("create client") {
public void run() {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
getSystem(props);
try {
Cache cache = getCache();
PoolFactory pf = PoolManager.createFactory();
pf.addServer(NetworkUtils.getServerHostName(host), serverPort);
pf.setSubscriptionEnabled(true);
pf.create("pool");
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.NORMAL);
af.setScope(Scope.LOCAL);
af.setPoolName("pool");
Region region = cache.createRegion(PR_REGION_NAME, af.create());
try {
region.registerInterestRegex(".*");
} catch (ServerOperationException e) {
if (!(e.getCause() instanceof PartitionedRegionStorageException)) {
throw e;
}
}
} finally {
disconnectFromDS();
}
}
});
}
Aggregations