 Apache Geode
  
    CHANGELOG
  Apache Geode
  
    CHANGELOG
  
        
  Standard Custom Partitioning
By default, Geode partitions each data entry into a bucket using a hashing policy on the key. Additionally, the physical location of the key-value pair is abstracted away from the application. You can change these policies for a partitioned region by providing a standard custom partition resolver that maps entries in a custom manner.
Note: If you are both colocating region data and custom partitioning, all colocated regions must use the same custom partitioning mechanism. See Colocate Data from Different Partitioned Regions.
To custom-partition your region data, follow two steps:
- implement the interface
- configure the regions
Implementing Standard Custom Partitioning
- Implement the - org.apache.geode.cache.PartitionResolverinterface in one of the following ways, listed here in the search order used by Geode:-   Using a custom class. Implement the PartitionResolverwithin your class, and then specify your class as the partition resolver during region creation.
-   Using the key’s class. Have the entry key’s class implement the PartitionResolverinterface.
-   Using the callback argument’s class. Have the class that
implements your callback argument implement the PartitionResolverinterface. When using this implementation, any and allRegionoperations must be those that specify the callback argument.
 
-   Using a custom class. Implement the 
- Implement the resolver’s - getName,- init, and- closemethods.- A simple implementation of - getNameis- return getClass().getName();- The - initmethod does any initialization steps upon cache start that relate to the partition resolver’s task. This method is only invoked when using a custom class that is configured by- gfshor by XML (in a- cache.xmlfile).- The - closemethod accomplishes any clean up that must be accomplished before a cache close completes. For example,- closemight close files or connections that the partition resolver opened.
- Implement the resolver’s - getRoutingObjectmethod to return the routing object for each entry. A hash of that returned routing object determines the bucket. Therefore,- getRoutingObjectshould return an object that, when run through its- hashCode, directs grouped objects to the desired bucket.- Note: Only the key, as returned by - getKey, should be used by- getRoutingObject. Do not use the value associated with the key or any additional metadata in the implementation of- getRoutingObject. Do not use- getOperationor- getValue.
Implementing the String Prefix Partition Resolver
Geode provides an implementation of a
string-based partition resolver in
org.apache.geode.cache.util.StringPrefixPartitionResolver.
This resolver does not require any further implementation.
It groups entries into buckets based on a portion of the key.
All keys must be strings, and each key must include
a ’|’ character, which delimits the string.
The substring that precedes the ’|’ delimiter within the key
will be returned by getRoutingObject.
Configuring the Partition Resolver Region Attribute
Configure the region so Geode finds your resolver for all region operations.
- Custom class. Use one of these methods to specify the partition resolver region attribute: - gfsh: - Add the option - --partition-resolverto the- gfsh create regioncommand, specifying the package and class name of the standard custom partition resolver.- gfsh for the String Prefix Partition Resolver: - Add the option - --partition-resolver=org.apache.geode.cache.util.StringPrefixPartitionResolverto the- gfsh create regioncommand.- Java API: - PartitionResolver resolver = new TradesPartitionResolver(); PartitionAttributes attrs = new PartitionAttributesFactory() .setPartitionResolver(resolver).create(); Cache c = new CacheFactory().create(); Region r = c.createRegionFactory() .setPartitionAttributes(attrs) .create("trades");- Java API for the String Prefix Partition Resolver: - PartitionAttributes attrs = new PartitionAttributesFactory() .setPartitionResolver(new StringPrefixPartitionResolver()).create(); Cache c = new CacheFactory().create(); Region r = c.createRegionFactory() .setPartitionAttributes(attrs) .create("customers");- XML: - <region name="trades"> <region-attributes> <partition-attributes> <partition-resolver> <class-name>myPackage.TradesPartitionResolver </class-name> </partition-resolver> <partition-attributes> </region-attributes> </region>- XML for the String Prefix Partition Resolver: - <region name="customers"> <region-attributes> <partition-attributes> <partition-resolver> <class-name>org.apache.geode.cache.util.StringPrefixPartitionResolver </class-name> </partition-resolver> <partition-attributes> </region-attributes> </region>
- If your colocated data is in a server system, add the - PartitionResolverimplementation class to the- CLASSPATHof your Java clients. For Java single-hop access to work, the resolver class needs to have a zero-argument constructor, and the resolver class must not have any state; the- initmethod is included in this restriction.