use of org.apache.geode.cache.control.RebalanceFactory in project geode by apache.
the class RegionHelper method rebalanceRegion.
public static RebalanceResults rebalanceRegion(Region region) throws CancellationException, InterruptedException {
// FilterByName only looks at name and not full path
String regionName = region.getName();
if (!PartitionRegionHelper.isPartitionedRegion(region)) {
StringBuilder builder = new StringBuilder();
builder.append("Region ").append(regionName).append(" is not partitioned. Instead, it is ").append(region.getAttributes().getDataPolicy()).append(". It can't be rebalanced.");
throw new IllegalArgumentException(builder.toString());
}
// Rebalance the region
ResourceManager resourceManager = region.getCache().getResourceManager();
RebalanceFactory rebalanceFactory = resourceManager.createRebalanceFactory();
Set<String> regionsToRebalance = new HashSet<String>();
regionsToRebalance.add(regionName);
rebalanceFactory.includeRegions(regionsToRebalance);
RebalanceOperation rebalanceOperation = rebalanceFactory.start();
// Return the results
return rebalanceOperation.getResults();
}
use of org.apache.geode.cache.control.RebalanceFactory in project geode by apache.
the class RegionHelper method rebalanceCache.
public static RebalanceResults rebalanceCache(GemFireCache cache) throws CancellationException, InterruptedException {
ResourceManager resourceManager = cache.getResourceManager();
RebalanceFactory rebalanceFactory = resourceManager.createRebalanceFactory();
RebalanceOperation rebalanceOperation = rebalanceFactory.start();
return rebalanceOperation.getResults();
}
use of org.apache.geode.cache.control.RebalanceFactory in project geode by apache.
the class MyGatewayEventSubstitutionFilter method doRebalance.
/**
* Do a rebalance and verify balance was improved. If evictionPercentage > 0 (the default) then we
* have heapLRU and this can cause simulate and rebalance results to differ if eviction kicks in
* between. (See BUG 44899).
*/
public static void doRebalance() {
ResourceManager resMan = cache.getResourceManager();
boolean heapEviction = (resMan.getEvictionHeapPercentage() > 0);
RebalanceFactory factory = resMan.createRebalanceFactory();
try {
RebalanceResults simulateResults = null;
if (!heapEviction) {
LogWriterUtils.getLogWriter().info("Calling rebalance simulate");
RebalanceOperation simulateOp = factory.simulate();
simulateResults = simulateOp.getResults();
}
LogWriterUtils.getLogWriter().info("Starting rebalancing");
RebalanceOperation rebalanceOp = factory.start();
RebalanceResults rebalanceResults = rebalanceOp.getResults();
} catch (InterruptedException e) {
Assert.fail("Interrupted", e);
}
}
use of org.apache.geode.cache.control.RebalanceFactory in project geode by apache.
the class RebalanceFunction method execute.
@Override
public void execute(FunctionContext context) {
RebalanceOperation op = null;
String[] str = new String[0];
Cache cache = CacheFactory.getAnyInstance();
ResourceManager manager = cache.getResourceManager();
Object[] args = (Object[]) context.getArguments();
String simulate = ((String) args[0]);
Set<String> includeRegionNames = (Set<String>) args[1];
Set<String> excludeRegionNames = (Set<String>) args[2];
RebalanceFactory rbFactory = manager.createRebalanceFactory();
rbFactory.excludeRegions(excludeRegionNames);
rbFactory.includeRegions(includeRegionNames);
RebalanceResults results = null;
if (simulate.equals("true")) {
op = rbFactory.simulate();
} else {
op = rbFactory.start();
}
try {
results = op.getResults();
logger.info("Starting RebalanceFunction got results = {}", results);
StringBuilder str1 = new StringBuilder();
str1.append(results.getTotalBucketCreateBytes() + "," + results.getTotalBucketCreateTime() + "," + results.getTotalBucketCreatesCompleted() + "," + results.getTotalBucketTransferBytes() + "," + results.getTotalBucketTransferTime() + "," + results.getTotalBucketTransfersCompleted() + "," + results.getTotalPrimaryTransferTime() + "," + results.getTotalPrimaryTransfersCompleted() + "," + results.getTotalTime() + ",");
Set<PartitionRebalanceInfo> regns1 = results.getPartitionRebalanceDetails();
Iterator it = regns1.iterator();
while (it.hasNext()) {
PartitionRebalanceInfo rgn = (PartitionRebalanceInfo) it.next();
str1.append(rgn.getRegionPath() + ",");
}
logger.info("Starting RebalanceFunction str1={}", str1);
context.getResultSender().lastResult(str1.toString());
} catch (CancellationException e) {
logger.info("Starting RebalanceFunction CancellationException: ", e.getMessage(), e);
context.getResultSender().lastResult("CancellationException1 " + e.getMessage());
} catch (InterruptedException e) {
logger.info("Starting RebalanceFunction InterruptedException: {}", e.getMessage(), e);
context.getResultSender().lastResult("InterruptedException2 " + e.getMessage());
}
}
use of org.apache.geode.cache.control.RebalanceFactory in project geode by apache.
the class TestFunction method executeWithLastResult.
private void executeWithLastResult(FunctionContext context) {
RegionFunctionContext rfContext = (RegionFunctionContext) context;
final PartitionedRegion pr = (PartitionedRegion) rfContext.getDataSet();
ResourceManager resMan = pr.getCache().getResourceManager();
RebalanceFactory factory = resMan.createRebalanceFactory();
RebalanceOperation rebalanceOp = factory.start();
try {
RebalanceResults rebalanceResults = rebalanceOp.getResults();
} catch (CancellationException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
context.getResultSender().lastResult((Serializable) context.getArguments());
}
Aggregations