Function execution service like FunctionService.onServers() gets executed twice on a Gemfire cluster with a gateway receiver if server groups are configured.
An example of Server_Cache.xml with gateway receiver:
<cache> <gateway-receiver start-port="1530" end-port="1551" > </gateway-receiver> <cache-server port="40404"/> <region name="exampleRegion"> <region-attributes refid="REPLICATE"> </region-attributes> </region> <function-service> <function> <class-name>test.TestFunction</class-name> </function> </function-service> </cache> An example of gfsh start server script with group configuration: gfsh start server --name=server1 --locators=localhost[40100] --server-port=40404 --cache-xml-file=Server_Cache.xml--group=test1,test2 An example of client code calling function execution service: public class TestClient { public static void main(String[] args) throws Exception{ TestClient testClient=new TestClient(); ClientCache cache = new ClientCacheFactory() .set("name", "TestClient") .set("cache-xml-file", "xml/Client.xml") .set("log-file", "xml/Client.log") .set("log-level", "fine") .create(); Pool pool = PoolManager.find("client"); testClient.executeFunction(pool); try{ Thread.sleep(10000); }catch(InterruptedException e){} cache.close(); } void executeFunction(Pool pool){ TestFunction function =new TestFunction(); Execution execution =FunctionService.onServers(pool); ResultCollector collector=execution.execute("TestFunction"); List result=(List)collector.getResult(); System.out.println("******start getting result********"); for(String str : result){ System.out.println(str); } System.out.println("******end getting result********"); } } With the above setting and code, you can see below, the log when calling the client code: function is initialized ******start getting result******** Function run onserver1 Function run onserver1 ******end getting result********
This is a known bug in GatewayReceiverImpls which registers themselves with the locator in both the receiver group and any configured groups defined by the groups property.
GEM-961: Function no longer gets executed twice on gateway receivers with groups
This issue is fixed in Gemfire8.2.1.2 and later versions.
One quick workaround is to define the group in the cache.xml in cache-server section, instead of defining the group in the gemfire.properties or using the GFSH start server command:
Example:
<cache-server port="40404"> <group>test1</group> <group>test2</group> </cache-server>
Please note that using the group definition in the cache.xml is deprecated in Gemfire7.0 and later. A side effect of this workaround is that GFSH command with the --group parameter may not work.