Search in sources :

Example 26 with PartitionedRegionDataStore

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

the class InterestEventMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(final DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
    if (logger.isTraceEnabled(LogMarker.DM)) {
        logger.debug("InterestEventMessage operateOnPartitionedRegion: {}", r.getFullPath());
    }
    PartitionedRegionDataStore ds = r.getDataStore();
    if (ds != null) {
        try {
            ds.handleInterestEvent(this.event);
            r.getPrStats().endPartitionMessagesProcessing(startTime);
            InterestEventReplyMessage.send(getSender(), getProcessorId(), dm);
        } catch (Exception e) {
            sendReply(getSender(), getProcessorId(), dm, new ReplyException(new ForceReattemptException("Caught exception during interest registration processing:", e)), r, startTime);
            return false;
        }
    } else {
        throw new InternalError("InterestEvent message was sent to a member with no storage.");
    }
    // response
    return false;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) ReplyException(org.apache.geode.distributed.internal.ReplyException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 27 with PartitionedRegionDataStore

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

the class ManageBackupBucketMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) {
    if (logger.isTraceEnabled(LogMarker.DM)) {
        logger.trace(LogMarker.DM, "ManageBucketMessage operateOnRegion: {}", r.getFullPath());
    }
    // serviced. BUGFIX for 35888
    if (!r.isInitialized()) {
        // This VM is NOT ready to manage a new bucket, refuse operation
        ManageBackupBucketReplyMessage.sendStillInitializing(getSender(), getProcessorId(), dm);
        return false;
    }
    // Don't allow closed PartitionedRegions that have datastores to host
    r.checkReadiness();
    // buckets
    PartitionedRegionDataStore prDs = r.getDataStore();
    boolean managingBucket = prDs.grabBucket(this.bucketId, this.moveSource, this.forceCreation, replaceOfflineData, this.isRebalance, null, false) == CreateBucketResult.CREATED;
    r.getPrStats().endPartitionMessagesProcessing(startTime);
    if (managingBucket) {
        ManageBackupBucketReplyMessage.sendAcceptance(getSender(), getProcessorId(), dm);
    } else {
        ManageBackupBucketReplyMessage.sendRefusal(getSender(), getProcessorId(), dm);
    }
    return false;
}
Also used : PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore)

Example 28 with PartitionedRegionDataStore

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

the class RemoveBucketMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion region, long startTime) throws ForceReattemptException {
    PartitionedRegionDataStore dataStore = region.getDataStore();
    boolean removed = dataStore.removeBucket(this.bucketId, this.forceRemovePrimary);
    region.getPrStats().endPartitionMessagesProcessing(startTime);
    RemoveBucketReplyMessage.send(getSender(), getProcessorId(), dm, null, removed);
    return false;
}
Also used : PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore)

Example 29 with PartitionedRegionDataStore

use of org.apache.geode.internal.cache.PartitionedRegionDataStore 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 30 with PartitionedRegionDataStore

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

the class Bug39356DUnitTest method testMoveBucketToHostThatHasTheBucketAlready.

/**
   * A test to make sure that we cannot move a bucket to a member which already hosts the bucket,
   * thereby reducing our redundancy.
   */
@Test
public void testMoveBucketToHostThatHasTheBucketAlready() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            paf.setRecoveryDelay(-1);
            paf.setStartupRecoveryDelay(-1);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
        }
    };
    vm0.invoke(createPrRegion);
    vm1.invoke(createPrRegion);
    // Create a bucket
    vm0.invoke(new SerializableRunnable("createSomeBuckets") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            region.put(Integer.valueOf(0), "A");
        }
    });
    final InternalDistributedMember vm1MemberId = (InternalDistributedMember) vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            return InternalDistributedSystem.getAnyInstance().getDistributedMember();
        }
    });
    // Move the bucket
    vm0.invoke(new SerializableRunnable("moveBucket") {

        public void run() {
            Cache cache = getCache();
            PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
            Set<InternalDistributedMember> owners = region.getRegionAdvisor().getBucketOwners(0);
            assertEquals(2, owners.size());
            PartitionedRegionDataStore ds = region.getDataStore();
            assertTrue(ds.isManagingBucket(0));
            // try to move the bucket from the other member to this one. This should
            // fail because we already have the bucket
            assertFalse(ds.moveBucket(0, vm1MemberId, true));
            assertEquals(owners, region.getRegionAdvisor().getBucketOwners(0));
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)30 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)9 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)9 ReplyException (org.apache.geode.distributed.internal.ReplyException)7 BucketRegion (org.apache.geode.internal.cache.BucketRegion)7 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)7 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)6 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)6 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)5 Released (org.apache.geode.internal.offheap.annotations.Released)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 CacheWriterException (org.apache.geode.cache.CacheWriterException)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)3 DataLocationException (org.apache.geode.internal.cache.DataLocationException)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2