2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
7 * @(#)txn.h 10.11 (Sleepycat) 10/25/97
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 DB_ENV *dbenv; /* Environment. */
56 int (*recover) /* Recovery dispatch routine */
57 __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
58 int fd; /* mapped file descriptor */
59 u_int flags; /* DB_TXN_NOSYNC, DB_THREAD */
60 size_t reg_size; /* how large we think the region is */
61 DB_TXNREGION *region; /* address of shared memory region */
62 void *mem; /* address of the shalloc space */
66 * Layout of the shared memory region.
67 * The region consists of a DB_TXNREGION structure followed by a large
68 * pool of shalloc'd memory which is used to hold TXN_DETAIL structures
69 * and thread mutexes (which are dynamically allocated).
71 struct __db_txnregion {
72 RLAYOUT hdr; /* Shared memory region header. */
73 u_int32_t magic; /* transaction magic number */
74 u_int32_t version; /* version number */
75 u_int32_t maxtxns; /* maximum number of active txns */
76 u_int32_t last_txnid; /* last transaction id given out */
77 DB_LSN pending_ckp; /* last checkpoint did not finish */
78 DB_LSN last_ckp; /* lsn of the last checkpoint */
79 time_t time_ckp; /* time of last checkpoint */
80 u_int32_t logtype; /* type of logging */
81 u_int32_t locktype; /* lock type */
82 u_int32_t naborts; /* number of aborted transactions */
83 u_int32_t ncommits; /* number of committed transactions */
84 u_int32_t nbegins; /* number of begun transactions */
85 SH_TAILQ_HEAD(_active) active_txn; /* active transaction list */
89 * Make the region large enough to hold N transaction detail structures
90 * plus some space to hold thread handles and the beginning of the shalloc
93 #define TXN_REGION_SIZE(N) \
94 (sizeof(DB_TXNREGION) + N * sizeof(TXN_DETAIL) + 1000)
96 /* Macros to lock/unlock the region and threads. */
97 #define LOCK_TXNTHREAD(tmgrp) \
98 if (F_ISSET(tmgrp, DB_THREAD)) \
99 (void)__db_mutex_lock((tmgrp)->mutexp, -1)
100 #define UNLOCK_TXNTHREAD(tmgrp) \
101 if (F_ISSET(tmgrp, DB_THREAD)) \
102 (void)__db_mutex_unlock((tmgrp)->mutexp, -1)
104 #define LOCK_TXNREGION(tmgrp) \
105 (void)__db_mutex_lock(&(tmgrp)->region->hdr.lock, (tmgrp)->fd)
106 #define UNLOCK_TXNREGION(tmgrp) \
107 (void)__db_mutex_unlock(&(tmgrp)->region->hdr.lock, (tmgrp)->fd)
114 #define TXN_PREPARE 3
115 #define TXN_CHECKPOINT 4
117 #include "txn_auto.h"
119 #endif /* !_TXN_H_ */