Search in sources :

Example 1 with PRLocallyDestroyedException

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

the class PartitionedRegion method containsKeyInBucket.

boolean containsKeyInBucket(final InternalDistributedMember targetNode, final Integer bucketIdInt, final Object key, boolean valueCheck) {
    final int retryAttempts = calcRetry();
    if (logger.isDebugEnabled()) {
        logger.debug("containsKeyInBucket: {}{} ({}) from: {} bucketId={}", (valueCheck ? "ValueForKey key=" : "Key key="), key, key.hashCode(), targetNode, bucketStringForLogs(bucketIdInt));
    }
    boolean ret;
    int count = 0;
    RetryTimeKeeper retryTime = null;
    InternalDistributedMember retryNode = targetNode;
    while (count <= retryAttempts) {
        // Every continuation should check for DM cancellation
        if (retryNode == null) {
            checkReadiness();
            if (retryTime == null) {
                retryTime = new RetryTimeKeeper(this.retryTimeout);
            }
            if (retryTime.overMaximum()) {
                break;
            }
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
            // No storage found for bucket, early out preventing hot loop, bug 36819
            if (retryNode == null) {
                // Prefer closed style exceptions over empty result
                checkShutdown();
                return false;
            }
            continue;
        }
        // retryNode != null
        try {
            final boolean loc = retryNode.equals(getMyId());
            if (loc) {
                if (valueCheck) {
                    ret = this.dataStore.containsValueForKeyLocally(bucketIdInt, key);
                } else {
                    ret = this.dataStore.containsKeyLocally(bucketIdInt, key);
                }
            } else {
                if (valueCheck) {
                    ret = containsValueForKeyRemotely(retryNode, bucketIdInt, key);
                } else {
                    ret = containsKeyRemotely(retryNode, bucketIdInt, key);
                }
            }
            return ret;
        } catch (PRLocallyDestroyedException pde) {
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket: Encountered PRLocallyDestroyedException", pde);
            }
            checkReadiness();
        } catch (ForceReattemptException prce) {
            prce.checkKey(key);
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket: retry attempt:{} of {}", count, retryAttempts, prce);
            }
            checkReadiness();
            InternalDistributedMember lastNode = retryNode;
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
            if (lastNode.equals(retryNode)) {
                if (retryTime == null) {
                    retryTime = new RetryTimeKeeper(this.retryTimeout);
                }
                if (retryTime.overMaximum()) {
                    break;
                }
                retryTime.waitToRetryNode();
            }
        } catch (PrimaryBucketException notPrimary) {
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
            }
            getRegionAdvisor().notPrimary(bucketIdInt, retryNode);
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
        } catch (RegionDestroyedException rde) {
            if (!rde.getRegionFullPath().equals(getFullPath())) {
                throw new RegionDestroyedException(toString(), getFullPath(), rde);
            }
        }
        // It's possible this is a GemFire thread e.g. ServerConnection
        // which got to this point because of a distributed system shutdown or
        // region closure which uses interrupt to break any sleep() or wait()
        // calls
        // e.g. waitForPrimary
        checkShutdown();
        count++;
        if (count == 1) {
            this.prStats.incContainsKeyValueOpsRetried();
        }
        this.prStats.incContainsKeyValueRetries();
    }
    StringId msg = null;
    if (valueCheck) {
        msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_VALUE_FOR_KEY_IN_1_ATTEMPTS;
    } else {
        msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_KEY_IN_1_ATTEMPTS;
    }
    Integer countInteger = count;
    // Fix for bug 36014
    PartitionedRegionDistributionException e = null;
    if (logger.isDebugEnabled()) {
        e = new PartitionedRegionDistributionException(msg.toLocalizedString(countInteger));
    }
    logger.warn(LocalizedMessage.create(msg, countInteger), e);
    return false;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) StringId(org.apache.geode.i18n.StringId) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException)

Example 2 with PRLocallyDestroyedException

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

the class PartitionedRegion method fetchAllLocalKeys.

