Post

2 followers Follow
0
Avatar

rebalance on partition regions

hi guys.

Now I'm migrating replicated regions to partition regions.
seems subregion is still not supported by partition regions?

we have a parent replicated region, and all subregions. now I need convert the subregions to partition regions, it's fine with the subregions change,
but when I run rebalance in GFSH, it does nothing.

so the rebalance only happens when all the root regions are partition regions?

thanks in advance

LiangleiPan

Please sign in to leave a comment.

3 comments

0
Avatar

This looks like a bug. The rebalance command in gfsh is only using the name of the region and not its full path. I don't really see a way to attach files to this, so I pasted a function below that you can use to rebalance a cache.

Execute it like:

Execution execution = FunctionService.onServer(this.cache);
ResultCollector collector = execution.execute("RebalanceFunction");
System.out.println(((List) collector.getResult()).get(0));

It prints output like:

Rebalanced cache in 3,608 ms
Created 0 buckets containing 0 bytes in 0 ms
Transferred 114 buckets containing 101,424,120 bytes in 3,423 ms
Transferred 2 primary buckets in 55 ms

Rebalanced region /base/data in 3,605 ms
Created 0 buckets containing 0 bytes in 0 ms
Transferred 114 buckets containing 101,424,120 bytes in 3,423 ms
Transferred 2 primary buckets in 55 ms
Member details before rebalance:
member=192.168.2.5(6511)<v56>:9677, size=102,760,000 bytes, bucketCount=113, primaryCount=57
member=192.168.2.5(6580)<v59>:34190, size=0 bytes, bucketCount=0, primaryCount=0
member=192.168.2.5(6561)<v57>:44644, size=102,760,000 bytes, bucketCount=113, primaryCount=56
member=192.168.2.5(6578)<v58>:53274, size=0 bytes, bucketCount=0, primaryCount=0
Member details after rebalance:
member=192.168.2.5(6511)<v56>:9677, size=52,047,940 bytes, bucketCount=56, primaryCount=28
member=192.168.2.5(6580)<v59>:34190, size=50,712,060 bytes, bucketCount=57, primaryCount=28
member=192.168.2.5(6561)<v57>:44644, size=52,047,940 bytes, bucketCount=56, primaryCount=28
member=192.168.2.5(6578)<v58>:53274, size=50,712,060 bytes, bucketCount=57, primaryCount=29

===

import com.gemstone.gemfire.cache.Declarable;
import com.gemstone.gemfire.cache.CacheFactory;

import com.gemstone.gemfire.cache.control.RebalanceFactory;
import com.gemstone.gemfire.cache.control.RebalanceOperation;
import com.gemstone.gemfire.cache.control.RebalanceResults;
import com.gemstone.gemfire.cache.control.ResourceManager;

import com.gemstone.gemfire.cache.execute.Function;
import com.gemstone.gemfire.cache.execute.FunctionContext;

import com.gemstone.gemfire.cache.partition.PartitionMemberInfo;
import com.gemstone.gemfire.cache.partition.PartitionRebalanceInfo;

