This function is called by the replica application to request a connection to the master.
MCO_RET mco_HA_attach_master(mco_db_h* db,
const char* connection_string,
const mco_HA_replica_params_t* params,
MCO_E_HA_REPLICA_STOP_REASON* reason,
timer_unit timeout);
db
*db is NULL, mco_HA_attach_master() creates a new database using parameters from db_params. If *db is a valid connection to an existing database, the database switches to replica mode and is synchronized with the master database.connection_string
masterhost is the hostname or IP address of the master node and <port> is the number of the listening port (defined on the master side by the masterport parameter of mco_nw_attach_replica()). For example, “192.168.0.1:10000”. For PIPES transport, it should be a pipe name (for example, “/tmp/test00”).params
reason
mco_HA_attach_master() is interrupted, as defined below.timeout
MCO_E_NW_TIMEOUT.This function is called by a replica application after calling the
mco_db_open_dev() or
mco_db_load() to open a database. Note that
mco_HA_attach_master() is a blocking call that internally performs handshaking with the master, loads the
master’s current database state, and waits to accept transactions from the master. It exits when one of the following occurs:
mco_HA_replica_stop().mco_HA_cancel().MCO_HAMODE_FORCE_MASTER. This causes the attaching process (a replica at this moment) to synchronize the database with the current master, then send a KILL_MASTER message to the current master, detach itself from the master, and become the new master. This flag is normally associated with Binary Schema Evolution.When the function returns, the application may elect to destroy the database, to start using it as a master database, or to start using it as a standby database again.
MCO_S_OK
MCO_E_HA_PROTOCOLERR
MCO_E_HA_IOERROR
MCO_E_NW_TIMEOUT
other MCO_E_NW_* codes