Search in sources :

Example 6 with RegionAdvisor

use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.

the class PartitionedRegion method sendIndexCreationMsg.

/**
   * Explicitly sends an index creation message to a newly added node to the system on prs.
   * 
   * @param idM id on the newly added node.
   */
public void sendIndexCreationMsg(InternalDistributedMember idM) {
    if (!this.isIndexed()) {
        return;
    }
    RegionAdvisor advisor = (RegionAdvisor) getCacheDistributionAdvisor();
    final Set<InternalDistributedMember> recipients = advisor.adviseDataStore();
    if (!recipients.contains(idM)) {
        logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_NEWLY_ADDED_MEMBER_TO_THE_PR_IS_AN_ACCESSOR_AND_WILL_NOT_RECEIVE_INDEX_INFORMATION_0, idM));
        return;
    }
    // this should add the member to a synchronized set and then sent this member
    // and index creation msg latter after its completed creating the partitioned region.
    IndexCreationMsg.IndexCreationResponse response;
    IndexCreationMsg.IndexCreationResult result;
    if (this.indexes.isEmpty()) {
        return;
    }
    Iterator it = this.indexes.values().iterator();
    HashSet<IndexCreationData> indexDefinitions = new HashSet<>();
    Set<PartitionedIndex> indexes = new HashSet<>();
    while (it.hasNext()) {
        Object ind = it.next();
        // the index is not in create phase, its created successfully).
        if (!(ind instanceof Index)) {
            continue;
        }
        PartitionedIndex prIndex = (PartitionedIndex) ind;
        indexes.add(prIndex);
        IndexCreationData icd = new IndexCreationData(prIndex.getName());
        icd.setIndexData(prIndex.getType(), prIndex.getFromClause(), prIndex.getIndexedExpression(), prIndex.getImports(), true);
        indexDefinitions.add(icd);
    }
    response = (IndexCreationMsg.IndexCreationResponse) IndexCreationMsg.send(idM, this, indexDefinitions);
    if (logger.isDebugEnabled()) {
        logger.debug("Sending explicitly index creation message to : {}", idM);
    }
    if (response != null) {
        try {
            result = response.waitForResult();
            Map<String, Integer> remoteIndexBucketsMap = result.getIndexBucketsMap();
            // set the number of remote buckets indexed for each pr index
            for (Index ind : indexes) {
                ((PartitionedIndex) ind).setRemoteBucketesIndexed(remoteIndexBucketsMap.get(ind.getName()));
            }
        } catch (ForceReattemptException e) {
            logger.info(LocalizedStrings.PartitionedRegion_FORCEREATTEMPT_EXCEPTION___0, e);
        }
    }
}
Also used : RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) IndexCreationMsg(org.apache.geode.internal.cache.partitioned.IndexCreationMsg) HashSet(java.util.HashSet)

Example 7 with RegionAdvisor

use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.

the class MemoryThresholdsOffHeapDUnitTest method testPRLoadRejection.

/**
   * Test that a Partitioned Region loader invocation is rejected if the VM with the bucket is in a
   * critical state.
   */
