Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

txn.h

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: txn.h,v 12.7 2005/10/13 00:53:00 bostic Exp $
00008  */
00009 
00010 #ifndef _TXN_H_
00011 #define _TXN_H_
00012 
00013 #include "dbinc/xa.h"
00014 
00015 /* Operation parameters to the delayed commit processing code. */
00016 typedef enum {
00017         TXN_CLOSE,              /* Close a DB handle whose close had failed. */
00018         TXN_REMOVE,             /* Remove a file. */
00019         TXN_TRADE,              /* Trade lockers. */
00020         TXN_TRADED              /* Already traded; downgrade lock. */
00021 } TXN_EVENT_T;
00022 
00023 struct __db_txnregion;  typedef struct __db_txnregion DB_TXNREGION;
00024 struct __txn_logrec;    typedef struct __txn_logrec DB_TXNLOGREC;
00025 
00026 /*
00027  * !!!
00028  * TXN_MINIMUM = (DB_LOCK_MAXID + 1) but this makes compilers complain.
00029  */
00030 #define TXN_MINIMUM     0x80000000
00031 #define TXN_MAXIMUM     0xffffffff      /* Maximum number of txn ids. */
00032 #define TXN_INVALID     0               /* Invalid transaction ID. */
00033 
00034 #define DEF_MAX_TXNS    20              /* Default max transactions. */
00035 
00036 /*
00037  * Internal data maintained in shared memory for each transaction.
00038  */
00039 typedef struct __txn_detail {
00040         u_int32_t txnid;                /* current transaction id
00041                                            used to link free list also */
00042         pid_t pid;                      /* Process owning txn */
00043         db_threadid_t tid;      /* Thread owning txn */
00044 
00045         DB_LSN  last_lsn;               /* last lsn written for this txn */
00046         DB_LSN  begin_lsn;              /* lsn of begin record */
00047         roff_t  parent;                 /* Offset of transaction's parent. */
00048         roff_t  name;                   /* Offset of txn name. */
00049 
00050         SH_TAILQ_HEAD(__tdkids) kids;   /* Linked list of child txn detail. */
00051         SH_TAILQ_ENTRY          klinks;
00052 
00053 #define TXN_RUNNING             1
00054 #define TXN_ABORTED             2
00055 #define TXN_PREPARED            3
00056 #define TXN_COMMITTED           4
00057         u_int32_t status;               /* status of the transaction */
00058 #define TXN_DTL_COLLECTED       0x1     /* collected during txn_recover */
00059 #define TXN_DTL_RESTORED        0x2     /* prepared txn restored */
00060 #define TXN_DTL_INMEMORY        0x4     /* uses in memory logs */
00061         u_int32_t flags;
00062 
00063         SH_TAILQ_ENTRY  links;          /* free/active list */
00064 
00065 #define TXN_XA_ABORTED          1
00066 #define TXN_XA_DEADLOCKED       2
00067 #define TXN_XA_ENDED            3
00068 #define TXN_XA_PREPARED         4
00069 #define TXN_XA_STARTED          5
00070 #define TXN_XA_SUSPENDED        6
00071         u_int32_t xa_status;            /* XA status */
00072 
00073         /*
00074          * XID (xid_t) structure: because these fields are logged, the
00075          * sizes have to be explicit.
00076          */
00077         u_int8_t xid[XIDDATASIZE];      /* XA global transaction id */
00078         u_int32_t bqual;                /* bqual_length from XID */
00079         u_int32_t gtrid;                /* gtrid_length from XID */
00080         int32_t format;                 /* XA format */
00081 } TXN_DETAIL;
00082 
00083 /*
00084  * DB_TXNMGR --
00085  *      The transaction manager encapsulates the transaction system.
00086  */
00087 struct __db_txnmgr {
00088         /*
00089          * These fields need to be protected for multi-threaded support.
00090          *
00091          * Lock list of active transactions (including the content of each
00092          * TXN_DETAIL structure on the list).
00093          */
00094         db_mutex_t mutex;
00095                                         /* List of active transactions. */
00096         TAILQ_HEAD(_chain, __db_txn)    txn_chain;
00097 
00098         u_int32_t n_discards;           /* Number of txns discarded. */
00099 
00100         /* These fields are never updated after creation, so not protected. */
00101         DB_ENV  *dbenv;                 /* Environment. */
00102         REGINFO  reginfo;               /* Region information. */
00103 };
00104 
00105 /* Macros to lock/unlock the transaction region as a whole. */
00106 #define TXN_SYSTEM_LOCK(dbenv)                                          \
00107         MUTEX_LOCK(dbenv, ((DB_TXNREGION *)((DB_TXNMGR *)               \
00108             (dbenv)->tx_handle)->reginfo.primary)->mtx_region)
00109 #define TXN_SYSTEM_UNLOCK(dbenv)                                        \
00110         MUTEX_UNLOCK(dbenv, ((DB_TXNREGION *)((DB_TXNMGR *)             \
00111             (dbenv)->tx_handle)->reginfo.primary)->mtx_region)
00112 
00113 /*
00114  * DB_TXNREGION --
00115  *      The primary transaction data structure in the shared memory region.
00116  */
00117 struct __db_txnregion {
00118         db_mutex_t      mtx_region;     /* Region mutex. */
00119 
00120         u_int32_t       maxtxns;        /* maximum number of active TXNs */
00121         u_int32_t       last_txnid;     /* last transaction id given out */
00122         u_int32_t       cur_maxid;      /* current max unused id. */
00123 
00124         db_mutex_t      mtx_ckp;        /* Single thread checkpoints. */
00125         DB_LSN          last_ckp;       /* lsn of the last checkpoint */
00126         time_t          time_ckp;       /* time of last checkpoint */
00127 
00128         DB_TXN_STAT     stat;           /* Statistics for txns. */
00129 
00130 #define TXN_IN_RECOVERY  0x01           /* environment is being recovered */
00131         u_int32_t       flags;
00132                                         /* active TXN list */
00133         SH_TAILQ_HEAD(__active) active_txn;
00134 };
00135 
00136 /*
00137  * DB_TXNLOGREC --
00138  *      An in-memory, linked-list copy of a log record.
00139  */
00140 struct __txn_logrec {
00141         STAILQ_ENTRY(__txn_logrec) links;/* Linked list. */
00142 
00143         u_int8_t data[1];               /* Log record. */
00144 };
00145 
00146 /*
00147  * Log record types.  Note that these are *not* alphabetical.  This is
00148  * intentional so that we don't change the meaning of values between
00149  * software upgrades.
00150  *
00151  * EXPECTED, UNEXPECTED, IGNORE, and OK are used in the txnlist functions.
00152  * Here is an explanation of how the statuses are used.
00153  *
00154  * TXN_OK
00155  *      BEGIN records for transactions found on the txnlist during
00156  *      OPENFILES (BEGIN records are those with a prev_lsn of 0,0)
00157  *
00158  * TXN_COMMIT
00159  *      Transaction committed and should be rolled forward.
00160  *
00161  * TXN_ABORT
00162  *      This transaction's changes must be undone.  Either there was
00163  *      never a prepare or commit record for this transaction OR there
00164  *      was a commit, but we are recovering to a timestamp or particular
00165  *      LSN and that point is before this transaction's commit.
00166  *
00167  * TXN_PREPARE
00168  *      Prepare record, but no commit record is in the log.
00169  *
00170  * TXN_IGNORE
00171  *      Generic meaning is that this transaction should not be
00172  *      processed during later recovery passes.  We use it in a
00173  *      number of different manners:
00174  *
00175  *      1. We never saw its BEGIN record.  Therefore, the logs have
00176  *         been reclaimed and we *know* that this transaction doesn't
00177  *         need to be aborted, because in order for it to be
00178  *         reclaimed, there must have been a subsequent checkpoint
00179  *         (and any dirty pages for this transaction made it to
00180  *         disk).
00181  *
00182  *      2. This is a child transaction that created a database.
00183  *         For some reason, we don't want to recreate that database
00184  *         (i.e., it already exists or some other database created
00185  *         after it exists).
00186  *
00187  *      3. During recovery open of subdatabases, if the master check fails,
00188  *         we use a TXN_IGNORE on the create of the subdb in the nested
00189  *         transaction.
00190  *
00191  *      4. During a remove, the file with the name being removed isn't
00192  *         the file for which we are recovering a remove.
00193  *
00194  * TXN_EXPECTED
00195  *      After a successful open during recovery, we update the
00196  *      transaction's status to TXN_EXPECTED.  The open was done
00197  *      in the parent, but in the open log record, we record the
00198  *      child transaction's ID if we also did a create.  When there
00199  *      is a valid ID in that field, we use it and mark the child's
00200  *      status as TXN_EXPECTED (indicating that we don't need to redo
00201  *      a create for this file).
00202  *
00203  *      When recovering a remove, if we don't find or can't open
00204  *      the file, the child (which does the remove) gets marked
00205  *      EXPECTED (indicating that we don't need to redo the remove).
00206  *
00207  * TXN_UNEXPECTED
00208  *      During recovery, we attempted an open that should have succeeded
00209  *      and we got ENOENT, so like with the EXPECTED case, we indicate
00210  *      in the child that we got the UNEXPECTED return so that we do redo
00211  *      the creating/deleting operation.
00212  *
00213  */
00214 #define TXN_OK          0
00215 #define TXN_COMMIT      1
00216 #define TXN_PREPARE     2
00217 #define TXN_ABORT       3
00218 #define TXN_IGNORE      4
00219 #define TXN_EXPECTED    5
00220 #define TXN_UNEXPECTED  6
00221 
00222 #include "dbinc_auto/txn_auto.h"
00223 #include "dbinc_auto/txn_ext.h"
00224 #include "dbinc_auto/xa_ext.h"
00225 #endif /* !_TXN_H_ */

Generated on Sun Dec 25 12:14:22 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2