From 732c817f8b6b90304412d0fda7abbb9a881b9adb Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 16 Jun 2007 11:17:45 +0000 Subject: [PATCH] A minor logic correction in the previous check-in. Also added a lengthy comment describing the meanings of various flags in the {quote: PgHdr} structure. (CVS 4080) FossilOrigin-Name: 57bf8204cde47dfeb31c064f2b128b9a8d94189f --- manifest | 12 ++++---- manifest.uuid | 2 +- src/pager.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 81 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 584b41bf23..6db6574913 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sdatabase\scorruption\sproblem\sthat\scan\soccur\sin\sauto-vacuum\smode\swhen\na\smalloc()\sfailure\scauses\sa\sstatement\srollback,\sadditional\sstatements\nare\srun\sin\sthe\ssame\stransaction,\sthen\sthe\stotal\stransaction\srolls\sback.\s(CVS\s4079) -D 2007-06-16T04:42:12 +C A\sminor\slogic\scorrection\sin\sthe\sprevious\scheck-in.\s\sAlso\sadded\sa\slengthy\r\ncomment\sdescribing\sthe\smeanings\sof\svarious\sflags\sin\sthe\s\r\n{quote:\sPgHdr}\sstructure.\s(CVS\s4080) +D 2007-06-16T11:17:46 F Makefile.in b9971ab07868cf2b3209fe3bf8c52e7e25af4193 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -94,7 +94,7 @@ F src/os_unix.c f2ccf2e9a925fc679faf7a8fe85700e0f13cf0e1 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c d868d5f9e95ec9c1b9e2a30c54c996053db6dddd F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c a8e5c2fd00737ddd7d8c8416d0fdbbf904d78b64 +F src/pager.c d7e2b57f573aa3e4183c6112a4e7b5dd480b25e1 F src/pager.h 94110a5570dca30d54a883e880a3633b2e4c05ae F src/parse.y 2ed1d91fdcb4ae7ae7d1f4674544297807c7cc26 F src/pragma.c 0d25dad58bdfd6789943a10f1b9663c2eb85b96d @@ -506,7 +506,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P dcdb20f81ae923f6f56d75c7b8b89a0b3abff954 -R e52cc159103410bf628cb2caa9ba87b2 +P c9dcf2b926c99ff9cee68589f364461ab2a1d11f +R 74c0238a5e30e1bd72611d04385a904b U drh -Z 5e8ccb501c2183f5e479995480e6033d +Z 50e1ec7f55bb4b42bf19c7a688ba2066 diff --git a/manifest.uuid b/manifest.uuid index 67410fda45..fff2b6d068 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c9dcf2b926c99ff9cee68589f364461ab2a1d11f \ No newline at end of file +57bf8204cde47dfeb31c064f2b128b9a8d94189f \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 94432b6164..e264f6fe6f 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.345 2007/06/16 04:42:12 drh Exp $ +** @(#) $Id: pager.c,v 1.346 2007/06/16 11:17:46 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -150,6 +150,78 @@ ** The PgHdr.dirty flag is set when sqlite3PagerWrite() is called and ** is cleared again when the page content is written back to the original ** database file. +** +** Details of important structure elements: +** +** needSync +** +** If this is true, this means that it is not safe to write the page +** content to the database because the original content needed +** for rollback has not by synced to the main rollback journal. +** The original content may have been written to the rollback journal +** but it has not yet been synced. So we cannot write to the database +** file because power failure might cause the page in the journal file +** to never reach the disk. It is as if the write to the journal file +** does not occur until the journal file is synced. +** +** This flag is false if the page content exactly matches what +** currently exists in the database file. The needSync flag is also +** false if the original content has been written to the main rollback +** journal and synced. If the page represents a new page that has +** been added onto the end of the database during the current +** transaction, the needSync flag is true until the original database +** size in the journal header has been synced to disk. +** +** inJournal +** +** This is true if the original page has been written into the main +** rollback journal. This is always false for new pages added to +** the end of the database file during the current transaction. +** And this flag says nothing about whether or not the journal +** has been synced to disk. For pages that are in the original +** database file, the following expression should always be true: +** +** inJournal = (pPager->aInJournal[(pgno-1)/8] & (1<<((pgno-1)%8))!=0 +** +** The pPager->aInJournal[] array is only valid for the original +** pages of the database, not new pages that are added to the end +** of the database, so obviously the above expression cannot be +** valid for new pages. For new pages inJournal is always 0. +** +** dirty +** +** When true, this means that the content of the page has been +** modified and needs to be written back to the database file. +** If false, it means that either the content of the page is +** unchanged or else the content is unimportant and we do not +** care whether or not it is preserved. +** +** alwaysRollback +** +** This means that the sqlite3PagerDontRollback() API should be +** ignored for this page. The DontRollback() API attempts to say +** that the content of the page on disk is unimportant (it is an +** unused page on the freelist) so that it is unnecessary to +** rollback changes to this page because the content of the page +** can change without changing the meaning of the database. This +** flag overrides any DontRollback() attempt. This flag is set +** when a page that originally contained valid data is added to +** the freelist. Later in the same transaction, this page might +** be pulled from the freelist and reused for something different +** and at that point the DontRollback() API will be called because +** pages taken from the freelist do not need to be protected by +** the rollback journal. But this flag says that the page was +** not originally part of the freelist so that it still needs to +** be rolled back in spite of any subsequent DontRollback() calls. +** +** needRead +** +** This flag means (when true) that the content of the page has +** not yet been loaded from disk. The in-memory content is just +** garbage. (Actually, we zero the content, but you should not +** make any assumptions about the content nevertheless.) If the +** content is needed in the future, it should be read from the +** original database file. */ typedef struct PgHdr PgHdr; struct PgHdr { @@ -4299,11 +4371,9 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){ } if( pPager->aInJournal && (int)pgno<=pPager->origDbSize ){ pPg->inJournal = (pPager->aInJournal[pgno/8] & (1<<(pgno&7)))!=0; - }else if( (int)pgno>=pPager->origDbSize ){ - pPg->inJournal = 1; }else{ pPg->inJournal = 0; - assert( pPg->needSync==0 ); + assert( pPg->needSync==0 || (int)pgno>pPager->origDbSize ); } /* Change the page number for pPg and insert it into the new hash-chain. */