Search in sources :

Example 1 with ClientMetadataService

use of org.apache.geode.cache.client.internal.ClientMetadataService in project geode by apache.

the class GemFireCacheImpl method close.

public void close(String reason, Throwable systemFailureCause, boolean keepAlive, boolean keepDS) {
    this.securityService.close();
    if (isClosed()) {
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    synchronized (GemFireCacheImpl.class) {
        // static synchronization is necessary due to static resources
        if (isClosed()) {
            return;
        }
        /*
       * First close the ManagementService as it uses a lot of infra which will be closed by
       * cache.close()
       */
        this.system.handleResourceEvent(ResourceEvent.CACHE_REMOVE, this);
        if (this.resourceEventsListener != null) {
            this.system.removeResourceListener(this.resourceEventsListener);
            this.resourceEventsListener = null;
        }
        if (systemFailureCause != null) {
            this.forcedDisconnect = systemFailureCause instanceof ForcedDisconnectException;
            if (this.forcedDisconnect) {
                this.disconnectCause = new ForcedDisconnectException(reason);
            } else {
                this.disconnectCause = systemFailureCause;
            }
        }
        this.keepAlive = keepAlive;
        this.isClosing = true;
        logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_NOW_CLOSING, this));
        // available to anyone "fishing" for a cache...
        if (GemFireCacheImpl.instance == this) {
            GemFireCacheImpl.instance = null;
        }
        // threads may be hung trying to communicate with the map locked
        if (systemFailureCause == null) {
            PartitionedRegion.clearPRIdMap();
        }
        TXStateProxy tx = null;
        try {
            if (this.transactionManager != null) {
                tx = this.transactionManager.internalSuspend();
            }
            // do this before closing regions
            this.resourceManager.close();
            try {
                this.resourceAdvisor.close();
            } catch (CancelException ignore) {
            // ignore
            }
            try {
                this.jmxAdvisor.close();
            } catch (CancelException ignore) {
            // ignore
            }
            for (GatewaySender sender : this.allGatewaySenders) {
                try {
                    sender.stop();
                    GatewaySenderAdvisor advisor = ((AbstractGatewaySender) sender).getSenderAdvisor();
                    if (advisor != null) {
                        if (isDebugEnabled) {
                            logger.debug("Stopping the GatewaySender advisor");
                        }
                        advisor.close();
                    }
                } catch (CancelException ignore) {
                }
            }
            destroyGatewaySenderLockService();
            if (this.eventThreadPool != null) {
                if (isDebugEnabled) {
                    logger.debug("{}: stopping event thread pool...", this);
                }
                this.eventThreadPool.shutdown();
            }
            /*
         * IMPORTANT: any operation during shut down that can time out (create a CancelException)
         * must be inside of this try block. If all else fails, we *must* ensure that the cache gets
         * closed!
         */
            try {
                this.stopServers();
                stopMemcachedServer();
                stopRedisServer();
                stopRestAgentServer();
                // cacheServers or gatewayHubs
                if (this.partitionedRegions != null) {
                    if (isDebugEnabled) {
                        logger.debug("{}: clearing partitioned regions...", this);
                    }
                    synchronized (this.partitionedRegions) {
                        int prSize = -this.partitionedRegions.size();
                        this.partitionedRegions.clear();
                        getCachePerfStats().incPartitionedRegions(prSize);
                    }
                }
                prepareDiskStoresForClose();
                if (GemFireCacheImpl.pdxInstance == this) {
                    GemFireCacheImpl.pdxInstance = null;
                }
                List<LocalRegion> rootRegionValues;
                synchronized (this.rootRegions) {
                    rootRegionValues = new ArrayList<>(this.rootRegions.values());
                }
                {
                    final Operation op;
                    if (this.forcedDisconnect) {
                        op = Operation.FORCED_DISCONNECT;
                    } else if (isReconnecting()) {
                        op = Operation.CACHE_RECONNECT;
                    } else {
                        op = Operation.CACHE_CLOSE;
                    }
                    LocalRegion prRoot = null;
                    for (LocalRegion lr : rootRegionValues) {
                        if (isDebugEnabled) {
                            logger.debug("{}: processing region {}", this, lr.getFullPath());
                        }
                        if (PartitionedRegionHelper.PR_ROOT_REGION_NAME.equals(lr.getName())) {
                            prRoot = lr;
                        } else {
                            if (lr.getName().contains(ParallelGatewaySenderQueue.QSTRING)) {
                                // this region will be closed internally by parent region
                                continue;
                            }
                            if (isDebugEnabled) {
                                logger.debug("{}: closing region {}...", this, lr.getFullPath());
                            }
                            try {
                                lr.handleCacheClose(op);
                            } catch (RuntimeException e) {
                                if (isDebugEnabled || !this.forcedDisconnect) {
                                    logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_ERROR_CLOSING_REGION_1, new Object[] { this, lr.getFullPath() }), e);
                                }
                            }
                        }
                    }
                    try {
                        if (isDebugEnabled) {
                            logger.debug("{}: finishing partitioned region close...", this);
                        }
                        PartitionedRegion.afterRegionsClosedByCacheClose(this);
                        if (prRoot != null) {
                            // do the PR meta root region last
                            prRoot.handleCacheClose(op);
                        }
                    } catch (CancelException e) {
                        logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_ERROR_IN_LAST_STAGE_OF_PARTITIONEDREGION_CACHE_CLOSE, this), e);
                    }
                    destroyPartitionedRegionLockService();
                }
                closeDiskStores();
                this.diskMonitor.close();
                // Close the CqService Handle.
                try {
                    if (isDebugEnabled) {
                        logger.debug("{}: closing CQ service...", this);
                    }
                    this.cqService.close();
                } catch (RuntimeException ignore) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_1));
                }
                PoolManager.close(keepAlive);
                if (isDebugEnabled) {
                    logger.debug("{}: notifying admins of close...", this);
                }
                try {
                    SystemMemberCacheEventProcessor.send(this, Operation.CACHE_CLOSE);
                } catch (CancelException ignore) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Ignored cancellation while notifying admins");
                    }
                }
                if (isDebugEnabled) {
                    logger.debug("{}: stopping destroyed entries processor...", this);
                }
                this.tombstoneService.stop();
                // NOTICE: the CloseCache message is the *last* message you can send!
                DM distributionManager = null;
                try {
                    distributionManager = this.system.getDistributionManager();
                    distributionManager.removeMembershipListener(this.transactionManager);
                } catch (CancelException ignore) {
                // distributionManager = null;
                }
                if (distributionManager != null) {
                    // Send CacheClosedMessage (and NOTHING ELSE) here
                    if (isDebugEnabled) {
                        logger.debug("{}: sending CloseCache to peers...", this);
                    }
                    Set otherMembers = distributionManager.getOtherDistributionManagerIds();
                    ReplyProcessor21 processor = new ReplyProcessor21(this.system, otherMembers);
                    CloseCacheMessage msg = new CloseCacheMessage();
                    msg.setRecipients(otherMembers);
                    msg.setProcessorId(processor.getProcessorId());
                    distributionManager.putOutgoing(msg);
                    try {
                        processor.waitForReplies();
                    } catch (InterruptedException ignore) {
                    // Thread.currentThread().interrupt(); // TODO ??? should we reset this bit later?
                    // Keep going, make best effort to shut down.
                    } catch (ReplyException ignore) {
                    // keep going
                    }
                // set closed state after telling others and getting responses
                // to avoid complications with others still in the process of
                // sending messages
                }
                // NO MORE Distributed Messaging AFTER THIS POINT!!!!
                ClientMetadataService cms = this.clientMetadataService;
                if (cms != null) {
                    cms.close();
                }
                closeHeapEvictor();
                closeOffHeapEvictor();
            } catch (CancelException ignore) {
                // make sure the disk stores get closed
                closeDiskStores();
            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
            }
            // Close the CqService Handle.
            try {
                this.cqService.close();
            } catch (RuntimeException ignore) {
                logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_2));
            }
            this.cachePerfStats.close();
            TXLockService.destroyServices();
            EventTracker.stopTrackerServices(this);
            synchronized (this.ccpTimerMutex) {
                if (this.ccpTimer != null) {
                    this.ccpTimer.cancel();
                }
            }
            this.expirationScheduler.cancel();
            // Stop QueryMonitor if running.
            if (this.queryMonitor != null) {
                this.queryMonitor.stopMonitoring();
            }
            stopDiskStoreTaskPool();
        } finally {
            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
            if (this.transactionManager != null) {
                this.transactionManager.close();
            }
            ((DynamicRegionFactoryImpl) DynamicRegionFactory.get()).close();
            if (this.transactionManager != null) {
                this.transactionManager.internalResume(tx);
            }
            TXCommitMessage.getTracker().clearForCacheClose();
        }
        // Added to close the TransactionManager's cleanup thread
        TransactionManagerImpl.refresh();
        if (!keepDS) {
            // keepDS is used by ShutdownAll. It will override DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE
            if (!this.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE) {
                this.system.disconnect();
            }
        }
        TypeRegistry.close();
        // do this late to prevent 43412
        TypeRegistry.setPdxSerializer(null);
        for (CacheLifecycleListener listener : cacheLifecycleListeners) {
            listener.cacheClosed(this);
        }
        // Fix for #49856
        SequenceLoggerImpl.signalCacheClose();
        SystemFailure.signalCacheClose();
    }
