Update.
[glibc.git] / db2 / include / log.h
blob7d5161cc9dd16590ec74c8070aee712471cabad6
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
7 * @(#)log.h 10.25 (Sleepycat) 4/10/98
8 */
10 #ifndef _LOG_H_
11 #define _LOG_H_
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;
18 #ifndef MAXLFNAME
19 #define MAXLFNAME 99999 /* Maximum log file name. */
20 #define LFNAME "log.%05d" /* Log file name template. */
21 #endif
22 /* Default log name. */
23 #define DB_DEFAULT_LOG_FILE "__db_log.share"
25 #define DEFAULT_MAX (10 * MEGABYTE) /* 10 Mb. */
27 /* Macros to lock/unlock the region and threads. */
28 #define LOCK_LOGTHREAD(dblp) \
29 if (F_ISSET(dblp, DB_AM_THREAD)) \
30 (void)__db_mutex_lock((dblp)->mutexp, -1)
31 #define UNLOCK_LOGTHREAD(dblp) \
32 if (F_ISSET(dblp, DB_AM_THREAD)) \
33 (void)__db_mutex_unlock((dblp)->mutexp, -1);
34 #define LOCK_LOGREGION(dblp) \
35 (void)__db_mutex_lock(&((RLAYOUT *)(dblp)->lp)->lock, \
36 (dblp)->reginfo.fd)
37 #define UNLOCK_LOGREGION(dblp) \
38 (void)__db_mutex_unlock(&((RLAYOUT *)(dblp)->lp)->lock, \
39 (dblp)->reginfo.fd)
42 * The per-process table that maps log file-id's to DB structures.
44 typedef struct __db_entry {
45 DB *dbp; /* Associated DB structure. */
46 u_int32_t refcount; /* Reference counted. */
47 int deleted; /* File was not found during open. */
48 } DB_ENTRY;
51 * DB_LOG
52 * Per-process log structure.
54 struct __db_log {
55 /* These fields need to be protected for multi-threaded support. */
56 db_mutex_t *mutexp; /* Mutex for thread protection. */
58 DB_ENTRY *dbentry; /* Recovery file-id mapping. */
59 #define DB_GROW_SIZE 64
60 u_int32_t dbentry_cnt; /* Entries. Grows by DB_GROW_SIZE. */
63 * These fields are always accessed while the region lock is held, so they do
64 * not have to be protected by the thread lock as well OR, they are only used
65 * when threads are not being used, i.e. most cursor operations are disallowed
66 * on threaded logs.
68 u_int32_t lfname; /* Log file "name". */
69 int lfd; /* Log file descriptor. */
71 DB_LSN c_lsn; /* Cursor: current LSN. */
72 DBT c_dbt; /* Cursor: return DBT structure. */
73 int c_fd; /* Cursor: file descriptor. */
74 u_int32_t c_off; /* Cursor: previous record offset. */
75 u_int32_t c_len; /* Cursor: current record length. */
77 /* These fields are not protected. */
78 LOG *lp; /* Address of the shared LOG. */
80 DB_ENV *dbenv; /* Reference to error information. */
81 REGINFO reginfo; /* Region information. */
83 void *addr; /* Address of shalloc() region. */
85 char *dir; /* Directory argument. */
87 u_int32_t flags; /* Support the DB_AM_XXX flags. */
91 * HDR --
92 * Log record header.
94 struct __hdr {
95 u_int32_t prev; /* Previous offset. */
96 u_int32_t cksum; /* Current checksum. */
97 u_int32_t len; /* Current length. */
100 struct __log_persist {
101 u_int32_t magic; /* DB_LOGMAGIC */
102 u_int32_t version; /* DB_LOGVERSION */
104 u_int32_t lg_max; /* Maximum file size. */
105 int mode; /* Log file mode. */
109 * LOG --
110 * Shared log region. One of these is allocated in shared memory,
111 * and describes the log.
113 struct __log {
114 RLAYOUT rlayout; /* General region information. */
116 LOGP persist; /* Persistent information. */
118 SH_TAILQ_HEAD(__fq) fq; /* List of file names. */
121 * The lsn LSN is the file offset that we're about to write and which
122 * we will return to the user.
124 DB_LSN lsn; /* LSN at current file offset. */
127 * The s_lsn LSN is the last LSN that we know is on disk, not just
128 * written, but synced.
130 DB_LSN s_lsn; /* LSN of the last sync. */
132 u_int32_t len; /* Length of the last record. */
134 u_int32_t w_off; /* Current write offset in the file. */
136 DB_LSN chkpt_lsn; /* LSN of the last checkpoint. */
137 time_t chkpt; /* Time of the last checkpoint. */
139 DB_LOG_STAT stat; /* Log statistics. */
142 * The f_lsn LSN is the LSN (returned to the user) that "owns" the
143 * first byte of the buffer. If the record associated with the LSN
144 * spans buffers, it may not reflect the physical file location of
145 * the first byte of the buffer.
147 DB_LSN f_lsn; /* LSN of first byte in the buffer. */
148 size_t b_off; /* Current offset in the buffer. */
149 u_int8_t buf[4 * 1024]; /* Log buffer. */
153 * FNAME --
154 * File name and id.
156 struct __fname {
157 SH_TAILQ_ENTRY q; /* File name queue. */
159 u_int16_t ref; /* Reference count. */
161 u_int32_t id; /* Logging file id. */
162 DBTYPE s_type; /* Saved DB type. */
164 size_t name_off; /* Name offset. */
165 u_int8_t ufid[DB_FILE_ID_LEN]; /* Unique file id. */
168 /* File open/close register log record opcodes. */
169 #define LOG_CHECKPOINT 1 /* Checkpoint: file name/id dump. */
170 #define LOG_CLOSE 2 /* File close. */
171 #define LOG_OPEN 3 /* File open. */
173 #include "log_auto.h"
174 #include "log_ext.h"
175 #endif /* _LOG_H_ */