xref: /illumos-gate/usr/src/cmd/sendmail/db/include/log.h (revision 2f172c55ef76964744bc62b4500ece87f3089b4d)
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1996, 1997, 1998
5  *	Sleepycat Software.  All rights reserved.
6  *
7  *	@(#)log.h	10.30 (Sleepycat) 10/11/98
8  */
9 
10 #ifndef _LOG_H_
11 #define	_LOG_H_
12 
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;
17 
18 #ifndef MAXLFNAME
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. */
23 #endif
24 					/* Default log name. */
25 #define DB_DEFAULT_LOG_FILE	"__db_log.share"
26 
27 #define	DEFAULT_MAX	(10 * MEGABYTE)	/* 10 Mb. */
28 
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,		\
38 	    (dblp)->reginfo.fd)
39 #define	UNLOCK_LOGREGION(dblp)						\
40 	(void)__db_mutex_unlock(&((RLAYOUT *)(dblp)->lp)->lock,		\
41 	    (dblp)->reginfo.fd)
42 
43 /* Check for region catastrophic shutdown. */
44 #define	LOG_PANIC_CHECK(dblp) {						\
45 	if ((dblp)->lp->rlayout.panic)					\
46 		return (DB_RUNRECOVERY);				\
47 }
48 
49 /*
50  * The per-process table that maps log file-id's to DB structures.
51  */
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. */
57 } DB_ENTRY;
58 
59 /*
60  * DB_LOG
61  *	Per-process log structure.
62  */
63 struct __db_log {
64 /* These fields need to be protected for multi-threaded support. */
65 	db_mutex_t	*mutexp;	/* Mutex for thread protection. */
66 
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. */
70 
71 /*
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
75  * on threaded logs.
76  */
77 	u_int32_t lfname;		/* Log file "name". */
78 	int	  lfd;			/* Log file descriptor. */
79 
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. */
85 
86 /* These fields are not protected. */
87 	LOG	 *lp;			/* Address of the shared LOG. */
88 
89 	DB_ENV	 *dbenv;		/* Reference to error information. */
90 	REGINFO	  reginfo;		/* Region information. */
91 
92 	void     *addr;			/* Address of shalloc() region. */
93 
94 	char	 *dir;			/* Directory argument. */
95 
96 /*
97  * These fields are used by XA; since XA forbids threaded execution, these
98  * do not have to be protected.
99  */
100 	void 	*xa_info;		/* Committed transaction list that
101 					 * has to be carried between calls
102 					 * to xa_recover. */
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. */
106 
107 	/*
108 	 * !!!
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.
113 	 */
114 #if DB_AM_THREAD == DBC_RECOVER
115 	DB_AM_THREAD, DBC_RECOVER, FLAG MISMATCH
116 #endif
117 	u_int32_t flags;
118 };
119 
120 /*
121  * HDR --
122  *	Log record header.
123  */
124 struct __hdr {
125 	u_int32_t prev;			/* Previous offset. */
126 	u_int32_t cksum;		/* Current checksum. */
127 	u_int32_t len;			/* Current length. */
128 };
129 
130 struct __log_persist {
131 	u_int32_t magic;		/* DB_LOGMAGIC */
132 	u_int32_t version;		/* DB_LOGVERSION */
133 
134 	u_int32_t lg_max;		/* Maximum file size. */
135 	int	  mode;			/* Log file mode. */
136 };
137 
138 /*
139  * LOG --
140  *	Shared log region.  One of these is allocated in shared memory,
141  *	and describes the log.
142  */
143 struct __log {
144 	RLAYOUT	  rlayout;		/* General region information. */
145 
146 	LOGP	  persist;		/* Persistent information. */
147 
148 	SH_TAILQ_HEAD(__fq) fq;		/* List of file names. */
149 
150 	/*
151 	 * The lsn LSN is the file offset that we're about to write and which
152 	 * we will return to the user.
153 	 */
154 	DB_LSN	  lsn;			/* LSN at current file offset. */
155 
156 	/*
157 	 * The s_lsn LSN is the last LSN that we know is on disk, not just
158 	 * written, but synced.
159 	 */
160 	DB_LSN	  s_lsn;		/* LSN of the last sync. */
161 
162 	u_int32_t len;			/* Length of the last record. */
163 
164 	u_int32_t w_off;		/* Current write offset in the file. */
165 
166 	DB_LSN	  chkpt_lsn;		/* LSN of the last checkpoint. */
167 	time_t	  chkpt;		/* Time of the last checkpoint. */
168 
169 	DB_LOG_STAT stat;		/* Log statistics. */
170 
171 	/*
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.
176 	 */
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. */
180 };
181 
182 /*
183  * FNAME --
184  *	File name and id.
185  */
186 struct __fname {
187 	SH_TAILQ_ENTRY q;		/* File name queue. */
188 
189 	u_int16_t ref;			/* Reference count. */
190 
191 	u_int32_t id;			/* Logging file id. */
192 	DBTYPE	  s_type;		/* Saved DB type. */
193 
194 	size_t	  name_off;		/* Name offset. */
195 	u_int8_t  ufid[DB_FILE_ID_LEN];	/* Unique file id. */
196 };
197 
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. */
202 
203 #include "log_auto.h"
204 #include "log_ext.h"
205 #endif /* _LOG_H_ */
206