Search in sources :

Example 1 with PartitionedRegionRebalanceOp

use of org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp 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 2 with PartitionedRegionRebalanceOp

use of org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp 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 3 with PartitionedRegionRebalanceOp

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

the class RebalanceOperationImpl method scheduleRebalance.

private void scheduleRebalance() {
    ResourceManagerStats stats = cache.getInternalResourceManager().getStats();
    long start = stats.startRebalance();
    try {
        for (PartitionedRegion region : cache.getPartitionedRegions()) {
            if (cancelled.get()) {
                break;
            }
            try {
                // Colocated regions will be rebalanced as part of rebalancing their leader
                if (region.getColocatedWith() == null && filter.include(region)) {
                    if (region.isFixedPartitionedRegion()) {
                        if (Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_MOVE_PRIMARIES_ON_STARTUP")) {
                            PartitionedRegionRebalanceOp prOp = new PartitionedRegionRebalanceOp(region, simulation, new CompositeDirector(false, false, false, true), true, true, cancelled, stats);
                            this.futureList.add(submitRebalanceTask(prOp, start));
                        } else {
                            continue;
                        }
                    } else {
                        PartitionedRegionRebalanceOp prOp = new PartitionedRegionRebalanceOp(region, simulation, new CompositeDirector(true, true, true, true), true, true, cancelled, stats);
                        this.futureList.add(submitRebalanceTask(prOp, start));
                    }
                }
            } catch (RegionDestroyedException ignore) {
            // ignore, go on to the next region
            }
        }
    } finally {
        if (pendingTasks == 0) {
            // if we didn't submit any tasks, end the rebalance now.
            stats.endRebalance(start);
        }
    }
}
Also used : PartitionedRegionRebalanceOp(org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)

Aggregations

PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 PartitionedRegionRebalanceOp (org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 RebalanceResultsImpl (org.apache.geode.internal.cache.control.RebalanceResultsImpl)1 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)1 ExplicitMoveDirector (org.apache.geode.internal.cache.partitioned.rebalance.ExplicitMoveDirector)1 PercentageMoveDirector (org.apache.geode.internal.cache.partitioned.rebalance.PercentageMoveDirector)1