Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 2.24 KB

README.md

File metadata and controls

53 lines (35 loc) · 2.24 KB

Geode colocation example

This is a simple example that illustrates how to colocate the data of two regions.

By default, Geode selects the data locations for a partitioned region independent of the data locations for any other partitioned region using a hashing policy on the key. This example shows how to modify this policy in order to store related data from two regions (orderand customer) in the same member.

customer region stores Customer objects using an int as key:

Region<Integer, Customer> customerRegion

order region stores Order object using an OrderKey object as key:

Region<OrderKey, Order> accountRegion

In order to store Order objects in the same member than their related customer info, a custom partition-resolved is needed: OrderPartitionResolved. When this partition resolver receives an OrderKey object, it returns the same key (the customer id) that was used to store the related customer. In this way, Geode applies the hashing policy over the same key for Orderand Customer related objects and as a consequence, they are stored in the same member.

Steps

  1. From the geode-examples/colocation directory, build the example.

     $ ../gradlew build
    
  2. Next start a locator, start two servers, create customer region, and create orderregion colocated with customer region.

     $ ../gradlew start
    
  3. Run the example to put entries into both regions.

     $ ../gradlew run
    
  4. Shut down the system.

     $ ../gradlew stop