Search code examples
pivotgemfiregeode

how to configure gemfire in a HA mode


how to configure gemfire in a ha mode in cache.xml

<?xml version="1.0" encoding="UTF-8"?><cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://geode.apache.org/schema/cache" xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" version="1.0" lock-lease="120" lock-timeout="60" search-timeout="300" is-server="false" copy-on-read="false"/>
<!-- Run one secondary server -->
<cache>
   <pool name="red1" subscription-enabled="true" subscription-redundancy="1">
   <locator host="node5" port="41111"/>
   <locator host="node6" port="41111"/>
   </pool>
</cache>


Solution

  • To get HA, you need to have multiple GemFire/Geode locators and servers running.

    gfsh>start locator --name=loc1 --port=10334
    gfsh>start locator --name=loc2 --port=10335
    gfsh>start server --name=serv1 --server-port=40404
    gfsh>start server --name=serv2 --server-port=40405
    gfsh>start server --name=serv3 --server-port=40406
    

    You then need to make sure that your region has redundant copies. For a Partition Region this can be defined as follows:

    gfsh>create region --name=myPR --type=PARTITION_REDUNDANT
    

    This will gurantee that you will be able to tolerate loss of one Geode Server. You can configure upto 3 redundant copies for a Partition Region, make sure that these redundant copies are on different racks etc. please see docs for how to accomplish this. A Replicated region has same data on all servers, so it is always highly available.

    Once, you have the server side configured, you need to point your client connection pool to the locator. The client pool will establish connection to available servers, in case of server failures, the pool will automatically try to re-execute the operation on another server. To configure a pool, simply point to the locators, and then use the pool in region definition.

    <client-cache>
      <pool name="publisher" subscription-enabled="true">
        <locator host="lucy" port="41111"/> 
        <locator host="lucy" port="41111"/> 
      </pool>
    ...
    <region name="clientRegion" ...
      <region-attributes pool-name="publisher" ...
    

    Please refer to the docs for more details.