Pivotal GemFire® v8.1

How Functions Execute

How Functions Execute

This chapter discusses the basic function execution process, how highly available functions execute after a failure, and the execution scenarios for data-dependent and data-independent functions.

How Functions Execute

  1. The calling client application runs the execute method on the Function Execution object. The object must be already registered on the servers.
  2. The execution is sent to all servers where it needs to run. The locations are determined by the FunctionService on* method calls, region configuration, and any filters.
  3. If the function has results, the result is returned to the execute method call in a ResultCollector object.
  4. The client collects results using the result collector getResult.

How Highly Available Functions Execute after a Failure

If a failure occurs in function execution, the error is returned to the calling application. You can code for high availability for onRegion functions that return a result, so the function is automatically retried. For information on setting this up on the server side, see Executing a Function in Pivotal GemFire in the GemFire User’s Guide. To use a highly available function, the client must call the results collector getResult method. When an execution error occurs or a member crashes while executing, the system does the following:

  1. Waits for all calls to return.
  2. Sets a boolean indicating a reexecution is being done.
  3. Calls the result collector’s clearResults method.
  4. Executes the function.

The system retries the execution up to the number specified in the server pool’s retryAttempts setting. If the function continues to fail, the final exception is returned to the getResult method.

Data-Independent Function Execution

The figure shows the sequence of events for a data-independent function executed against all available servers.

Figure 1. Data-Independent Function Invoked from a Client
Data-Independent Function Invoked on All Servers

Data-Dependent Function Execution

The figure shows a data-dependent function run by a client. The specified region is connected to the server system, so the function automatically goes there to run against all servers holding data for the region.

Figure 2. Data-Dependent Function Invoked From a Client
Data-Dependent Function Invoked from a Client

This shows the same data-dependent function with the added specification of a set of keys on which to run. Servers that don't hold any of the keys are left out of the function execution.

Figure 3. Data-Dependent Function with Filter Invoked from a Client
Data-Dependent Function with Filter Invoked From a Client

This scenario demonstrates the steps in a call to a highly available function. The call fails the first time on one of the participating servers and is successfully run a second time on all servers.

Figure 4. Highly Available Data-Dependent Function with Failure on First Executions
Highly Available Data Dependent Function with Failure on First Execution