Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

bt_upgrade.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: bt_upgrade.c,v 12.1 2005/06/16 20:20:23 bostic Exp $
00008  */
00009 #include "db_config.h"
00010 
00011 #ifndef NO_SYSTEM_INCLUDES
00012 #include <sys/types.h>
00013 
00014 #include <string.h>
00015 #endif
00016 
00017 #include "db_int.h"
00018 #include "dbinc/db_page.h"
00019 #include "dbinc/db_upgrade.h"
00020 #include "dbinc/btree.h"
00021 
00022 /*
00023  * __bam_30_btreemeta --
00024  *      Upgrade the metadata pages from version 6 to version 7.
00025  *
00026  * PUBLIC: int __bam_30_btreemeta __P((DB *, char *, u_int8_t *));
00027  */
00028 int
00029 __bam_30_btreemeta(dbp, real_name, buf)
00030         DB *dbp;
00031         char *real_name;
00032         u_int8_t *buf;
00033 {
00034         BTMETA30 *newmeta;
00035         BTMETA2X *oldmeta;
00036         DB_ENV *dbenv;
00037         int ret;
00038 
00039         dbenv = dbp->dbenv;
00040 
00041         newmeta = (BTMETA30 *)buf;
00042         oldmeta = (BTMETA2X *)buf;
00043 
00044         /*
00045          * Move things from the end up, so we do not overwrite things.
00046          * We are going to create a new uid, so we can move the stuff
00047          * at the end of the structure first, overwriting the uid.
00048          */
00049 
00050         newmeta->re_pad = oldmeta->re_pad;
00051         newmeta->re_len = oldmeta->re_len;
00052         newmeta->minkey = oldmeta->minkey;
00053         newmeta->maxkey = oldmeta->maxkey;
00054         newmeta->dbmeta.free = oldmeta->free;
00055         newmeta->dbmeta.flags = oldmeta->flags;
00056         newmeta->dbmeta.type  = P_BTREEMETA;
00057 
00058         newmeta->dbmeta.version = 7;
00059         /* Replace the unique ID. */
00060         if ((ret = __os_fileid(dbenv, real_name, 1, buf + 36)) != 0)
00061                 return (ret);
00062 
00063         newmeta->root = 1;
00064 
00065         return (0);
00066 }
00067 
00068 /*
00069  * __bam_31_btreemeta --
00070  *      Upgrade the database from version 7 to version 8.
00071  *
00072  * PUBLIC: int __bam_31_btreemeta
00073  * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
00074  */
00075 int
00076 __bam_31_btreemeta(dbp, real_name, flags, fhp, h, dirtyp)
00077         DB *dbp;
00078         char *real_name;
00079         u_int32_t flags;
00080         DB_FH *fhp;
00081         PAGE *h;
00082         int *dirtyp;
00083 {
00084         BTMETA31 *newmeta;
00085         BTMETA30 *oldmeta;
00086 
00087         COMPQUIET(dbp, NULL);
00088         COMPQUIET(real_name, NULL);
00089         COMPQUIET(fhp, NULL);
00090 
00091         newmeta = (BTMETA31 *)h;
00092         oldmeta = (BTMETA30 *)h;
00093 
00094         /*
00095          * Copy the effected fields down the page.
00096          * The fields may overlap each other so we
00097          * start at the bottom and use memmove.
00098          */
00099         newmeta->root = oldmeta->root;
00100         newmeta->re_pad = oldmeta->re_pad;
00101         newmeta->re_len = oldmeta->re_len;
00102         newmeta->minkey = oldmeta->minkey;
00103         newmeta->maxkey = oldmeta->maxkey;
00104         memmove(newmeta->dbmeta.uid,
00105             oldmeta->dbmeta.uid, sizeof(oldmeta->dbmeta.uid));
00106         newmeta->dbmeta.flags = oldmeta->dbmeta.flags;
00107         newmeta->dbmeta.record_count = 0;
00108         newmeta->dbmeta.key_count = 0;
00109         ZERO_LSN(newmeta->dbmeta.unused3);
00110 
00111         /* Set the version number. */
00112         newmeta->dbmeta.version = 8;
00113 
00114         /* Upgrade the flags. */
00115         if (LF_ISSET(DB_DUPSORT))
00116                 F_SET(&newmeta->dbmeta, BTM_DUPSORT);
00117 
00118         *dirtyp = 1;
00119         return (0);
00120 }
00121 
00122 /*
00123  * __bam_31_lbtree --
00124  *      Upgrade the database btree leaf pages.
00125  *
00126  * PUBLIC: int __bam_31_lbtree
00127  * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
00128  */
00129 int
00130 __bam_31_lbtree(dbp, real_name, flags, fhp, h, dirtyp)
00131         DB *dbp;
00132         char *real_name;
00133         u_int32_t flags;
00134         DB_FH *fhp;
00135         PAGE *h;
00136         int *dirtyp;
00137 {
00138         BKEYDATA *bk;
00139         db_pgno_t pgno;
00140         db_indx_t indx;
00141         int ret;
00142 
00143         ret = 0;
00144         for (indx = O_INDX; indx < NUM_ENT(h); indx += P_INDX) {
00145                 bk = GET_BKEYDATA(dbp, h, indx);
00146                 if (B_TYPE(bk->type) == B_DUPLICATE) {
00147                         pgno = GET_BOVERFLOW(dbp, h, indx)->pgno;
00148                         if ((ret = __db_31_offdup(dbp, real_name, fhp,
00149                             LF_ISSET(DB_DUPSORT) ? 1 : 0, &pgno)) != 0)
00150                                 break;
00151                         if (pgno != GET_BOVERFLOW(dbp, h, indx)->pgno) {
00152                                 *dirtyp = 1;
00153                                 GET_BOVERFLOW(dbp, h, indx)->pgno = pgno;
00154                         }
00155                 }
00156         }
00157 
00158         return (ret);
00159 }

Generated on Sun Dec 25 12:14:13 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2