[Help][Terracotta OS]How Ehcache Client connect to passive/mirror Server on Active Server Failure

53 views
Skip to first unread message

Danish Gondal

unread,
Nov 17, 2020, 1:54:39 PM11/17/20
to terracotta-oss
I am new with terracotta open source with ehcache 3.8 .So need some clarity  
Specifying only the active server url in client level code 
How the following client will connect to passive/mirror server when erver active server goes down??

Any change is required in the client code where i am specifying the url ????
or how it will connect to passive/mirror ??


Command to shut down the active server if I want to check make sure passive /mirror got active and start communicate with it  ???? 

Waiting for kind reply 


starting only one server 
F:\torracottaserver\server\bin start-tc-server.bat -f ..\conf\tc-config.xml -n clustered
 

Client Code :
  StatisticsService statisticsService = new DefaultStatisticsService();
    URI uriClusteredOne = create("terracotta://192.168.0.119:9410/clustered");
    try (CacheManager cacheManager = newCacheManagerBuilder()
            .with(cluster(uriClusteredOne).autoCreate().defaultServerResource("default-resource"))
            .withCache("basicCache",
                    newCacheConfigurationBuilder(Long.class, String.class,
                            heap(100).offheap(1, MB).with(clusteredDedicated(5, MB))))
            .using(statisticsService).build(true)) {
      Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

      //LOGGER.info("Putting to cache");
      basicCache.put((long) 1, "Ehsan Gondal");
      //System.out.println("cache retrival"+ basicCache.get(1L));

      //LOGGER.info("Closing cache manager");
    }



Terracotta Server Config file :


<?xml version="1.0" encoding="UTF-8"?>
  <!--
    This is the default Terracotta server configuration file for the Ehcache kit.

    It defines a single offheap resource of 512MB to be used for caching data.

    It also defines a single server, but you can add another one to benefit from high availability.
  -->

  <plugins>
    <config>
      <ohr:offheap-resources>
        <ohr:resource name="default-resource" unit="MB">512</ohr:resource>
      </ohr:offheap-resources>
    </config>
  </plugins>

  <servers>
    <server host="localhost" name="clustered">
      <!--
        Indicates the location for logs files - %H will resolve to user home directory.
        Note that relative path will be resolved from the location of this configuration file.
       -->
      <logs>%H/terracotta1-logs</logs>

      <!--
        This port is used by clients to communicate to the server.
        Its value is actually the default one and is thus omitted.
      -->
      <tsa-port>9410</tsa-port>

      <!--
        This port is used for server to server communication.
        Its value is actually the default one and is thus omitted.
      -->
      <tsa-group-port>9430</tsa-group-port>
    </server>
<server host="localhost" name="clustered2">
      <!--
        Indicates the location for logs files - %H will resolve to user home directory.
        Note that relative path will be resolved from the location of this configuration file.
       -->
      <logs>%H/terracotta2-logs</logs>

      <!--
        This port is used by clients to communicate to the server.
        Its value is actually the default one and is thus omitted.
      -->
      <tsa-port>9410</tsa-port>

      <!--
        This port is used for server to server communication.
        Its value is actually the default one and is thus omitted.
      -->
      <tsa-group-port>9430</tsa-group-port>
    </server>

    <!--
      Below a sample server definition that will give HA to the cluster if run on a different host.

      Servers know how to communicate between each others because each version of the config file on each host
      will list all servers in it.
    -->
    <!--<server host="otherhost" name="other-server">-->
      <!--<logs>logs</logs>-->
      <!--<tsa-port>9410</tsa-port>-->
    <!--</server>-->

    <!--
      Indicates how much time a server taking over after a failure in an active will wait
      to allow existing clients to reconnect. The time unit is seconds.
    -->
    <client-reconnect-window>120</client-reconnect-window>
  </servers>
  <failover-priority>
    <availability/>
  </failover-priority>
</tc-config>

Reply all
Reply to author
Forward
0 new messages