log.h
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:6k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1996, 1997, 1998, 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  *
  7.  * $Id: log.h,v 11.19 2001/01/11 18:19:52 bostic Exp $
  8.  */
  9. #ifndef _LOG_H_
  10. #define _LOG_H_
  11. struct __db_log; typedef struct __db_log DB_LOG;
  12. struct __fname; typedef struct __fname FNAME;
  13. struct __hdr; typedef struct __hdr HDR;
  14. struct __log; typedef struct __log LOG;
  15. struct __log_persist; typedef struct __log_persist LOGP;
  16. #define LFPREFIX "log." /* Log file name prefix. */
  17. #define LFNAME "log.%010d" /* Log file name template. */
  18. #define LFNAME_V1 "log.%05d" /* Log file name template, rev 1. */
  19. #define LG_MAX_DEFAULT (10 * MEGABYTE) /* 10 MB. */
  20. #define LG_BSIZE_DEFAULT (32 * 1024) /* 32 KB. */
  21. #define LG_BASE_REGION_SIZE (480 * 1024) /* 480 KB. */
  22. /*
  23.  * The per-process table that maps log file-id's to DB structures.
  24.  */
  25. typedef struct __db_entry {
  26. TAILQ_HEAD(dblist, __db) dblist; /* Associated DB structures. */
  27. u_int32_t refcount; /* Reference counted. */
  28. u_int32_t count; /* Number of ops on a deleted db. */
  29. int   deleted; /* File was not found during open. */
  30. } DB_ENTRY;
  31. /*
  32.  * DB_LOG
  33.  * Per-process log structure.
  34.  */
  35. struct __db_log {
  36. /*
  37.  * These fields need to be protected for multi-threaded support.
  38.  *
  39.  * !!!
  40.  * As this structure is allocated in per-process memory, the mutex may need
  41.  * to be stored elsewhere on architectures unable to support mutexes in heap
  42.  * memory, e.g., HP/UX 9.
  43.  */
  44. MUTEX   *mutexp; /* Mutex for thread protection. */
  45. DB_ENTRY *dbentry; /* Recovery file-id mapping. */
  46. #define DB_GROW_SIZE 64
  47. int32_t dbentry_cnt; /* Entries.  Grows by DB_GROW_SIZE. */
  48. /*
  49.  * These fields are always accessed while the region lock is held, so they do
  50.  * not have to be protected by the thread lock as well, OR, they are only used
  51.  * when threads are not being used, i.e. most cursor operations are disallowed
  52.  * on threaded logs.
  53.  */
  54. u_int32_t lfname; /* Log file "name". */
  55. DB_FH   lfh; /* Log file handle. */
  56. DB_LSN   c_lsn; /* Cursor: current LSN. */
  57. DBT   c_dbt; /* Cursor: return DBT structure. */
  58. DB_FH   c_fh; /* Cursor: file handle. */
  59. FILE   *c_fp; /* Cursor: file pointer. */
  60. u_int32_t c_off; /* Cursor: previous record offset. */
  61. u_int32_t c_len; /* Cursor: current record length. */
  62. u_int32_t r_file; /* Cursor: current read file */
  63. u_int32_t r_off; /* Cursor: offset of read buffer. */
  64. u_int32_t r_size; /* Cursor: size of data in read buf. */
  65. u_int8_t *bufp; /* Region buffer. */
  66. u_int8_t *readbufp; /* Read buffer. */
  67. /* These fields are not protected. */
  68. DB_ENV  *dbenv; /* Reference to error information. */
  69. REGINFO   reginfo; /* Region information. */
  70. /*
  71.  * These fields are used by XA; since XA forbids threaded execution, these
  72.  * do not have to be protected.
  73.  */
  74. void *xa_info; /* Committed transaction list that
  75.  * has to be carried between calls
  76.  * to xa_recover. */
  77. DB_LSN xa_lsn; /* Position of an XA recovery scan. */
  78. DB_LSN xa_first; /* LSN to which we need to roll back
  79.    for this XA recovery scan. */
  80. #define DBLOG_RECOVER 0x01 /* We are in recovery. */
  81. #define DBLOG_FORCE_OPEN 0x02 /* Force the db open even
  82.  * if it appears to be deleted.
  83.  */
  84. u_int32_t flags;
  85. };
  86. /*
  87.  * HDR --
  88.  * Log record header.
  89.  */
  90. struct __hdr {
  91. u_int32_t prev; /* Previous offset. */
  92. u_int32_t cksum; /* Current checksum. */
  93. u_int32_t len; /* Current length. */
  94. };
  95. struct __log_persist {
  96. u_int32_t magic; /* DB_LOGMAGIC */
  97. u_int32_t version; /* DB_LOGVERSION */
  98. u_int32_t lg_max; /* Maximum file size. */
  99. int   mode; /* Log file mode. */
  100. };
  101. /*
  102.  * LOG --
  103.  * Shared log region.  One of these is allocated in shared memory,
  104.  * and describes the log.
  105.  */
  106. struct __log {
  107. LOGP   persist; /* Persistent information. */
  108. SH_TAILQ_HEAD(__fq) fq; /* List of file names. */
  109. /*
  110.  * The lsn LSN is the file offset that we're about to write and which
  111.  * we will return to the user.
  112.  */
  113. DB_LSN   lsn; /* LSN at current file offset. */
  114. /*
  115.  * The s_lsn LSN is the last LSN that we know is on disk, not just
  116.  * written, but synced.
  117.  */
  118. DB_LSN   s_lsn; /* LSN of the last sync. */
  119. u_int32_t len; /* Length of the last record. */
  120. u_int32_t w_off; /* Current write offset in the file. */
  121. DB_LSN   chkpt_lsn; /* LSN of the last checkpoint. */
  122. time_t   chkpt; /* Time of the last checkpoint. */
  123. DB_LOG_STAT stat; /* Log statistics. */
  124. /*
  125.  * The f_lsn LSN is the LSN (returned to the user) that "owns" the
  126.  * first byte of the buffer.  If the record associated with the LSN
  127.  * spans buffers, it may not reflect the physical file location of
  128.  * the first byte of the buffer.
  129.  */
  130. DB_LSN   f_lsn; /* LSN of first byte in the buffer. */
  131. size_t   b_off; /* Current offset in the buffer. */
  132. roff_t   buffer_off; /* Log buffer offset. */
  133. u_int32_t buffer_size; /* Log buffer size. */
  134. };
  135. /*
  136.  * FNAME --
  137.  * File name and id.
  138.  */
  139. struct __fname {
  140. SH_TAILQ_ENTRY q; /* File name queue. */
  141. u_int16_t ref; /* Reference count. */
  142. u_int16_t locked; /* Table is locked. */
  143. int32_t id; /* Logging file id. */
  144. DBTYPE   s_type; /* Saved DB type. */
  145. roff_t   name_off; /* Name offset. */
  146. db_pgno_t meta_pgno; /* Page number of the meta page. */
  147. u_int8_t  ufid[DB_FILE_ID_LEN]; /* Unique file id. */
  148. };
  149. /* File open/close register log record opcodes. */
  150. #define LOG_CHECKPOINT 1 /* Checkpoint: file name/id dump. */
  151. #define LOG_CLOSE 2 /* File close. */
  152. #define LOG_OPEN 3 /* File open. */
  153. #define CHECK_LSN(redo, cmp, lsn, prev)
  154. DB_ASSERT(!DB_REDO(redo) || (cmp) >= 0);
  155. if (DB_REDO(redo) && (cmp) < 0) {
  156. __db_err(dbenv,
  157. "Log sequence error: page LSN %lu:%lu; previous LSN %lu %lu",
  158.     (u_long)(lsn)->file, (u_long)(lsn)->offset,
  159.     (u_long)(prev)->file, (u_long)(prev)->offset);
  160. goto out;
  161. }
  162. /*
  163.  * Status codes indicating the validity of a log file examined by
  164.  * __log_valid().
  165.  */
  166. typedef enum {
  167. DB_LV_INCOMPLETE,
  168. DB_LV_NORMAL,
  169. DB_LV_OLD_READABLE,
  170. DB_LV_OLD_UNREADABLE
  171. } logfile_validity;
  172. #include "log_auto.h"
  173. #include "log_ext.h"
  174. #endif /* _LOG_H_ */