1

I have local Region and I want to persist the Region data to disk. How to define it using DataPolicy?

John Blum
  • 7,381
  • 1
  • 20
  • 30
user1628688
  • 85
  • 1
  • 1
  • 4

2 Answers2

0

I'm not exactly sure about what you're asking here, the question is not detailed enough... either way, the DataPolicy enumeration has the PERSISTENT_REPLICATE and PERSISTENT_PARTITION values which you can use when configuring a region to make it persistent.

Hope this helps.

Juan Ramos
  • 1,421
  • 1
  • 8
  • 13
  • Those 2 values are not supported in Local region. I am asking how I configure persistency on Java to Local (embeded) region? – user1628688 Aug 20 '18 at 13:39
0

If your Region is truly "local", in that the data for the Region is only stored local to the GemFire data node (server) or perhaps your application if it is either a client or perhaps a peer member of the cluster (either way), then you can specify the data policy using the correct Region shortcut.

For example, if your application/arrangement is using a ClientCache (i.e. your application is a cache client), then you can still define LOCAL-only, persistent Regions using ClientRegionShortcut.LOCAL_PERSISTENT.

If your application/arrangement is using a peer Cache, (i.e. your application is actually participating as a data node/server, peer member in the cluster), then you can still define LOCAL-only, persistent Regions using RegionShortcut.LOCAL_PERSISTENT.

By way of GemFire API (peer Cache):

Cache peerCache = new CacheFactory(..)
  .set(..)
  .create();

RegionFactory localPersistentServerRegion = 
  peerCache.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT);

By way of GemFire API (ClientCache):

ClientCache clientCache = new ClientCacheFactory(..)
  .set(..)
  .create();

ClientRegionFactory localPersistentClientRegion = 
  clientCache.createClientRegionFactory(ClientRegionShortcut.LOCAL_PERSISTENT);

By using SDG XML (peer Cache):

<gfe:local-region id="ExampleLocalPersistentServerRegion" persistent="true"/>

By using SDG XML (ClientCache):

<gfe:client-region id="ExampleLocalPersistentClientRegion" 
  shortcut="LOCAL_PERSISTENT"/>

By using SDG JavaConfig (peer Cache):

@Configuration
@PeerCacheApplication
class GemFireConfiguration {

  @Bean
  LocalRegionFactoryBean exampleLocalPersistentServerRegion(
      GemFireCache peerCache) {

    LocalRegionFactoryBean exampleRegion = 
      new LocalRegionFactoryBean();

    exampleRegion.setCache(peerCache);
    exampleRegion.setClose(false);
    exampleRegion.setPersistent(true);

    return exampleRegion;
}

By using SDG JavaConfig (ClientCache):

@Configuration
@ClientCacheApplication
class GemFireConfiguration {

  @Bean
  ClientRegionFactoryBean exampleLocalPersistentClientRegion(
      GemFireCache clientCache) {

    ClientRegionFactoryBean exampleRegion = 
      new ClientRegionFactoryBean();

    exampleRegion.setCache(peerCache);
    exampleRegion.setClose(false);
    exampleRegion.setPersistent(true);

    return exampleRegion;
}

There are also other ways of accomplishing the same using the pure Annotation-based configuration model in SDG, but this should get you going.

Cheers! -John

John Blum
  • 7,381
  • 1
  • 20
  • 30