Search in sources :

Example 1 with RemoveBucketResponse

use of org.apache.geode.internal.cache.partitioned.RemoveBucketMessage.RemoveBucketResponse 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 2 with RemoveBucketResponse

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

the class PartitionedRegionDataStore method moveBucket.

/**
   * Moves the bucket from the <code>source</code> member to this datastore.
   * 
   * If the bucket is the leader bucket then it will recursively create all colocated children and
   * then remove all colocated children as well from the <code>source</code> member.
   * 
   * @param bucketId the bucket to move
   * @param source the member to move the bucket from
   * @return true if bucket was successfully moved to this datastore
   */
public boolean moveBucket(int bucketId, InternalDistributedMember source, final boolean isRebalance) {
    if (createRedundantBucket(bucketId, isRebalance, source) != CreateBucketResult.CREATED) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to move bucket {} to {}", bucketId, this);
        }
        return false;
    }
    BucketAdvisor bucketAdvisor = this.partitionedRegion.getRegionAdvisor().getBucketAdvisor(bucketId);
    if (source.equals(bucketAdvisor.getPrimary())) {
        if (!bucketAdvisor.becomePrimary(true)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to become primary for bucket {} on {}", bucketId, this);
            }
        }
    }
    RemoveBucketResponse response = RemoveBucketMessage.send(source, this.partitionedRegion, bucketId, false);
    if (response != null) {
        boolean removed = response.waitForResponse();
        if (removed == false) {
            if (logger.isDebugEnabled()) {
                logger.debug("Successfully created bucket {} in {} but failed to remove it from {}", bucketId, this, source);
            }
        }
    // TODO rebalance - perhaps we should thow an error if we
    // can't remove the bucket??
    }
    // The new bucket's size is counted in when GII
    return true;
}
Also used : RemoveBucketResponse(org.apache.geode.internal.cache.partitioned.RemoveBucketMessage.RemoveBucketResponse)

Example 3 with RemoveBucketResponse

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

the class ResourceManagerDUnitTest method testRemoveColocatedBuckets.

/**
   * Creates a chain of three colocated PRs and then calls removeBucket to make sure that all
   * colocated buckets are removed together.
   */
// GEODE-928: RemoveBucketMessage failure?
@Category(FlakyTest.class)
@Test
public void testRemoveColocatedBuckets() {
    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;
    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]);
    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 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() {
            for (int i = 0; i < regionPath.length; i++) {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[i]);
                Bucket bucket = pr.getRegionAdvisor().getBucket(0);
                assertTrue("Target member is not hosting bucket to remove for " + regionPath[i], bucket.isHosting());
                assertNotNull("Bucket is null on target member for " + regionPath[i], bucket);
                assertNotNull("BucketRegion is null on target member for " + regionPath[i], 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() {
            for (int i = 0; i < regionPath.length; i++) {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[i]);
                Bucket bucket = pr.getRegionAdvisor().getBucket(0);
                BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
                assertFalse("Target member is still hosting removed bucket for " + regionPath[i], bucket.isHosting());
                assertNull("BucketRegion is not null on target member for " + regionPath[i], 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) 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)

Aggregations

RemoveBucketResponse (org.apache.geode.internal.cache.partitioned.RemoveBucketMessage.RemoveBucketResponse)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 Bucket (org.apache.geode.internal.cache.partitioned.Bucket)2 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 Test (org.junit.Test)2 Category (org.junit.experimental.categories.Category)1