#ifndef TX_H #define TX_H /****************************************************************************** * * TX.h - UniVerse Transaction processing defines * * Module %M% Version %I% Date %H% * * (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved * This is unpublished proprietary source code of Ardent Software Inc. * The copyright notice above does not evidence any actual or intended * publication of such source code. * ******************************************************************************* * * Maintenence log - insert most recent change descriptions at top * * Date.... GTAR# WHO Description........................................ * 04/12/99 24742 GMH Implement get/set_t25info functions * 03/28/99 24729 RGA Change from T30TAB to T30TABNEW. * 10/14/98 23801 SAP Change copyrights. * 09/28/98 23672 GMH Convert DBITEM to DBITEMNEW * 02/23/98 21285 CSM Add TX_DEMOTE_SQL_LOCK TX_UPD_COUNTS_LOCK * 05/29/97 20606 LAG Added support for replication to TXtopinfo structure * 05/07/97 20453 CSM Fix typos * 05/02/97 20453 CSM Add list of trigger blocks to tx structure * 11/19/96 19511 CSM Internal transactions do not notify Resource manager * 08/08/95 17086 CSM Add flags to TXUINFO,TX_NUMERIC,use comp/compare func * 06/22/95 15958 PVW Add defines for TX_BEGIN_INPROGRESS * 06/20/95 15958 PVW,CSM Add defines for tx status * 06/14/95 15958 PVW Remove TXmemlist structure define * 06/08/95 15958 CSM Add TX_FREE_ITEM macro to free a tx disk cache item * 05/24/95 15958 CSM Add TX_GET_PARENT macro for Rollforward of Nested tx * 05/18/95 16554 PVW Added TX_CHECK_LOCK and TX_ACQUIRE_LOCK * 04/10/95 16244 GMM Changed ino_t to uv_ino_t * 05/05/95 15958 PVW Added TXSCANC * 04/27/95 16446 PVW Add TX_NESTING_LEVEL * 04/13/95 16346 PVW Changes for isolation level * 04/11/95 16323 PVW Fix Error Recovery within a tx * 03/29/95 15958 PVW,CSM Implement Nested Transactions * 03/29/95 16247 PVW Added TXmemlist and TXdisklist structures * 01/13/95 15479 RM Remove TXlist * 10/25/94 15040 PVW Add DBlatch structures to TXDESC * 10/24/94 14855 MGM Add uniqinfo struct and uqptr to TXdesc * 10/19/94 15024 PVW Add scanned data structure to TXdesc * 10/07/94 14895 CSM 1 warn/trn for non-active fils,14825 cnt for uncommit * 09/02/94 14831 PVW Add TXTEST_makefile * 09/01/94 14711 PVW,CSM Implement debugging code * 07/27/94 14504 EAP Changed split30_info and merge30_info * 07/21/94 14134 WLG Added #ifndef TX_H to guard against multi-includes. * 07/12/94 14371 RM Added TX QA tests * 07/11/94 14173 EAP Corrected merge30_item_size() macro * 07/06/94 14371 RM Added TX QA tests * 06/23/94 14173 EAP Added Type 25 structures to TXWARM_info * 06/21/94 13835 PVW Add sqlmode to TXdesc structure * 06/09/94 14173 EAP included DBFILE.h to fix compile errors * 06/07/94 14173 EAP added TXWARM_info structure * 05/25/94 13836 PVW Remove FXLOCK define * 05/25/94 13835 PVW Implement SQL interface to the Transaction * Manager * 05/23/94 13835 PVW add TX_flist structure * 03/29/94 13511 JKW add TXbefore * 06/11/93 11704 JKW add ODBC TX interface * 08/27/92 8806 JKW add log_set to tx descriptor * 06/18/92 8806 JKW add logging defines * 06/01/92 8806 JKW delete module define * 05/31/92 8806 JKW add tx support ******************************************************************************/ #include "xa.h" #include "DBFILE.h" #include "btree.h" #include "inlist.h" /* The following are valid values of the TX/API function return code: */ typedef int TXRTNCODE; #define TX_OKAY 0 #define TX_ERR_GENERIC -1 #define TX_ERR_FILETYPE -2 /* The following are valid values of the transaction isolation: */ #define TX_NO_ISOLATION 0 #define TX_READ_UNCOMMITTED 1 #define TX_READ_COMMITTED 2 #define TX_REPEATABLE_READ 3 #define TX_SERIALIZABLE 4 #define TX_CURRENT_ISOLATION 42 /* The following are used in calls to TXCleanCache: */ #define TX_DEMOTE_LOCK 0x1 /* demote lock across tx boundary */ #define TX_RELEASE_LOCK 0x2 #define TX_DEMOTE_SQL_LOCK 0x4 /* demote lock within a tx by SQL */ #define TX_UPD_COUNTS_LOCK 0x8 /* update lock counts if SQL released or demoted a lock in an active tx */ /* The following are used in calls to TXCheckIsolation: */ #define TX_CHECK_LOCK 0x0 #define TX_ACQUIRE_LOCK 0x1 /**********************************************************************/ #define IS_A_TX (TX_active?1:0) #define TX_EXISTS (TX_active?1:0) #define TX_ID TX_active->id #define TX_NESTING_LEVEL (TX_active?TX_active->level:0) #define TX_ISOLATION_LEVEL TX_active->isolation #define TX_TOP_LEVEL TX_active->top #define TX_GET_CHILD(tx) (tx?((tx)->child?(tx)->child->id:0):0) #define TX_GET_PARENT(tx) (tx?((tx)->parent?(tx)->parent->id:0):0) #define ISOLATION_LEVEL (TX_active?TX_active->isolation:DEFAULT_ISOLATION) #define TX_GET_TRIGGER (TX_active?TX_active->top->tli->trcount:0) #define TX_GET_TRSCHEMA (TX_active->top->tli->trfired->ptrigblk->schema) #define TX_GET_TRTABLE (TX_active->top->tli->trfired->ptrigblk->table) #define TX_GET_TRID (TX_active->top->tli->trfired->id) #define TX_GET_TRREC (TX_active->top->tli->trfired->rec) #define TX_GET_TRIDOLD (TX_active->top->tli->trfired->id_old) #define TX_GET_TRRECOLD (TX_active->top->tli->trfired->rec_old) #define TX_GET_TREVENT (TX_active->top->tli->trfired->event) #define TX_GET_UDR_STARTED (TX_active->top->tli->udr_started) #define TX_GET_UDR_ABORTED (TX_active->top->tli->udr_aborted) #define TX_SET_UDR_STARTED(x) ((TX_active->top->tli->udr_started) = (x)) #define TX_SET_UDR_ABORTED(x) ((TX_active->top->tli->udr_aborted) = (x)) #define TXREAD 1 #define TXWRITE 2 #define TXDELETE 3 #define TXCOMMIT 4 #define TXROLLBACK 5 #define TXBEFORE 6 #define TXNOBEFORE 7 #define TXRELOVERSZ 8 #define TXGETOVERSZ 9 #define TXGETOVERFL 10 #define TXRELOVERFL 11 #define TXSPLIT30 12 #define TXMERGE30 13 #define TXPACK25 14 #define TXMERGE25 15 #define TXSPLIT25 16 #define TXFREE25 17 #define TXSPLITROOT25 18 #define TX_LOGNOIO_WAIT 1000 #define TX_MAXCACHE 30720 /* temp -- cannot overflow to file */ #define TX_FATAL 909014 /* fatal error code for now */ /**************************************************** * TX QA test masks used by ASSIGN command from BASIC * see Fassign() in RMmisc.c ****************************************************/ #define TXTEST_commit 0x01 #define TXTEST_rollback 0x02 #define TXTEST_escalate 0x04 #define TXTEST_cleanup 0x08 #define TXTEST_listreadu 0x10 #define TXTEST_prepare 0x20 #define TXTEST_debugcache 0x40 #define TXTEST_makefile 0x80 #define TXTEST_precommit_fatal 0x100 #define TXTEST_commit_fatal 0x200 #define TXTEST_postcommit_fatal 0x400 #define TXTEST_lockdisplay 0x1000 /* These defines are for use by TXPrintCache */ #define TX_TEST_LOCK 0x1 #define TX_TEST_DATA 0x2 #define TX_TEST_STATUS 0x4 /* There is a tunable array of TXid's in global memory This allows a daemon to monitor that active transactions are making progress. */ struct TXid { int id; int pid; int state; }; typedef struct TXid TXID; #define TX_NUMERIC 0x1 /* unique for numeric field */ /********************************************************************** TXuinfo structure **********************************************************************/ struct TXuinfo { struct TXuinfo *next; uUVLONG dev; uv_ino_t inode; INLIST *cache; int flags; }; typedef struct TXuinfo TXUINFO; /********************************************************************** TXlatch structure **********************************************************************/ struct TXlatch { struct TXlatch *next; DBDADDR group; uUVLONG latchacquired; }; typedef struct TXlatch TXLATCH; /********************************************************************** TXinfo structure **********************************************************************/ #define TX_PREIMAGE 0x1 #define TX_NOPREIMAGE 0x2 #define TX_TRUE_INSERT 0x4 #define TX_TRUE_UPDATE 0x10 #define TX_TRUE_OPERATION 0x14 #define TX_FREE_ITEM(txitem) ((txitem)->m.pfile->status & TX_INMEMORY?0:TXfree_item(txitem)) struct TXinfo { struct TXpfile *pfile; int status; int operation; DBDADDR group; uUVLONG lockexisting; uUVLONG lockacquired; }; typedef struct TXinfo TXINFO; /********************************************************************** TXitem structure **********************************************************************/ struct TXitem { TXINFO m; STRING pre; STRING post; }; typedef struct TXitem TXITEM; /********************************************************************** TXlfile structure **********************************************************************/ struct TXlfile { struct TXlfile *next; DBFILE *fdesc; }; typedef struct TXlfile TXLFILE; /********************************************************************** TXpfile structure The following defines are used for the status element **********************************************************************/ #define TX_INMEMORY 0x1 struct TXpfile { struct TXpfile *next; struct TXpfile *ancestor; struct TXdesc *tx; uUVLONG dev; uv_ino_t inode; int status; uUVLONG lockexisting; uUVLONG lockacquired; TXLFILE *lfilelist; STRING disk_key; int disk_key_len; INLIST *mem_cache; int mem_usage; SELFILE *true_insert_list; int true_insert_count; int true_update_count; int tlfilenum; int RL_count; int RU_count; TXLATCH *held_latch; }; typedef struct TXpfile TXPFILE; /********************************************************************** TXpflist structure **********************************************************************/ struct TXpflist { struct TXpflist *next; TXPFILE *pfile; }; typedef struct TXpflist TXPFLIST; /********************************************************************** Trigger Events **********************************************************************/ #define TRINSERT 0 #define TRUPDATE 1 #define TRDELETE 2 #define TRBEFORE 0 #define TRAFTER 1 /********************************************************************** TXtrinfo structure - information of a single trigger **********************************************************************/ struct TXtrinfo { char *name; /* trigger name */ char *creator; /* trigger creator name for Authid */ char *hstmt; char *progloc; /* trigger program name */ PROGRAM *program; /* ptr to program in Programs struct */ int chksum; /* checksum of trigger object code */ short trigloc; /* location+1 of trigger information */ }; typedef struct TXtrinfo TXTRINFO; /********************************************************************** TXtrlist structure - information of all enabled triggers of a table **********************************************************************/ struct TXtrlist { struct TXtrlist *next; TXTRINFO trig[6]; TXLFILE *trdesc; /* list of fdescs pointing here */ uv_ino_t inode; uUVLONG dev; STRING schema; /* used for trig arg, @OLD,NEW */ STRING table; /* used for trig arg, @OLD,NEW */ }; typedef struct TXtrlist TXTRLIST; /********************************************************************** TXtrfired structure - information of a trigger in the fired state **********************************************************************/ struct TXtrfired { struct TXtrfired *next; /* ptr to next trig on stack */ STRING id, rec, id_old, rec_old; DATUM atid, /* @ ID for error handling */ atrec, /* @ REC for error handling */ atfile; /* @ FILE for error handling */ int tx_level; /* tx lvl at which trig fired */ TXTRLIST *ptrigblk; /* pointer to trigger block */ uid_t sav_authid; /* Auth id before trig exec */ DATUM argptr[14]; /* trigger arguments, datums */ char *sav_hstmt; /* @HSTMT before trig execut */ char savcasc; /* @CASCADE before trig exec */ short trigloc; /* loc+1 of trig in ptrigblk */ short event; /* 0, 1 or 2 - Ins, Upd, Del */ }; typedef struct TXtrfired TXTRFIRED; /********************************************************************** TXtopinfo structure - information relevant in top level of nested transaction **********************************************************************/ struct TXtopinfo { TXTRLIST *trlist; /* list of active triggers */ TXTRFIRED *trfired; /* stack of fired triggers */ TXTRFIRED *trfree; /* list of free fired triggers */ int trcount; /* count of active triggers */ int trchain_casc; /* trig nest lvl after casc,0 */ BITMAP sparebits:((8*sizeof(BITMAP))-2), udr_started:1, /* set if transaction is involved in UDR */ udr_aborted:1; /* set if transaction is being uncommitted */ }; typedef struct TXtopinfo TXTOPINFO; /********************************************************************** TXdesc structure **********************************************************************/ /* The following are valid values of the transaction type: */ #define TX_TYPE_BASIC 0x0001 #define TX_TYPE_DML 0x0002 #define TX_TYPE_INSERT 0x0012 #define TX_TYPE_UPDATE 0x0022 #define TX_TYPE_DELETE 0x0042 #define TX_TYPE_SELECT 0x0102 #define TX_TYPE_ROLLFWD 0x0200 #define TX_TYPE_INTERNAL 0x0400 /* The following are valid values of the transaction status: */ #define TX_BEGIN_INPROGRESS 0x01 #define TX_COMMIT_STARTED 0x02 #define TX_COMMIT_COMPLETED 0x04 #define TX_RELEASE_STARTED 0x08 #define TX_RM_NOTIFIED 0x10 #define TX_LOGDATA_STARTED 0x20 #define TX_ROLLBACK_STARTED 0x40 #define TX_UNCOMMIT_STARTED 0x80 #define TX_LOGIT 0x40000000 #define TX_NONACTFL 0x80000000 struct TXdesc { int id; long starttime; long committime; int status; short type; short level; short isolation; struct TXdesc *child; struct TXdesc *parent; struct TXdesc *top; TXPFILE *pfilelist; TXUINFO *uinfo; int rmid; XID xid; int mem_max; int mem_usage; DBFILE *disk_cache; uchar *disk_file; struct SHdata disk_shd; TXLATCH *gfree_latch; TXLFILE *scanlist; int commitcnt; struct DBlatch *held_latch; struct DBlatch *free_latch; TXTOPINFO *tli; /* top level transaction information */ }; typedef struct TXdesc TXDESC; /********************************************************************** TXscanc structure **********************************************************************/ struct TXscanc { TXDESC *scan_tx; SELFILE *selfile; /* merge of all true insert lists */ int has_inserts; STRING key; STRING record; }; typedef struct TXscanc TXSCANC; /*********************************************************************/ #define TX_KEYBASE (sizeof(long) + sizeof(long)) #define TX_MAX_RM 3 #define TX_RM_START 1 #define TX_RM_COMMIT 2 #define TX_RM_ROLLBACK 3 #define TX_RM_END 4 struct TXrm_entry { int rmid; struct xa_switch_t table; }; /*********************************************************************/ struct TXdisklist { struct TXdisklist *next; STRING item; }; typedef struct TXdisklist TXDISKLIST; /********************************************************************** Data structures used to encode warm start transaction info **********************************************************************/ struct freelist_info { int type; DBDADDR freelist_hdr; int ovf30; int count; DBDADDR list[1]; }; struct split30_info{ int type; DBDADDR freelist_hdr; DBDADDR allocated[2]; DBDADDR freed; T30INFONEW t30_params; int Bsize; int count; DBITEMNEW data[1]; }; struct merge30_info{ int type; DBDADDR freelist_hdr; DBDADDR allocated[2]; DBDADDR freed; T30INFONEW t30_params; int Bsize; int orig_count; int count; DBITEMNEW data[1]; }; struct pack25_info{ int type; DBDADDR freelist_hdr; DBDADDR parent; int parent_slot; DBDADDR leaf; TERMINAL_NODE data; }; struct merge25_info{ int type; DBDADDR parent; int parent_slot; DBDADDR left_node; DBDADDR right_node; TERMINAL_NODE data; }; struct split25_info{ int type; DBDADDR freelist_hdr; DBDADDR parent; int parent_slot; DBDADDR new; DBDADDR orig; TERMINAL_NODE data; }; struct splitroot25_info{ int type; DBDADDR freelist_hdr; DBDADDR left; DBDADDR right; TERMINAL_NODE data; }; struct free25_info{ int type; DBDADDR freelist_hdr; DBDADDR parent; int parent_slot; DBDADDR leafaddr; DBDADDR l_sibling; DBDADDR r_sibling; }; typedef union { struct freelist_info freelist_info; struct split30_info split30_info; struct merge30_info merge30_info; struct pack25_info pack25_info; struct split25_info split25_info; struct merge25_info merge25_info; struct free25_info free25_info; struct splitroot25_info splitroot25_info; } TXWARM_info; #define freelist_item_size(n) (sizeof(struct freelist_info)+((n)-1)*sizeof(DBDADDR)) #define split30_item_size(fdesc,n) (sizeof(struct split30_info)+(n)*(fdesc->Bsize)-(fdesc->addr_support!=NEW64?sizeof(DBITEMNEW32):sizeof(DBITEMNEW64))) #define merge30_item_size(fdesc,n) (sizeof(struct merge30_info)+(n)*(fdesc->Bsize)-(fdesc->addr_support!=NEW64?sizeof(DBITEMNEW32):sizeof(DBITEMNEW64))) #define pack25_item_size(fdesc) (sizeof(struct pack25_info)-sizeof(TERMINAL_NODE)+((fdesc)->Bsize)) #define merge25_item_size(fdesc) (sizeof(struct merge25_info)-sizeof(TERMINAL_NODE)+2*((fdesc)->Bsize)) #define split25_item_size(fdesc) (sizeof(struct split25_info)-sizeof(TERMINAL_NODE)+((fdesc)->Bsize)) #define free25_item_size(fdesc) (sizeof(struct free25_info)) #define splitroot25_item_size(fdesc) (sizeof(struct splitroot25_info)-sizeof(TERMINAL_NODE)+((fdesc)->Bsize)) #endif