Search in sources :

Example 21 with Bucket

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

the class ResourceManagerDUnitTest method testCreateRedundantColocatedBuckets.

/**
   * Creates colocated buckets on two members. Then brings up a third member and creates an extra
   * redundant copy of the buckets on it.
   */
@Test
public void testCreateRedundantColocatedBuckets() {
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0", getUniqueName() + "-PR-1", getUniqueName() + "-PR-2" };
    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);
    createRegion(Host.getHost(0).getVM(0), regionPath[1], localMaxMemory, numBuckets, redundantCopies, regionPath[0]);
    createRegion(Host.getHost(0).getVM(1), regionPath[1], localMaxMemory, numBuckets, redundantCopies, regionPath[0]);
    createRegion(Host.getHost(0).getVM(0), regionPath[2], localMaxMemory, numBuckets, redundantCopies, regionPath[1]);
    createRegion(Host.getHost(0).getVM(1), regionPath[2], localMaxMemory, numBuckets, redundantCopies, regionPath[1]);
    // create the bucket on the first two members
    final Integer bucketKey = Integer.valueOf(0);
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKey, value);
    createBucket(0, regionPath[1], bucketKey, value);
    createBucket(0, regionPath[2], 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 colocated buckets exists on otherVM
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

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

        public void run() {
            for (int i = 0; i < regionPath.length; i++) {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[i]);
                if (i == 0) {
                    // only call createRedundantBucket on leader PR
                    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 22 with Bucket

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

the class ResourceManagerDUnitTest method testMoveColocatedBuckets.

/**
   * Creates colocated buckets on two members. Then brings up a third member and moves the
   * non-primary colocated buckets to it.
   */
@Test
public void testMoveColocatedBuckets() {
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0", getUniqueName() + "-PR-1", getUniqueName() + "-PR-2" };
    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);
    createRegion(Host.getHost(0).getVM(0), regionPath[1], localMaxMemory, numBuckets, redundantCopies, regionPath[0]);
    createRegion(Host.getHost(0).getVM(1), regionPath[1], localMaxMemory, numBuckets, redundantCopies, regionPath[0]);
    createRegion(Host.getHost(0).getVM(0), regionPath[2], localMaxMemory, numBuckets, redundantCopies, regionPath[1]);
    createRegion(Host.getHost(0).getVM(1), regionPath[2], localMaxMemory, numBuckets, redundantCopies, regionPath[1]);
    // create the bucket on the first two members
    final Integer bucketKey = Integer.valueOf(0);
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKey, value);
    createBucket(0, regionPath[1], bucketKey, value);
    createBucket(0, regionPath[2], 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 colocated buckets exists on otherVM
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            for (int i = 0; i < regionPath.length; i++) {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[i]);
                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 buckets on
    final int finalNewVM = 2;
    createRegion(Host.getHost(0).getVM(finalNewVM), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    createRegion(Host.getHost(0).getVM(finalNewVM), regionPath[1], localMaxMemory, numBuckets, redundantCopies, regionPath[0]);
    createRegion(Host.getHost(0).getVM(finalNewVM), regionPath[2], localMaxMemory, numBuckets, redundantCopies, regionPath[1]);
    // create extra redundant buckets on finalNewVM
    Host.getHost(0).getVM(finalNewVM).invoke(new SerializableRunnable() {

        public void run() {
            for (int i = 0; i < regionPath.length; i++) {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[i]);
                if (i == 0) {
                    // only call createRedundantBucket on leader PR
                    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());
            }
        }
    });
    if (true)
        return;
    // 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 colocated buckets
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            for (int i = 0; i < regionPath.length; i++) {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[i]);
                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 colocated bucket
    Host.getHost(0).getVM(finalNewVM).invoke(new SerializableRunnable() {

        public void run() {
            for (int i = 0; i < regionPath.length; i++) {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[i]);
                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)

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