Can GemFire cache clients create Regions on servers?

1.2k views Asked by At

I have a client/server topology scenario.

Running a simple cluster of one Locator and two servers locally, different JVM processes, the servers have no Regions created on startup with the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:gfe="http://www.springframework.org/schema/gemfire"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<util:properties id="gemfireProperties">
    <prop key="name">${gemfire.server.name}</prop>
    <prop key="mcast-port">${gemfire.server.mcast-port}</prop>
    <prop key="log-level">${gemfire.server.log-level}</prop>
    <prop key="locators">${gemfire.server.locators}</prop>
</util:properties>

<gfe:cache properties-ref="gemfireProperties" use-cluster-configuration="true"/>

<gfe:cache-server auto-startup="true" bind-address="${gemfire.server.bind-address}"
                  host-name-for-clients="${gemfire.server.hostname-for-clients}"
                  port="${gemfire.server.port}"
                  max-connections="${gemfire.server.max-connections}"/>

Then, I am running a client with the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:gfe="http://www.springframework.org/schema/gemfire"
   xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
                        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<beans>
    <gfe:client-cache id="gemfireClientCache" pool-name="gemfireConnectionPool" ready-for-events="true"/>

    <gfe:pool id="gemfireConnectionPool" subscription-enabled="true">
        <gfe:locator host="localhost" port="10334"/>
    </gfe:pool>

    <gfe:client-region id="MYREGION"
                       shortcut="PROXY"
                       key-constraint="java.lang.String"
                       value-constraint="MYPOJO"
                       cache-ref="gemfireClientCache"
                       pool-name="gemfireConnectionPool"/>

</beans>

The Spring Boot app starts up without any issue, but I find the following log weird:

[info 2017/01/05 20:37:56.103 WET <main> tid=0x1] Running in local mode since mcast-port was 0 and locators was empty.

Although I can see all cluster members in Pulse, the servers don't have "MYREGION" Region. So, I'm wondering, can cache clients actually create Regions on servers or can they only "use" existing Regions?

The Pivotal documentation does have a section for "Dynamically create regions" but I'm not going that way yet because I lose partitioning.

Thanks

2

There are 2 answers

1
John Blum On BEST ANSWER

So, I'm wondering, can cache-clients actually create regions on servers or can they only "use" existing regions?

OOTB, no. Cache clients only use existing Regions, by default.

However, it is possible to use a GemFire Function to dynamically create a Region on one more more GemFire Servers in a GemFire Cluster. This is exactly what Gfsh does.

Still, there are many things to consider...

  1. What "type" of Region should be created (i.e. PARTITION, REPLICATE, etc), which is not easily based on the client Region alone?

  2. What servers in the cluster should actually host the Region?

This can be restricted by which GemFire Pool the client uses to create a corresponding Region on the server(s), which must be done by Function execution from the client as previously mentioned.

If a (particular) GemFire Pool is configured with a specific server "group", then only servers in the cluster in that "group" will be able to create that Region.

  1. Along with the type of data policy the Region should have, there are many other configuration settings and considerations (consistency, eviction/expiration policies, security, Transactional scope, serialization (especially if multiple language clients will be involved... think .NET), etc) that need to be weighed properly before a client can arbitrarily have a server or group of servers create some arbitrary Region.

When you start mixing this with other things like Cluster Config, you can run into problems pretty quickly (e.g. conflicting named Regions).

While this is a useful feature during development and something I have am even considering for the new Annotation-based configuration model in SDG, coupled with the (new) mapping Region annotations that are used by the SD Repository abstraction, specifically on the client with the new @ClientRegion annotation used to annotate application domain objects (entities), this probably not advisable in a production environment.

Hope this helps! John

1
prashanth yet On

EnableClusterConfiguration can do this for u --> check this - https://docs.spring.io/spring-data/gemfire/docs/current/reference/html/#bootstrap-annotation-config

Consider the power expressed in the following configuration:

Spring ClientCache application

@SpringBootApplication
@ClientCacheApplication
@EnableCachingDefinedRegions
@EnableEntityDefinedRegions
@EnableIndexing
@EnableGemfireCaching
@EnableGemfireRepositories
@EnableClusterConfiguration
class ClientApplication { .. }

You instantly get a Spring Boot application with a Pivotal GemFire ClientCache instance, Spring Data Repositories, Spring’s Cache Abstraction with Pivotal GemFire as the caching provider (where Regions and indexes are not only created on the client but pushed to the servers in the cluster).