txn.h

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: txn_8h-source.html,v 1.1 2008/06/08 10:24:49 sebdiaz Exp $
00008  */
00009 
00010 #ifndef _TXN_H_
00011 #define _TXN_H_
00012 
00013 #include "xa.h"
00014 
00015 struct __db_txnmgr;     typedef struct __db_txnmgr DB_TXNMGR;
00016 struct __db_txnregion;  typedef struct __db_txnregion DB_TXNREGION;
00017 
00018 /*
00019  * !!!
00020  * TXN_MINIMUM = (DB_LOCK_MAXID + 1) but this makes compilers complain.
00021  */
00022 #define TXN_MINIMUM     0x80000000
00023 #define TXN_INVALID     0xffffffff      /* Maximum number of txn ids. */
00024 #define TXN_INVALID_ID  0               /* Invalid transaction ID. */
00025 
00026 #define DEF_MAX_TXNS    20              /* Default max transactions. */
00027 
00028 /* The structure allocated for every transaction. */
00029 struct __db_txn {
00030         DB_TXNMGR       *mgrp;          /* Pointer to transaction manager. */
00031         DB_TXN          *parent;        /* Pointer to transaction's parent. */
00032         DB_LSN          last_lsn;       /* Lsn of last log write. */
00033         u_int32_t       txnid;          /* Unique transaction id. */
00034         roff_t          off;            /* Detail structure within region. */
00035         TAILQ_ENTRY(__db_txn) links;    /* Links transactions off manager. */
00036         TAILQ_HEAD(__kids, __db_txn) kids; /* Child transactions. */
00037         TAILQ_ENTRY(__db_txn) klinks;   /* Links child transactions. */
00038 
00039 #define TXN_CHILDCOMMIT 0x01            /* Transaction that has committed. */
00040 #define TXN_MALLOC      0x02            /* Structure allocated by TXN system. */
00041 #define TXN_MUSTFLUSH   0x04            /* A child has committed. */
00042 #define TXN_NOSYNC      0x08            /* Do not sync on prepare and commit. */
00043 #define TXN_NOWAIT      0x10            /* Do not wait on locks. */
00044 #define TXN_SYNC        0x20            /* Sync on prepare and commit. */
00045         u_int32_t       flags;
00046 };
00047 
00048 /*
00049  * Internal data maintained in shared memory for each transaction.
00050  */
00051 typedef char DB_XID[XIDDATASIZE];
00052 
00053 typedef struct __txn_detail {
00054         u_int32_t txnid;                /* current transaction id
00055                                            used to link free list also */
00056         DB_LSN  last_lsn;               /* last lsn written for this txn */
00057         DB_LSN  begin_lsn;              /* lsn of begin record */
00058         roff_t  parent;                 /* Offset of transaction's parent. */
00059 
00060 #define TXN_UNALLOC             0
00061 #define TXN_RUNNING             1
00062 #define TXN_ABORTED             2
00063 #define TXN_PREPARED            3
00064 #define TXN_COMMITTED           4
00065         u_int32_t status;               /* status of the transaction */
00066 
00067         SH_TAILQ_ENTRY  links;          /* free/active list */
00068 
00069 #define TXN_XA_ABORTED          1
00070 #define TXN_XA_DEADLOCKED       2
00071 #define TXN_XA_ENDED            3
00072 #define TXN_XA_PREPARED         4
00073 #define TXN_XA_STARTED          5
00074 #define TXN_XA_SUSPENDED        6
00075         u_int32_t xa_status;            /* XA status */
00076 
00077         /*
00078          * XID (xid_t) structure: because these fields are logged, the
00079          * sizes have to be explicit.
00080          */
00081         DB_XID xid;                     /* XA global transaction id */
00082         u_int32_t bqual;                /* bqual_length from XID */
00083         u_int32_t gtrid;                /* gtrid_length from XID */
00084         int32_t format;                 /* XA format */
00085 } TXN_DETAIL;
00086 
00087 /*
00088  * DB_TXNMGR --
00089  *      The transaction manager encapsulates the transaction system.
00090  */
00091 struct __db_txnmgr {
00092 /*
00093  * These fields need to be protected for multi-threaded support.
00094  *
00095  * !!!
00096  * As this structure is allocated in per-process memory, the mutex may need
00097  * to be stored elsewhere on architectures unable to support mutexes in heap
00098  * memory, e.g., HP/UX 9.
00099  */
00100         MUTEX           *mutexp;        /* Lock list of active transactions
00101                                          * (including the content of each
00102                                          * TXN_DETAIL structure on the list).
00103                                          */
00104                                         /* List of active transactions. */
00105         TAILQ_HEAD(_chain, __db_txn)    txn_chain;
00106 
00107 /* These fields are never updated after creation, and so not protected. */
00108         DB_ENV          *dbenv;         /* Environment. */
00109         REGINFO          reginfo;       /* Region information. */
00110 
00111         int (*recover)                  /* Recovery dispatch routine */
00112             __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
00113 };
00114 
00115 /*
00116  * DB_TXNREGION --
00117  *      The primary transaction data structure in the shared memory region.
00118  */
00119 struct __db_txnregion {
00120         u_int32_t       maxtxns;        /* maximum number of active TXNs */
00121         u_int32_t       last_txnid;     /* last transaction id given out */
00122         DB_LSN          pending_ckp;    /* last checkpoint did not finish */
00123         DB_LSN          last_ckp;       /* lsn of the last checkpoint */
00124         time_t          time_ckp;       /* time of last checkpoint */
00125         u_int32_t       logtype;        /* type of logging */
00126         u_int32_t       locktype;       /* lock type */
00127         u_int32_t       naborts;        /* number of aborted TXNs */
00128         u_int32_t       ncommits;       /* number of committed TXNs */
00129         u_int32_t       nbegins;        /* number of begun TXNs */
00130         u_int32_t       nactive;        /* number of active TXNs */
00131         u_int32_t       maxnactive;     /* maximum number of active TXNs */
00132                                         /* active TXN list */
00133         SH_TAILQ_HEAD(__active) active_txn;
00134 };
00135 
00136 /*
00137  * Make the region large enough to hold N transaction detail structures
00138  * plus some space to hold thread handles and the beginning of the shalloc
00139  * region.
00140  */
00141 #define TXN_REGION_SIZE(N)                                              \
00142         (sizeof(DB_TXNREGION) + N * sizeof(TXN_DETAIL) + 1000)
00143 
00144 /*
00145  * Log record types.
00146  */
00147 #define TXN_COMMIT      1
00148 #define TXN_PREPARE     2
00149 #define TXN_CHECKPOINT  3
00150 
00151 #include "txn_auto.h"
00152 #include "txn_ext.h"
00153 
00154 #include "xa_ext.h"
00155 #endif /* !_TXN_H_ */

Generated on Sun Jun 8 10:56:39 2008 for GNUmifluz by  doxygen 1.5.5