📄 mcoha.h
字号:
uint4 mode_flags; uint2 max_number_of_replicas; ///< for master void * async_databuf; ///< user-defined data buffer for asynchronous replication uint4 bufsize; ///< the size of the user-defined data buffer}mco_HA_params_t;/****************************************************************** Commmon HA methods (API)******************************************************************//** HA error codes */#define MCO_E_HA_PROTOCOLERR MCO_E_HA /**< error in protocol */#define MCO_E_HA_TIMEOUT MCO_E_HA+1 /**< timeout */#define MCO_E_HA_IOERROR MCO_E_HA+2 /**< input/output error */#define MCO_E_HA_MAXREPLICAS MCO_E_HA+3 /**< Too many replicas requested *//** fatal HA error codes */#define MCO_E_HA_INVCHANNEL MCO_ERR_HA+0 /**< invalid channel handler specified */#define MCO_E_HA_INVCOMMAND MCO_ERR_HA+1 /**< invalid command in protocol */#define MCO_E_HA_NO_DATA MCO_ERR_HA+2 /**< no data to send */#define MCO_E_HA_NOTREPLICA MCO_ERR_HA+3 /**< this method for master DB only */#define MCO_E_HA_NOWRITETXN MCO_ERR_HA+4 /**< read only txn in replica mode */#define MCO_E_HA_DATACORRUPT MCO_ERR_HA+5 /**< not identical data in replica */MCO_RET mco_HA_set_mode (mco_db_h db, mco_HA_params_t *par);MCO_RET mco_HA_get_sequencer(mco_db_h db, /* OUT */ mco_trans_sequencer_h seq);/****************************************************************** Master DB in HA configuration has the following methods (API)*******************************************************************//** HA error codes */#define MCO_E_HA_MANYREPLICAS MCO_E_HA+20 /**< trying to attach too many replicas*/#define MCO_E_KILLED_BY_REPLICA MCO_E_HA+21 /**< the master connection is killed by replica *//**\fn MCO_RET mco_HA_attach_replica( mco_db_h db, mco_channel_h ch, const mco_connection_param_t * params, const char * application_specific_replica_name, mco_HA_ErrorHandler errhandler // error handler callback );\description Attaches replica to the master.\param mco_db_h db - handle to the created database instance\param mco_channel_h ch - handle to the associated communication channel, also used as replica id on master side\param const mco_connection_param_t * params - connection parameters (timeouts, notification callback address) \param const char * application_specific_replica_name - optional, must be unique if specified\param mco_HA_ErrorHandler errhandler - error handler callback\return Returns MCO_S_OK or HA error code (see error codes) */MCO_RET mco_HA_attach_replica( mco_db_h db, mco_channel_h ch, const mco_connection_param_t * params, const char * application_specific_replica_name, mco_HA_ErrorHandler errhandler // error handler callback );/**\fn MCO_RET mco_HA_detach_replica( mco_db_h db, mco_channel_h ch); Detach replica from master.\param mco_db_h db - handle to the created database instance\param mco_channel_h ch - handle to the associated communication channel,\description Detaches replica from master.\return Returns MCO_S_OK or HA error code (see error codes)*/MCO_RET mco_HA_detach_replica( mco_db_h db, mco_channel_h ch);/**\fn uint2 mco_HA_get_number_of_replicas(mco_db_h db); * * returns current number of replicas by database handle */uint2 mco_HA_get_number_of_replicas(mco_db_h db);/**\fn mco_channel_h mco_HA_get_io_channel(mco_db_h db, int2 index); * * returns a pointer to the communication channel of the current replica * by database handle & replica's list index */mco_channel_h mco_HA_get_io_channel(mco_db_h db, int2 index);/**\fn MCO_RET mco_HA_keep_alive( mco_db_h db, timer_unit timeout); * * Master uses this function in order to send "KEEP_ALIVE" signal to replicas */MCO_RET mco_HA_keep_alive( mco_db_h db, timer_unit timeout);/**\fn MCO_RET mco_HA_trans_commit_synch( mco_db_h db ); * * This function is called by the separate thread of the MAIN master process * in order to implement the synchronization of the shared commit */MCO_RET mco_HA_trans_commit_synch( mco_db_h db );/****************************************************************** Replica DB in HA configuration has the following methods (API)******************************************************************//** Replica stop reason codes */typedef enum { MCO_HA_REPLICA_CONNECTION_ABORTED, MCO_HA_REPLICA_MASTER_REQUESTED_DISCONNECT, MCO_HA_REPLICA_HANDSHAKE_FAILED, MCO_HA_REPLICA_STOPPED_BY_LOCAL_REQUEST, ///< mco_replica_stop() called asynchronously MCO_HA_REPLICA_BECOMES_MASTER ///< special mode}MCO_E_HA_REPLICA_STOP_REASON;MCO_RET mco_HA_replica_set_param( ///< optional call to change parameters mco_db_h db, const mco_connection_param_t * params );MCO_RET mco_HA_replica_get_stat( mco_db_h db, mco_channel_h ch, // replica id const mco_HA_replica_stat_t * stat // this structure is not specified now, TBD );/**\fn MCO_RET mco_HA_attach_master( mco_db_h * db, mco_channel_h ch, const mco_connection_param_t * params, MCO_E_HA_REPLICA_STOP_REASON * stop_reason, const char * db_name, mco_dictionary_h dict, void * mem_ptr, uint4 total_size, uint2 flag);\description Attaches replica to master. In special mode (flag = 1) replica attaches to existing master, creates the copy of master's database and then returns. This call is blocking. It performs handshaking with master through given channel, then load's current master state, then it will accept update (2 phase commit protocol) requests. Function exits, when: a) unrecoverable error occured; b) by master request c) by async request (see below mco_replica_stop() ) from Replica's Application all main reasons are enumerated. After function returns application may choose to destroy db, or to use it as master, or to use it as replica again.\param IN OUT mco_db_h* db - returned handle to the created database instance\param mco_channel_h ch - pointer to the descriptor of the communication channel\param const mco_connection_param_t * params - connection parameters (timeouts)\param OUT MCO_E_HA_REPLICA_STOP_REASON * stop_reason - pointer to the returned STOP REASON value\param const char * db_name - the name of the of the new copy of database\param mco_dictionary_h dict - pointer to the database dictionary\param void * mem_ptr - pointer to the memory segment of the new copy of database\param uint4 total_size - database memory segment size\param uint2 flag - special mode flag. If(flag==1) replica creates the copy of master's database and returns\return Returns MCO_S_OK orr the error code (see HA error codes) */MCO_RET mco_HA_attach_master( /* IN OUT */ mco_db_h * db, mco_channel_h ch, const mco_connection_param_t * params, /* OUT */ MCO_E_HA_REPLICA_STOP_REASON * stop_reason, const char * db_name, mco_dictionary_h dict, void * mem_ptr, uint4 total_size, uint2 flag);/**\fn MCO_RET mco_HA_replica_stop(mco_db_h db);\description This function sets flag for mco_attach_master() to return; */MCO_RET mco_HA_replica_stop(mco_db_h db);MCO_RET mco_HA_replica_become_master(mco_db_h db);// used to set internal mode to master mode;// parameters should have been specified before, at mco_db_open/**\fn MCO_RET mco_HA_async_send_data_to_replicas(mco_db_h dbh);\description Asynchronous writing of commit data*/MCO_RET mco_HA_async_send_data_to_replicas(mco_db_h dbh);#ifdef __cplusplus}#endif#endif /* MCO_HA_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -