Search in sources :

Example 1 with RegionDistributionException

use of org.apache.geode.cache.RegionDistributionException in project geode by apache.

the class TXCommitMessage method checkDistributionReliability.

/**
   * Checks reliable regions and throws CommitDistributionException if any required roles may not
   * have received the commit message.
   *
   * @param distMap map of RegionCommitList keys to Sets of receivers
   * @param processor the reply processor
   * @throws CommitDistributionException if any required roles may not have received the commit
   *         message
   */
private void checkDistributionReliability(Map distMap, CommitReplyProcessor processor) {
    // key=RegionCommit, value=Set of recipients
    Map regionToRecipients = new IdentityHashMap();
    // build up the keys in regionToRecipients and add all receivers
    for (Iterator distIter = distMap.entrySet().iterator(); distIter.hasNext(); ) {
        Map.Entry me = (Map.Entry) distIter.next();
        RegionCommitList rcl = (RegionCommitList) me.getKey();
        Set recipients = (Set) me.getValue();
        for (Iterator rclIter = rcl.iterator(); rclIter.hasNext(); ) {
            RegionCommit rc = (RegionCommit) rclIter.next();
            // skip region if no required roles
            if (!rc.r.requiresReliabilityCheck()) {
                continue;
            }
            Set recipientsForRegion = (Set) regionToRecipients.get(rc);
            if (recipientsForRegion == null) {
                recipientsForRegion = new HashSet();
                regionToRecipients.put(rc, recipientsForRegion);
            }
            // get the receiver Set for rcl and perform addAll
            if (recipients != null) {
                recipientsForRegion.addAll(recipients);
            }
        }
    }
    Set cacheClosedMembers = (processor == null) ? Collections.emptySet() : processor.getCacheClosedMembers();
    Set departedMembers = (processor == null) ? Collections.emptySet() : processor.getDepartedMembers();
    // check reliability on each region
    Set regionDistributionExceptions = Collections.emptySet();
    Set failedRegionNames = Collections.emptySet();
    for (Iterator iter = regionToRecipients.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry me = (Map.Entry) iter.next();
        final RegionCommit rc = (RegionCommit) me.getKey();
        final Set successfulRecipients = new HashSet(msgMap.keySet());
        successfulRecipients.removeAll(departedMembers);
        // remove members who destroyed that region or closed their cache
        Set regionDestroyedMembers = (processor == null) ? Collections.emptySet() : processor.getRegionDestroyedMembers(rc.r.getFullPath());
        successfulRecipients.removeAll(cacheClosedMembers);
        successfulRecipients.removeAll(regionDestroyedMembers);
        try {
            rc.r.handleReliableDistribution(successfulRecipients);
        } catch (RegionDistributionException e) {
            if (regionDistributionExceptions == Collections.emptySet()) {
                regionDistributionExceptions = new HashSet();
                failedRegionNames = new HashSet();
            }
            regionDistributionExceptions.add(e);
            failedRegionNames.add(rc.r.getFullPath());
        }
    }
    if (!regionDistributionExceptions.isEmpty()) {
        throw new CommitDistributionException(LocalizedStrings.TXCommitMessage_THESE_REGIONS_EXPERIENCED_RELIABILITY_FAILURE_DURING_DISTRIBUTION_OF_THE_OPERATION_0.toLocalizedString(failedRegionNames), regionDistributionExceptions);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) Iterator(java.util.Iterator) CommitDistributionException(org.apache.geode.cache.CommitDistributionException) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with RegionDistributionException

use of org.apache.geode.cache.RegionDistributionException in project geode by apache.

the class RegionReliabilityTestCase method testRegionDistributionException.

@Test
public void testRegionDistributionException() throws Exception {
    if (getRegionScope().isDistributedNoAck())
        // skip test under DistributedNoAck
        return;
    final String name = this.getUniqueName();
    final String roleA = name + "-A";
    final String[] requiredRoles = { roleA };
    Set requiredRolesSet = new HashSet();
    for (int i = 0; i < requiredRoles.length; i++) {
        requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
    }
    assertEquals(requiredRoles.length, requiredRolesSet.size());
    // connect controller to system...
    Properties config = new Properties();
    config.setProperty(ROLES, "");
    getSystem(config);
    getCache();
    RegionMembershipListener listener = new RegionMembershipListenerAdapter() {

        public void afterRemoteRegionDeparture(RegionEvent event) {
            synchronized (detectedDeparture_testRegionDistributionException) {
                detectedDeparture_testRegionDistributionException[0] = Boolean.TRUE;
                detectedDeparture_testRegionDistributionException.notify();
            }
        }
    };
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(getRegionScope());
    // fac.addCacheListener(listener);
    RegionAttributes attr = fac.create();
    Region region = createRootRegion(name, attr);
    assertTrue(((AbstractRegion) region).requiresReliabilityCheck());
    // use vm1 to create role
    CacheSerializableRunnable createRegion = new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            createConnection(new String[] { roleA });
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    };
    Host.getHost(0).getVM(1).invoke(createRegion);
    region.put("DESTROY_ME", "VAL");
    region.put("INVALIDATE_ME", "VAL");
    // define the afterReleaseLocalLocks callback
    SerializableRunnable removeRequiredRole = new SerializableRunnable() {

        public void run() {
            Host.getHost(0).getVM(1).invoke(new SerializableRunnable("Close Region") {

                public void run() {
                    getRootRegion(name).close();
                }
            });
        // try {
        // synchronized (detectedDeparture_testRegionDistributionException) {
        // while (detectedDeparture_testRegionDistributionException[0] == Boolean.FALSE) {
        // detectedDeparture_testRegionDistributionException.wait();
        // }
        // }
        // }
        // catch (InterruptedException e) {}
        }
    };
    DistributedCacheOperation.setBeforePutOutgoing(() -> {
        try {
            removeRequiredRole.run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    Runnable reset = new Runnable() {

        public void run() {
        // synchronized (detectedDeparture_testRegionDistributionException) {
        // detectedDeparture_testRegionDistributionException[0] = Boolean.FALSE;
        // }
        }
    };
    // PUT
    try {
        region.put("KEY", "VAL");
        fail("Should have thrown RegionDistributionException");
    } catch (RegionDistributionException e) {
    // pass
    }
    // INVALIDATE
    reset.run();
    Host.getHost(0).getVM(1).invoke(createRegion);
    try {
        region.invalidate("INVALIDATE_ME");
        fail("Should have thrown RegionDistributionException");
    } catch (RegionDistributionException e) {
    // pass
    }
    // DESTROY
    reset.run();
    Host.getHost(0).getVM(1).invoke(createRegion);
    try {
        region.destroy("DESTROY_ME");
        fail("Should have thrown RegionDistributionException");
    } catch (RegionDistributionException e) {
    // pass
    }
    // CLEAR
    reset.run();
    Host.getHost(0).getVM(1).invoke(createRegion);
    try {
        region.clear();
        fail("Should have thrown RegionDistributionException");
    } catch (RegionDistributionException e) {
    // pass
    }
    // PUTALL
    reset.run();
    Host.getHost(0).getVM(1).invoke(createRegion);
    try {
        Map putAll = new HashMap();
        putAll.put("PUTALL_ME", "VAL");
        region.putAll(putAll);
        fail("Should have thrown RegionDistributionException");
    } catch (RegionDistributionException e) {
    // pass
    }
    // INVALIDATE REGION
    reset.run();
    Host.getHost(0).getVM(1).invoke(createRegion);
    try {
        region.invalidateRegion();
        fail("Should have thrown RegionDistributionException");
    } catch (RegionDistributionException e) {
    // pass
    }
    // DESTROY REGION
    reset.run();
    Host.getHost(0).getVM(1).invoke(createRegion);
    try {
        region.destroyRegion();
        fail("Should have thrown RegionDistributionException");
    } catch (RegionDistributionException e) {
    // pass
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RegionAttributes(org.apache.geode.cache.RegionAttributes) HashMap(java.util.HashMap) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) RegionMembershipListener(org.apache.geode.cache.RegionMembershipListener) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CommitDistributionException(org.apache.geode.cache.CommitDistributionException) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) RegionAccessException(org.apache.geode.cache.RegionAccessException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheException(org.apache.geode.cache.CacheException) AttributesFactory(org.apache.geode.cache.AttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionMembershipListenerAdapter(org.apache.geode.cache.util.RegionMembershipListenerAdapter) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 3 with RegionDistributionException

use of org.apache.geode.cache.RegionDistributionException in project geode by apache.

the class DistributedRegion method isNoDistributionOk.

/**
   * Called when we do a distributed operation and don't have anyone to distributed it too. Since
   * this is only called when no distribution was done (i.e. no recipients) we do not check
   * isMissingRequiredRoles because it might not longer be true due to race conditions
   * 
   * @return false if this region has at least one required role and queuing is configured. Returns
   *         true if sending to no one is ok.
   * @throws RoleException if a required role is missing and the LossAction is either NO_ACCESS or
   *         LIMITED_ACCESS.
   * @since GemFire 5.0
   */
boolean isNoDistributionOk() {
    if (this.requiresReliabilityCheck) {
        MembershipAttributes ra = getMembershipAttributes();
        Set<Role> failedRoles = ra.getRequiredRoles();
        throw new RegionDistributionException(LocalizedStrings.DistributedRegion_OPERATION_DISTRIBUTION_WAS_NOT_DONE_TO_THESE_REQUIRED_ROLES_0.toLocalizedString(failedRoles), getFullPath(), failedRoles);
    }
    return true;
}
Also used : Role(org.apache.geode.distributed.Role) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) MembershipAttributes(org.apache.geode.cache.MembershipAttributes)

Example 4 with RegionDistributionException

use of org.apache.geode.cache.RegionDistributionException in project geode by apache.

the class DistributedRegion method handleReliableDistribution.

private void handleReliableDistribution(Set successfulRecipients, Set otherRecipients1, Set otherRecipients2) {
    if (this.requiresReliabilityCheck) {
        MembershipAttributes ra = getMembershipAttributes();
        // determine the successful roles
        Set roles = new HashSet();
        for (Object successfulRecipient : successfulRecipients) {
            InternalDistributedMember mbr = (InternalDistributedMember) successfulRecipient;
            if (mbr != null) {
                roles.addAll(mbr.getRoles());
            }
        }
        for (Object anOtherRecipients1 : otherRecipients1) {
            InternalDistributedMember mbr = (InternalDistributedMember) anOtherRecipients1;
            if (mbr != null) {
                roles.addAll(mbr.getRoles());
            }
        }
        for (Object anOtherRecipients2 : otherRecipients2) {
            InternalDistributedMember mbr = (InternalDistributedMember) anOtherRecipients2;
            if (mbr != null) {
                roles.addAll(mbr.getRoles());
            }
        }
        // determine the missing roles
        Set failedRoles = new HashSet(ra.getRequiredRoles());
        failedRoles.removeAll(roles);
        if (failedRoles.isEmpty()) {
            return;
        }
        throw new RegionDistributionException(LocalizedStrings.DistributedRegion_OPERATION_DISTRIBUTION_MAY_HAVE_FAILED_TO_NOTIFY_THESE_REQUIRED_ROLES_0.toLocalizedString(failedRoles), getFullPath(), failedRoles);
    }
}
Also used : Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) HashSet(java.util.HashSet)

Aggregations

RegionDistributionException (org.apache.geode.cache.RegionDistributionException)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 MembershipAttributes (org.apache.geode.cache.MembershipAttributes)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CommitDistributionException (org.apache.geode.cache.CommitDistributionException)2 IdentityHashMap (java.util.IdentityHashMap)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheException (org.apache.geode.cache.CacheException)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 Region (org.apache.geode.cache.Region)1 RegionAccessException (org.apache.geode.cache.RegionAccessException)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 RegionEvent (org.apache.geode.cache.RegionEvent)1 RegionMembershipListener (org.apache.geode.cache.RegionMembershipListener)1 RegionReinitializedException (org.apache.geode.cache.RegionReinitializedException)1