Enabling replication within a grid transaction
You can enable replication within a transaction that is run in the context of the grid.
By default, the results of transactions run in the context
of the grid are not also replicated by Enterprise Replication. In
certain situations you might want to both propagate a transaction
to the servers in the grid and replicate the results of the transaction.
To enable replication within a transaction:
Example
Suppose that a retail chain wants to run a procedure to create a report that populates a summary table of each store's current inventory and then replicates that summary information to a central server. A stored procedure named low_inventory() that creates a low inventory report exists on all the servers in the grid named grid1. The following example creates a new procedure named xqt_low_inventory() that enables replication for the low_inventory() procedure, and then runs the low_inventory() procedure:
EXECUTE PROCEDURE ifx_grid_connect('grid1');
CREATE PROCEDURE xqt_low_inventory()
DEFINE curstate integer;
EXECUTE FUNCTION ifx_get_erstate() INTO curstate;
EXECUTE PROCEDURE ifx_set_erstate(1);
EXECUTE PROCEDURE low_inventory();
EXECUTE PROCEDURE ifx_set_erstate(curstate);
END PROCEDURE;
EXECUTE PROCEDURE ifx_grid_disconnect();
EXECUTE PROCEDURE ifx_grid_procedure('grid1', 'xqt_low_inventory()');
The following events occur in this example:
- The ifx_grid_connect() procedure connects to the grid1 grid so that the xqt_low_inventory() procedure is propagated to all the servers in the grid1 grid.
- The xqt_low_inventory() procedure defines a data variable called curstate to hold the Enterprise Replication state information.
- The ifx_get_erstate() function obtains the Enterprise Replication state and stores it in the curstate variable. The ifx_set_state() procedure enables replication.
- The low_inventory() procedure is run.
- The replication state is reset back to its original value.
- The connection to the grid is closed by the ifx_grid_disconnect() procedure.
- The ifx_grid_procedure() procedure runs the xqt_low_inventory() procedure on all the servers in the grid and the result of the low_inventory() procedure is replicated like any normal updating activity.