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