bt_upgrade.c

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

Generated on Sun Jun 8 10:56:35 2008 for GNUmifluz by  doxygen 1.5.5