~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/include/db_verify.h

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

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