How Functions Execute
This section 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.
- The calling client application runs the
executemethod on the
Executionobject. The object must already be registered on the servers.
- The function is invoked on all servers where it needs to run. The locations are determined by the
FunctionService on*method calls, region configuration, and any filters.
- If the function has results, the result is returned to the
AddResultmethod call in a
- The client collects results using the result collector
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. 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:
- Waits for all calls to return.
- Sets a boolean indicating a reexecution is being done.
- Calls the result collector’s
- 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
The figure shows the sequence of events for a data-independent function executed against all available servers.
Figure: Data-Independent Function Invoked from a Client
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: 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: 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: Highly Available Data-Dependent Function with Failure on First Executions