2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
7 * @(#)log.h 10.30 (Sleepycat) 10/11/98
13 struct __fname
; typedef struct __fname FNAME
;
14 struct __hdr
; typedef struct __hdr HDR
;
15 struct __log
; typedef struct __log LOG
;
16 struct __log_persist
; typedef struct __log_persist LOGP
;
19 #define LFPREFIX "log." /* Log file name prefix. */
20 #define LFNAME "log.%010d" /* Log file name template. */
21 #define LFNAME_V1 "log.%05d" /* Log file name template, rev 1. */
22 #define MAXLFNAME 2000000000 /* Maximum log file name. */
24 /* Default log name. */
25 #define DB_DEFAULT_LOG_FILE "__db_log.share"
27 #define DEFAULT_MAX (10 * MEGABYTE) /* 10 Mb. */
29 /* Macros to lock/unlock the region and threads. */
30 #define LOCK_LOGTHREAD(dblp) \
31 if (F_ISSET(dblp, DB_AM_THREAD)) \
32 (void)__db_mutex_lock((dblp)->mutexp, -1)
33 #define UNLOCK_LOGTHREAD(dblp) \
34 if (F_ISSET(dblp, DB_AM_THREAD)) \
35 (void)__db_mutex_unlock((dblp)->mutexp, -1);
36 #define LOCK_LOGREGION(dblp) \
37 (void)__db_mutex_lock(&((RLAYOUT *)(dblp)->lp)->lock, \
39 #define UNLOCK_LOGREGION(dblp) \
40 (void)__db_mutex_unlock(&((RLAYOUT *)(dblp)->lp)->lock, \
43 /* Check for region catastrophic shutdown. */
44 #define LOG_PANIC_CHECK(dblp) { \
45 if ((dblp)->lp->rlayout.panic) \
46 return (DB_RUNRECOVERY); \
50 * The per-process table that maps log file-id's to DB structures.
52 typedef struct __db_entry
{
53 DB
*dbp
; /* Associated DB structure. */
54 char *name
; /* File name. */
55 u_int32_t refcount
; /* Reference counted. */
56 int deleted
; /* File was not found during open. */
61 * Per-process log structure.
64 /* These fields need to be protected for multi-threaded support. */
65 db_mutex_t
*mutexp
; /* Mutex for thread protection. */
67 DB_ENTRY
*dbentry
; /* Recovery file-id mapping. */
68 #define DB_GROW_SIZE 64
69 u_int32_t dbentry_cnt
; /* Entries. Grows by DB_GROW_SIZE. */
72 * These fields are always accessed while the region lock is held, so they do
73 * not have to be protected by the thread lock as well OR, they are only used
74 * when threads are not being used, i.e. most cursor operations are disallowed
77 u_int32_t lfname
; /* Log file "name". */
78 int lfd
; /* Log file descriptor. */
80 DB_LSN c_lsn
; /* Cursor: current LSN. */
81 DBT c_dbt
; /* Cursor: return DBT structure. */
82 int c_fd
; /* Cursor: file descriptor. */
83 u_int32_t c_off
; /* Cursor: previous record offset. */
84 u_int32_t c_len
; /* Cursor: current record length. */
86 /* These fields are not protected. */
87 LOG
*lp
; /* Address of the shared LOG. */
89 DB_ENV
*dbenv
; /* Reference to error information. */
90 REGINFO reginfo
; /* Region information. */
92 void *addr
; /* Address of shalloc() region. */
94 char *dir
; /* Directory argument. */
97 * These fields are used by XA; since XA forbids threaded execution, these
98 * do not have to be protected.
100 void *xa_info
; /* Committed transaction list that
101 * has to be carried between calls
103 DB_LSN xa_lsn
; /* Position of an XA recovery scan. */
104 DB_LSN xa_first
; /* LSN to which we need to roll back
105 for this XA recovery scan. */
109 * Currently used to hold:
110 * DB_AM_THREAD (a DB flag)
111 * DBC_RECOVER (a DBC flag)
112 * If they are ever the same bits, we're in serious trouble.
114 #if DB_AM_THREAD == DBC_RECOVER
115 DB_AM_THREAD
, DBC_RECOVER
, FLAG MISMATCH
125 u_int32_t prev
; /* Previous offset. */
126 u_int32_t cksum
; /* Current checksum. */
127 u_int32_t len
; /* Current length. */
130 struct __log_persist
{
131 u_int32_t magic
; /* DB_LOGMAGIC */
132 u_int32_t version
; /* DB_LOGVERSION */
134 u_int32_t lg_max
; /* Maximum file size. */
135 int mode
; /* Log file mode. */
140 * Shared log region. One of these is allocated in shared memory,
141 * and describes the log.
144 RLAYOUT rlayout
; /* General region information. */
146 LOGP persist
; /* Persistent information. */
148 SH_TAILQ_HEAD(__fq
) fq
; /* List of file names. */
151 * The lsn LSN is the file offset that we're about to write and which
152 * we will return to the user.
154 DB_LSN lsn
; /* LSN at current file offset. */
157 * The s_lsn LSN is the last LSN that we know is on disk, not just
158 * written, but synced.
160 DB_LSN s_lsn
; /* LSN of the last sync. */
162 u_int32_t len
; /* Length of the last record. */
164 u_int32_t w_off
; /* Current write offset in the file. */
166 DB_LSN chkpt_lsn
; /* LSN of the last checkpoint. */
167 time_t chkpt
; /* Time of the last checkpoint. */
169 DB_LOG_STAT stat
; /* Log statistics. */
172 * The f_lsn LSN is the LSN (returned to the user) that "owns" the
173 * first byte of the buffer. If the record associated with the LSN
174 * spans buffers, it may not reflect the physical file location of
175 * the first byte of the buffer.
177 DB_LSN f_lsn
; /* LSN of first byte in the buffer. */
178 size_t b_off
; /* Current offset in the buffer. */
179 u_int8_t buf
[4 * 1024]; /* Log buffer. */
187 SH_TAILQ_ENTRY q
; /* File name queue. */
189 u_int16_t ref
; /* Reference count. */
191 u_int32_t id
; /* Logging file id. */
192 DBTYPE s_type
; /* Saved DB type. */
194 size_t name_off
; /* Name offset. */
195 u_int8_t ufid
[DB_FILE_ID_LEN
]; /* Unique file id. */
198 /* File open/close register log record opcodes. */
199 #define LOG_CHECKPOINT 1 /* Checkpoint: file name/id dump. */
200 #define LOG_CLOSE 2 /* File close. */
201 #define LOG_OPEN 3 /* File open. */
203 #include "log_auto.h"