1*7c478bd9Sstevel@tonic-gate /*- 2*7c478bd9Sstevel@tonic-gate * See the file LICENSE for redistribution information. 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996, 1997, 1998 5*7c478bd9Sstevel@tonic-gate * Sleepycat Software. All rights reserved. 6*7c478bd9Sstevel@tonic-gate * 7*7c478bd9Sstevel@tonic-gate * @(#)txn.h 10.18 (Sleepycat) 1/3/99 8*7c478bd9Sstevel@tonic-gate */ 9*7c478bd9Sstevel@tonic-gate #ifndef _TXN_H_ 10*7c478bd9Sstevel@tonic-gate #define _TXN_H_ 11*7c478bd9Sstevel@tonic-gate 12*7c478bd9Sstevel@tonic-gate #include "xa.h" 13*7c478bd9Sstevel@tonic-gate 14*7c478bd9Sstevel@tonic-gate /* 15*7c478bd9Sstevel@tonic-gate * The name of the transaction shared memory region is DEFAULT_TXN_FILE and 16*7c478bd9Sstevel@tonic-gate * the region is always created group RW of the group owning the directory. 17*7c478bd9Sstevel@tonic-gate */ 18*7c478bd9Sstevel@tonic-gate #define DEFAULT_TXN_FILE "__db_txn.share" 19*7c478bd9Sstevel@tonic-gate /* TXN_MINIMUM = (DB_LOCK_MAXID + 1) but this makes compilers complain. */ 20*7c478bd9Sstevel@tonic-gate #define TXN_MINIMUM 0x80000000 21*7c478bd9Sstevel@tonic-gate #define TXN_INVALID 0xffffffff /* Maximum number of txn ids. */ 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate /* 24*7c478bd9Sstevel@tonic-gate * Transaction type declarations. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* 28*7c478bd9Sstevel@tonic-gate * Internal data maintained in shared memory for each transaction. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate typedef char DB_XID[XIDDATASIZE]; 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate typedef struct __txn_detail { 33*7c478bd9Sstevel@tonic-gate u_int32_t txnid; /* current transaction id 34*7c478bd9Sstevel@tonic-gate used to link free list also */ 35*7c478bd9Sstevel@tonic-gate DB_LSN last_lsn; /* last lsn written for this txn */ 36*7c478bd9Sstevel@tonic-gate DB_LSN begin_lsn; /* lsn of begin record */ 37*7c478bd9Sstevel@tonic-gate size_t last_lock; /* offset in lock region of last lock 38*7c478bd9Sstevel@tonic-gate for this transaction. */ 39*7c478bd9Sstevel@tonic-gate size_t parent; /* Offset of transaction's parent. */ 40*7c478bd9Sstevel@tonic-gate #define TXN_UNALLOC 0 41*7c478bd9Sstevel@tonic-gate #define TXN_RUNNING 1 42*7c478bd9Sstevel@tonic-gate #define TXN_ABORTED 2 43*7c478bd9Sstevel@tonic-gate #define TXN_PREPARED 3 44*7c478bd9Sstevel@tonic-gate #define TXN_COMMITTED 4 45*7c478bd9Sstevel@tonic-gate u_int32_t status; /* status of the transaction */ 46*7c478bd9Sstevel@tonic-gate SH_TAILQ_ENTRY links; /* free/active list */ 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #define TXN_XA_ABORTED 1 49*7c478bd9Sstevel@tonic-gate #define TXN_XA_DEADLOCKED 2 50*7c478bd9Sstevel@tonic-gate #define TXN_XA_ENDED 3 51*7c478bd9Sstevel@tonic-gate #define TXN_XA_PREPARED 4 52*7c478bd9Sstevel@tonic-gate #define TXN_XA_STARTED 5 53*7c478bd9Sstevel@tonic-gate #define TXN_XA_SUSPENDED 6 54*7c478bd9Sstevel@tonic-gate u_int32_t xa_status; /* XA status */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate /* 57*7c478bd9Sstevel@tonic-gate * XID (xid_t) structure: because these fields are logged, the 58*7c478bd9Sstevel@tonic-gate * sizes have to be explicit. 59*7c478bd9Sstevel@tonic-gate */ 60*7c478bd9Sstevel@tonic-gate DB_XID xid; /* XA global transaction id */ 61*7c478bd9Sstevel@tonic-gate u_int32_t bqual; /* bqual_length from XID */ 62*7c478bd9Sstevel@tonic-gate u_int32_t gtrid; /* gtrid_length from XID */ 63*7c478bd9Sstevel@tonic-gate int32_t format; /* XA format */ 64*7c478bd9Sstevel@tonic-gate } TXN_DETAIL; 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate /* 67*7c478bd9Sstevel@tonic-gate * The transaction manager encapsulates the transaction system. It contains 68*7c478bd9Sstevel@tonic-gate * references to the log and lock managers as well as the state that keeps 69*7c478bd9Sstevel@tonic-gate * track of the shared memory region. 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate struct __db_txnmgr { 72*7c478bd9Sstevel@tonic-gate /* These fields need to be protected for multi-threaded support. */ 73*7c478bd9Sstevel@tonic-gate db_mutex_t *mutexp; /* Synchronization. */ 74*7c478bd9Sstevel@tonic-gate /* list of active transactions */ 75*7c478bd9Sstevel@tonic-gate TAILQ_HEAD(_chain, __db_txn) txn_chain; 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate /* These fields are not protected. */ 78*7c478bd9Sstevel@tonic-gate REGINFO reginfo; /* Region information. */ 79*7c478bd9Sstevel@tonic-gate DB_ENV *dbenv; /* Environment. */ 80*7c478bd9Sstevel@tonic-gate int (*recover) /* Recovery dispatch routine */ 81*7c478bd9Sstevel@tonic-gate __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); 82*7c478bd9Sstevel@tonic-gate u_int32_t flags; /* DB_TXN_NOSYNC, DB_THREAD */ 83*7c478bd9Sstevel@tonic-gate DB_TXNREGION *region; /* address of shared memory region */ 84*7c478bd9Sstevel@tonic-gate void *mem; /* address of the shalloc space */ 85*7c478bd9Sstevel@tonic-gate }; 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* 88*7c478bd9Sstevel@tonic-gate * Layout of the shared memory region. 89*7c478bd9Sstevel@tonic-gate * The region consists of a DB_TXNREGION structure followed by a large 90*7c478bd9Sstevel@tonic-gate * pool of shalloc'd memory which is used to hold TXN_DETAIL structures 91*7c478bd9Sstevel@tonic-gate * and thread mutexes (which are dynamically allocated). 92*7c478bd9Sstevel@tonic-gate */ 93*7c478bd9Sstevel@tonic-gate struct __db_txnregion { 94*7c478bd9Sstevel@tonic-gate RLAYOUT hdr; /* Shared memory region header. */ 95*7c478bd9Sstevel@tonic-gate u_int32_t magic; /* transaction magic number */ 96*7c478bd9Sstevel@tonic-gate u_int32_t version; /* version number */ 97*7c478bd9Sstevel@tonic-gate u_int32_t maxtxns; /* maximum number of active txns */ 98*7c478bd9Sstevel@tonic-gate u_int32_t last_txnid; /* last transaction id given out */ 99*7c478bd9Sstevel@tonic-gate DB_LSN pending_ckp; /* last checkpoint did not finish */ 100*7c478bd9Sstevel@tonic-gate DB_LSN last_ckp; /* lsn of the last checkpoint */ 101*7c478bd9Sstevel@tonic-gate time_t time_ckp; /* time of last checkpoint */ 102*7c478bd9Sstevel@tonic-gate u_int32_t logtype; /* type of logging */ 103*7c478bd9Sstevel@tonic-gate u_int32_t locktype; /* lock type */ 104*7c478bd9Sstevel@tonic-gate u_int32_t naborts; /* number of aborted transactions */ 105*7c478bd9Sstevel@tonic-gate u_int32_t ncommits; /* number of committed transactions */ 106*7c478bd9Sstevel@tonic-gate u_int32_t nbegins; /* number of begun transactions */ 107*7c478bd9Sstevel@tonic-gate SH_TAILQ_HEAD(_active) active_txn; /* active transaction list */ 108*7c478bd9Sstevel@tonic-gate }; 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate /* 111*7c478bd9Sstevel@tonic-gate * Make the region large enough to hold N transaction detail structures 112*7c478bd9Sstevel@tonic-gate * plus some space to hold thread handles and the beginning of the shalloc 113*7c478bd9Sstevel@tonic-gate * region. 114*7c478bd9Sstevel@tonic-gate */ 115*7c478bd9Sstevel@tonic-gate #define TXN_REGION_SIZE(N) \ 116*7c478bd9Sstevel@tonic-gate (sizeof(DB_TXNREGION) + N * sizeof(TXN_DETAIL) + 1000) 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /* Macros to lock/unlock the region and threads. */ 119*7c478bd9Sstevel@tonic-gate #define LOCK_TXNTHREAD(tmgrp) \ 120*7c478bd9Sstevel@tonic-gate if (F_ISSET(tmgrp, DB_THREAD)) \ 121*7c478bd9Sstevel@tonic-gate (void)__db_mutex_lock((tmgrp)->mutexp, -1) 122*7c478bd9Sstevel@tonic-gate #define UNLOCK_TXNTHREAD(tmgrp) \ 123*7c478bd9Sstevel@tonic-gate if (F_ISSET(tmgrp, DB_THREAD)) \ 124*7c478bd9Sstevel@tonic-gate (void)__db_mutex_unlock((tmgrp)->mutexp, -1) 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate #define LOCK_TXNREGION(tmgrp) \ 127*7c478bd9Sstevel@tonic-gate (void)__db_mutex_lock(&(tmgrp)->region->hdr.lock, (tmgrp)->reginfo.fd) 128*7c478bd9Sstevel@tonic-gate #define UNLOCK_TXNREGION(tmgrp) \ 129*7c478bd9Sstevel@tonic-gate (void)__db_mutex_unlock(&(tmgrp)->region->hdr.lock, (tmgrp)->reginfo.fd) 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate /* Check for region catastrophic shutdown. */ 132*7c478bd9Sstevel@tonic-gate #define TXN_PANIC_CHECK(tmgrp) { \ 133*7c478bd9Sstevel@tonic-gate if ((tmgrp)->region->hdr.panic) \ 134*7c478bd9Sstevel@tonic-gate return (DB_RUNRECOVERY); \ 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * Log record types. 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate #define TXN_COMMIT 1 141*7c478bd9Sstevel@tonic-gate #define TXN_PREPARE 2 142*7c478bd9Sstevel@tonic-gate #define TXN_CHECKPOINT 3 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate #include "txn_auto.h" 145*7c478bd9Sstevel@tonic-gate #include "txn_ext.h" 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate #include "xa_ext.h" 148*7c478bd9Sstevel@tonic-gate #endif /* !_TXN_H_ */ 149