Description
It should be possible via the o.s.data.gemfire.PartitionedRegionFactoryBean
API to directly configure or customize PARTITION
Region attributes, such as, but not limited to:
- Collocation
- Fixed Partitioning
- Local & Total Max Memory
PartitionResolvers
- Redundant Copies
- Etc
Essentially, any property or attribute exposed in the org.apache.geode.cache.PartitionAttributes
API (Javadoc), or rather the org.apache.geode.cache.PartitionAttributesFactory
API (Javadoc), should be configurable via the SDG PartitionedRegionFactoryBean
API (Javadoc).
The Apache Geode API is a bit confusing in that the attributes specific to PARTITION
Regions are still configured with generic Region attributes (i.e. RegionAttributes
) set on the RegionFactory
used when creating a Region, regardless if it is a PARTITION
Region or otherwise.
For example, a developer using the Apache Geode API would need to use the peer Cache
instance to create a RegionFactory
and then set the appropriate attributes when creating a Region of the desired type (e.g. PARTITION
).
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
regionFactory.setPartitionAttributes(new PartitionAttributesFactory().setColocatedWith("/B"));
Region A = regionFactory.create("A");
While the SDG XML namespace is quite convenient when configuring a PARTITION
Region, using JavaConfig is less apparent in its approach given the SDG Java API (Javadoc) more closely aligns with the Apache Geode API (Javadoc).
For example, in the SDG XML namespace, it is quite easy to collocate a PARTITION
Region (B) with another PARTITION
Region (A) by doing the following:
<beans>
<gfe:partitioned-region id="A"/>
<gfe:patitioned-region id="B" colocated-with="A"/>
</beans>
However, it is less apparent, perhaps, when using Spring JavaConfig and API (and specifically, the SDG PartitionedRegionFactoryBean
class in JavaConfig), and especially SDG Annotations, such as @EnableEntityDefinedRegions
to say, collocate 2 PARTITION
Regions, or even configure other PARTITION
Region attributes (e.g. PartitionResolvers
).
By way of example, using SDG Annotation a user would do the following in his/her Spring Boot, Spring Data Geode application:
@SpringBootApplication
@PeerCacheApplication
@EnableEntityDefinedRegions(basePackageClasses = NonEntityType.class)
public class SpringBootSpringDataGeodeApplication {
...
}
NOTE: Alternatively, the
@PeerCacheApplication
annotation can be replaced with the@CacheServerApplication
annotation if the application needs to serve cache clients as well. A@CacheServerApplication
creates a peerCache
in addition to aCacheServer
to serve cache clients (ClientCache
instances, most likely running in a separate JVM process, particularly when using the client/server topology).
Then, a package of [persistent] entities used by the application could be defined as:
package example.app.model;
import ...;
@PartitionRegion(name = "A")
class AEntity { }
package example.app.model;
import ...;
@PartitionRegion(name = "B", collocatedWith = "A");
class BEntity { }
package example.app.model;
interface NonEntityType { }