bt_upgrade.c 3.52 KB
Newer Older
unknown's avatar
unknown committed
1 2 3
/*-
 * See the file LICENSE for redistribution information.
 *
unknown's avatar
unknown committed
4
 * Copyright (c) 1996-2002
unknown's avatar
unknown committed
5 6 7 8 9
 *	Sleepycat Software.  All rights reserved.
 */
#include "db_config.h"

#ifndef lint
unknown's avatar
unknown committed
10
static const char revid[] = "$Id: bt_upgrade.c,v 11.25 2002/08/06 06:11:13 bostic Exp $";
unknown's avatar
unknown committed
11 12 13 14 15 16 17 18 19 20
#endif /* not lint */

#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>

#include <limits.h>
#include <string.h>
#endif

#include "db_int.h"
unknown's avatar
unknown committed
21 22 23
#include "dbinc/db_page.h"
#include "dbinc/db_am.h"
#include "dbinc/db_upgrade.h"
unknown's avatar
unknown committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

/*
 * __bam_30_btreemeta --
 *	Upgrade the metadata pages from version 6 to version 7.
 *
 * PUBLIC: int __bam_30_btreemeta __P((DB *, char *, u_int8_t *));
 */
int
__bam_30_btreemeta(dbp, real_name, buf)
	DB *dbp;
	char *real_name;
	u_int8_t *buf;
{
	BTMETA30 *newmeta;
	BTMETA2X *oldmeta;
	DB_ENV *dbenv;
	int ret;

	dbenv = dbp->dbenv;

	newmeta = (BTMETA30 *)buf;
	oldmeta = (BTMETA2X *)buf;

	/*
	 * Move things from the end up, so we do not overwrite things.
	 * We are going to create a new uid, so we can move the stuff
	 * at the end of the structure first, overwriting the uid.
	 */

	newmeta->re_pad = oldmeta->re_pad;
	newmeta->re_len = oldmeta->re_len;
	newmeta->minkey = oldmeta->minkey;
	newmeta->maxkey = oldmeta->maxkey;
	newmeta->dbmeta.free = oldmeta->free;
	newmeta->dbmeta.flags = oldmeta->flags;
	newmeta->dbmeta.type  = P_BTREEMETA;

	newmeta->dbmeta.version = 7;
	/* Replace the unique ID. */
	if ((ret = __os_fileid(dbenv, real_name, 1, buf + 36)) != 0)
		return (ret);

	newmeta->root = 1;

	return (0);
}

/*
 * __bam_31_btreemeta --
 *	Upgrade the database from version 7 to version 8.
 *
 * PUBLIC: int __bam_31_btreemeta
 * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
 */
int
__bam_31_btreemeta(dbp, real_name, flags, fhp, h, dirtyp)
	DB *dbp;
	char *real_name;
	u_int32_t flags;
	DB_FH *fhp;
	PAGE *h;
	int *dirtyp;
{
	BTMETA31 *newmeta;
	BTMETA30 *oldmeta;

	COMPQUIET(dbp, NULL);
	COMPQUIET(real_name, NULL);
	COMPQUIET(fhp, NULL);

	newmeta = (BTMETA31 *)h;
	oldmeta = (BTMETA30 *)h;

	/*
	 * Copy the effected fields down the page.
	 * The fields may overlap each other so we
	 * start at the bottom and use memmove.
	 */
	newmeta->root = oldmeta->root;
	newmeta->re_pad = oldmeta->re_pad;
	newmeta->re_len = oldmeta->re_len;
	newmeta->minkey = oldmeta->minkey;
	newmeta->maxkey = oldmeta->maxkey;
	memmove(newmeta->dbmeta.uid,
unknown's avatar
unknown committed
108
	    oldmeta->dbmeta.uid, sizeof(oldmeta->dbmeta.uid));
unknown's avatar
unknown committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
	newmeta->dbmeta.flags = oldmeta->dbmeta.flags;
	newmeta->dbmeta.record_count = 0;
	newmeta->dbmeta.key_count = 0;
	ZERO_LSN(newmeta->dbmeta.unused3);

	/* Set the version number. */
	newmeta->dbmeta.version = 8;

	/* Upgrade the flags. */
	if (LF_ISSET(DB_DUPSORT))
		F_SET(&newmeta->dbmeta, BTM_DUPSORT);

	*dirtyp = 1;
	return (0);
}

/*
 * __bam_31_lbtree --
unknown's avatar
unknown committed
127
 *	Upgrade the database btree leaf pages.
unknown's avatar
unknown committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
 *
 * PUBLIC: int __bam_31_lbtree
 * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
 */
int
__bam_31_lbtree(dbp, real_name, flags, fhp, h, dirtyp)
	DB *dbp;
	char *real_name;
	u_int32_t flags;
	DB_FH *fhp;
	PAGE *h;
	int *dirtyp;
{
	BKEYDATA *bk;
	db_pgno_t pgno;
	db_indx_t indx;
	int ret;

	ret = 0;
	for (indx = O_INDX; indx < NUM_ENT(h); indx += P_INDX) {
unknown's avatar
unknown committed
148
		bk = GET_BKEYDATA(dbp, h, indx);
unknown's avatar
unknown committed
149
		if (B_TYPE(bk->type) == B_DUPLICATE) {
unknown's avatar
unknown committed
150
			pgno = GET_BOVERFLOW(dbp, h, indx)->pgno;
unknown's avatar
unknown committed
151 152 153
			if ((ret = __db_31_offdup(dbp, real_name, fhp,
			    LF_ISSET(DB_DUPSORT) ? 1 : 0, &pgno)) != 0)
				break;
unknown's avatar
unknown committed
154
			if (pgno != GET_BOVERFLOW(dbp, h, indx)->pgno) {
unknown's avatar
unknown committed
155
				*dirtyp = 1;
unknown's avatar
unknown committed
156
				GET_BOVERFLOW(dbp, h, indx)->pgno = pgno;
unknown's avatar
unknown committed
157 158 159 160 161 162
			}
		}
	}

	return (ret);
}