public Set fetchAllLocalKeys(Integer id, Set<Integer> failures, String regex) {
    Set result = new HashSet();
    try {
        Set keys = null;
        if (regex != null) {
            keys = this.dataStore.handleRemoteGetKeys(id, InterestType.REGULAR_EXPRESSION, regex, true);
        } else {
            keys = this.dataStore.getKeysLocally(id, true);
        }
        result.addAll(keys);
    } catch (ForceReattemptException ignore) {
        failures.add(id);
    } catch (PRLocallyDestroyedException ignore) {
        failures.add(id);
    }
    return result;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) HashSet(java.util.HashSet)

Example 3 with PRLocallyDestroyedException

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

the class ColocationHelper method getColocatedRegion.

/**
   * An utility method to retrieve colocated region of a given partitioned region
   *
   * @return colocated PartitionedRegion
   * @throws IllegalStateException for missing colocated region
   * @since GemFire 5.8Beta
   */
public static PartitionedRegion getColocatedRegion(final PartitionedRegion partitionedRegion) {
    // precondition1
    Assert.assertTrue(partitionedRegion != null);
    String colocatedWith = partitionedRegion.getPartitionAttributes().getColocatedWith();
    if (colocatedWith == null) {
        // the region is not colocated with any region
        return null;
    }
    Region prRoot = PartitionedRegionHelper.getPRRoot(partitionedRegion.getCache());
    PartitionRegionConfig prConf = (PartitionRegionConfig) prRoot.get(getRegionIdentifier(colocatedWith));
    if (prConf == null) {
        throw new IllegalStateException(LocalizedStrings.ColocationHelper_REGION_SPECIFIED_IN_COLOCATEDWITH_DOES_NOT_EXIST.toLocalizedString(new Object[] { colocatedWith, partitionedRegion.getFullPath() }));
    }
    int prID = prConf.getPRId();
    PartitionedRegion colocatedPR = null;
    try {
        colocatedPR = PartitionedRegion.getPRFromId(prID);
        if (colocatedPR != null) {
            colocatedPR.waitOnBucketMetadataInitialization();
        } else {
            throw new IllegalStateException(LocalizedStrings.ColocationHelper_REGION_SPECIFIED_IN_COLOCATEDWITH_DOES_NOT_EXIST.toLocalizedString(new Object[] { colocatedWith, partitionedRegion.getFullPath() }));
        }
    } catch (PRLocallyDestroyedException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("PRLocallyDestroyedException : Region with prId={} is locally destroyed on this node", prID, e);
        }
    }
    return colocatedPR;
}
Also used : PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Region(org.apache.geode.cache.Region)

Example 4 with PRLocallyDestroyedException

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

the class PartitionedRegion method _getKeysWithInterest.

/**
   * finds all the keys matching the given interest type and passes them to the given collector
   * 
   * @param allowTombstones whether to return destroyed entries
   */
