Search in sources :

Example 6 with HARegion

use of org.apache.geode.internal.cache.HARegion in project geode by apache.

the class vmListenerToCheckHARegionQueue method afterCreate.

public void afterCreate(EntryEvent event) {
    if (HAGIIBugDUnitTest.isHARegionQueueUp) {
        Cache cache = event.getRegion().getCache();
        HARegion regionForQueue = (HARegion) cache.getRegion(Region.SEPARATOR + HARegionQueue.createRegionName(HAGIIBugDUnitTest.regionQueueName));
        HARegionQueue regionqueue = regionForQueue.getOwner();
        try {
            regionqueue.put(new ConflatableObject(event.getKey(), event.getNewValue(), ((EntryEventImpl) event).getEventId(), false, "region1"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) HARegion(org.apache.geode.internal.cache.HARegion) CacheException(org.apache.geode.cache.CacheException) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache)

Example 7 with HARegion

use of org.apache.geode.internal.cache.HARegion in project geode by apache.

the class vmListenerToCheckHARegionQueue method testGIIBug.

@Ignore("TODO")
@Test
public void testGIIBug() throws Exception {
    vm0.invoke(putFromVmBeforeGII("vm0_1"));
    populateKeySet("vm0_1");
    Thread t1 = new Thread() {

        public void run() {
            try {
                createCache(new Properties());
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setDataPolicy(DataPolicy.REPLICATE);
                CacheListener regionListener = new vmListenerToCheckHARegionQueue();
                factory.setCacheListener(regionListener);
                RegionAttributes attrs = factory.create();
                Region region = cache.createRegion(REGION_NAME, attrs);
                LogWriterUtils.getLogWriter().info("Name of the region is : " + region.getFullPath());
                HARegionQueueAttributes hattr = new HARegionQueueAttributes();
                // setting expiry time for the regionqueue.
                hattr.setExpiryTime(12000000);
                RegionQueue regionqueue = null;
                regionqueue = HARegionQueue.getHARegionQueueInstance(regionQueueName, cache, hattr, HARegionQueue.NON_BLOCKING_HA_QUEUE, false);
                isHARegionQueueUp = true;
                vm0.invoke(setStopFlag());
                assertNotNull(regionqueue);
            } catch (Exception e) {
                isTestFailed = true;
                e.printStackTrace();
            }
        }
    };
    AsyncInvocation[] async = new AsyncInvocation[4];
    async[0] = vm0.invokeAsync(putFrmVm("vm0_2"));
    t1.start();
    ThreadUtils.join(t1, 30 * 1000);
    if (isTestFailed)
        fail("HARegionQueue can not be created");
    for (int count = 0; count < 1; count++) {
        ThreadUtils.join(async[count], 30 * 1000);
        if (async[count].exceptionOccurred()) {
            Assert.fail("Got exception on " + count, async[count].getException());
        }
    }
    total_no_puts[0] = vm0.invoke(() -> HAGIIBugDUnitTest.getTotalNoPuts());
    populate_keys_after_gii();
    boolean validationFlag = false;
    validateResults(validationFlag);
    if (keys_set_before_gii.size() != 0)
        fail("Data in the HARegion Queue is inconsistent for the keys that are put before GII");
    validationFlag = true;
    validateResults(validationFlag);
    LogWriterUtils.getLogWriter().info("No. of keys that are missed by HARegion Queue during GII " + keys_set_after_gii.size());
    if (keys_set_after_gii.size() != 0)
        fail("Set of the keys are missed by HARegion Queue during GII");
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) Properties(java.util.Properties) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) CacheListener(org.apache.geode.cache.CacheListener) RegionQueue(org.apache.geode.internal.cache.RegionQueue) CacheException(org.apache.geode.cache.CacheException) AttributesFactory(org.apache.geode.cache.AttributesFactory) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) Ignore(org.junit.Ignore) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with HARegion

use of org.apache.geode.internal.cache.HARegion in project geode by apache.

the class HABug36738DUnitTest method checkRegionQueueSize.

private void checkRegionQueueSize() {
    final HARegion region = (HARegion) cache.getRegion(Region.SEPARATOR + HAHelper.getRegionQueueName(HAREGION_NAME));
    assertNotNull(region);
    assertEquals(COUNT, region.size());
}
Also used : HARegion(org.apache.geode.internal.cache.HARegion)

Example 9 with HARegion

use of org.apache.geode.internal.cache.HARegion in project geode by apache.

the class GemFireMemberStatus method initializeRegionSizes.

protected void initializeRegionSizes() {
    Iterator rootRegions = cache.rootRegions().iterator();
    while (rootRegions.hasNext()) {
        LocalRegion rootRegion = (LocalRegion) rootRegions.next();
        if (!(rootRegion instanceof HARegion)) {
            RegionStatus rootRegionStatus = rootRegion instanceof PartitionedRegion ? new PartitionedRegionStatus((PartitionedRegion) rootRegion) : new RegionStatus(rootRegion);
            putRegionStatus(rootRegion.getFullPath(), rootRegionStatus);
            Iterator subRegions = rootRegion.subregions(true).iterator();
            while (subRegions.hasNext()) {
                LocalRegion subRegion = (LocalRegion) subRegions.next();
                RegionStatus subRegionStatus = subRegion instanceof PartitionedRegion ? new PartitionedRegionStatus((PartitionedRegion) subRegion) : new RegionStatus(subRegion);
                putRegionStatus(subRegion.getFullPath(), subRegionStatus);
            }
        }
    }
}
Also used : PartitionedRegionStatus(org.apache.geode.internal.cache.PartitionedRegionStatus) RegionStatus(org.apache.geode.internal.cache.RegionStatus) PartitionedRegionStatus(org.apache.geode.internal.cache.PartitionedRegionStatus) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) HARegion(org.apache.geode.internal.cache.HARegion)

