Search in sources :

Example 6 with PartitionedRegion

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

the class PartitionRegionHelper method getPartitionRegionInfo.

/**
   * Gathers details about the specified partitioned region. Returns null if the partitioned region
   * is not locally defined.
   * 
   * @param region the region to get info about
   * @return details about the specified partitioned region
   * @since GemFire 6.0
   */
public static PartitionRegionInfo getPartitionRegionInfo(final Region<?, ?> region) {
    try {
        PartitionedRegion partitionedRegion = isPartitionedCheck(region);
        InternalCache cache = (InternalCache) region.getCache();
        return partitionedRegion.getRedundancyProvider().buildPartitionedRegionInfo(false, cache.getInternalResourceManager().getLoadProbe());
    } catch (ClassCastException ignore) {
    // not a PR so return null
    }
    return null;
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 7 with PartitionedRegion

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

the class PartitionRegionHelper method moveBucketByKey.

/**
   * Moves the bucket which contains the given key from the source member to the destination member.
   * The bucket will be fully transferred once this method is complete, if the method does not throw
   * an exception.
   * <p>
   * All keys which exist in the same bucket will also be moved to the new node.
   * <p>
   * Any data in colocated regions that are colocated with this key will also be moved.
   * <p>
   * This method allows direct control of what data to move. To automatically balance buckets, see
   * {@link ResourceManager#createRebalanceFactory()}
   * 
   * @param region The region in which to move the bucket. Data in regions colocated with this
   *        region will also be moved.
   * @param source A member that is currently hosting this bucket. The bucket is moved off of this
   *        member.
   * @param destination A member that is not currently hosting this bucket, but has the partitioned
   *        region defined. The bucket is moved to this member.
   * @param key A key which maps to the bucket to move. This key does not actually need to exist in
   *        the region, but if using a {@link PartitionResolver} the resolver should be able to get
   *        the routing object from this key to determine the bucket to move.
   * 
   * @throws IllegalStateException if the bucket is not present on the source, if the source or
   *         destination are not valid members of the system, if the destination already hosts a
   *         copy of the bucket, or if the bucket does not exist.
   * 
   * @since GemFire 7.1
   */
public static <K> void moveBucketByKey(Region<K, ?> region, DistributedMember source, DistributedMember destination, K key) {
    PartitionedRegion pr = isPartitionedCheck(region);
    if (pr.isFixedPartitionedRegion()) {
        throw new IllegalStateException("Cannot move data in a fixed partitioned region");
    }
    int bucketId = pr.getKeyInfo(key).getBucketId();
    ExplicitMoveDirector director = new ExplicitMoveDirector(key, bucketId, source, destination, region.getCache().getDistributedSystem());
    PartitionedRegionRebalanceOp rebalance = new PartitionedRegionRebalanceOp(pr, false, director, true, true);
    rebalance.execute();
}
Also used : ExplicitMoveDirector(org.apache.geode.internal.cache.partitioned.rebalance.ExplicitMoveDirector) PartitionedRegionRebalanceOp(org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 8 with PartitionedRegion

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

the class PartitionRegionHelper method getPrimaryMemberForKey.

/**
   * Get the current primary owner for a key. Upon return there is no guarantee that primary owner
   * remains the primary owner, or that the member is still alive.
   * <p>
   * This method is not a substitute for {@link Region#containsKey(Object)}.
   * </p>
   * 
   * @param r a PartitionedRegion
   * @param key the key to evaluate
   * @throws IllegalStateException if the provided region is something other than a
   *         {@linkplain DataPolicy#PARTITION partitioned Region}
   * @return the primary member for the key, possibly null if a primary is not yet determined
   * @since GemFire 6.0
   */
public static <K, V> DistributedMember getPrimaryMemberForKey(final Region<K, V> r, final K key) {
    PartitionedRegion pr = isPartitionedCheck(r);
    int bucketId = PartitionedRegionHelper.getHashKey(pr, null, key, null, null);
    return pr.getBucketPrimary(bucketId);
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 9 with PartitionedRegion

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

the class PartitionRegionHelper method moveData.

/**
   * Moves data from the source member to the destination member, up to the given percentage of data
   * (measured in bytes). The data will be fully transferred once this method is complete, if the
   * method does not throw an exception. The percentage is a percentage of the amount of data in
   * bytes on the source member for this region.
   * <p>
   * 
   * If this region has colocated regions, the colocated data will also be moved. The total amount
   * of data in all colocated regions will be taken into consideration when determining what
   * percentage of data will be moved.
   * <p>
   * It may not be possible to move data to the destination member, if the destination member has no
   * available space, no bucket smaller than the given percentage exists, or if moving data would
   * violate redundancy constraints. If data cannot be moved, this method will return a
   * RebalanceResult object with 0 total bucket transfers.
   * <p>
   * This method allows direct control of what data to move. To automatically balance buckets, see
   * {@link ResourceManager#createRebalanceFactory()}
   * 
   * @param region The region in which to move data. Data in regions colocated with this region will
   *        also be moved.
   * @param source A member that is currently hosting data. The bucket is moved off of this member.
   * @param destination A member that that has the partitioned region defined. Data is moved to this
   *        member.
   * @param percentage the maximum amount of data to move, as a percentage from 0 to 100.
   * 
   * @throws IllegalStateException if the source or destination are not valid members of the system.
   * @throws IllegalArgumentException if the percentage is not between 0 to 100.
   * 
   * @return A RebalanceResult object that contains information about what what data was actually
   *         moved.
   * 
   * @since GemFire 7.1
   */
public static RebalanceResults moveData(Region<?, ?> region, DistributedMember source, DistributedMember destination, float percentage) {
    PartitionedRegion pr = isPartitionedCheck(region);
    if (pr.isFixedPartitionedRegion()) {
        throw new IllegalStateException("Cannot move data in a fixed partitioned region");
    }
    if (percentage <= 0 || percentage > 100.0) {
        throw new IllegalArgumentException("Percentage must be between 0 and 100");
    }
    PercentageMoveDirector director = new PercentageMoveDirector(source, destination, percentage);
    PartitionedRegionRebalanceOp rebalance = new PartitionedRegionRebalanceOp(pr, false, director, true, true);
    Set<PartitionRebalanceInfo> results = rebalance.execute();
    RebalanceResultsImpl rebalanceResults = new RebalanceResultsImpl();
    for (PartitionRebalanceInfo details : results) {
        rebalanceResults.addDetails(details);
    }
    return rebalanceResults;
}
Also used : RebalanceResultsImpl(org.apache.geode.internal.cache.control.RebalanceResultsImpl) PercentageMoveDirector(org.apache.geode.internal.cache.partitioned.rebalance.PercentageMoveDirector) PartitionedRegionRebalanceOp(org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 10 with PartitionedRegion

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

the class RestAPIOnRegionFunctionExecutionDUnitTest method populatePRRegion.

private void populatePRRegion() {
    PartitionedRegion pr = (PartitionedRegion) CacheFactory.getAnyInstance().getRegion(PR_REGION_NAME);
    DistributedSystem.setThreadsSocketPolicy(false);
    for (int i = (pr.getTotalNumberOfBuckets() * 3); i > 0; i--) {
        pr.put("execKey-" + i, i + 1);
    }
    // Assert there is data in each bucket
    for (int bid = 0; bid < pr.getTotalNumberOfBuckets(); bid++) {
        assertTrue(pr.getBucketKeys(bid).size() > 0);
    }
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Aggregations

PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)367 Test (org.junit.Test)135 Region (org.apache.geode.cache.Region)115 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)112 HashSet (java.util.HashSet)105 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)104 AttributesFactory (org.apache.geode.cache.AttributesFactory)86 VM (org.apache.geode.test.dunit.VM)86 Host (org.apache.geode.test.dunit.Host)85 ArrayList (java.util.ArrayList)77 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)75 Set (java.util.Set)69 IOException (java.io.IOException)66 Function (org.apache.geode.cache.execute.Function)66 FunctionException (org.apache.geode.cache.execute.FunctionException)63 List (java.util.List)62 RegionAttributes (org.apache.geode.cache.RegionAttributes)61 Iterator (java.util.Iterator)60 IgnoredException (org.apache.geode.test.dunit.IgnoredException)59 Cache (org.apache.geode.cache.Cache)56