GFSH does not support the gfsh> remove --region=/regionName --all operation for partitioned regions.
gfsh>remove --region=/part --all
The following error message is outputted:
gfsh>remove --region=/part --all Result : false Message : Option --all is not supported on partitioned region
gfsh> remove --region=/part --all is not supported for partitioned regions. Furthermore, this operation essentially translates into a region.clear(), which is still not supported for partitioned regions.
There are two workarounds to resolve this issue:
1. Use a client to clear the region:
Region<String, String> region = cache.getRegion("regionName");
Set<String> keySet = region.keySetOnServer();
region.removeAll(keySet);
Where "regionName" is configured as follows in the GemFire client configurations.
<region name="regionName" refid="PROXY" />
2. When the dataset is very large and the client is not able to hold the entire dataset, you can use a function to clear the region. Execute the following function, once registered on the server, to remove data from the partition region:
import org.apache.geode.cache.Declarable;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.RegionFunctionContext;
import org.apache.geode.cache.partition.PartitionRegionHelper;
import java.util.Iterator;
import java.util.Properties;
public class ClearRegionRemoveAllFunction implements Function, Declarable {
public void execute(FunctionContext context) {
System.out.println(Thread.currentThread().getName() + ": Executing " + getId());
RegionFunctionContext rfc = (RegionFunctionContext) context;
Region localRegion = PartitionRegionHelper.getLocalDataForContext(rfc);
int numLocalEntries = localRegion.size();
// Destroy each entry using removeAll
System.out.println(Thread.currentThread().getName() + ": About to clear " + numLocalEntries + " entries");
long start=0, end=0;
start = System.currentTimeMillis();
localRegion.removeAll(localRegion.keySet());
end = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName() + ": Cleared " + numLocalEntries + " entries in " + (end-start) + " ms");
context.getResultSender().lastResult(true);
}
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) {
}
}