1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1996, 1997, 1998, 1999
5  *	Sleepycat Software.  All rights reserved.
6  *
7  *	@(#)log.h	11.5 (Sleepycat) 9/18/99
8  */
9 
10 #ifndef _LOG_H_
11 #define	_LOG_H_
12 
13 struct __db_log;	typedef struct __db_log DB_LOG;
14 struct __fname;		typedef struct __fname FNAME;
15 struct __hdr;		typedef struct __hdr HDR;
16 struct __log;		typedef struct __log LOG;
17 struct __log_persist;	typedef struct __log_persist LOGP;
18 
19 #ifndef MAXLFNAME
20 #define	LFPREFIX	"log."		/* Log file name prefix. */
21 #define	LFNAME		"log.%010d"	/* Log file name template. */
22 #define	LFNAME_V1	"log.%05d"	/* Log file name template, rev 1. */
23 #define	MAXLFNAME	2000000000	/* Maximum log file name. */
24 #endif
25 
26 #define	LG_MAX_DEFAULT		(10 * MEGABYTE)	/* 10 MB. */
27 #define	LG_BSIZE_DEFAULT	(32 * 1024)	/* 32 KB. */
28 #define	LG_BASE_REGION_SIZE	(60 * 1024)	/* 60 KB. */
29 
30 /*
31  * The log region isn't fixed size because we store the registered
32  * file names there.
33  */
34 #define	LOG_REGION_SIZE	(30 * 1024)
35 
36 /*
37  * The per-process table that maps log file-id's to DB structures.
38  */
39 typedef	struct __db_entry {
40 	DB	 *dbp;			/* Associated DB structure. */
41 	u_int32_t refcount;		/* Reference counted. */
42 	u_int32_t count;		/* Number of ops on a deleted db. */
43 	int	  deleted;		/* File was not found during open. */
44 } DB_ENTRY;
45 
46 /*
47  * DB_LOG
48  *	Per-process log structure.
49  */
50 struct __db_log {
51 /*
52  * These fields need to be protected for multi-threaded support.
53  *
54  * !!!
55  * As this structure is allocated in per-process memory, the mutex may need
56  * to be stored elsewhere on architectures unable to support mutexes in heap
57  * memory, e.g., HP/UX 9.
58  */
59 	MUTEX	  *mutexp;		/* Mutex for thread protection. */
60 
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. */
64 
65 /*
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
69  * on threaded logs.
70  */
71 	u_int32_t lfname;		/* Log file "name". */
72 	DB_FH	  lfh;			/* Log file handle. */
73 
74 	DB_LSN	  c_lsn;		/* Cursor: current LSN. */
75 	DBT	  c_dbt;		/* Cursor: return DBT structure. */
76 	DB_FH	  c_fh;			/* Cursor: file handle. */
77 	u_int32_t c_off;		/* Cursor: previous record offset. */
78 	u_int32_t c_len;		/* Cursor: current record length. */
79 
80 	u_int8_t *bufp;			/* Region buffer. */
81 
82 /* These fields are not protected. */
83 	DB_ENV	 *dbenv;		/* Reference to error information. */
84 	REGINFO	  reginfo;		/* Region information. */
85 
86 /*
87  * These fields are used by XA; since XA forbids threaded execution, these
88  * do not have to be protected.
89  */
90 	void 	*xa_info;		/* Committed transaction list that
91 					 * has to be carried between calls
92 					 * to xa_recover. */
93 	DB_LSN	xa_lsn;			/* Position of an XA recovery scan. */
94 	DB_LSN	xa_first;		/* LSN to which we need to roll back
95 					   for this XA recovery scan. */
96 
97 	/*
98 	 * !!!
99 	 * Currently used to hold:
100 	 *	DBC_RECOVER	(a DBC flag)
101 	 */
102 	u_int32_t flags;
103 };
104 
105 /*
106  * HDR --
107  *	Log record header.
108  */
109 struct __hdr {
110 	u_int32_t prev;			/* Previous offset. */
111 	u_int32_t cksum;		/* Current checksum. */
112 	u_int32_t len;			/* Current length. */
113 };
114 
115 struct __log_persist {
116 	u_int32_t magic;		/* DB_LOGMAGIC */
117 	u_int32_t version;		/* DB_LOGVERSION */
118 
119 	u_int32_t lg_max;		/* Maximum file size. */
120 	int	  mode;			/* Log file mode. */
121 };
122 
123 /*
124  * LOG --
125  *	Shared log region.  One of these is allocated in shared memory,
126  *	and describes the log.
127  */
128 struct __log {
129 	LOGP	  persist;		/* Persistent information. */
130 
131 	SH_TAILQ_HEAD(__fq) fq;		/* List of file names. */
132 
133 	/*
134 	 * The lsn LSN is the file offset that we're about to write and which
135 	 * we will return to the user.
136 	 */
137 	DB_LSN	  lsn;			/* LSN at current file offset. */
138 
139 	/*
140 	 * The s_lsn LSN is the last LSN that we know is on disk, not just
141 	 * written, but synced.
142 	 */
143 	DB_LSN	  s_lsn;		/* LSN of the last sync. */
144 
145 	u_int32_t len;			/* Length of the last record. */
146 
147 	u_int32_t w_off;		/* Current write offset in the file. */
148 
149 	DB_LSN	  chkpt_lsn;		/* LSN of the last checkpoint. */
150 	time_t	  chkpt;		/* Time of the last checkpoint. */
151 
152 	DB_LOG_STAT stat;		/* Log statistics. */
153 
154 	/*
155 	 * The f_lsn LSN is the LSN (returned to the user) that "owns" the
156 	 * first byte of the buffer.  If the record associated with the LSN
157 	 * spans buffers, it may not reflect the physical file location of
158 	 * the first byte of the buffer.
159 	 */
160 	DB_LSN	  f_lsn;		/* LSN of first byte in the buffer. */
161 	size_t	  b_off;		/* Current offset in the buffer. */
162 
163 	roff_t	  buffer_off;		/* Log buffer offset. */
164 	u_int32_t buffer_size;		/* Log buffer size. */
165 };
166 
167 /*
168  * FNAME --
169  *	File name and id.
170  */
171 struct __fname {
172 	SH_TAILQ_ENTRY q;		/* File name queue. */
173 
174 	u_int16_t ref;			/* Reference count. */
175 
176 	int32_t id;			/* Logging file id. */
177 	DBTYPE	  s_type;		/* Saved DB type. */
178 
179 	roff_t	  name_off;		/* Name offset. */
180 	u_int8_t  ufid[DB_FILE_ID_LEN];	/* Unique file id. */
181 };
182 
183 /* File open/close register log record opcodes. */
184 #define	LOG_CHECKPOINT	1		/* Checkpoint: file name/id dump. */
185 #define	LOG_CLOSE	2		/* File close. */
186 #define	LOG_OPEN	3		/* File open. */
187 
188 #include "log_auto.h"
189 #include "log_ext.h"
190 #endif /* _LOG_H_ */
191