import java.text.NumberFormat;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class RebalanceFunction implements Function, Declarable {

private static NumberFormat FORMAT = NumberFormat.getInstance();

public void execute(FunctionContext context) {
System.out.println(Thread.currentThread().getName() + " executing " + getId());
ResourceManager resourceManager = CacheFactory.getAnyInstance().getResourceManager();
RebalanceFactory rebalanceFactory = resourceManager.createRebalanceFactory();
RebalanceOperation rebalanceOperation = rebalanceFactory.start();
RebalanceResults rebalanceResults = null;
try {
rebalanceResults = rebalanceOperation.getResults();
} catch (InterruptedException e) {
System.out.println("Caught the following exception attempting to rebalance: " + e);
}
context.getResultSender().lastResult(getResultString(rebalanceResults));
}

private String getResultString(RebalanceResults rebalanceResults) {
StringBuilder builder = new StringBuilder();
fillInRebalanceTotals(rebalanceResults, builder);
for (PartitionRebalanceInfo info : rebalanceResults.getPartitionRebalanceDetails()) {
// Log the overall results
fillInRebalanceResultsSummary(builder, info);

  // Log the 'Before' results
  fillInRebalanceResultsMemberDetails(builder, info.getPartitionMemberDetailsBefore(), "before");

  // Log the 'After' results
  fillInRebalanceResultsMemberDetails(builder, info.getPartitionMemberDetailsAfter(), "after");
}
return builder.toString();

}

private void fillInRebalanceTotals(RebalanceResults rebalanceResults, StringBuilder builder) {
builder
.append("Rebalanced cache in ")
.append(FORMAT.format(rebalanceResults.getTotalTime()))
.append(" ms")

  .append("\nCreated ")
  .append(rebalanceResults.getTotalBucketCreatesCompleted())
  .append(" buckets containing ")
  .append(FORMAT.format(rebalanceResults.getTotalBucketCreateBytes()))
  .append(" bytes in ")
  .append(FORMAT.format(rebalanceResults.getTotalBucketCreateTime()))
  .append(" ms")

  .append("\nTransferred ")
  .append(rebalanceResults.getTotalBucketTransfersCompleted())
  .append(" buckets containing ")
  .append(FORMAT.format(rebalanceResults.getTotalBucketTransferBytes()))
  .append(" bytes in ")
  .append(FORMAT.format(rebalanceResults.getTotalBucketTransferTime()))
  .append(" ms")

  .append("\nTransferred ")
  .append(rebalanceResults.getTotalPrimaryTransfersCompleted())
  .append(" primary buckets in ")
  .append(FORMAT.format(rebalanceResults.getTotalPrimaryTransferTime()))
  .append(" ms");

}

private void fillInRebalanceResultsSummary(StringBuilder builder, PartitionRebalanceInfo rebalanceInfo) {
builder
.append("\n\nRebalanced region ")
.append(rebalanceInfo.getRegionPath())
.append(" in ")
.append(FORMAT.format(rebalanceInfo.getTime()))
.append(" ms")

  .append("\nCreated ")
  .append(rebalanceInfo.getBucketCreatesCompleted())
  .append(" buckets containing ")
  .append(FORMAT.format(rebalanceInfo.getBucketCreateBytes()))
  .append(" bytes in ")
  .append(FORMAT.format(rebalanceInfo.getBucketCreateTime()))
  .append(" ms")

  .append("\nTransferred ")
  .append(rebalanceInfo.getBucketTransfersCompleted())
  .append(" buckets containing ")
  .append(FORMAT.format(rebalanceInfo.getBucketTransferBytes()))
  .append(" bytes in ")
  .append(FORMAT.format(rebalanceInfo.getBucketTransferTime()))
  .append(" ms")

  .append("\nTransferred ")
  .append(rebalanceInfo.getPrimaryTransfersCompleted())
  .append(" primary buckets in ")
  .append(FORMAT.format(rebalanceInfo.getPrimaryTransferTime()))
  .append(" ms");

}

private void fillInRebalanceResultsMemberDetails(StringBuilder builder, Set<PartitionMemberInfo> memberInfoSet, String when) {
builder
.append("\nMember details ")
.append(when)
.append(" rebalance:");
for (PartitionMemberInfo memberInfo : memberInfoSet) {
builder
.append("\n\tmember=")
.append(memberInfo.getDistributedMember())
.append(", size=")
.append(FORMAT.format(memberInfo.getSize()))
.append(" bytes, bucketCount=")
.append(memberInfo.getBucketCount())
.append(", primaryCount=")
.append(memberInfo.getPrimaryCount());
}
}

public String getId() {
return getClass().getSimpleName();
}

public boolean optimizeForWrite() {
return true;
}

public boolean hasResult() {
return true;
}

public boolean isHA() {
return true;
}

public void init(Properties properties) {
}
}

Barry Oglesby 0 votes
0
Avatar

Hi

Just verify the code you supplied. it works fine.
but give some false information of the primary count after rebalance.

I have 4 partitions, and split to 2 redundacy zone, and have the redundancy copy as 1.
seems it actually rebalance the regions amond the members of same group, but it shows rebalance among all the members.

any idea to print the correct information?

thanks

LiangleiPan 0 votes