// static synchronization on GemFireCache.class
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) Set(java.util.Set) ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) DM(org.apache.geode.distributed.internal.DM) GatewaySenderAdvisor(org.apache.geode.internal.cache.wan.GatewaySenderAdvisor) Operation(org.apache.geode.cache.Operation) ReplyException(org.apache.geode.distributed.internal.ReplyException) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) CancelException(org.apache.geode.CancelException) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Example 2 with ClientMetadataService

use of org.apache.geode.cache.client.internal.ClientMetadataService in project geode by apache.

the class PartitionedRegionSingleHopWithServerGroupDUnitTest method verifyMetadata.

public static void verifyMetadata(final int numRegions, final int numBucketLocations) {
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            if (regionMetaData.size() == numRegions) {
                return true;
            }
            return false;
        }

        public String description() {
            return "expected metadata for each region to be" + numRegions + " but it is " + regionMetaData.size() + "Metadata is " + regionMetaData.keySet();
        }
    };
    Wait.waitForCriterion(wc, 60000, 1000, true);
    if (numRegions != 0) {
        assertTrue(regionMetaData.containsKey(region.getFullPath()));
        ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
        if (cache.getLogger().fineEnabled()) {
            for (Entry e : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
                cache.getLogger().fine("For bucket id " + e.getKey() + " the locations are " + e.getValue());
            }
        }
        for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
            assertEquals(numBucketLocations, ((List) entry.getValue()).size());
        }
    }
}
Also used : Entry(java.util.Map.Entry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Example 3 with ClientMetadataService

use of org.apache.geode.cache.client.internal.ClientMetadataService in project geode by apache.

the class Shipment method test_MetadataServiceCallAccuracy_FromDestroyOp.

@Test
public void test_MetadataServiceCallAccuracy_FromDestroyOp() {
    Integer port0 = (Integer) member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(0, 4));
    Integer port1 = (Integer) member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(0, 4));
    member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.createClient(port0));
    createClient(port1);
    member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.putIntoSinglePR());
    member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.printView());
    member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.printView());
    final ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.satisfyRefreshMetadata_TEST_ONLY(false);
    region.destroy(new Integer(0));
    region.destroy(new Integer(1));
    region.destroy(new Integer(2));
    region.destroy(new Integer(3));
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> cms.isRefreshMetadataTestOnly() == true);
}
Also used : ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 4 with ClientMetadataService