Example 10 with HARegion

use of org.apache.geode.internal.cache.HARegion in project geode by apache.

the class HARegionQueue method putGIIDataInRegion.

/**
   * Repopulates the HARegion after the GII is over so as to reset the counters and populate the
   * DACE objects for the thread identifiers . This method should be invoked as the last method in
   * the constructor . Thus while creating BlockingQueue this method should be invoked lastly in the
   * derived class constructor , after the HARegionQueue contructor is complete. Otherwise, the
   * ReentrantLock will be null.
   */
void putGIIDataInRegion() throws CacheException, InterruptedException {
    Set entrySet = this.region.entrySet(false);
    // be populated
    if (!entrySet.isEmpty()) {
        this.puttingGIIDataInQueue = true;
        final boolean isDebugEnabled = logger.isDebugEnabled();
        try {
            Region.Entry entry = null;
            Map orderedMap = new TreeMap();
            Iterator iterator = entrySet.iterator();
            Object key = null;
            while (iterator.hasNext()) {
                entry = (Region.Entry) iterator.next();
                key = entry.getKey();
                if (isDebugEnabled) {
                    logger.debug("processing queue key {} and value {}", key, entry.getValue());
                }
                if (key instanceof Long) {
                    if (!(entry.getValue() instanceof ClientMarkerMessageImpl)) {
                        orderedMap.put(key, entry.getValue());
                    }
                }
                this.region.localDestroy(key);
            }
            long max = 0;
            long counterInRegion = 0;
            entrySet = orderedMap.entrySet();
            if (!entrySet.isEmpty()) {
                Map.Entry mapEntry = null;
                iterator = entrySet.iterator();
                while (iterator.hasNext()) {
                    mapEntry = (Map.Entry) iterator.next();
                    Conflatable val = (Conflatable) mapEntry.getValue();
                    if (val != null && val.getEventId() != null) {
                        counterInRegion = ((Long) mapEntry.getKey()).intValue();
                        // TODO: remove this assertion
                        Assert.assertTrue(counterInRegion > max);
                        max = counterInRegion;
                        // putInQueue(val);
                        // logger.info(LocalizedStrings.DEBUG, this + " putting GII entry #" + counterInRegion
                        // + " into queue: " + val);
                        this.put(val);
                    } else if (isDebugEnabled) {
                        logger.debug("bug 44959 encountered: HARegion.putGIIDataInRegion found null eventId in {}", val);
                    }
                }
            }
            this.tailKey.set(max);
        } finally {
            this.puttingGIIDataInQueue = false;
            if (isDebugEnabled) {
                logger.debug("{} done putting GII data into queue", this);
            }
        }
    }
    // TODO:Asif: Avoid invocation of this method
    startHAServices(this.region.getCache());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) TreeMap(java.util.TreeMap) Iterator(java.util.Iterator) AtomicLong(java.util.concurrent.atomic.AtomicLong) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) ClientMarkerMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientMarkerMessageImpl) Conflatable(org.apache.geode.internal.cache.Conflatable) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Aggregations

HARegion (org.apache.geode.internal.cache.HARegion)15 Iterator (java.util.Iterator)7 Region (org.apache.geode.cache.Region)6 CacheException (org.apache.geode.cache.CacheException)4 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)3 Test (org.junit.Test)3 Map (java.util.Map)2 Set (java.util.Set)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 Cache (org.apache.geode.cache.Cache)2 RegionAttributes (org.apache.geode.cache.RegionAttributes)2 EventID (org.apache.geode.internal.cache.EventID)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1