-C Drop\ssupport\sfor\sMAC\sOS9.\s\sSQLite\s3\shas\snever\sworked\sfor\sthat\sOS\sbecause\nthe\sdevelopers\sdo\snot\shave\saccess\sto\sa\smachine\srunning\sit\sand\snobody\sfrom\nthe\scommunity\shas\sstepped\sforward\sto\sprovide\sa\sport.\s\sBy\smoving\sthe\nos_mac.c\sfile\sinto\sthe\sattic,\swe\smake\sthe\slack\sof\ssupport\sofficial.\s(CVS\s2220)
-D 2005-01-16T20:47:41
+C Turn\son\squick-balance\sby\sdefault.\s(CVS\s2221)
+D 2005-01-16T23:21:00
F Makefile.in 78d6d0af3725aef32468ac9923444d7645d21a28
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689
F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea
-F src/btree.c 4a9313065dcfb31c702158ed4c5c0e1ed69889a8
+F src/btree.c 528a661ae10ee7513b3db724a4acfd0e90991798
F src/btree.h 74d19cf40ab49fd69abe9e4e12a6c321ad86c497
F src/build.c af1296e8a21a406b4f4c4f1e1365e075071219f3
F src/cursor.c f883813759742068890b1f699335872bfa8fdf41
F test/collate5.test 7999fb3122386bae38acd8ccd61e0b7c5a30e289
F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
F test/conflict.test c5b849b01cfbe0a4f63a90cba6f68e2fe3a75f87
-F test/corrupt.test 0080ddcece23e8ba47c44608c4fb73fd4d1d8ce2
+F test/corrupt.test 4b289dfd45b5987a4f12bef9693c49e42b6e76ea
F test/corrupt2.test cb1f813df7559de3021e01170af0bba31507a9a5
F test/crash.test fa5d79ece85e8f6677bd81703db5f869a15963aa
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
-P 6237c294d1211d5848bafb1310574e2486a43757
-R ca099b3c791f0b796eb74e72a082b2c7
+P de9ad673d037f7bfca3a2d439259a63c9ed954db
+R a3c633ca18ad9c504d2c45368f1d4e12
U drh
-Z 5cc4e0ef8392da0ae950aaff44fc3d28
+Z 9410eca575f29e730c32c01825919813
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.237 2005/01/16 11:07:07 danielk1977 Exp $
+** $Id: btree.c,v 1.238 2005/01/16 23:21:00 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
u8 isValid; /* TRUE if points to a valid entry */
};
+/*
+** The TRACE macro will print high-level status information about the
+** btree operation when the global variable sqlite3_btree_trace is
+** enabled.
+*/
+#if SQLITE_TEST
+# define TRACE(X) if( sqlite3_btree_trace )\
+ { sqlite3DebugPrintf X; fflush(stdout); }
+#else
+# define TRACE(X)
+#endif
+int sqlite3_btree_trace=0; /* True to enable tracing */
+
/*
** Forward declaration
*/
static int checkReadLocks(Btree*,Pgno,BtCursor*);
-
/*
** Read or write a two- and four-byte big-endian integer values.
*/
#define PTRMAP_ISPAGE(pgsz, pgno) (PTRMAP_PAGENO(pgsz,pgno)==pgno)
/*
-** The pointer map is a lookup table that contains an entry for each database
-** page in the file except for page 1. In this context 'database page' refers
-** to any page that is not part of the pointer map itself. Each pointer map
-** entry consists of a single byte 'type' and a 4 byte page number. The
-** PTRMAP_XXX identifiers below are the valid types. The interpretation
-** of the page-number depends on the type, as follows:
+** The pointer map is a lookup table that identifies the parent page for
+** each child page in the database file. The parent page is the page that
+** contains a pointer to the child. Every page in the database contains
+** 0 or 1 parent pages. (In this context 'database page' refers
+** to any page that is not part of the pointer map itself.) Each pointer map
+** entry consists of a single byte 'type' and a 4 byte parent page number.
+** The PTRMAP_XXX identifiers below are the valid types.
+**
+** The purpose of the pointer map is to facility moving pages from one
+** position in the file to another as part of autovacuum. When a page
+** is moved, the pointer in its parent must be updated to point to the
+** new location. The pointer map is used to locate the parent page quickly.
**
** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
** used in this case.
** so that it maps to type 'eType' and parent page number 'pgno'.
** An error code is returned if something goes wrong, otherwise SQLITE_OK.
*/
-static int ptrmapPut(Btree *pBt, Pgno key, u8 eType, Pgno pgno){
+static int ptrmapPut(Btree *pBt, Pgno key, u8 eType, Pgno parent){
u8 *pPtrmap; /* The pointer map page */
Pgno iPtrmap; /* The pointer map page number */
int offset; /* Offset in pointer map page */
}
offset = PTRMAP_PTROFFSET(pBt->usableSize, key);
- if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=pgno ){
+ if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
+ TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
rc = sqlite3pager_write(pPtrmap);
if( rc!=0 ){
return rc;
}
pPtrmap[offset] = eType;
- put4byte(&pPtrmap[offset+1], pgno);
+ put4byte(&pPtrmap[offset+1], parent);
}
sqlite3pager_unref(pPtrmap);
return rc;
}
-/*
-** The TRACE macro will print high-level status information about the
-** btree operation when the global variable sqlite3_btree_trace is
-** enabled.
-*/
-#if SQLITE_TEST
-# define TRACE(X) if( sqlite3_btree_trace )\
- { sqlite3DebugPrintf X; fflush(stdout); }
-#else
-# define TRACE(X)
-#endif
-int sqlite3_btree_trace=0; /* True to enable tracing */
-
#ifndef SQLITE_OMIT_AUTOVACUUM
/*
/* Forward reference */
static int balance(MemPage*, int);
+#ifndef SQLITE_OMIT_QUICKBALANCE
/*
** This version of balance() handles the common special case where
** a new entry is being inserted on the extreme right-end of the
releasePage(pNew);
return balance(pParent, 0);
}
+#endif /* SQLITE_OMIT_QUICKBALANCE */
/*
** The ISAUTOVACUUM macro is used within balance_nonroot() to determine
assert( pParent );
TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
-#ifdef SQLITE_BALANCE_QUICK
+#ifndef SQLITE_OMIT_QUICKBALANCE
/*
** A special case: If a new entry has just been inserted into a
** table (that is, a btree with integer keys and all data at the leaves)
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
-# $Id: corrupt.test,v 1.1 2004/08/30 16:52:19 drh Exp $
+# $Id: corrupt.test,v 1.2 2005/01/16 23:21:00 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
}
} {ok}
-# Copy a file
+# Copy file $from into $to
#
proc copy_file {from to} {
set f [open $from]
close $f
}
-# Setup for the tests.
+# Setup for the tests. Make a backup copy of the good database in test.bu.
+# Create a string of garbage data that is 256 bytes long.
+#
copy_file test.db test.bu
set fsize [file size test.db]
set junk "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while {[string length $junk]<256} {append junk $junk}
set junk [string range $junk 0 255]
-
+# Go through the database and write garbage data into each 256 segment
+# of the file. Then do various operations on the file to make sure that
+# the database engine can recover gracefully from the corruption.
+#
for {set i [expr {1*256}]} {$i<$fsize-256} {incr i 256} {
set tn [expr {$i/256}]
db close
catchsql {DROP TABLE t1}
set x {}
} {}
-if {$tn==724} btree_breakpoint
do_test corrupt-2.$tn.7 {
catchsql {PRAGMA integrity_check}
set x {}