2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
7 * @(#)log.h 10.9 (Sleepycat) 9/23/97
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 #define MAXLFNAME 99999 /* Maximum log file name. */
19 #define LFNAME "log.%05d" /* Log file name template. */
21 /* Default log name. */
22 #define DB_DEFAULT_LOG_FILE "__db_log.share"
24 #define DEFAULT_MAX (10 * 1048576) /* 10 Mb. */
26 /* Macros to return per-process address, offsets. */
27 #define ADDR(base, offset) ((void *)((u_int8_t *)((base)->addr) + offset))
28 #define OFFSET(base, p) ((u_int8_t *)(p) - (u_int8_t *)(base)->addr)
30 /* Macros to lock/unlock the region and threads. */
31 #define LOCK_LOGTHREAD(dblp) \
32 if (F_ISSET(dblp, DB_AM_THREAD)) \
33 (void)__db_mutex_lock((dblp)->mutexp, -1, \
34 (dblp)->dbenv == NULL ? NULL : (dblp)->dbenv->db_yield)
35 #define UNLOCK_LOGTHREAD(dblp) \
36 if (F_ISSET(dblp, DB_AM_THREAD)) \
37 (void)__db_mutex_unlock((dblp)->mutexp, -1);
38 #define LOCK_LOGREGION(dblp) \
39 (void)__db_mutex_lock(&((RLAYOUT *)(dblp)->lp)->lock, \
40 (dblp)->fd, (dblp)->dbenv == NULL ? NULL : (dblp)->dbenv->db_yield)
41 #define UNLOCK_LOGREGION(dblp) \
42 (void)__db_mutex_unlock(&((RLAYOUT *)(dblp)->lp)->lock, (dblp)->fd)
45 * The per-process table that maps log file-id's to DB structures.
47 typedef struct __db_entry {
48 DB *dbp; /* Associated DB structure. */
49 int refcount; /* Reference counted. */
50 int deleted; /* File was not found during open. */
55 * Per-process log structure.
58 /* These fields need to be protected for multi-threaded support. */
59 db_mutex_t *mutexp; /* Mutex for thread protection. */
61 DB_ENTRY *dbentry; /* Recovery file-id mapping. */
62 #define DB_GROW_SIZE 64
63 u_int32_t dbentry_cnt; /* Entries. Grows by DB_GROW_SIZE. */
66 * These fields are always accessed while the region lock is held, so they do
67 * not have to be protected by the thread lock as well OR, they are only used
68 * when threads are not being used, i.e. most cursor operations are disallowed
71 u_int32_t lfname; /* Log file "name". */
72 int lfd; /* Log file descriptor. */
74 DB_LSN c_lsn; /* Cursor: current LSN. */
75 DBT c_dbt; /* Cursor: return DBT structure. */
76 int c_fd; /* Cursor: file descriptor. */
77 u_int32_t c_off; /* Cursor: previous record offset. */
78 u_int32_t c_len; /* Cursor: current record length. */
80 /* These fields are not protected. */
81 LOG *lp; /* Address of the shared LOG. */
83 DB_ENV *dbenv; /* Reference to error information. */
85 void *maddr; /* Address of mmap'd region. */
86 void *addr; /* Address of shalloc() region. */
87 int fd; /* Region file descriptor. */
89 char *dir; /* Directory argument. */
91 u_int32_t flags; /* Support the DB_AM_XXX flags. */
99 u_int32_t prev; /* Previous offset. */
100 u_int32_t cksum; /* Current checksum. */
101 u_int32_t len; /* Current length. */
104 struct __log_persist {
105 u_int32_t magic; /* DB_LOGMAGIC */
106 u_int32_t version; /* DB_LOGVERSION */
108 u_int32_t lg_max; /* Maximum file size. */
109 int mode; /* Log file mode. */
114 * Shared log region. One of these is allocated in shared memory,
115 * and describes the log.
118 RLAYOUT rlayout; /* General region information. */
120 LOGP persist; /* Persistent information. */
122 SH_TAILQ_HEAD(__fq) fq; /* List of file names. */
124 DB_LSN lsn; /* LSN at current file offset. */
125 DB_LSN c_lsn; /* LSN of the last checkpoint. */
126 DB_LSN s_lsn; /* LSN of the last sync. */
127 DB_LSN span_lsn; /* LSN spanning buffer write. */
129 u_int32_t len; /* Length of the last record. */
131 size_t b_off; /* Current offset in the buffer. */
132 u_int32_t w_off; /* Current write offset in the file. */
134 time_t chkpt; /* Time of the last checkpoint. */
135 u_int32_t written; /* Bytes written since checkpoint. */
137 u_int8_t buf[4 * 1024]; /* Log buffer. */
145 SH_TAILQ_ENTRY q; /* File name queue. */
147 u_int16_t ref; /* Reference count. */
149 u_int32_t id; /* Logging file id. */
150 DBTYPE s_type; /* Saved DB type. */
152 u_int32_t fileid_off; /* Unique file id offset. */
154 size_t name_off; /* Name offset. */
157 #include "log_auto.h"