private void _getKeysWithInterest(int interestType, Object interestArg, boolean allowTombstones, SetCollector collector) throws IOException {
    // this could be parallelized by building up a list of buckets for each
    // vm and sending out the requests for keys in parallel. That might dump
    // more onto this vm in one swoop than it could handle, though, so we're
    // keeping it simple for now
    int totalBuckets = getTotalNumberOfBuckets();
    int retryAttempts = calcRetry();
    for (int bucket = 0; bucket < totalBuckets; bucket++) {
        Set bucketSet = null;
        Integer lbucket = bucket;
        final RetryTimeKeeper retryTime = new RetryTimeKeeper(Integer.MAX_VALUE);
        InternalDistributedMember bucketNode = getOrCreateNodeForBucketRead(lbucket);
        for (int count = 0; count <= retryAttempts; count++) {
            if (logger.isDebugEnabled()) {
                logger.debug("_getKeysWithInterest bucketId={} attempt={}", bucket, (count + 1));
            }
            try {
                if (bucketNode != null) {
                    if (bucketNode.equals(getMyId())) {
                        bucketSet = this.dataStore.handleRemoteGetKeys(lbucket, interestType, interestArg, allowTombstones);
                    } else {
                        FetchKeysResponse r = FetchKeysMessage.sendInterestQuery(bucketNode, this, lbucket, interestType, interestArg, allowTombstones);
                        bucketSet = r.waitForKeys();
                    }
                }
                break;
            } catch (PRLocallyDestroyedException ignore) {
                if (logger.isDebugEnabled()) {
                    logger.debug("_getKeysWithInterest: Encountered PRLocallyDestroyedException");
                }
                checkReadiness();
            } catch (ForceReattemptException prce) {
                // no checkKey possible
                if (logger.isDebugEnabled()) {
                    logger.debug("_getKeysWithInterest: retry attempt: {}", count, prce);
                }
                checkReadiness();
                InternalDistributedMember lastTarget = bucketNode;
                bucketNode = getOrCreateNodeForBucketRead(lbucket);
                if (lastTarget != null && lastTarget.equals(bucketNode)) {
                    if (retryTime.overMaximum()) {
                        break;
                    }
                    retryTime.waitToRetryNode();
                }
            }
        }
        // for(count)
        if (bucketSet != null) {
            collector.receiveSet(bucketSet);
        }
    }
// for(bucket)
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) FetchKeysResponse(org.apache.geode.internal.cache.partitioned.FetchKeysMessage.FetchKeysResponse)

Example 5 with PRLocallyDestroyedException

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

the class PartitionedRegion method validatePRID.

/**
   * Verify that the given prId is correct for the given region name in this vm
   * 
   * @param sender the member requesting validation
   * @param prId the ID being used for the pr by the sender
   * @param regionId the regionIdentifier used for prId by the sender
   */
public static void validatePRID(InternalDistributedMember sender, int prId, String regionId) {
    try {
        PartitionedRegion pr = null;
        synchronized (prIdToPR) {
            // first do a quick probe
            pr = (PartitionedRegion) prIdToPR.getRegion(prId);
        }
        if (pr != null && !pr.isLocallyDestroyed && pr.getRegionIdentifier().equals(regionId)) {
            return;
        }
    } catch (RegionDestroyedException ignore) {
    // ignore and do full pass over prid map
    } catch (PartitionedRegionException ignore) {
    // ditto
    } catch (PRLocallyDestroyedException ignore) {
    // ignore and do full check
    }
    synchronized (prIdToPR) {
        for (Iterator it = prIdToPR.values().iterator(); it.hasNext(); ) {
            Object o = it.next();
            if (o instanceof String) {
                continue;
            }
            PartitionedRegion pr = (PartitionedRegion) o;
            if (pr.getPRId() == prId) {
                if (!pr.getRegionIdentifier().equals(regionId)) {
                    logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_0_IS_USING_PRID_1_FOR_2_BUT_THIS_PROCESS_MAPS_THAT_PRID_TO_3, new Object[] { sender.toString(), prId, pr.getRegionIdentifier() }));
                }
            } else if (pr.getRegionIdentifier().equals(regionId)) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_0_IS_USING_PRID_1_FOR_2_BUT_THIS_PROCESS_IS_USING_PRID_3, new Object[] { sender, prId, pr.getRegionIdentifier(), pr.getPRId() }));
            }
        }
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator)

Aggregations

PRLocallyDestroyedException (org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException)13 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Region (org.apache.geode.cache.Region)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)4 ResultsSet (org.apache.geode.cache.query.internal.ResultsSet)4 Cache (org.apache.geode.cache.Cache)3 PartitionedRegionDistributionException (org.apache.geode.cache.PartitionedRegionDistributionException)3 Entry (org.apache.geode.cache.Region.Entry)3 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)3 FetchKeysResponse (org.apache.geode.internal.cache.partitioned.FetchKeysMessage.FetchKeysResponse)3 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)3 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)3 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)3 Host (org.apache.geode.test.dunit.Host)3 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)3 VM (org.apache.geode.test.dunit.VM)3