Search in sources :

Example 6 with BucketAdvisor

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

the class BecomePrimaryBucketMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion region, long startTime) throws ForceReattemptException {
    // this is executing in the WAITING_POOL_EXECUTOR
    byte responseCode = BecomePrimaryBucketReplyMessage.NOT_SECONDARY;
    BucketAdvisor bucketAdvisor = region.getRegionAdvisor().getBucketAdvisor(this.bucketId);
    if (bucketAdvisor.isHosting()) {
        if (bucketAdvisor.becomePrimary(this.isRebalance)) {
            // sends a request/reply message
            responseCode = BecomePrimaryBucketReplyMessage.OK;
        }
    }
    region.getPrStats().endPartitionMessagesProcessing(startTime);
    BecomePrimaryBucketReplyMessage.send(getSender(), getProcessorId(), dm, null, responseCode);
    return false;
}
Also used : BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Example 7 with BucketAdvisor

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

the class DeposePrimaryBucketMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion region, long startTime) throws ForceReattemptException {
    BucketAdvisor bucketAdvisor = region.getRegionAdvisor().getBucketAdvisor(this.bucketId);
    bucketAdvisor.deposePrimary();
    region.getPrStats().endPartitionMessagesProcessing(startTime);
    DeposePrimaryBucketReplyMessage.send(getSender(), getProcessorId(), dm, (ReplyException) null);
    return false;
}
Also used : BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Example 8 with BucketAdvisor

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

the class AcceptorImpl method notifyCacheMembersOfClose.

private void notifyCacheMembersOfClose() {
    if (!this.cache.forcedDisconnect()) {
        for (PartitionedRegion pr : this.cache.getPartitionedRegions()) {
            Map<Integer, BucketAdvisor.BucketProfile> profiles = new HashMap<>();
            // get all local real bucket advisors
            Map<Integer, BucketAdvisor> advisors = pr.getRegionAdvisor().getAllBucketAdvisors();
            for (Map.Entry<Integer, BucketAdvisor> entry : advisors.entrySet()) {
                BucketAdvisor advisor = entry.getValue();
                BucketProfile bp = (BucketProfile) advisor.createProfile();
                advisor.updateServerBucketProfile(bp);
                profiles.put(entry.getKey(), bp);
            }
            Set recipients = pr.getRegionAdvisor().adviseAllPRNodes();
            // send it to all in one message
            ReplyProcessor21 reply = AllBucketProfilesUpdateMessage.send(recipients, pr.getDistributionManager(), pr.getPRId(), profiles, true);
            if (reply != null) {
                reply.waitForRepliesUninterruptibly();
            }
            if (logger.isDebugEnabled()) {
                logger.debug("sending messages to all peers for removing this server..");
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) BucketProfile(org.apache.geode.internal.cache.BucketAdvisor.BucketProfile) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor) Map(java.util.Map) HashMap(java.util.HashMap) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Example 9 with BucketAdvisor

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

the class SizedBasedLoadProbe method getLoad.

public PRLoad getLoad(PartitionedRegion pr) {
    PartitionedRegionDataStore ds = pr.getDataStore();
    int configuredBucketCount = pr.getTotalNumberOfBuckets();
    PRLoad prLoad = new PRLoad(configuredBucketCount, pr.getLocalMaxMemory());
    // key: bid, value: size
    for (Integer bidInt : ds.getAllLocalBucketIds()) {
        int bid = bidInt.intValue();
        long bucketSize = ds.getBucketSize(bid);
        if (bucketSize < MIN_BUCKET_SIZE) {
            bucketSize = MIN_BUCKET_SIZE;
        }
        BucketAdvisor bucketAdvisor = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor();
        // Wait for a primary to exist for this bucket, because
        // it might be this member.
        bucketAdvisor.getPrimary();
        boolean isPrimary = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor().isPrimary();
        prLoad.addBucket(bid, bucketSize, isPrimary ? 1 : 0);
    }
    return prLoad;
}
Also used : PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Example 10 with BucketAdvisor

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

the class ResourceManagerDUnitTest method testBecomePrimaryBucketMessage.

@Test
public void testBecomePrimaryBucketMessage() {
    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 two members
    final int[] localMaxMemory = new int[] { 100, 100, 0 };
    // bucketKeys to use for making one bucket
    final Integer[] bucketKeys = new Integer[] { Integer.valueOf(0) };
    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]);
    createRegion(Host.getHost(0).getVM(2), regionPath[0], localMaxMemory[2], numBuckets[0], redundantCopies[0]);
    // 2 MB in size
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKeys[0], 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);
    int accessorVM = 2;
    assertTrue(accessorVM != primaryVM && accessorVM != otherVM);
    final int finalOtherVM = otherVM;
    boolean becamePrimary = ((Boolean) Host.getHost(0).getVM(accessorVM).invoke(new SerializableCallable() {

        public Object call() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            BecomePrimaryBucketResponse response = BecomePrimaryBucketMessage.send(members[finalOtherVM], pr, 0, false);
            if (response != null) {
                return Boolean.valueOf(response.waitForResponse());
            } else {
                return Boolean.FALSE;
            }
        }
    })).booleanValue();
    assertTrue(becamePrimary);
    // do a put from all three members to ensure primary is identified
    for (int i = 0; i < localMaxMemory.length; i++) {
        final int vm = i;
        performPuts(vm, regionPath[0], bucketKeys, value);
    }
    // use BucketAdvisor on all three members to assert that otherVM is now the primary
    for (int i = 0; i < localMaxMemory.length; i++) {
        final int vm = i;
        Host.getHost(0).getVM(vm).invoke(new SerializableRunnable() {

            public void run() {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
                BucketAdvisor advisor = pr.getRegionAdvisor().getBucketAdvisor(0);
                assertEquals(members[finalOtherVM], advisor.getPrimary());
            }
        });
    }
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) BecomePrimaryBucketResponse(org.apache.geode.internal.cache.partitioned.BecomePrimaryBucketMessage.BecomePrimaryBucketResponse) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

BucketAdvisor (org.apache.geode.internal.cache.BucketAdvisor)10 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)2 BucketProfile (org.apache.geode.internal.cache.BucketAdvisor.BucketProfile)2 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 Region (org.apache.geode.cache.Region)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 LuceneIndexStats (org.apache.geode.cache.lucene.internal.LuceneIndexStats)1 RegionDirectory (org.apache.geode.cache.lucene.internal.directory.RegionDirectory)1 FileSystemStats (org.apache.geode.cache.lucene.internal.filesystem.FileSystemStats)1 HeterogeneousLuceneSerializer (org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer)1