source: trunk/third/db/btree/bt_upgrade.c @ 17055

Revision 17055, 3.6 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17054, which included commits to RCS files with non-trunk default branches.
Line 
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#include "db_config.h"
8
9#ifndef lint
10static const char revid[] = "$Id: bt_upgrade.c,v 1.1.1.1 2002-02-11 16:29:14 ghudson Exp $";
11#endif /* not lint */
12
13#ifndef NO_SYSTEM_INCLUDES
14#include <sys/types.h>
15
16#include <errno.h>
17#include <limits.h>
18#include <string.h>
19#endif
20
21#include "db_int.h"
22#include "db_page.h"
23#include "db_swap.h"
24#include "btree.h"
25#include "db_am.h"
26#include "db_upgrade.h"
27
28/*
29 * __bam_30_btreemeta --
30 *      Upgrade the metadata pages from version 6 to version 7.
31 *
32 * PUBLIC: int __bam_30_btreemeta __P((DB *, char *, u_int8_t *));
33 */
34int
35__bam_30_btreemeta(dbp, real_name, buf)
36        DB *dbp;
37        char *real_name;
38        u_int8_t *buf;
39{
40        BTMETA30 *newmeta;
41        BTMETA2X *oldmeta;
42        DB_ENV *dbenv;
43        int ret;
44
45        dbenv = dbp->dbenv;
46
47        newmeta = (BTMETA30 *)buf;
48        oldmeta = (BTMETA2X *)buf;
49
50        /*
51         * Move things from the end up, so we do not overwrite things.
52         * We are going to create a new uid, so we can move the stuff
53         * at the end of the structure first, overwriting the uid.
54         */
55
56        newmeta->re_pad = oldmeta->re_pad;
57        newmeta->re_len = oldmeta->re_len;
58        newmeta->minkey = oldmeta->minkey;
59        newmeta->maxkey = oldmeta->maxkey;
60        newmeta->dbmeta.free = oldmeta->free;
61        newmeta->dbmeta.flags = oldmeta->flags;
62        newmeta->dbmeta.type  = P_BTREEMETA;
63
64        newmeta->dbmeta.version = 7;
65        /* Replace the unique ID. */
66        if ((ret = __os_fileid(dbenv, real_name, 1, buf + 36)) != 0)
67                return (ret);
68
69        newmeta->root = 1;
70
71        return (0);
72}
73
74/*
75 * __bam_31_btreemeta --
76 *      Upgrade the database from version 7 to version 8.
77 *
78 * PUBLIC: int __bam_31_btreemeta
79 * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
80 */
81int
82__bam_31_btreemeta(dbp, real_name, flags, fhp, h, dirtyp)
83        DB *dbp;
84        char *real_name;
85        u_int32_t flags;
86        DB_FH *fhp;
87        PAGE *h;
88        int *dirtyp;
89{
90        BTMETA31 *newmeta;
91        BTMETA30 *oldmeta;
92
93        COMPQUIET(dbp, NULL);
94        COMPQUIET(real_name, NULL);
95        COMPQUIET(fhp, NULL);
96
97        newmeta = (BTMETA31 *)h;
98        oldmeta = (BTMETA30 *)h;
99
100        /*
101         * Copy the effected fields down the page.
102         * The fields may overlap each other so we
103         * start at the bottom and use memmove.
104         */
105        newmeta->root = oldmeta->root;
106        newmeta->re_pad = oldmeta->re_pad;
107        newmeta->re_len = oldmeta->re_len;
108        newmeta->minkey = oldmeta->minkey;
109        newmeta->maxkey = oldmeta->maxkey;
110        memmove(newmeta->dbmeta.uid,
111             oldmeta->dbmeta.uid, sizeof(oldmeta->dbmeta.uid));
112        newmeta->dbmeta.flags = oldmeta->dbmeta.flags;
113        newmeta->dbmeta.record_count = 0;
114        newmeta->dbmeta.key_count = 0;
115        ZERO_LSN(newmeta->dbmeta.alloc_lsn);
116
117        /* Set the version number. */
118        newmeta->dbmeta.version = 8;
119
120        /* Upgrade the flags. */
121        if (LF_ISSET(DB_DUPSORT))
122                F_SET(&newmeta->dbmeta, BTM_DUPSORT);
123
124        *dirtyp = 1;
125        return (0);
126}
127
128/*
129 * __bam_31_lbtree --
130 *      Upgrade the database btree leaf pages.
131 *
132 * PUBLIC: int __bam_31_lbtree
133 * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
134 */
135int
136__bam_31_lbtree(dbp, real_name, flags, fhp, h, dirtyp)
137        DB *dbp;
138        char *real_name;
139        u_int32_t flags;
140        DB_FH *fhp;
141        PAGE *h;
142        int *dirtyp;
143{
144        BKEYDATA *bk;
145        db_pgno_t pgno;
146        db_indx_t indx;
147        int ret;
148
149        ret = 0;
150        for (indx = O_INDX; indx < NUM_ENT(h); indx += P_INDX) {
151                bk = GET_BKEYDATA(h, indx);
152                if (B_TYPE(bk->type) == B_DUPLICATE) {
153                        pgno = GET_BOVERFLOW(h, indx)->pgno;
154                        if ((ret = __db_31_offdup(dbp, real_name, fhp,
155                            LF_ISSET(DB_DUPSORT) ? 1 : 0, &pgno)) != 0)
156                                break;
157                        if (pgno != GET_BOVERFLOW(h, indx)->pgno) {
158                                *dirtyp = 1;
159                                GET_BOVERFLOW(h, indx)->pgno = pgno;
160                        }
161                }
162        }
163
164        return (ret);
165}
Note: See TracBrowser for help on using the repository browser.