Search in sources :

Example 1 with Bucket

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

the class ResourceManagerDUnitTest method doOpDuringBucketRemove.

private void doOpDuringBucketRemove(final OpDuringBucketRemove op) {
    final String[] regionPath = new String[] { getUniqueName() + "_PR_0" };
    final int[] numBuckets = new int[] { 1 };
    final int[] redundantCopies = new int[] { 1 };
    // localMaxMemory config to use for three members
    final int[] localMaxMemory = new int[] { 100, 100 };
    final Integer KEY = Integer.valueOf(69);
    // bucketKeys to use for making one bucket
    final Integer[] bucketKeys = new Integer[] { KEY };
    createRegion(Host.getHost(0).getVM(0), regionPath[0], localMaxMemory[0], numBuckets[0], redundantCopies[0]);
    createRegion(Host.getHost(0).getVM(1), regionPath[0], localMaxMemory[1], numBuckets[0], redundantCopies[0]);
    final String VALUE = "doOpDuringBucketRemove.VALUE";
    createBuckets(0, regionPath[0], bucketKeys, VALUE);
    // identify the members and their config values
    final InternalDistributedMember[] members = new InternalDistributedMember[2];
    final long[] memberSizes = new long[members.length];
    final int[] memberBucketCounts = new int[members.length];
    final int[] memberPrimaryCounts = new int[members.length];
    fillValidationArrays(members, memberSizes, memberBucketCounts, memberPrimaryCounts, regionPath[0]);
    int primaryVM = -1;
    int otherVM = -1;
    for (int i = 0; i < memberPrimaryCounts.length; i++) {
        if (memberPrimaryCounts[i] == 0) {
            otherVM = i;
        } else if (memberPrimaryCounts[i] == 1) {
            // found the primary
            primaryVM = i;
        }
    }
    assertTrue(primaryVM > -1);
    assertTrue(otherVM > -1);
    assertTrue(primaryVM != otherVM);
    final int finalOtherVM = otherVM;
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertTrue("Target member is not hosting bucket to remove", bucket.isHosting());
            assertNotNull("Bucket is null on target member", bucket);
            assertNotNull("BucketRegion is null on target member", bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion());
            EntrySnapshot re = (EntrySnapshot) pr.getEntry(KEY);
            assertEquals(true, re.wasInitiallyLocal());
            assertEquals(false, re.isLocal());
            assertEquals(VALUE, re.getValue());
        }
    });
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            final PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            final boolean[] invoked = new boolean[] { false };
            final PartitionedRegionDataStore prds = pr.getDataStore();
            prds.setBucketReadHook(new Runnable() {

                public void run() {
                    invoked[0] = true;
                    logger.debug("In bucketReadHook");
                    assertTrue(prds.removeBucket(0, false));
                }
            });
            try {
                Bucket bucket = pr.getRegionAdvisor().getBucket(0);
                assertTrue("Target member is not hosting bucket to remove", bucket.isHosting());
                assertNotNull("Bucket is null on target member", bucket);
                assertNotNull("BucketRegion is null on target member", bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion());
                assertEquals(false, invoked[0]);
                op.runit(pr, KEY, VALUE);
                assertEquals(true, invoked[0]);
            } finally {
                prds.setBucketReadHook(null);
            }
        }
    });
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertFalse("Target member is still hosting removed bucket. Bucket:" + bucket + " Advisor state:" + bucket.getBucketAdvisor(), bucket.isHosting());
            assertNull(bucketRegion);
            // assertTrue(bucketRegion == null || bucketRegion.isDestroyed());
            EntrySnapshot re = (EntrySnapshot) pr.getEntry(KEY);
            assertEquals(false, re.wasInitiallyLocal());
            assertEquals(false, re.isLocal());
            assertEquals(VALUE, re.getValue());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 2 with Bucket

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

the class ResourceManagerDUnitTest method testMoveBucket.

/**
   * Creates a bucket on two members. Then brings up a third member and moves the non-primary bucket
   * to it.
   */
