db

log.h

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00005  * Sleepycat Software. All rights reserved.
00006  *
00007  * $Id: log_8h-source.html,v 1.1 2008年06月08日 10:20:10 sebdiaz Exp $
00008  */
00009 
00010 #ifndef _LOG_H_
00011 #define _LOG_H_
00012 
00013 struct __db_log; typedef struct __db_log DB_LOG;
00014 struct __fname; typedef struct __fname FNAME;
00015 struct __hdr; typedef struct __hdr HDR;
00016 struct __log; typedef struct __log LOG;
00017 struct __log_persist; typedef struct __log_persist LOGP;
00018 
00019 #ifndef MAXLFNAME
00020 #define LFPREFIX "log." /* Log file name prefix. */
00021 #define LFNAME "log.%010d" /* Log file name template. */
00022 #define LFNAME_V1 "log.%05d" /* Log file name template, rev 1. */
00023 #define MAXLFNAME 2000000000 /* Maximum log file name. */
00024 #endif
00025 
00026 #define LG_MAX_DEFAULT (10 * MEGABYTE) /* 10 MB. */
00027 #define LG_BSIZE_DEFAULT (32 * 1024) /* 32 KB. */
00028 #define LG_BASE_REGION_SIZE (60 * 1024) /* 60 KB. */
00029 
00030 /*
00031  * The log region isn't fixed size because we store the registered
00032  * file names there.
00033  */
00034 #define LOG_REGION_SIZE (30 * 1024)
00035 
00036 /*
00037  * The per-process table that maps log file-id's to DB structures.
00038  */
00039 typedef struct __db_entry {
00040 TAILQ_HEAD(dblist, __db) dblist; /* Associated DB structures. */
00041 u_int32_t refcount; /* Reference counted. */
00042 u_int32_t count; /* Number of ops on a deleted db. */
00043 int deleted; /* File was not found during open. */
00044 } DB_ENTRY;
00045 
00046 /*
00047  * DB_LOG
00048  * Per-process log structure.
00049  */
00050 struct __db_log {
00051 /*
00052  * These fields need to be protected for multi-threaded support.
00053  *
00054  * !!!
00055  * As this structure is allocated in per-process memory, the mutex may need
00056  * to be stored elsewhere on architectures unable to support mutexes in heap
00057  * memory, e.g., HP/UX 9.
00058  */
00059 MUTEX *mutexp; /* Mutex for thread protection. */
00060 
00061 DB_ENTRY *dbentry; /* Recovery file-id mapping. */
00062 #define DB_GROW_SIZE 64
00063 int32_t dbentry_cnt; /* Entries. Grows by DB_GROW_SIZE. */
00064 
00065 /*
00066  * These fields are always accessed while the region lock is held, so they do
00067  * not have to be protected by the thread lock as well, OR, they are only used
00068  * when threads are not being used, i.e. most cursor operations are disallowed
00069  * on threaded logs.
00070  */
00071 u_int32_t lfname; /* Log file "name". */
00072 DB_FH lfh; /* Log file handle. */
00073 
00074 DB_LSN c_lsn; /* Cursor: current LSN. */
00075 DBT c_dbt; /* Cursor: return DBT structure. */
00076 DB_FH c_fh; /* Cursor: file handle. */
00077 FILE *c_fp; /* Cursor: file pointer. */
00078 u_int32_t c_off; /* Cursor: previous record offset. */
00079 u_int32_t c_len; /* Cursor: current record length. */
00080 u_int32_t r_file; /* Cursor: current read file */
00081 u_int32_t r_off; /* Cursor: offset of read buffer. */
00082 u_int32_t r_size; /* Cursor: size of data in read buf. */
00083 
00084 u_int8_t *bufp; /* Region buffer. */
00085 u_int8_t *readbufp; /* Read buffer. */
00086 
00087 /* These fields are not protected. */
00088 DB_ENV *dbenv; /* Reference to error information. */
00089 REGINFO reginfo; /* Region information. */
00090 
00091 /*
00092  * These fields are used by XA; since XA forbids threaded execution, these
00093  * do not have to be protected.
00094  */
00095 void *xa_info; /* Committed transaction list that
00096  * has to be carried between calls
00097  * to xa_recover. */
00098 DB_LSN xa_lsn; /* Position of an XA recovery scan. */
00099 DB_LSN xa_first; /* LSN to which we need to roll back
00100  for this XA recovery scan. */
00101 
00102 #define DBLOG_RECOVER 0x01 /* We are in recovery. */
00103 #define DBLOG_FORCE_OPEN 0x02 /* Force the db open even
00104  * if it appears to be deleted.
00105  */
00106 u_int32_t flags;
00107 };
00108 
00109 /*
00110  * HDR --
00111  * Log record header.
00112  */
00113 struct __hdr {
00114 u_int32_t prev; /* Previous offset. */
00115 u_int32_t cksum; /* Current checksum. */
00116 u_int32_t len; /* Current length. */
00117 };
00118 
00119 struct __log_persist {
00120 u_int32_t magic; /* DB_LOGMAGIC */
00121 u_int32_t version; /* DB_LOGVERSION */
00122 
00123 u_int32_t lg_max; /* Maximum file size. */
00124 int mode; /* Log file mode. */
00125 };
00126 
00127 /*
00128  * LOG --
00129  * Shared log region. One of these is allocated in shared memory,
00130  * and describes the log.
00131  */
00132 struct __log {
00133 LOGP persist; /* Persistent information. */
00134 
00135 SH_TAILQ_HEAD(__fq) fq; /* List of file names. */
00136 
00137 /*
00138  * The lsn LSN is the file offset that we're about to write and which
00139  * we will return to the user.
00140  */
00141 DB_LSN lsn; /* LSN at current file offset. */
00142 
00143 /*
00144  * The s_lsn LSN is the last LSN that we know is on disk, not just
00145  * written, but synced.
00146  */
00147 DB_LSN s_lsn; /* LSN of the last sync. */
00148 
00149 u_int32_t len; /* Length of the last record. */
00150 
00151 u_int32_t w_off; /* Current write offset in the file. */
00152 
00153 DB_LSN chkpt_lsn; /* LSN of the last checkpoint. */
00154 time_t chkpt; /* Time of the last checkpoint. */
00155 
00156 DB_LOG_STAT stat; /* Log statistics. */
00157 
00158 /*
00159  * The f_lsn LSN is the LSN (returned to the user) that "owns" the
00160  * first byte of the buffer. If the record associated with the LSN
00161  * spans buffers, it may not reflect the physical file location of
00162  * the first byte of the buffer.
00163  */
00164 DB_LSN f_lsn; /* LSN of first byte in the buffer. */
00165 size_t b_off; /* Current offset in the buffer. */
00166 
00167 roff_t buffer_off; /* Log buffer offset. */
00168 u_int32_t buffer_size; /* Log buffer size. */
00169 };
00170 
00171 /*
00172  * FNAME --
00173  * File name and id.
00174  */
00175 struct __fname {
00176 SH_TAILQ_ENTRY q; /* File name queue. */
00177 
00178 u_int16_t ref; /* Reference count. */
00179 u_int16_t locked; /* Table is locked. */
00180 
00181 int32_t id; /* Logging file id. */
00182 DBTYPE s_type; /* Saved DB type. */
00183 
00184 roff_t name_off; /* Name offset. */
00185 db_pgno_t meta_pgno; /* Page number of the meta page. */
00186 u_int8_t ufid[DB_FILE_ID_LEN]; /* Unique file id. */
00187 };
00188 
00189 /* File open/close register log record opcodes. */
00190 #define LOG_CHECKPOINT 1 /* Checkpoint: file name/id dump. */
00191 #define LOG_CLOSE 2 /* File close. */
00192 #define LOG_OPEN 3 /* File open. */
00193 
00194 #define CHECK_LSN(redo, cmp, lsn, prev) \
00195  DB_ASSERT(!DB_REDO(redo) || cmp >=0); \
00196  if (DB_REDO(redo) && cmp < 0) { \
00197  CDB___db_err(dbenv, "Log sequence error: page LSN %lu %lu" \
00198  "previous LSN %lu %lu", lsn.file, lsn.offset, \
00199  prev.file, prev.offset); \
00200  goto out; \
00201  }
00202 
00203 #include "log_auto.h"
00204 #include "log_ext.h"
00205 #endif /* _LOG_H_ */

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by doxygen 1.5.5

AltStyle によって変換されたページ (->オリジナル) /