Assigning buckets in run-time using a function
search cancel

Assigning buckets in run-time using a function

book

Article ID: 293969

calendar_today

Updated On:

Products

VMware Tanzu Gemfire

Issue/Introduction

This article describes how buckets can be assigned in run-time after servers are started up.


Resolution

There is no gfsh command to assign buckets. The "start server" command has the option --assign-bucket at start time but that doesn't help if you want to assign buckets after start-up.

A solution is to use a function and run that on the server or servers where buckets should be assigned.

The following function takes a list of region names to assign buckets to. Use the Execution methods to choose where to run:

public class AssignBucketsFunction implements Function, Declarable {
public void execute(FunctionContext context) {
 Set<String> regionNames = (Set<String>) context.getArguments();
 System.out.println(Thread.currentThread().getName() + ": Function " + getId() + ": Assigning buckets for " + regionNames);
 Cache cache = CacheFactory.getAnyInstance();
 for (String regionName : regionNames) {
 Region region = cache.getRegion(regionName);
 PartitionRegionHelper.assignBucketsToPartitions(region);
 }
 context.getResultSender().lastResult(regionNames);
 }
 
 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) {
 }
}

Additional Information

Applies To

GemFire