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 #define LOGPARSE_ATTEMPTS_DFLT  1   /* Number of attempts to parse unknown logs */
0055 
0056 #define XA_RETRIES_DFLT         3   /* number of foreground retries */
0057 #define TMSRV_HOUSEKEEP_DEFAULT   (90*60)     /**< houskeep 1 hour 30 min  */
0058 
0059 /*---------------------------Enums--------------------------------------*/
0060 /*---------------------------Typedefs-----------------------------------*/
0061 
0062 /*
0063  * TM ndrx_config.handler
0064  */
0065 typedef struct
0066 {
0067     long dflt_timeout; /**, how long monitored transaction can be open        */
0068     char tlog_dir[PATH_MAX]; /* Where to write tx log files                   */
0069     int scan_time;      /**< Number of seconds retries */
0070     long max_tries;      /**< Number of tries for running session for single 
0071                          * transaction, until stop processing it 
0072                          * (in this process session) */
0073     int tout_check_time; /**< seconds used for detecting transaction timeout  */
0074     int threadpoolsize; /**< thread pool size */
0075     /** Number of foreground retries in stage for XA_RETRY */
0076     int xa_retries;
0077     
0078     int ping_time; /**< Number of seconds for interval of doing "pings" to db */
0079     int ping_mode_jointran; /**< PING with join non existent transaction      */
0080     threadpool thpool;
0081     
0082     int housekeeptime;        /**< Number of seconds for corrupted log cleanup*/
0083     long vnodeid;            /**< Node id, command id used for failovers      */
0084 
0085     int chkdisk_time;     /**< Check against duplicate process runs, sec      */
0086 
0087     int logparse_attempts;      /**< Number of attempts to parse unknown logs */
0088     
0089 } tmsrv_cfg_t;
0090 
0091 struct thread_server
0092 {
0093     char *context_data; /* malloced by enduro/x */
0094     int cd;
0095     char *buffer; /* buffer data, managed by enduro/x */
0096 };
0097 /* note we must malloc this struct too. */
0098 typedef struct thread_server thread_server_t;
0099 
0100 /**
0101  * hash register of unknown
0102  * transaction files.
0103  */
0104 typedef struct
0105 {
0106     char tmxid[NDRX_XID_SERIAL_BUFSIZE+1];
0107     /**< Number attempts to load the unknown transaction.
0108      * Might be useful as transactions, which are not
0109      * logged for commit/abort, might have delayed
0110      * content appearance in the log file.
0111      */
0112     int attempts;
0113     EX_hash_handle hh;              /**< hash handle                    */
0114     int housekeepable;              /**< Is housekeepable?              */
0115 } ndrx_tms_file_registry_t;
0116 
0117 /*---------------------------Prototypes---------------------------------*/
0118 /* init */
0119 extern void tm_thread_init(void);
0120 extern void tm_thread_uninit(void);
0121 extern void tm_thread_shutdown(void *ptr, int *p_finish_off);
0122 
0123 extern void tm_ping_db(void *ptr, int *p_finish_off);
0124 
0125 extern tmsrv_cfg_t G_tmsrv_cfg;
0126 
0127 extern void atmi_xa_new_xid(XID *xid);
0128 
0129 extern int tms_unlock_entry(atmi_xa_log_t *p_tl);
0130 extern int tms_log_exists_entry(char *tmxid);
0131 extern int tms_log_exists_file(char *tmxid);
0132 extern atmi_xa_log_t * tms_log_get_entry(char *tmxid, int dowait, int *is_tout);
0133 extern int tms_log_start(atmi_xa_tx_info_t *xai, int txtout, long tmflags, long *btid);
0134 extern int tms_log_addrm(atmi_xa_tx_info_t *xai, short rmid, int *p_is_already_logged, 
0135         long *btid, long flags);
0136 extern int tms_log_chrmstat(atmi_xa_tx_info_t *xai, short rmid, 
0137         long btid, char rmstatus, UBFH *p_ub);
0138 extern int tms_open_logfile(atmi_xa_log_t *p_tl, char *mode);
0139 extern int tms_is_logfile_open(atmi_xa_log_t *p_tl);
0140 extern void tms_close_logfile(atmi_xa_log_t *p_tl);
0141 extern void tms_remove_logfree(atmi_xa_log_t *p_tl, int hash_rm);
0142 extern void tms_remove_logfile(atmi_xa_log_t *p_tl, int hash_rm);
0143 extern int tms_log_info(atmi_xa_log_t *p_tl);
0144 extern int tms_log_stage(atmi_xa_log_t *p_tl, short stage, int forced);
0145 extern int tms_log_rmstatus(atmi_xa_log_t *p_tl, atmi_xa_rm_status_btid_t *bt, 
0146         char rmstatus, int rmerrorcode, short rmreason);
0147 extern int tms_load_logfile(char *logfile, char *tmxid, atmi_xa_log_t **pp_tl,
0148         int *log_removed, int *housekeepable);
0149 extern int tms_housekeep(char *logfile);
0150 extern int tm_chk_tx_status(atmi_xa_log_t *p_tl);
0151 extern atmi_xa_log_list_t* tms_copy_hash2list(int copy_mode);
0152 extern void tms_tx_hash_lock(void);
0153 extern void tms_tx_hash_unlock(void);
0154 extern int tms_log_cpy_info_to_fb(UBFH *p_ub, atmi_xa_log_t *p_tl, int inc_rm_stat);
0155         
0156 extern int tm_drive(atmi_xa_tx_info_t *p_xai, atmi_xa_log_t *p_tl, int master_op,
0157                         short rmid, long flags);
0158 
0159 /* Prepare API */
0160 extern int tm_prepare_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0161 extern int tm_prepare_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0162 extern int tm_prepare_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0163 
0164 /* Rollback API */
0165 extern int tm_rollback_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0166 extern int tm_rollback_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0167 extern int tm_rollback_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0168 
0169 /* Forget API */
0170 extern int tm_forget_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0171 extern int tm_forget_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0172 extern int tm_forget_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0173 
0174 /* Commit API */
0175 extern int tm_commit_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid);
0176 extern int tm_commit_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0177 extern int tm_commit_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid);
0178 
0179 extern int tm_tpbegin(UBFH *p_ub);
0180 extern int tm_tpcommit(UBFH *p_ub);
0181 extern int tm_tpabort(UBFH *p_ub);
0182 
0183 extern int tm_tmprepare(UBFH *p_ub);
0184 extern int tm_tmcommit(UBFH *p_ub);
0185 extern int tm_tmabort(UBFH *p_ub);
0186 extern int tm_tmforget(UBFH *p_ub);
0187 extern int tm_tmregister(UBFH *p_ub);
0188 extern int tm_rmstatus(UBFH *p_ub);
0189 
0190 /* Background API */
0191 extern int background_read_log(void);
0192 extern void background_wakeup(void);
0193 extern int background_process_init(void);
0194 extern void background_lock(void);
0195 extern void background_unlock(void);
0196 
0197 /* singleton group related */
0198 extern ndrx_tms_file_registry_t *ndrx_tms_file_registry_get(ndrx_tms_file_registry_t ** hash, const char *tmxid);
0199 extern int ndrx_tms_file_registry_add(ndrx_tms_file_registry_t ** hash, 
0200     const char *tmxid, int housekeepable);
0201 extern int ndrx_tms_file_registry_del(ndrx_tms_file_registry_t ** hash, ndrx_tms_file_registry_t *ent);
0202 extern void ndrx_tms_file_registry_free(ndrx_tms_file_registry_t ** hash);
0203 
0204 extern int tms_log_checkpointseq(atmi_xa_log_t *p_tl);
0205 
0206 /* Admin functions */
0207 extern int tm_tpprinttrans(UBFH *p_ub, int cd);
0208 extern int tm_aborttrans(UBFH *p_ub);
0209 extern int tm_status(UBFH *p_ub);
0210 extern int tm_committrans(UBFH *p_ub);
0211 extern int tm_recoverlocal(UBFH *p_ub, int cd);
0212 extern int tm_proclocal(char cmd, UBFH *p_ub, int cd);
0213 
0214 /* Branch TID manipulations */
0215 extern long tms_btid_gettid(atmi_xa_log_t *p_tl, short rmid);
0216 
0217 
0218 extern atmi_xa_rm_status_btid_t *tms_btid_find(atmi_xa_log_t *p_tl, 
0219         short rmid, long btid);
0220 extern int tms_btid_add(atmi_xa_log_t *p_tl, short rmid, 
0221             long btid, char rmstatus, int  rmerrorcode, short rmreason,
0222             atmi_xa_rm_status_btid_t **bt);
0223 extern int tms_btid_addupd(atmi_xa_log_t *p_tl, short rmid, 
0224             long *btid, char rmstatus, int  rmerrorcode, short rmreason, int *exists,
0225             atmi_xa_rm_status_btid_t **bt);
0226 
0227 
0228 #ifdef  __cplusplus
0229 }
0230 #endif
0231 
0232 #endif  /* TMSRV_H */
0233 
0234 /* vim: set ts=4 sw=4 et smartindent: */