// GEODE-551: waitForCriterion, memory sensitive
@Category(FlakyTest.class)
@Test
public void testPRLoadRejection() throws Exception {
    final Host host = Host.getHost(0);
    final VM accessor = host.getVM(1);
    final VM ds1 = host.getVM(2);
    final String rName = getUniqueName();
    // Make sure the desired VMs will have a fresh DS. TODO: convert these from AsyncInvocation to
    // invoke
    AsyncInvocation d0 = accessor.invokeAsync(() -> disconnectFromDS());
    AsyncInvocation d1 = ds1.invokeAsync(() -> disconnectFromDS());
    d0.join();
    assertFalse(d0.exceptionOccurred());
    d1.join();
    assertFalse(d1.exceptionOccurred());
    CacheSerializableRunnable establishConnectivity = new CacheSerializableRunnable("establishcConnectivity") {

        @Override
        public void run2() throws CacheException {
            getSystem();
        }
    };
    ds1.invoke(establishConnectivity);
    accessor.invoke(establishConnectivity);
    ds1.invoke(createPR(rName, false));
    accessor.invoke(createPR(rName, true));
    final AtomicInteger expectedInvocations = new AtomicInteger(0);
    Integer ex = (Integer) accessor.invoke(new SerializableCallable("Invoke loader from accessor, non-critical") {

        public Object call() throws Exception {
            Region<Integer, String> r = getCache().getRegion(rName);
            Integer k = new Integer(1);
            Integer expectedInvocations0 = new Integer(expectedInvocations.getAndIncrement());
            // should load for new key
            assertEquals(k.toString(), r.get(k, expectedInvocations0));
            assertTrue(r.containsKey(k));
            Integer expectedInvocations1 = new Integer(expectedInvocations.get());
            // no load
            assertEquals(k.toString(), r.get(k, expectedInvocations1));
            // no load
            assertEquals(k.toString(), r.get(k, expectedInvocations1));
            return expectedInvocations1;
        }
    });
    expectedInvocations.set(ex.intValue());
    ex = (Integer) ds1.invoke(new SerializableCallable("Invoke loader from datastore, non-critical") {

        public Object call() throws Exception {
            Region<Integer, String> r = getCache().getRegion(rName);
            Integer k = new Integer(2);
            Integer expectedInvocations1 = new Integer(expectedInvocations.getAndIncrement());
            // should load for new key
            assertEquals(k.toString(), r.get(k, expectedInvocations1));
            assertTrue(r.containsKey(k));
            Integer expectedInvocations2 = new Integer(expectedInvocations.get());
            // no load
            assertEquals(k.toString(), r.get(k, expectedInvocations2));
            // no load
            assertEquals(k.toString(), r.get(k, expectedInvocations2));
            String oldVal = r.remove(k);
            assertFalse(r.containsKey(k));
            assertEquals(k.toString(), oldVal);
            return expectedInvocations2;
        }
    });
    expectedInvocations.set(ex.intValue());
    accessor.invoke(addExpectedException);
    ds1.invoke(addExpectedException);
    ex = (Integer) ds1.invoke(new SerializableCallable("Set critical state, assert local load behavior") {

        public Object call() throws Exception {
            final OffHeapMemoryMonitor ohmm = ((InternalResourceManager) getCache().getResourceManager()).getOffHeapMonitor();
            final PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
            final RegionAdvisor advisor = pr.getRegionAdvisor();
            pr.put("oh1", new byte[838860]);
            pr.put("oh3", new byte[157287]);
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "verify critical state";
                }

                public boolean done() {
                    for (final ProxyBucketRegion bucket : advisor.getProxyBucketArray()) {
                        if (bucket.isBucketSick()) {
                            return true;
                        }
                    }
                    return false;
                }
            };
            Wait.waitForCriterion(wc, 30 * 1000, 10, true);
            // reload with same key again and again
            final Integer k = new Integer(2);
            final Integer expectedInvocations3 = new Integer(expectedInvocations.getAndIncrement());
            // load
            assertEquals(k.toString(), pr.get(k, expectedInvocations3));
            assertFalse(pr.containsKey(k));
            Integer expectedInvocations4 = new Integer(expectedInvocations.getAndIncrement());
            // load
            assertEquals(k.toString(), pr.get(k, expectedInvocations4));
            assertFalse(pr.containsKey(k));
            Integer expectedInvocations5 = new Integer(expectedInvocations.get());
            // load
            assertEquals(k.toString(), pr.get(k, expectedInvocations5));
            assertFalse(pr.containsKey(k));
            return expectedInvocations5;
        }
    });
    expectedInvocations.set(ex.intValue());
    ex = (Integer) accessor.invoke(new SerializableCallable("During critical state on datastore, assert accesor load behavior") {

        public Object call() throws Exception {
            // reload with same key again and again
            final Integer k = new Integer(2);
            Integer expectedInvocations6 = new Integer(expectedInvocations.incrementAndGet());
            Region<Integer, String> r = getCache().getRegion(rName);
            // load
            assertEquals(k.toString(), r.get(k, expectedInvocations6));
            assertFalse(r.containsKey(k));
            Integer expectedInvocations7 = new Integer(expectedInvocations.incrementAndGet());
            // load
            assertEquals(k.toString(), r.get(k, expectedInvocations7));
            assertFalse(r.containsKey(k));
            return expectedInvocations7;
        }
    });
    expectedInvocations.set(ex.intValue());
    ex = (Integer) ds1.invoke(new SerializableCallable("Set safe state on datastore, assert local load behavior") {

        public Object call() throws Exception {
            final PartitionedRegion r = (PartitionedRegion) getCache().getRegion(rName);
            r.destroy("oh3");
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "verify critical state";
                }

                public boolean done() {
                    return !r.memoryThresholdReached.get();
                }
            };
            Wait.waitForCriterion(wc, 30 * 1000, 10, true);
            // same key as previously used, this time is should stick
            Integer k = new Integer(3);
            Integer expectedInvocations8 = new Integer(expectedInvocations.incrementAndGet());
            // last load for 3
            assertEquals(k.toString(), r.get(k, expectedInvocations8));
            assertTrue(r.containsKey(k));
            return expectedInvocations8;
        }
    });
    expectedInvocations.set(ex.intValue());
    accessor.invoke(new SerializableCallable("Data store in safe state, assert load behavior, accessor sets critical state, assert load behavior") {

        public Object call() throws Exception {
            final OffHeapMemoryMonitor ohmm = ((InternalResourceManager) getCache().getResourceManager()).getOffHeapMonitor();
            assertFalse(ohmm.getState().isCritical());
            Integer k = new Integer(4);
            Integer expectedInvocations9 = new Integer(expectedInvocations.incrementAndGet());
            final PartitionedRegion r = (PartitionedRegion) getCache().getRegion(rName);
            // load for 4
            assertEquals(k.toString(), r.get(k, expectedInvocations9));
            assertTrue(r.containsKey(k));
            // no load
            assertEquals(k.toString(), r.get(k, expectedInvocations9));
            // Go critical in accessor
            r.put("oh3", new byte[157287]);
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "verify critical state";
                }

                public boolean done() {
                    return r.memoryThresholdReached.get();
                }
            };
            k = new Integer(5);
            Integer expectedInvocations10 = new Integer(expectedInvocations.incrementAndGet());
            // load for key 5
            assertEquals(k.toString(), r.get(k, expectedInvocations10));
            assertTrue(r.containsKey(k));
            // no load
            assertEquals(k.toString(), r.get(k, expectedInvocations10));
            // Clean up critical state
            r.destroy("oh3");
            wc = new WaitCriterion() {

                public String description() {
                    return "verify critical state";
                }

                public boolean done() {
                    return !ohmm.getState().isCritical();
                }
            };
            return expectedInvocations10;
        }
    });
    accessor.invoke(removeExpectedException);
    ds1.invoke(removeExpectedException);
}
Also used : OffHeapMemoryMonitor(org.apache.geode.internal.cache.control.OffHeapMemoryMonitor) RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) CacheException(org.apache.geode.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 8 with RegionAdvisor

use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.

the class PartitionedRegionQueryEvaluatorIntegrationTest method populateBucket2Node.

/**
   * This function populates bucket2Node region of the partition region
   * 
   * @param pr
   */
public void populateBucket2Node(PartitionedRegion pr, List nodes, int numOfBuckets) {
    assertEquals(0, pr.getRegionAdvisor().getCreatedBucketsCount());
    final RegionAdvisor ra = pr.getRegionAdvisor();
    int nodeListCnt = 0;
    Random ran = new Random();
    // Map tracking version for profile insertion purposes
    HashMap verMap = new HashMap();
    for (int i = 0; i < numOfBuckets; i++) {
        nodeListCnt = setNodeListCnt(nodeListCnt);
        for (int j = 0; j < nodeListCnt; j++) {
            BucketProfile bp = new BucketProfile();
            bp.peerMemberId = (InternalDistributedMember) nodes.get(ran.nextInt(nodes.size()));
            Integer v;
            if ((v = (Integer) verMap.get(bp.getDistributedMember())) != null) {
                bp.version = v.intValue() + 1;
                verMap.put(bp.getDistributedMember(), new Integer(bp.version));
            } else {
                verMap.put(bp.getDistributedMember(), new Integer(0));
                bp.version = 0;
            }
            bp.isHosting = true;
            if (j == 0) {
                bp.isPrimary = true;
            }
            bp.scope = Scope.DISTRIBUTED_ACK;
            boolean forceBadProfile = true;
            assertTrue(ra.getBucket(i).getBucketAdvisor().putProfile(bp, forceBadProfile));
        }
    }
}
Also used : Random(java.util.Random) RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) HashMap(java.util.HashMap) BucketProfile(org.apache.geode.internal.cache.BucketAdvisor.BucketProfile)

