Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Transaction Monitor for XA
0003  *
0004  * @file tmsrv.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 #ifndef TMSRV_H
0036 #define TMSRV_H
0037 
0038 #ifdef  __cplusplus
0039 extern "C" {
0040 #endif
0041 
0042 /*---------------------------Includes-----------------------------------*/
0043 #include <xa_cmn.h>
0044 #include <exthpool.h>
0045 #include <exhash.h>
0046 /*---------------------------Externs------------------------------------*/
0047 extern pthread_t G_bacground_thread;
0048 extern int G_bacground_req_shutdown;    /* Is shutdown request? */
0049 /*---------------------------Macros-------------------------------------*/
0050 #define SCAN_TIME_DFLT          10  /* Every 10 sec try to complete TXs    */
0051 #define MAX_TRIES_DFTL          100 /* Try count for transaction completion */
0052 #define TOUT_CHECK_TIME         1   /* Check for transaction timeout, sec  */
0053 #define THREADPOOL_DFLT         10  /* Default number of threads spawned   */
0054 
0055 #define XA_RETRIES_DFLT         3   /* number of foreground retries */
0056 #define TMSRV_HOUSEKEEP_DEFAULT   (90*60)     /**< houskeep 1 hour 30 min  */
0057 
0058 /*---------------------------Enums--------------------------------------*/
0059 /*---------------------------Typedefs-----------------------------------*/
0060 
0061 /*
0062  * TM ndrx_config.handler
0063  */
0064 typedef struct
0065 {
0066     long dflt_timeout; /**, how long monitored transaction can be open        */
0067     char tlog_dir[PATH_MAX]; /* Where to write tx log files                 */
0068     int scan_time;      /**< Number of seconds retries */
0069     long max_tries;      /**< Number of tries for running session for single 
0070                          * transaction, until stop processing it 
0071                          * (in this process session) */
0072     int tout_check_time; /**< seconds used for detecting transaction timeout   */
0073     int threadpoolsize; /**< thread pool size */
0074     /** Number of foreground retries in stage for XA_RETRY */
0075     int xa_retries;
0076     
0077     int ping_time; /**< Number of seconds for interval of doing "pings" to db */
0078     int ping_mode_jointran; /**< PING with join non existent transaction    */
0079     threadpool thpool;
0080     
0081     int housekeeptime;        /**< Number of seconds for corrupted log cleanup*/
0082     long vnodeid;            /**< Node id, command id used for failovers    */
0083 
0084     int chkdisk_time;     /**< Check against duplicate process runs, sec     */
0085     
0086 } tmsrv_cfg_t;
0087 
0088 struct thread_server
0089 {
0090     char *context_data; /* malloced by enduro/x */
0091     int cd;
0092     char *buffer; /* buffer data, managed by enduro/x */
0093 };
0094 /* note we must malloc this struct too. */
0095 typedef struct thread_server thread_server_t;
0096 
0097 /**
0098  * hash register of unknown
0099  * transaction files.
0100  */
0101 typedef struct
0102 {
0103     char tmxid[NDRX_XID_SERIAL_BUFSIZE+1];
0104     int state;
0105     EX_hash_handle hh;              /**< hash handle                    */
0106 } ndrx_tms_file_registry_t;
0107 
0108 /*---------------------------Prototypes---------------------------------*/
0109 /* init */
0110 extern void tm_thread_init(void);
0111 extern void tm_thread_uninit(void);
0112 extern void tm_thread_shutdown(void *ptr, int *p_finish_off);
0113 
0114 extern void tm_ping_db(void *ptr, int *p_finish_off);
0115 
0116 extern tmsrv_cfg_t G_tmsrv_cfg;
0117 
0118 extern void atmi_xa_new_xid(XID *xid);
0119 
0120 extern int tms_unlock_entry(atmi_xa_log_t *p_tl);
0121 extern int tms_log_exists_entry(char *tmxid);
0122 extern int tms_log_exists_file(char *tmxid);
0123 extern atmi_xa_log_t * tms_log_get_entry(char *tmxid, int dowait, int *is_tout);
0124 extern int tms_log_start(atmi_xa_tx_info_t *xai, int txtout, long tmflags, long *btid);
0125 extern int tms_log_addrm(atmi_xa_tx_info_t *xai, short rmid, int *p_is_already_logged, 
0126         long *btid, long flags);
0127 extern int tms_log_chrmstat(atmi_xa_tx_info_t *xai, short rmid, 
0128         long btid, char rmstatus, UBFH *p_ub);
0129 extern int tms_open_logfile(atmi_xa_log_t *p_tl, char *mode);
0130 extern int tms_is_logfile_open(atmi_xa_log_t *p_tl);
0131 extern void tms_close_logfile(atmi_xa_log_t *p_tl);
0132 extern void tms_remove_logfree(atmi_xa_log_t *p_tl, int hash_rm);
0133 extern void tms_remove_logfile(atmi_xa_log_t *p_tl, int hash_rm);
0134 extern int tms_log_info(atmi_xa_log_t *p_tl);
0135 extern int tms_log_stage(atmi_xa_log_t *p_tl, short stage, int forced);
0136 extern int tms_log_rmstatus(atmi_xa_log_t *p_tl, atmi_xa_rm_status_btid_t *bt, 
0137         char rmstatus, int rmerrorcode, short rmreason);
0138 extern int tms_load_logfile(char *logfile, char *tmxid, atmi_xa_log_t **pp_tl);
0139 extern int tm_chk_tx_status(atmi_xa_log_t *p_tl);
0140 extern atmi_xa_log_list_t* tms_copy_hash2list(int copy_mode);
0141 extern void tms_tx_hash_lock(void);
0142 extern void tms_tx_hash_unlock(void);
0143 extern int tms_log_cpy_info_to_fb(UBFH *p_ub, atmi_xa_log_t *p_tl, int inc_rm_stat);
0144         
0145 extern int tm_drive(atmi_xa_tx_info_t *p_xai, atmi_xa_log_t *p_tl, int master_op,
0146                         short rmid, long flags);
0147 
0148 /* Prepare API */
0149 extern int tm_prepare_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0150 extern int tm_prepare_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0151 extern int tm_prepare_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0152 
0153 /* Rollback API */
0154 extern int tm_rollback_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0155 extern int tm_rollback_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0156 extern int tm_rollback_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0157 
0158 /* Forget API */
0159 extern int tm_forget_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0160 extern int tm_forget_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0161 extern int tm_forget_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0162 
0163 /* Commit API */
0164 extern int tm_commit_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0165 extern int tm_commit_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0166 extern int tm_commit_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0167 
0168 extern int tm_tpbegin(UBFH *p_ub);
0169 extern int tm_tpcommit(UBFH *p_ub);
0170 extern int tm_tpabort(UBFH *p_ub);
0171 
0172 extern int tm_tmprepare(UBFH *p_ub);
0173 extern int tm_tmcommit(UBFH *p_ub);
0174 extern int tm_tmabort(UBFH *p_ub);
0175 extern int tm_tmforget(UBFH *p_ub);
0176 extern int tm_tmregister(UBFH *p_ub);
0177 extern int tm_rmstatus(UBFH *p_ub);
0178 
0179 /* Background API */
0180 extern int background_read_log(void);
0181 extern void background_wakeup(void);
0182 extern int background_process_init(void);
0183 extern void background_lock(void);
0184 extern void background_unlock(void);
0185 
0186 /* singleton group related */
0187 extern ndrx_tms_file_registry_t *ndrx_tms_file_registry_get(const char *tmxid);
0188 extern int ndrx_tms_file_registry_add(const char *tmxid, int state);
0189 extern int ndrx_tms_file_registry_del(ndrx_tms_file_registry_t *ent);
0190 extern void ndrx_tms_file_registry_free(void);
0191 extern int tms_log_checkpointseq(atmi_xa_log_t *p_tl);
0192 
0193 /* Admin functions */
0194 extern int tm_tpprinttrans(UBFH *p_ub, int cd);
0195 extern int tm_aborttrans(UBFH *p_ub);
0196 extern int tm_status(UBFH *p_ub);
0197 extern int tm_committrans(UBFH *p_ub);
0198 extern int tm_recoverlocal(UBFH *p_ub, int cd);
0199 extern int tm_proclocal(char cmd, UBFH *p_ub, int cd);
0200 
0201 /* Branch TID manipulations */
0202 extern long tms_btid_gettid(atmi_xa_log_t *p_tl, short rmid);
0203 
0204 
0205 extern atmi_xa_rm_status_btid_t *tms_btid_find(atmi_xa_log_t *p_tl, 
0206         short rmid, long btid);
0207 extern int tms_btid_add(atmi_xa_log_t *p_tl, short rmid, 
0208             long btid, char rmstatus, int  rmerrorcode, short rmreason,
0209             atmi_xa_rm_status_btid_t **bt);
0210 extern int tms_btid_addupd(atmi_xa_log_t *p_tl, short rmid, 
0211             long *btid, char rmstatus, int  rmerrorcode, short rmreason, int *exists,
0212             atmi_xa_rm_status_btid_t **bt);
0213 
0214 
0215 #ifdef  __cplusplus
0216 }
0217 #endif
0218 
0219 #endif  /* TMSRV_H */
0220 
0221 /* vim: set ts=4 sw=4 et smartindent: */