@Test
public void testMoveBucket() {
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0" };
    final int numBuckets = 1;
    final int redundantCopies = 1;
    final int localMaxMemory = 100;
    // create the PartitionedRegion on the first two members
    createRegion(Host.getHost(0).getVM(0), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    createRegion(Host.getHost(0).getVM(1), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    // create the bucket on the first two members
    final Integer bucketKey = Integer.valueOf(0);
    // 2 MB in size
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKey, value);
    // identify the primaryVM and otherVM
    final InternalDistributedMember[] members = new InternalDistributedMember[2];
    final long[] memberSizes = new long[members.length];
    final int[] memberBucketCounts = new int[members.length];
    final int[] memberPrimaryCounts = new int[members.length];
    fillValidationArrays(members, memberSizes, memberBucketCounts, memberPrimaryCounts, regionPath[0]);
    int primaryVM = -1;
    int otherVM = -1;
    for (int i = 0; i < memberPrimaryCounts.length; i++) {
        if (memberPrimaryCounts[i] == 0) {
            otherVM = i;
        } else if (memberPrimaryCounts[i] == 1) {
            // found the primary
            primaryVM = i;
        }
    }
    assertTrue(primaryVM > -1);
    assertTrue(otherVM > -1);
    assertTrue(primaryVM != otherVM);
    final int finalOtherVM = otherVM;
    // make sure bucket exists on otherVM
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertNotNull("Bucket is null on SRC member", bucket);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertTrue("SRC member is not hosting bucket", bucket.isHosting());
            assertNotNull("BucketRegion is null on SRC member", bucketRegion);
            int redundancy = bucket.getBucketAdvisor().getBucketRedundancy();
            assertEquals("SRC member reports redundancy " + redundancy, redundantCopies, redundancy);
        }
    });
    // create newVM to move bucket to
    final int finalNewVM = 2;
    createRegion(Host.getHost(0).getVM(finalNewVM), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    // initiate moveBucket to move from otherVM to newVM
    boolean movedBucket = ((Boolean) Host.getHost(0).getVM(finalNewVM).invoke(new SerializableCallable() {

        public Object call() {
            InternalDistributedMember recipient = members[finalOtherVM];
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            return pr.getDataStore().moveBucket(0, recipient, true);
        }
    })).booleanValue();
    assertTrue("Failed in call to moveBucket", movedBucket);
    // validate that otherVM no longer hosts bucket
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertFalse("SRC member is still hosting moved bucket", bucket.isHosting());
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertNull("BucketRegion is not null on SRC member", bucketRegion);
        }
    });
    // validate that newVM now hosts bucket
    Host.getHost(0).getVM(finalNewVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertNotNull("Bucket is null on DST member", bucket);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertTrue("DST member is not hosting bucket", bucket.isHosting());
            assertNotNull("BucketRegion is null on DST member", bucketRegion);
            assertEquals(redundantCopies, bucket.getBucketAdvisor().getBucketRedundancy());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 3 with Bucket

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

the class ResourceManagerDUnitTest method testCreateRedundantBucket.

/**
   * Creates a bucket on two members. Then brings up a third member and creates an extra redundant
   * copy of the bucket on it.
   */
@Test
public void testCreateRedundantBucket() {
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0" };
    final int numBuckets = 1;
    final int redundantCopies = 1;
    final int localMaxMemory = 100;
    // create the PartitionedRegion on the first two members
    createRegion(Host.getHost(0).getVM(0), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    createRegion(Host.getHost(0).getVM(1), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    // create the bucket on the first two members
    final Integer bucketKey = Integer.valueOf(0);
    // 2 MB in size
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKey, value);
    // identify the primaryVM and otherVM
    final InternalDistributedMember[] members = new InternalDistributedMember[2];
    final long[] memberSizes = new long[members.length];
    final int[] memberBucketCounts = new int[members.length];
    final int[] memberPrimaryCounts = new int[members.length];
    fillValidationArrays(members, memberSizes, memberBucketCounts, memberPrimaryCounts, regionPath[0]);
    int primaryVM = -1;
    int otherVM = -1;
    for (int i = 0; i < memberPrimaryCounts.length; i++) {
        if (memberPrimaryCounts[i] == 0) {
            otherVM = i;
        } else if (memberPrimaryCounts[i] == 1) {
            // found the primary
            primaryVM = i;
        }
    }
    assertTrue(primaryVM > -1);
    assertTrue(otherVM > -1);
    assertTrue(primaryVM != otherVM);
    final int finalOtherVM = otherVM;
    // make sure bucket exists on otherVM
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertNotNull("Bucket is null on SRC member", bucket);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertTrue("SRC member is not hosting bucket", bucket.isHosting());
            assertNotNull("BucketRegion is null on SRC member", bucketRegion);
            int redundancy = bucket.getBucketAdvisor().getBucketRedundancy();
            assertEquals("SRC member reports redundancy " + redundancy, redundantCopies, redundancy);
        }
    });
    // create newVM to create extra redundant bucket on
    final int finalNewVM = 2;
    createRegion(Host.getHost(0).getVM(finalNewVM), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    // create an extra redundant bucket on finalNewVM
    Host.getHost(0).getVM(finalNewVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            assertEquals(CreateBucketResult.CREATED, pr.getDataStore().createRedundantBucket(0, false, new InternalDistributedMember()));
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertNotNull("Bucket is null on DST member", bucket);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertTrue("DST member is not hosting bucket", bucket.isHosting());
            assertNotNull("BucketRegion is null on DST member", bucketRegion);
            assertEquals(redundantCopies + 1, bucket.getBucketAdvisor().getBucketRedundancy());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 4 with Bucket

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

the class ResourceManagerDUnitTest method testRemoveBucketMessage.

@Test
public void testRemoveBucketMessage() {
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0" };
    final int[] numBuckets = new int[] { 1 };
    final int[] redundantCopies = new int[] { 1 };
    // localMaxMemory config to use for 2 members
    final int[] localMaxMemory = new int[] { 100, 100 };
    createRegion(Host.getHost(0).getVM(0), regionPath[0], localMaxMemory[0], numBuckets[0], redundantCopies[0]);
    createRegion(Host.getHost(0).getVM(1), regionPath[0], localMaxMemory[1], numBuckets[0], redundantCopies[0]);
    final Integer bucketKey = Integer.valueOf(0);
    // 2 MB in size
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKey, value);
    // identify the members and their config values
    final InternalDistributedMember[] members = new InternalDistributedMember[2];
    final long[] memberSizes = new long[members.length];
    final int[] memberBucketCounts = new int[members.length];
    final int[] memberPrimaryCounts = new int[members.length];
    fillValidationArrays(members, memberSizes, memberBucketCounts, memberPrimaryCounts, regionPath[0]);
    int primaryVM = -1;
    int otherVM = -1;
    for (int i = 0; i < memberPrimaryCounts.length; i++) {
        if (memberPrimaryCounts[i] == 0) {
            otherVM = i;
        } else if (memberPrimaryCounts[i] == 1) {
            // found the primary
            primaryVM = i;
        }
    }
    assertTrue(primaryVM > -1);
    assertTrue(otherVM > -1);
    assertTrue(primaryVM != otherVM);
    final int finalOtherVM = otherVM;
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertTrue("Target member is not hosting bucket to remove", bucket.isHosting());
            assertNotNull("Bucket is null on target member", bucket);
            assertNotNull("BucketRegion is null on target member", bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion());
        }
    });
    boolean sentRemoveBucket = ((Boolean) Host.getHost(0).getVM(primaryVM).invoke(new SerializableCallable() {

        public Object call() {
            InternalDistributedMember recipient = members[finalOtherVM];
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            RemoveBucketResponse response = RemoveBucketMessage.send(recipient, pr, 0, false);
            if (response != null) {
                response.waitForRepliesUninterruptibly();
                return true;
            } else {
                return Boolean.FALSE;
            }
        }
    })).booleanValue();
    assertTrue("Failed to get reply to RemoveBucketMessage", sentRemoveBucket);
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertFalse("Target member is still hosting removed bucket", bucket.isHosting());
            assertNull("BucketRegion is not null on target member", bucketRegion);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) RemoveBucketResponse(org.apache.geode.internal.cache.partitioned.RemoveBucketMessage.RemoveBucketResponse) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 5 with Bucket

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

the class MembershipViewRequest method process.

@Override
protected void process(DistributionManager dm) {
    int initLevel = this.targetReinitializing ? LocalRegion.AFTER_INITIAL_IMAGE : LocalRegion.ANY_INIT;
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
    PersistentMembershipView view = null;
    ReplyException exception = null;
    try {
        // get the region from the path, but do NOT wait on initialization,
        // otherwise we could have a distributed deadlock
        Cache cache = CacheFactory.getInstance(dm.getSystem());
        Region region = cache.getRegion(this.regionPath);
        PersistenceAdvisor persistenceAdvisor = null;
        if (region instanceof DistributedRegion) {
            persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
        } else if (region == null) {
            Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
            if (proxy != null) {
                persistenceAdvisor = proxy.getPersistenceAdvisor();
            }
        }
        if (persistenceAdvisor != null) {
            view = persistenceAdvisor.getMembershipView();
        }
    } catch (RegionDestroyedException e) {
        // exception = new ReplyException(e);
        logger.debug("<RegionDestroyed> {}", this);
    } catch (CancelException e) {
        // exception = new ReplyException(e);
        logger.debug("<CancelException> {}", this);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        MembershipViewReplyMessage replyMsg = new MembershipViewReplyMessage();
        replyMsg.setRecipient(getSender());
        replyMsg.setProcessorId(processorId);
        replyMsg.view = view;
        if (logger.isDebugEnabled()) {
            logger.debug("MembershipViewRequest returning view {} for region {}", view, this.regionPath);
        }
        if (exception != null) {
            replyMsg.setException(exception);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Cache(org.apache.geode.cache.Cache)

Aggregations

Bucket (org.apache.geode.internal.cache.partitioned.Bucket)22 BucketRegion (org.apache.geode.internal.cache.BucketRegion)11 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Test (org.junit.Test)6 CancelException (org.apache.geode.CancelException)5 Cache (org.apache.geode.cache.Cache)4 Region (org.apache.geode.cache.Region)4 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)4 ReplyException (org.apache.geode.distributed.internal.ReplyException)4 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)4 LocalRegion (org.apache.geode.internal.cache.LocalRegion)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 ReplyMessage (org.apache.geode.distributed.internal.ReplyMessage)3 RemoveBucketResponse (org.apache.geode.internal.cache.partitioned.RemoveBucketMessage.RemoveBucketResponse)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1