Example 9 with RegionAdvisor

use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.

the class PartitionedRegionQueryEvaluatorIntegrationTest method populateAllPartitionedRegion.

private void populateAllPartitionedRegion(PartitionedRegion pr, List nodes) {
    // int totalNodes = 4;
    Region rootReg = PartitionedRegionHelper.getPRRoot(pr.getCache());
    // Region allPRs = PartitionedRegionHelper.getPRConfigRegion(rootReg, pr
    // .getCache());
    PartitionRegionConfig prConf = new PartitionRegionConfig(pr.getPRId(), pr.getFullPath(), pr.getPartitionAttributes(), pr.getScope());
    RegionAdvisor ra = pr.getRegionAdvisor();
    for (Iterator itr = nodes.iterator(); itr.hasNext(); ) {
        Node n = (Node) itr.next();
        prConf.addNode(n);
        PartitionProfile pp = (PartitionProfile) ra.createProfile();
        pp.peerMemberId = n.getMemberId();
        pp.isDataStore = true;
        final boolean forceFakeProfile = true;
        pr.getRegionAdvisor().putProfile(pp, forceFakeProfile);
    }
    rootReg.put(pr.getRegionIdentifier(), prConf);
}
Also used : PartitionProfile(org.apache.geode.internal.cache.partitioned.RegionAdvisor.PartitionProfile) RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region)

Aggregations

RegionAdvisor (org.apache.geode.internal.cache.partitioned.RegionAdvisor)9 Iterator (java.util.Iterator)4 HashMap (java.util.HashMap)3 Region (org.apache.geode.cache.Region)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ProxyBucketRegion (org.apache.geode.internal.cache.ProxyBucketRegion)2 PartitionProfile (org.apache.geode.internal.cache.partitioned.RegionAdvisor.PartitionProfile)2 HashSet (java.util.HashSet)1 Random (java.util.Random)1 Set (java.util.Set)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheException (org.apache.geode.cache.CacheException)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 LowMemoryException (org.apache.geode.cache.LowMemoryException)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)1 Index (org.apache.geode.cache.query.Index)1 AbstractIndex (org.apache.geode.cache.query.internal.index.AbstractIndex)1