From e576521d96c07b18d21c11eb94856be126f171e8 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Wed, 17 Jun 2009 11:13:28 +0000 Subject: [PATCH] Fix for #3918. Also, fix the TRACE macros in balance_nonroot(). (CVS 6772) FossilOrigin-Name: 368e44ec2e648b04f3b817f82586ccd864e60c89 --- manifest | 15 ++++++------ manifest.uuid | 2 +- src/btree.c | 21 ++++++++++------- test/tkt3918.test | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 test/tkt3918.test diff --git a/manifest b/manifest index 81fa5a6b5b..4f691b9024 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C A\sminor\ssimplification\sto\sthe\stokenizer.\s(CVS\s6771) -D 2009-06-17T01:17:13 +C Fix\sfor\s#3918.\sAlso,\sfix\sthe\sTRACE\smacros\sin\sbalance_nonroot().\s(CVS\s6772) +D 2009-06-17T11:13:28 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 8b8fb7823264331210cddf103831816c286ba446 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -106,7 +106,7 @@ F src/auth.c 98db07c2088455797678eb1031f42d4d94d18a71 F src/backup.c ff50af53184a5fd7bdee4d620b5dabef74717c79 F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119 F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c -F src/btree.c 1edede2a80d466679754453794df2d9070bd14a8 +F src/btree.c 371458438e6436e02b50796edb124a8d0e51299f F src/btree.h f70b694e8c163227369a66863b01fbff9009f323 F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5 F src/build.c 75b57e3f4de1b34d4e1e49d350dc87febff48ba0 @@ -653,6 +653,7 @@ F test/tkt3841.test fe7451fb899bc31c5fbcee53362c621d0271e25f F test/tkt3871.test 43ecbc8d90dc83908e2a454aef345acc9d160c6f F test/tkt3879.test 2ad5bef2c87e9991ce941e054c31abe26ef7fb90 F test/tkt3911.test 74cd324f3ba653040cc6d94cc4857b290d12d633 +F test/tkt3918.test e6cdf6bfcfe9ba939d86a4238a9dc55d6eec5d42 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/trace.test 19ffbc09885c3321d56358a5738feae8587fb377 F test/trans.test d887cb07630dc39879a322d958ad8b006137485c @@ -734,7 +735,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 -P 08cca219f16efab93cb00f04d2e2f8033893e5f1 -R 7849aa14ee9aea370d50947a30a5b469 -U drh -Z 7a86c39b397e7cb764e22053087fdcff +P 18f2076ac21dd0ab343a79461837f5591f9d4d87 +R e09f9b7c30f5fb6a040ae5f6d3595072 +U danielk1977 +Z fa0237a4a1ebff673136562f4d6dd1cb diff --git a/manifest.uuid b/manifest.uuid index d62860e8ad..876cc839f6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -18f2076ac21dd0ab343a79461837f5591f9d4d87 \ No newline at end of file +368e44ec2e648b04f3b817f82586ccd864e60c89 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index c7688fd016..68c28214d9 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.630 2009/06/16 16:50:22 danielk1977 Exp $ +** $Id: btree.c,v 1.631 2009/06/17 11:13:28 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -4525,7 +4525,7 @@ static int allocateBtreePage( pTrunk = 0; TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1)); #endif - }else{ + }else if( k>0 ){ /* Extract a leaf from the trunk */ int closest; Pgno iPage; @@ -5412,7 +5412,9 @@ static int balance_nonroot( assert( sqlite3_mutex_held(pBt->mutex) ); assert( sqlite3PagerIswriteable(pParent->pDbPage) ); +#if 0 TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno)); +#endif /* At this point pParent may have at most one overflow cell. And if ** this overflow cell is present, it must be the cell with @@ -5640,6 +5642,12 @@ static int balance_nonroot( */ assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) ); + TRACE(("BALANCE: old: %d %d %d ", + apOld[0]->pgno, + nOld>=2 ? apOld[1]->pgno : 0, + nOld>=3 ? apOld[2]->pgno : 0 + )); + /* ** Allocate k new pages. Reuse old pages where possible. */ @@ -5715,10 +5723,7 @@ static int balance_nonroot( apNew[minI] = pT; } } - TRACE(("BALANCE: old: %d %d %d new: %d(%d) %d(%d) %d(%d) %d(%d) %d(%d)\n", - apOld[0]->pgno, - nOld>=2 ? apOld[1]->pgno : 0, - nOld>=3 ? apOld[2]->pgno : 0, + TRACE(("new: %d(%d) %d(%d) %d(%d) %d(%d) %d(%d)\n", apNew[0]->pgno, szNew[0], nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0, nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0, @@ -5914,8 +5919,8 @@ static int balance_nonroot( } assert( pParent->isInit ); - TRACE(("BALANCE: finished with %d: old=%d new=%d cells=%d\n", - pPage->pgno, nOld, nNew, nCell)); + TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n", + nOld, nNew, nCell)); /* ** Cleanup before returning. diff --git a/test/tkt3918.test b/test/tkt3918.test new file mode 100644 index 0000000000..c46ad8f6c1 --- /dev/null +++ b/test/tkt3918.test @@ -0,0 +1,60 @@ +# 2009 June 17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# $Id: tkt3918.test,v 1.1 2009/06/17 11:13:28 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test tkt3918.1 { + execsql { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = incremental; + CREATE TABLE t1(i, x); + } +} {} +do_test tkt3918.2 { + execsql { + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, zeroblob(248*1020 + 100)); + INSERT INTO t1 VALUES(3, zeroblob(2*1020 + 100)); + } +} {} + +# This set of statements sets up the free list so that the +# first free-list trunk page contains only a single leaf. +# The leaf page is also the last page in the database. The +# second free-list trunk page contains, amongst other things, +# page number 4. +do_test tkt3918.3 { + execsql { + DELETE FROM t1 WHERE i = 2; + DELETE FROM t1 WHERE i = 1; + DELETE FROM t1 WHERE i = 3; + } +} {} + +# Incrementally vacuum the database to reduce its size by a single +# page. This will remove the single leaf from the first page in +# the linked list of free-list trunk pages. +do_test tkt3918.4 { + execsql { PRAGMA incremental_vacuum = 1 } +} {} + +# Create another table. This operation will attempt to extract +# page 4 from the database free-list. Bug 3918 caused sqlite to +# incorrectly report corruption here. +do_test tkt3918.5 { + execsql { CREATE TABLE t2(a, b) } +} {} + +finish_test +