Search in sources :

Example 21 with ServerOperationException

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);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) AllConnectionsInUseException(org.apache.geode.cache.client.AllConnectionsInUseException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Example 22 with ServerOperationException

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;
}
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 23 with ServerOperationException

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;
}
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 24 with ServerOperationException

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);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SocketTimeoutException(java.net.SocketTimeoutException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) SocketTimeoutException(java.net.SocketTimeoutException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 25 with ServerOperationException

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();
            }
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolFactory(org.apache.geode.cache.client.PoolFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

ServerOperationException (org.apache.geode.cache.client.ServerOperationException)27 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)11 Region (org.apache.geode.cache.Region)10 CacheException (org.apache.geode.cache.CacheException)9 Host (org.apache.geode.test.dunit.Host)9 VM (org.apache.geode.test.dunit.VM)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 List (java.util.List)6 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Iterator (java.util.Iterator)5 ExecutionException (java.util.concurrent.ExecutionException)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)5 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)5 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)5 ArrayList (java.util.ArrayList)4