2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
7 * @(#)txn.h 10.15 (Sleepycat) 4/21/98
13 * The name of the transaction shared memory region is DEFAULT_TXN_FILE and
14 * the region is always created group RW of the group owning the directory.
16 #define DEFAULT_TXN_FILE "__db_txn.share"
17 /* TXN_MINIMUM = (DB_LOCK_MAXID + 1) but this makes compilers complain. */
18 #define TXN_MINIMUM 0x80000000
19 #define TXN_INVALID 0xffffffff /* Maximum number of txn ids. */
22 * Transaction type declarations.
26 * Internal data maintained in shared memory for each transaction.
28 typedef struct __txn_detail
{
29 u_int32_t txnid
; /* current transaction id
30 used to link free list also */
31 DB_LSN last_lsn
; /* last lsn written for this txn */
32 DB_LSN begin_lsn
; /* lsn of begin record */
33 size_t last_lock
; /* offset in lock region of last lock
34 for this transaction. */
38 #define TXN_PREPARED 3
39 u_int32_t status
; /* status of the transaction */
40 SH_TAILQ_ENTRY links
; /* free/active list */
44 * The transaction manager encapsulates the transaction system. It contains
45 * references to the log and lock managers as well as the state that keeps
46 * track of the shared memory region.
49 /* These fields need to be protected for multi-threaded support. */
50 db_mutex_t
*mutexp
; /* Synchronization. */
51 /* list of active transactions */
52 TAILQ_HEAD(_chain
, __db_txn
) txn_chain
;
54 /* These fields are not protected. */
55 REGINFO reginfo
; /* Region information. */
56 DB_ENV
*dbenv
; /* Environment. */
57 int (*recover
) /* Recovery dispatch routine */
58 __P((DB_LOG
*, DBT
*, DB_LSN
*, int, void *));
59 u_int32_t flags
; /* DB_TXN_NOSYNC, DB_THREAD */
60 DB_TXNREGION
*region
; /* address of shared memory region */
61 void *mem
; /* address of the shalloc space */
65 * Layout of the shared memory region.
66 * The region consists of a DB_TXNREGION structure followed by a large
67 * pool of shalloc'd memory which is used to hold TXN_DETAIL structures
68 * and thread mutexes (which are dynamically allocated).
70 struct __db_txnregion
{
71 RLAYOUT hdr
; /* Shared memory region header. */
72 u_int32_t magic
; /* transaction magic number */
73 u_int32_t version
; /* version number */
74 u_int32_t maxtxns
; /* maximum number of active txns */
75 u_int32_t last_txnid
; /* last transaction id given out */
76 DB_LSN pending_ckp
; /* last checkpoint did not finish */
77 DB_LSN last_ckp
; /* lsn of the last checkpoint */
78 time_t time_ckp
; /* time of last checkpoint */
79 u_int32_t logtype
; /* type of logging */
80 u_int32_t locktype
; /* lock type */
81 u_int32_t naborts
; /* number of aborted transactions */
82 u_int32_t ncommits
; /* number of committed transactions */
83 u_int32_t nbegins
; /* number of begun transactions */
84 SH_TAILQ_HEAD(_active
) active_txn
; /* active transaction list */
88 * Make the region large enough to hold N transaction detail structures
89 * plus some space to hold thread handles and the beginning of the shalloc
92 #define TXN_REGION_SIZE(N) \
93 (sizeof(DB_TXNREGION) + N * sizeof(TXN_DETAIL) + 1000)
95 /* Macros to lock/unlock the region and threads. */
96 #define LOCK_TXNTHREAD(tmgrp) \
97 if (F_ISSET(tmgrp, DB_THREAD)) \
98 (void)__db_mutex_lock((tmgrp)->mutexp, -1)
99 #define UNLOCK_TXNTHREAD(tmgrp) \
100 if (F_ISSET(tmgrp, DB_THREAD)) \
101 (void)__db_mutex_unlock((tmgrp)->mutexp, -1)
103 #define LOCK_TXNREGION(tmgrp) \
104 (void)__db_mutex_lock(&(tmgrp)->region->hdr.lock, (tmgrp)->reginfo.fd)
105 #define UNLOCK_TXNREGION(tmgrp) \
106 (void)__db_mutex_unlock(&(tmgrp)->region->hdr.lock, (tmgrp)->reginfo.fd)
112 #define TXN_PREPARE 2
113 #define TXN_CHECKPOINT 3
115 #include "txn_auto.h"
117 #endif /* !_TXN_H_ */