0

I am developing a very simple dashboard to clear Gemfire regions for testing purposes. I am mainly doing this to get testers a tool for doing this by themselves.

I would like to dynamically fetch the current available Regions names to clear.

I am searching spring-data-gemfire documentation but I couldn't find a way to get all region names.

The best hint I have so far is <gfe:auto-region-lookup/>, but I guess I would still need to have a cache.xml with all region names and also I am not sure how to dynamically displaying their names and how to remove all data from those regions.

Thanks

Cristiano Fontes
  • 4,920
  • 6
  • 43
  • 76

1 Answers1

1

<gfe:auto-region-lookup> is meant to automatically create beans in the Spring ApplicationContext for all GemFire Regions that have been explicitly created outside the Spring context (i.e. cache.xml or using GemFire's relatively new Cluster-based Configuration Service). However, a developer must use and/or enable those mechanisms to employ the auto-region-lookup functionality.

To get a list of all Region names in the GemFire "cluster", you need something equivalent to Gfsh's 'list region' command, which employs a Function to gather up all the Regions defined in the GemFire (Cache) cluster.

Note that members can define different Regions, i.e. all members participating in the cluster do not necessarily have to define the same Regions. In most cases they do since it is beneficial for replication and HA purposes. Still some members may define local Regions only that member will use.

To go on to clear the Regions from the list, you would again need to employ a GemFire Function to "clear" the other Regions in the cluster that the inquiring, acting member does not currently define.

Of course, this problem is real simple if you only want to clear Regions defined on the member itself...

@Autowired
private Cache gemfireCache;
...

public void clearRegions() {
  for (Region rootRegion : gemfireCache.rootRegions()) {
    for (Region subRegion : rootRegion.subregions(true)) {
      subRegion.clear();
    }
    rootRegion.clear());
  }
}

See rootRegions() and subregions(recursive:boolean) for more details.

Note, GemFire's Cache interface implements the RegionService interface.

Hope this helps.

Cheers!

John Blum
  • 7,381
  • 1
  • 20
  • 30
  • Note that you cannot call `clear()` on PartitionedRegions - you'll get an `UnsupportedOperationException`. For those, the typical approach is to use an onMember function call which iterates through and deletes each entry individually. – Jens D Aug 27 '15 at 16:38
  • That is correct. However, you can call "removeAll()" on a PARTITION Region. That is exactly what the SDG SimpleGemfireRepository impl does (https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java#L264-L266) and specifically (https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java#L249-L251). So, a Function is not strictly required here. – John Blum Sep 03 '15 at 17:43
  • Actually, was just thinking that partitionedRegion.removeAll(partitionRegion.keySet()) is most likely local to the member, in which case, you would need a Function targeting all members hosting that (PARTITION) Region. However, the removeAll(..) with keySet will take care of the "iterating" part for you, ;-) – John Blum Sep 03 '15 at 17:48