use of org.apache.geode.cache.client.internal.ClientMetadataService in project geode by apache.

the class Shipment method testServerLocationRemovalThroughPing.

// GEODE-853: random ports, pause sleeps, time sensitive, 5 second
@Category(FlakyTest.class)
// thread sleeps
@Test
public void testServerLocationRemovalThroughPing() {
    Integer port0 = (Integer) member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    Integer port1 = (Integer) member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    Integer port2 = (Integer) member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    Integer port3 = (Integer) member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    createClient(port0, port1, port2, port3);
    putIntoPartitionedRegions();
    getFromPartitionedRegions();
    Wait.pause(5000);
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    assertEquals(4, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
    assertTrue(regionMetaData.containsKey(orderRegion.getFullPath()));
    assertTrue(regionMetaData.containsKey(shipmentRegion.getFullPath()));
    ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    assertEquals(4, /* numBuckets */
    prMetaData.getBucketServerLocationsMap_TEST_ONLY().size());
    for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        assertEquals(4, ((List) entry.getValue()).size());
    }
    member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
    member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
    // make sure that ping detects the dead servers
    Wait.pause(5000);
    getFromPartitionedRegions();
    verifyDeadServer(regionMetaData, customerRegion, port0, port1);
    verifyDeadServer(regionMetaData, region, port0, port1);
}
Also used : Entry(java.util.Map.Entry) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 5 with ClientMetadataService

