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

MySQL数据库

开发平台:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  *
  7.  * $Id: db_verify.h,v 1.18 2000/12/31 17:51:52 bostic Exp $
  8.  */
  9. #ifndef _DB_VERIFY_H_
  10. #define _DB_VERIFY_H_
  11. /*
  12.  * Structures and macros for the storage and retrieval of all information
  13.  * needed for inter-page verification of a database.
  14.  */
  15. /*
  16.  * EPRINT is the macro for error printing.  Takes as an arg the arg set
  17.  * for DB->err.
  18.  */
  19. #define EPRINT(x)
  20. do {
  21. if (!LF_ISSET(DB_SALVAGE))
  22. __db_err x;
  23. } while (0)
  24. /* For fatal type errors--i.e., verifier bugs. */
  25. #define TYPE_ERR_PRINT(dbenv, func, pgno, ptype)
  26.     EPRINT(((dbenv), "%s called on nonsensical page %lu of type %lu",
  27. (func), (u_long)(pgno), (u_long)(ptype)));
  28. /* Is x a power of two?  (Tests true for zero, which doesn't matter here.) */
  29. #define POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)
  30. #define IS_VALID_PAGESIZE(x)
  31. (POWER_OF_TWO(x) && (x) >= DB_MIN_PGSIZE && ((x) <= DB_MAX_PGSIZE))
  32. /*
  33.  * Note that 0 is, in general, a valid pgno, despite equalling PGNO_INVALID;
  34.  * we have to test it separately where it's not appropriate.
  35.  */
  36. #define IS_VALID_PGNO(x) ((x) <= vdp->last_pgno)
  37. /*
  38.  * Flags understood by the btree structure checks (esp. __bam_vrfy_subtree).
  39.  * These share the same space as the global flags to __db_verify, and must not
  40.  * dip below 0x00010000.
  41.  */
  42. #define ST_DUPOK 0x00010000 /* Duplicates are acceptable. */
  43. #define ST_DUPSET 0x00020000 /* Subtree is in a duplicate tree. */
  44. #define ST_DUPSORT 0x00040000 /* Duplicates are sorted. */
  45. #define ST_IS_RECNO 0x00080000 /* Subtree is a recno. */
  46. #define ST_OVFL_LEAF 0x00100000 /* Overflow reffed from leaf page. */
  47. #define ST_RECNUM 0x00200000 /* Subtree has record numbering on. */
  48. #define ST_RELEN 0x00400000 /* Subtree has fixed-length records. */
  49. #define ST_TOPLEVEL 0x00800000 /* Subtree == entire tree */
  50. /*
  51.  * Flags understood by __bam_salvage and __db_salvage.  These need not share
  52.  * the same space with the __bam_vrfy_subtree flags, but must share with
  53.  * __db_verify.
  54.  */
  55. #define SA_SKIPFIRSTKEY 0x00080000
  56. /*
  57.  * VRFY_DBINFO is the fundamental structure;  it either represents the database
  58.  * of subdatabases, or the sole database if there are no subdatabases.
  59.  */
  60. struct __vrfy_dbinfo {
  61. /* Info about this database in particular. */
  62. DBTYPE type;
  63. /* List of subdatabase meta pages, if any. */
  64. LIST_HEAD(__subdbs, __vrfy_childinfo) subdbs;
  65. /* File-global info--stores VRFY_PAGEINFOs for each page. */
  66. DB *pgdbp;
  67. /* Child database--stores VRFY_CHILDINFOs of each page. */
  68. DB *cdbp;
  69. /* Page info structures currently in use. */
  70. LIST_HEAD(__activepips, __vrfy_pageinfo) activepips;
  71. /*
  72.  * DB we use to keep track of which pages are linked somehow
  73.  * during verification.  0 is the default, "unseen";  1 is seen.
  74.  */
  75. DB *pgset;
  76. /*
  77.  * This is a database we use during salvaging to keep track of which
  78.  * overflow and dup pages we need to come back to at the end and print
  79.  * with key "UNKNOWN".  Pages which print with a good key get set
  80.  * to SALVAGE_IGNORE;  others get set, as appropriate, to SALVAGE_LDUP,
  81.  * SALVAGE_LRECNODUP, SALVAGE_OVERFLOW for normal db overflow pages,
  82.  * and SALVAGE_BTREE, SALVAGE_LRECNO, and SALVAGE_HASH for subdb
  83.  * pages.
  84.  */
  85. #define SALVAGE_INVALID 0
  86. #define SALVAGE_IGNORE 1
  87. #define SALVAGE_LDUP 2
  88. #define SALVAGE_LRECNODUP 3
  89. #define SALVAGE_OVERFLOW 4
  90. #define SALVAGE_LBTREE 5
  91. #define SALVAGE_HASH 6
  92. #define SALVAGE_LRECNO 7
  93. DB *salvage_pages;
  94. db_pgno_t last_pgno;
  95. db_pgno_t pgs_remaining; /* For dbp->db_feedback(). */
  96. /* Queue needs these to verify data pages in the first pass. */
  97. u_int32_t re_len;
  98. u_int32_t rec_page;
  99. #define SALVAGE_PRINTHEADER 0x01
  100. #define SALVAGE_PRINTFOOTER 0x02
  101. u_int32_t flags;
  102. }; /* VRFY_DBINFO */
  103. /*
  104.  * The amount of state information we need per-page is small enough that
  105.  * it's not worth the trouble to define separate structures for each
  106.  * possible type of page, and since we're doing verification with these we
  107.  * have to be open to the possibility that page N will be of a completely
  108.  * unexpected type anyway.  So we define one structure here with all the
  109.  * info we need for inter-page verification.
  110.  */
  111. struct __vrfy_pageinfo {
  112. u_int8_t type;
  113. u_int8_t bt_level;
  114. u_int8_t unused1;
  115. u_int8_t unused2;
  116. db_pgno_t pgno;
  117. db_pgno_t prev_pgno;
  118. db_pgno_t next_pgno;
  119. /* meta pages */
  120. db_pgno_t root;
  121. db_pgno_t free; /* Free list head. */
  122. db_indx_t entries; /* Actual number of entries. */
  123. u_int16_t unused;
  124. db_recno_t rec_cnt; /* Record count. */
  125. u_int32_t re_len; /* Record length. */
  126. u_int32_t bt_minkey;
  127. u_int32_t bt_maxkey;
  128. u_int32_t h_ffactor;
  129. u_int32_t h_nelem;
  130. /* overflow pages */
  131. /*
  132.  * Note that refcount is the refcount for an overflow page; pi_refcount
  133.  * is this structure's own refcount!
  134.  */
  135. u_int32_t refcount;
  136. u_int32_t olen;
  137. #define VRFY_DUPS_UNSORTED 0x0001 /* Have to flag the negative! */
  138. #define VRFY_HAS_DUPS 0x0002
  139. #define VRFY_HAS_DUPSORT 0x0004 /* Has the flag set. */
  140. #define VRFY_HAS_SUBDBS 0x0008
  141. #define VRFY_HAS_RECNUMS 0x0010
  142. #define VRFY_INCOMPLETE 0x0020 /* Meta or item order checks incomp. */
  143. #define VRFY_IS_ALLZEROES 0x0040 /* Hash page we haven't touched? */
  144. #define VRFY_IS_FIXEDLEN 0x0080
  145. #define VRFY_IS_RECNO 0x0100
  146. #define VRFY_IS_RRECNO 0x0200
  147. #define VRFY_OVFL_LEAFSEEN 0x0400
  148. u_int32_t flags;
  149. LIST_ENTRY(__vrfy_pageinfo) links;
  150. u_int32_t pi_refcount;
  151. }; /* VRFY_PAGEINFO */
  152. struct __vrfy_childinfo {
  153. db_pgno_t pgno;
  154. #define V_DUPLICATE 1 /* off-page dup metadata */
  155. #define V_OVERFLOW 2 /* overflow page */
  156. #define V_RECNO 3 /* btree internal or leaf page */
  157. u_int32_t type;
  158. db_recno_t nrecs; /* record count on a btree subtree */
  159. u_int32_t tlen; /* ovfl. item total size */
  160. LIST_ENTRY(__vrfy_childinfo) links;
  161. }; /* VRFY_CHILDINFO */
  162. #endif /* _DB_VERIFY_H_ */