mco_HA_replica_params_init

This function is called by the replica to initialize the replica HA runtime parameters to default values.

For an overview, see HA Applications.

Prototype

    void mco_HA_replica_params_init(mco_HA_replica_params_t* params)

Arguments

params
HA replica parameters defined in structure mco_HA_replica_params_t.

Description

This function is called by a replica to initialize the replica HA runtime parameters to default values. The parameters are then set according to the application's needs and passed to mco_HA_attach_master().

Return Codes

void
No value is returned.

The mco_HA_replica_params_t structure is defined as follows:

    typedef struct
    {
        uint4 mode_flags;
        timer_unit initial_timeout;
        timer_unit commit_timeout;
        timer_unit wait_data_timeout;
        mco_ha_notifying notifying_callback;
        void* notifying_context;
        uint2 repeat_counter;
        uint2 mcast_port;
        const char *mcast_addr;
        const char* cancelpoint_addr;
    } mco_HA_replica_params_t;
mode_flags
A bit flag having one or more of the values described below.
initial_timeout
The time window during which initial synchronization with the master must complete.
commit_timeout
The time window during which a replica must receive transaction data from the master.
wait_data_timeout
The maximum time between two consecutive transactions. If the transaction rate on the master is low, the master should periodically call mco_HA_keep_alive() to prevent a timeout error.
notifying_callback
A pointer to the user-defined callback function. This can be used to receive notification about the state of the replica. To enable this feature, use the MCO_HAMODE_REPLICA_NOTIFICATION flag.
notifying_context
The pcontext parameter for the user-defined notification callback function (see below).
repeat_counter
The maximum number of attempts to repeat the commit for reliable multicast mode (MCO_HAMODE_MCAST_RELIABLE).
mcast_port
For multicast.
mcast_addr
For multicast.
cancelpoint_addr
A connection string containing the IP address (optionally) and port number for the process that creates the cancel socket, for example, "127.0.0.1:9999" or simply "9999". This is used if the MCO_HAMODE_ALLOW_CANCEL flag is set in flags. If the application does not use mco_HA_create_cancel_socket() and mco_HA_destroy_cancel_socket(), mco_HA_attach_master() implicitly creates the cancel socket before connecting to the master and closes it before exit. In other words, mco_HA_attach_master() "manages" the cancel socket.

The possible values for the mode_flags argument are defined as follows:

MCO_HAMODE_ALLOW_CANCEL
Enables the cancellation feature (see mco_HA_cancel()). The cancellation feature is implemented only for TCP and UDP transports.
MCO_HAMODE_FORCE_MASTER
Causes the replica to synchronize with the master with the intent of becoming the master itself after synchronization is complete.
MCO_HAMODE_REPLICA_NOTIFICATION
Enables replica notifications (see the notifying_callback and notifying_context parameters).
MCO_HAMODE_SEND_RESTLIST
MCO_HAMODE_EXPLICIT_WRITE_ACCESS
Using this flag means that WRITE access to the replica's database will not be restored automatically after returning from the mco_HA_attach_master() API. To enable write operations, the application must explicitly call mco_HA_set_master_params(). xSQL uses this flag to prohibit write/DDL operations in replica switch mode even if the replica is not currently connected to the master. Changing switch mode to master, auto, or standalone (using the xsql_ha_set_switch_mode() UDF) will enable write access to the database.

Notification callback

The notification callback prototype is as follows:

    typedef void(*mco_ha_notifying)
        (uint2 notification_code, uint4 param1, void *param2, void *pcontext);

Arguments param1 and param2 are optional parameters sent to the callback (to indicate error codes, replica channel, etc.). Argument pcontext is a user-defined parameter passed via the notifying_context field, and notification_code can have one of the following values:

MCO_REPL_NOTIFY_CONNECTED
The replica successfully connected to the master.
MCO_REPL_NOTIFY_CONNECT_FAILED
The replica is unable to connect to the master.
MCO_REPL_NOTIFY_DB_EQUAL
The databases on the master and replica sides are equal, so initial synchronization is not needed.
MCO_REPL_NOTIFY_DB_LOAD_BEGIN
The initial synchronization has started.
MCO_REPL_NOTIFY_DB_LOAD_FAILED
An error occurred during the initial synchronization. The param1 argument to the notification callback function contains the MCO_RET code.
MCO_REPL_NOTIFY_DB_LOAD_OK
The initial synchronization completed successfully. The param1 argument to the notification callback function contains the MCO_E_HA_REPLICA_STOP_REASON code.
MCO_REPL_NOTIFY_COMMIT_FAILED
An error occurred during replication (wrong transaction data or a broken connection). The param1 argument to the notification callback function contains the MCO_RET code.
MCO_REPL_NOTIFY_REPLICA_STOPPED
The replica was stopped by the master or a local request.
MCO_REPL_NOTIFY_DB_CREATION_FAILED
"Database creation failed" notification. The param1 argument of the notification callback contains the MCO_RET code.
MCO_REPL_NOTIFY_HOTSYNC
"Hot" synchronization has started.
MCO_REPL_NOTIFY_EOHOTSYNC
"Hot" synchronization has completed successfully.
MCO_REPL_NOTIFY_STATEFUL_SYNC
"Stateful" synchronization has started.
MCO_REPL_NOTIFY_STATEFUL_SYNC_END
"Stateful" synchronization has completed successfully.