2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
7 * @(#)log.h 10.15 (Sleepycat) 11/2/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 MEGABYTE (1024 * 1024)
20 #define MAXLFNAME 99999 /* Maximum log file name. */
21 #define LFNAME "log.%05d" /* Log file name template. */
23 /* Default log name. */
24 #define DB_DEFAULT_LOG_FILE "__db_log.share"
26 #define DEFAULT_MAX (10 * 1048576) /* 10 Mb. */
28 /* Macros to lock/unlock the region and threads. */
29 #define LOCK_LOGTHREAD(dblp) \
30 if (F_ISSET(dblp, DB_AM_THREAD)) \
31 (void)__db_mutex_lock((dblp)->mutexp, -1)
32 #define UNLOCK_LOGTHREAD(dblp) \
33 if (F_ISSET(dblp, DB_AM_THREAD)) \
34 (void)__db_mutex_unlock((dblp)->mutexp, -1);
35 #define LOCK_LOGREGION(dblp) \
36 (void)__db_mutex_lock(&((RLAYOUT *)(dblp)->lp)->lock, (dblp)->fd)
37 #define UNLOCK_LOGREGION(dblp) \
38 (void)__db_mutex_unlock(&((RLAYOUT *)(dblp)->lp)->lock, (dblp)->fd)
41 * The per-process table that maps log file-id's to DB structures.
43 typedef struct __db_entry {
44 DB *dbp; /* Associated DB structure. */
45 int refcount; /* Reference counted. */
46 int deleted; /* File was not found during open. */
51 * Per-process log structure.
54 /* These fields need to be protected for multi-threaded support. */
55 db_mutex_t *mutexp; /* Mutex for thread protection. */
57 DB_ENTRY *dbentry; /* Recovery file-id mapping. */
58 #define DB_GROW_SIZE 64
59 u_int32_t dbentry_cnt; /* Entries. Grows by DB_GROW_SIZE. */
62 * These fields are always accessed while the region lock is held, so they do
63 * not have to be protected by the thread lock as well OR, they are only used
64 * when threads are not being used, i.e. most cursor operations are disallowed
67 u_int32_t lfname; /* Log file "name". */
68 int lfd; /* Log file descriptor. */
70 DB_LSN c_lsn; /* Cursor: current LSN. */
71 DBT c_dbt; /* Cursor: return DBT structure. */
72 int c_fd; /* Cursor: file descriptor. */
73 u_int32_t c_off; /* Cursor: previous record offset. */
74 u_int32_t c_len; /* Cursor: current record length. */
76 /* These fields are not protected. */
77 LOG *lp; /* Address of the shared LOG. */
79 DB_ENV *dbenv; /* Reference to error information. */
81 void *maddr; /* Address of mmap'd region. */
82 void *addr; /* Address of shalloc() region. */
83 int fd; /* Region file descriptor. */
85 char *dir; /* Directory argument. */
87 u_int32_t flags; /* Support the DB_AM_XXX flags. */
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. */
110 * Shared log region. One of these is allocated in shared memory,
111 * and describes the log.
114 RLAYOUT rlayout; /* General region information. */
116 LOGP persist; /* Persistent information. */
118 SH_TAILQ_HEAD(__fq) fq; /* List of file names. */
120 DB_LSN lsn; /* LSN at current file offset. */
121 DB_LSN c_lsn; /* LSN of the last checkpoint. */
122 DB_LSN s_lsn; /* LSN of the last sync. */
123 DB_LSN uw_lsn; /* LSN of 1st rec not fully on disk. */
125 u_int32_t len; /* Length of the last record. */
127 size_t b_off; /* Current offset in the buffer. */
128 u_int32_t w_off; /* Current write offset in the file. */
130 time_t chkpt; /* Time of the last checkpoint. */
132 DB_LOG_STAT stat; /* Log statistics. */
134 u_int8_t buf[4 * 1024]; /* Log buffer. */
142 SH_TAILQ_ENTRY q; /* File name queue. */
144 u_int16_t ref; /* Reference count. */
146 u_int32_t id; /* Logging file id. */
147 DBTYPE s_type; /* Saved DB type. */
149 u_int32_t fileid_off; /* Unique file id offset. */
151 size_t name_off; /* Name offset. */
154 #include "log_auto.h"