use of org.apache.geode.cache.client.internal.ClientMetadataService in project geode by apache.

the class Shipment method testMetadataIsSameOnAllServersAndClientsHA.

@Test
public void testMetadataIsSameOnAllServersAndClientsHA() {
    Integer port0 = (Integer) member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(2, 4));
    Integer port1 = (Integer) member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(2, 4));
    createClient(port0, port1, port0, port1);
    put();
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.getClientPRMetadata((LocalRegion) region);
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (regionMetaData.size() == 1));
    assertEquals(1, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    member0.invoke(new CacheSerializableRunnable("aba") {

        @Override
        public void run2() throws CacheException {
            final PartitionedRegion pr = (PartitionedRegion) region;
            ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
        }
    });
    member1.invoke(new CacheSerializableRunnable("aba") {

        @Override
        public void run2() throws CacheException {
            final PartitionedRegion pr = (PartitionedRegion) region;
            ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
        }
    });
    ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    final Map<Integer, List<BucketServerLocation66>> clientMap = prMetaData.getBucketServerLocationsMap_TEST_ONLY();
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (clientMap.size() == 4));
    for (Entry entry : clientMap.entrySet()) {
        assertEquals(2, ((List) entry.getValue()).size());
    }
    member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
    member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
    member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
    put();
    cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.getClientPRMetadata((LocalRegion) region);
    // member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
    assertEquals(4, /* numBuckets */
    clientMap.size());
    for (Entry entry : clientMap.entrySet()) {
        assertEquals(1, ((List) entry.getValue()).size());
    }
    assertEquals(1, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    assertEquals(4, /* numBuckets */
    clientMap.size());
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> {
        int bucketId = -1;
        int size = -1;
        List globalList = new ArrayList();
        boolean finished = true;
        for (Entry entry : clientMap.entrySet()) {
            List list = (List) entry.getValue();
            if (list.size() != 1) {
                size = list.size();
                globalList = list;
                bucketId = (Integer) entry.getKey();
                finished = false;
                System.out.println("bucket copies are not created, the locations size for bucket id : " + bucketId + " size : " + size + " the list is " + globalList);
            }
        }
        return finished;
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ArrayList(java.util.ArrayList) ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) Entry(java.util.Map.Entry) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) List(java.util.List) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Aggregations

ClientMetadataService (org.apache.geode.cache.client.internal.ClientMetadataService)37 ClientPartitionAdvisor (org.apache.geode.cache.client.internal.ClientPartitionAdvisor)15 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)13 Test (org.junit.Test)13 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)12 Entry (java.util.Map.Entry)8 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 Region (org.apache.geode.cache.Region)5 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Cache (org.apache.geode.cache.Cache)2 CacheException (org.apache.geode.cache.CacheException)2 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)2 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)2 ServerBucketProfile (org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2