Allow SQLITE_PAGE_SIZE to be redefined on the compiler command-line. (CVS 1217)

FossilOrigin-Name: 4c7bf714b5f3d2bb7366367ddf906141a7e36407
This commit is contained in:
drh 2004-02-10 01:54:28 +00:00
parent f620b4e2cb
commit d0ba193dc7
7 changed files with 119 additions and 103 deletions

View File

@ -1,5 +1,5 @@
C After\scode\sis\sgenerated\sfor\sa\ssubquery,\sdelete\sthe\sSelect\sstructure\sin\sorder\nto\sforce\sthe\stemporary\stable\sto\sbe\sused\sand\sto\sprevent\sthe\ssubquery\sfrom\nbeing\sevaluated\sa\ssecond\stime.\s\sTicket\s#601.\s(CVS\s1216)
D 2004-02-09T14:37:50
C Allow\sSQLITE_PAGE_SIZE\sto\sbe\sredefined\son\sthe\scompiler\scommand-line.\s(CVS\s1217)
D 2004-02-10T01:54:28
F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -23,7 +23,7 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/attach.c 4a0a3c0885fec11a0a199a8031694d08925d0a27
F src/auth.c c59ad0dab501888f8b1fccc25e2f5965d2265116
F src/btree.c 9ab30f0504ef69ba4cba2f264d8096c5abc2b7b8
F src/btree.c 26d10f3149311665b2373273ca1cce29c3bc042f
F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048
F src/btree_rb.c 50210dfd2a5f410c8624ef8fde8e82babd376d9f
F src/build.c 0fdb0ce4bd87419b3930d0279e8277c4f9f69c1f
@ -40,8 +40,8 @@ F src/main.c 808ea1bda0798f4a714479aee8289d65f04cf29b
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
F src/os.c 681ec36217bc7c795d55d9a63ff79a8614ddee8c
F src/os.h 8d02b622153d2df442da1ec37cdd6b1bd9804a25
F src/pager.c 71d17c231d1bec68190be088a9652d31294ec30f
F src/pager.h 767867c835ebc29bb8929c50e6036ae8e79d534a
F src/pager.c cde4fd5a47b5109a26d44ac9daac94c0ea8e100d
F src/pager.h b618354fa6270a87e0105be8aeaa0a0c7c545ee2
F src/parse.y 7a121554c0c0c0150a77ab05417b01fa44813ac4
F src/pragma.c 89d62c31c6f0a43376fe8d20549b87a6d30c467a
F src/printf.c 84e4ea4ba49cbbf930e95e82295127ad5843ae1f
@ -53,7 +53,7 @@ F src/sqliteInt.h c5b727d5d07b88654c204c0fc1ae79c9f635a008
F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
F src/tclsqlite.c 30afbb2e446d193d867e49fb0ca5ed84f1e0867f
F src/test1.c 56e9a156df3ad5e4e98df776776e963effc727f7
F src/test2.c 5014337d8576b731cce5b5a14bec4f0daf432700
F src/test2.c 75819b0f2c63c6a0fd6995445881f2eb94036996
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
F src/test4.c dcbbbb382626fd466a7c46907f74db35fc8bad64
F src/tokenize.c 8c95dcd2620b18dc0db1cdc97f9e111d11e55fe0
@ -73,7 +73,7 @@ F test/auth.test 5c4d95cdaf539c0c236e20ce1f71a93e7dde9185
F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
F test/bind.test 56a57043b42c4664ca705f6050e56717a8a6699a
F test/btree.test 1e3463c7838e7e71bbf37c9c6e45beee9c8975ba
F test/btree.test 677aeaac7b7b81980b446ca9cab15aa0cc5550d5
F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
F test/btree3.test e597fb59be2ac0ea69c62aaa2064e998e528b665
F test/btree3rb.test 127efcf5cdfcc352054e7db12622b01cdd8b36ac
@ -183,7 +183,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 096312dacb9eb2f8da3cec1504aef8629b505e7f
R 485fc15d5916c254834a6d63a2aa701b
P 1cff18868dab5f8ead8ed8d07e088d7fdda04569
R 2282b1880e3a49fd92893af5cc842432
U drh
Z 235197ea178a89eec5c2077e08869e28
Z 382396977f47fa557ea3e3bc564ad2a2

View File

@ -1 +1 @@
1cff18868dab5f8ead8ed8d07e088d7fdda04569
4c7bf714b5f3d2bb7366367ddf906141a7e36407

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.98 2004/01/01 12:33:43 drh Exp $
** $Id: btree.c,v 1.99 2004/02/10 01:54:28 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@ -210,13 +210,13 @@ struct CellHdr {
** The maximum number of database entries that can be held in a single
** page of the database.
*/
#define MX_CELL ((SQLITE_PAGE_SIZE-sizeof(PageHdr))/MIN_CELL_SIZE)
#define MX_CELL ((SQLITE_USABLE_SIZE-sizeof(PageHdr))/MIN_CELL_SIZE)
/*
** The amount of usable space on a single page of the BTree. This is the
** page size minus the overhead of the page header.
*/
#define USABLE_SPACE (SQLITE_PAGE_SIZE - sizeof(PageHdr))
#define USABLE_SPACE (SQLITE_USABLE_SIZE - sizeof(PageHdr))
/*
** The maximum amount of payload (in bytes) that can be stored locally for
@ -261,7 +261,7 @@ struct FreeBlk {
/*
** The number of bytes of payload that will fit on a single overflow page.
*/
#define OVERFLOW_SIZE (SQLITE_PAGE_SIZE-sizeof(Pgno))
#define OVERFLOW_SIZE (SQLITE_USABLE_SIZE-sizeof(Pgno))
/*
** When the key and data for a single entry in the BTree will not fit in
@ -319,7 +319,7 @@ struct FreelistInfo {
** The pageDestructor() routine handles that chore.
*/
struct MemPage {
union {
union u_page_data {
char aDisk[SQLITE_PAGE_SIZE]; /* Page data stored on disk */
PageHdr hdr; /* Overlay page header */
} u;
@ -338,7 +338,7 @@ struct MemPage {
** to the end. EXTRA_SIZE is the number of bytes of space needed to hold
** that extra information.
*/
#define EXTRA_SIZE (sizeof(MemPage)-SQLITE_PAGE_SIZE)
#define EXTRA_SIZE (sizeof(MemPage)-sizeof(union u_page_data))
/*
** Everything we need to know about an open database
@ -421,7 +421,7 @@ static int cellSize(Btree *pBt, Cell *pCell){
static void defragmentPage(Btree *pBt, MemPage *pPage){
int pc, i, n;
FreeBlk *pFBlk;
char newPage[SQLITE_PAGE_SIZE];
char newPage[SQLITE_USABLE_SIZE];
assert( sqlitepager_iswriteable(pPage) );
assert( pPage->isInit );
@ -434,7 +434,7 @@ static void defragmentPage(Btree *pBt, MemPage *pPage){
/* This routine should never be called on an overfull page. The
** following asserts verify that constraint. */
assert( Addr(pCell) > Addr(pPage) );
assert( Addr(pCell) < Addr(pPage) + SQLITE_PAGE_SIZE );
assert( Addr(pCell) < Addr(pPage) + SQLITE_USABLE_SIZE );
n = cellSize(pBt, pCell);
pCell->h.iNext = SWAB16(pBt, pc + n);
@ -442,16 +442,16 @@ static void defragmentPage(Btree *pBt, MemPage *pPage){
pPage->apCell[i] = (Cell*)&pPage->u.aDisk[pc];
pc += n;
}
assert( pPage->nFree==SQLITE_PAGE_SIZE-pc );
assert( pPage->nFree==SQLITE_USABLE_SIZE-pc );
memcpy(pPage->u.aDisk, newPage, pc);
if( pPage->nCell>0 ){
pPage->apCell[pPage->nCell-1]->h.iNext = 0;
}
pFBlk = (FreeBlk*)&pPage->u.aDisk[pc];
pFBlk->iSize = SWAB16(pBt, SQLITE_PAGE_SIZE - pc);
pFBlk->iSize = SWAB16(pBt, SQLITE_USABLE_SIZE - pc);
pFBlk->iNext = 0;
pPage->u.hdr.firstFree = SWAB16(pBt, pc);
memset(&pFBlk[1], 0, SQLITE_PAGE_SIZE - pc - sizeof(FreeBlk));
memset(&pFBlk[1], 0, SQLITE_USABLE_SIZE - pc - sizeof(FreeBlk));
}
/*
@ -483,7 +483,7 @@ static int allocateSpace(Btree *pBt, MemPage *pPage, int nByte){
pIdx = &pPage->u.hdr.firstFree;
p = (FreeBlk*)&pPage->u.aDisk[SWAB16(pBt, *pIdx)];
while( (iSize = SWAB16(pBt, p->iSize))<nByte ){
assert( cnt++ < SQLITE_PAGE_SIZE/4 );
assert( cnt++ < SQLITE_USABLE_SIZE/4 );
if( p->iNext==0 ){
defragmentPage(pBt, pPage);
pIdx = &pPage->u.hdr.firstFree;
@ -598,12 +598,12 @@ static int initPage(Bt *pBt, MemPage *pPage, Pgno pgnoThis, MemPage *pParent){
freeSpace = USABLE_SPACE;
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
while( idx!=0 ){
if( idx>SQLITE_PAGE_SIZE-MIN_CELL_SIZE ) goto page_format_error;
if( idx>SQLITE_USABLE_SIZE-MIN_CELL_SIZE ) goto page_format_error;
if( idx<sizeof(PageHdr) ) goto page_format_error;
if( idx!=ROUNDUP(idx) ) goto page_format_error;
pCell = (Cell*)&pPage->u.aDisk[idx];
sz = cellSize(pBt, pCell);
if( idx+sz > SQLITE_PAGE_SIZE ) goto page_format_error;
if( idx+sz > SQLITE_USABLE_SIZE ) goto page_format_error;
freeSpace -= sz;
pPage->apCell[pPage->nCell++] = pCell;
idx = SWAB16(pBt, pCell->h.iNext);
@ -612,7 +612,7 @@ static int initPage(Bt *pBt, MemPage *pPage, Pgno pgnoThis, MemPage *pParent){
idx = SWAB16(pBt, pPage->u.hdr.firstFree);
while( idx!=0 ){
int iNext;
if( idx>SQLITE_PAGE_SIZE-sizeof(FreeBlk) ) goto page_format_error;
if( idx>SQLITE_USABLE_SIZE-sizeof(FreeBlk) ) goto page_format_error;
if( idx<sizeof(PageHdr) ) goto page_format_error;
pFBlk = (FreeBlk*)&pPage->u.aDisk[idx];
pPage->nFree += SWAB16(pBt, pFBlk->iSize);
@ -640,13 +640,13 @@ static void zeroPage(Btree *pBt, MemPage *pPage){
PageHdr *pHdr;
FreeBlk *pFBlk;
assert( sqlitepager_iswriteable(pPage) );
memset(pPage, 0, SQLITE_PAGE_SIZE);
memset(pPage, 0, SQLITE_USABLE_SIZE);
pHdr = &pPage->u.hdr;
pHdr->firstCell = 0;
pHdr->firstFree = SWAB16(pBt, sizeof(*pHdr));
pFBlk = (FreeBlk*)&pHdr[1];
pFBlk->iNext = 0;
pPage->nFree = SQLITE_PAGE_SIZE - sizeof(*pHdr);
pPage->nFree = SQLITE_USABLE_SIZE - sizeof(*pHdr);
pFBlk->iSize = SWAB16(pBt, pPage->nFree);
pPage->nCell = 0;
pPage->isOverfull = 0;
@ -697,7 +697,7 @@ int sqliteBtreeOpen(
assert( sizeof(PageHdr)==8 );
assert( sizeof(CellHdr)==12 );
assert( sizeof(FreeBlk)==4 );
assert( sizeof(OverflowPage)==SQLITE_PAGE_SIZE );
assert( sizeof(OverflowPage)==SQLITE_USABLE_SIZE );
assert( sizeof(FreelistInfo)==OVERFLOW_SIZE );
assert( sizeof(ptr)==sizeof(char*) );
assert( sizeof(uptr)==sizeof(ptr) );
@ -2082,7 +2082,7 @@ static void relinkCellList(Btree *pBt, MemPage *pPage){
pIdx = &pPage->u.hdr.firstCell;
for(i=0; i<pPage->nCell; i++){
int idx = Addr(pPage->apCell[i]) - Addr(pPage);
assert( idx>0 && idx<SQLITE_PAGE_SIZE );
assert( idx>0 && idx<SQLITE_USABLE_SIZE );
*pIdx = SWAB16(pBt, idx);
pIdx = &pPage->apCell[i]->h.iNext;
}
@ -2098,7 +2098,7 @@ static void relinkCellList(Btree *pBt, MemPage *pPage){
static void copyPage(MemPage *pTo, MemPage *pFrom){
uptr from, to;
int i;
memcpy(pTo->u.aDisk, pFrom->u.aDisk, SQLITE_PAGE_SIZE);
memcpy(pTo->u.aDisk, pFrom->u.aDisk, SQLITE_USABLE_SIZE);
pTo->pParent = 0;
pTo->isInit = 1;
pTo->nCell = pFrom->nCell;
@ -2108,7 +2108,7 @@ static void copyPage(MemPage *pTo, MemPage *pFrom){
from = Addr(pFrom);
for(i=0; i<pTo->nCell; i++){
uptr x = Addr(pFrom->apCell[i]);
if( x>from && x<from+SQLITE_PAGE_SIZE ){
if( x>from && x<from+SQLITE_USABLE_SIZE ){
*((uptr*)&pTo->apCell[i]) = x + to - from;
}else{
pTo->apCell[i] = pFrom->apCell[i];
@ -2203,7 +2203,7 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
** underfull.
*/
assert( sqlitepager_iswriteable(pPage) );
if( !pPage->isOverfull && pPage->nFree<SQLITE_PAGE_SIZE/2
if( !pPage->isOverfull && pPage->nFree<SQLITE_USABLE_SIZE/2
&& pPage->nCell>=2){
relinkCellList(pBt, pPage);
return SQLITE_OK;
@ -2229,7 +2229,7 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){
pgnoChild = SWAB32(pBt, pPage->u.hdr.rightChild);
rc = sqlitepager_get(pBt->pPager, pgnoChild, (void**)&pChild);
if( rc ) return rc;
memcpy(pPage, pChild, SQLITE_PAGE_SIZE);
memcpy(pPage, pChild, SQLITE_USABLE_SIZE);
pPage->isInit = 0;
rc = initPage(pBt, pPage, sqlitepager_pagenumber(pPage), 0);
assert( rc==SQLITE_OK );
@ -2907,7 +2907,7 @@ static int copyCell(Btree *pBtFrom, BTree *pBtTo, Cell *pCell){
if( rc==SQLITE_OK ){
rc = sqlitepager_write(pNew);
if( rc==SQLITE_OK ){
memcpy(pNew, pOvfl, SQLITE_PAGE_SIZE);
memcpy(pNew, pOvfl, SQLITE_USABLE_SIZE);
*pPrev = SWAB32(pBtTo, new);
if( pPrevPg ){
sqlitepager_unref(pPrevPg);
@ -2950,7 +2950,7 @@ static int copyDatabasePage(
rc = sqlitepager_write(pPage);
}
if( rc==SQLITE_OK ){
memcpy(pPage, pPageFrom, SQLITE_PAGE_SIZE);
memcpy(pPage, pPageFrom, SQLITE_USABLE_SIZE);
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
while( idx>0 ){
pCell = (Cell*)&pPage->u.aDisk[idx];
@ -3040,7 +3040,7 @@ static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){
if( recursive ) printf("PAGE %d:\n", pgno);
i = 0;
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
while( idx>0 && idx<=SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){
while( idx>0 && idx<=SQLITE_USABLE_SIZE-MIN_CELL_SIZE ){
Cell *pCell = (Cell*)&pPage->u.aDisk[idx];
int sz = cellSize(pBt, pCell);
sprintf(range,"%d..%d", idx, idx+sz-1);
@ -3070,7 +3070,7 @@ static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){
nFree = 0;
i = 0;
idx = SWAB16(pBt, pPage->u.hdr.firstFree);
while( idx>0 && idx<SQLITE_PAGE_SIZE ){
while( idx>0 && idx<SQLITE_USABLE_SIZE ){
FreeBlk *p = (FreeBlk*)&pPage->u.aDisk[idx];
sprintf(range,"%d..%d", idx, idx+p->iSize-1);
nFree += SWAB16(pBt, p->iSize);
@ -3084,7 +3084,7 @@ static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){
}
if( recursive && pPage->u.hdr.rightChild!=0 ){
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
while( idx>0 && idx<SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){
while( idx>0 && idx<SQLITE_USABLE_SIZE-MIN_CELL_SIZE ){
Cell *pCell = (Cell*)&pPage->u.aDisk[idx];
fileBtreePageDump(pBt, SWAB32(pBt, pCell->h.leftChild), 1);
idx = SWAB16(pBt, pCell->h.iNext);
@ -3129,7 +3129,7 @@ static int fileBtreeCursorDump(BtCursor *pCur, int *aResult){
aResult[4] = pPage->nFree;
cnt = 0;
idx = SWAB16(pBt, pPage->u.hdr.firstFree);
while( idx>0 && idx<SQLITE_PAGE_SIZE ){
while( idx>0 && idx<SQLITE_USABLE_SIZE ){
cnt++;
idx = SWAB16(pBt, ((FreeBlk*)&pPage->u.aDisk[idx])->iNext);
}
@ -3293,7 +3293,7 @@ static int checkTreePage(
Btree *pBt;
char zMsg[100];
char zContext[100];
char hit[SQLITE_PAGE_SIZE];
char hit[SQLITE_USABLE_SIZE];
/* Check that the page exists
*/
@ -3369,19 +3369,19 @@ static int checkTreePage(
*/
memset(hit, 0, sizeof(hit));
memset(hit, 1, sizeof(PageHdr));
for(i=SWAB16(pBt, pPage->u.hdr.firstCell); i>0 && i<SQLITE_PAGE_SIZE; ){
for(i=SWAB16(pBt, pPage->u.hdr.firstCell); i>0 && i<SQLITE_USABLE_SIZE; ){
Cell *pCell = (Cell*)&pPage->u.aDisk[i];
int j;
for(j=i+cellSize(pBt, pCell)-1; j>=i; j--) hit[j]++;
i = SWAB16(pBt, pCell->h.iNext);
}
for(i=SWAB16(pBt,pPage->u.hdr.firstFree); i>0 && i<SQLITE_PAGE_SIZE; ){
for(i=SWAB16(pBt,pPage->u.hdr.firstFree); i>0 && i<SQLITE_USABLE_SIZE; ){
FreeBlk *pFBlk = (FreeBlk*)&pPage->u.aDisk[i];
int j;
for(j=i+SWAB16(pBt,pFBlk->iSize)-1; j>=i; j--) hit[j]++;
i = SWAB16(pBt,pFBlk->iNext);
}
for(i=0; i<SQLITE_PAGE_SIZE; i++){
for(i=0; i<SQLITE_USABLE_SIZE; i++){
if( hit[i]==0 ){
sprintf(zMsg, "Unused space at byte %d of page %d", i, iPage);
checkAppendMsg(pCheck, zMsg, 0);
@ -3396,9 +3396,9 @@ static int checkTreePage(
/* Check that free space is kept to a minimum
*/
#if 0
if( pParent && pParent->nCell>2 && pPage->nFree>3*SQLITE_PAGE_SIZE/4 ){
if( pParent && pParent->nCell>2 && pPage->nFree>3*SQLITE_USABLE_SIZE/4 ){
sprintf(zMsg, "free space (%d) greater than max (%d)", pPage->nFree,
SQLITE_PAGE_SIZE/3);
SQLITE_USABLE_SIZE/3);
checkAppendMsg(pCheck, zContext, zMsg);
}
#endif
@ -3500,7 +3500,7 @@ static int fileBtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){
if( !pBtTo->inTrans || !pBtFrom->inTrans ) return SQLITE_ERROR;
if( pBtTo->needSwab!=pBtFrom->needSwab ) return SQLITE_ERROR;
if( pBtTo->pCursor ) return SQLITE_BUSY;
memcpy(pBtTo->page1, pBtFrom->page1, SQLITE_PAGE_SIZE);
memcpy(pBtTo->page1, pBtFrom->page1, SQLITE_USABLE_SIZE);
rc = sqlitepager_overwrite(pBtTo->pPager, 1, pBtFrom->page1);
nToPage = sqlitepager_pagecount(pBtTo->pPager);
nPage = sqlitepager_pagecount(pBtFrom->pPager);

View File

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.96 2004/02/09 01:20:37 drh Exp $
** @(#) $Id: pager.c,v 1.97 2004/02/10 01:54:28 drh Exp $
*/
#include "os.h" /* Must be first to enable large file support */
#include "sqliteInt.h"
@ -44,19 +44,6 @@ static Pager *mainPager = 0;
#define TRACE3(X,Y,Z)
#endif
/*
** Number of extra bytes of data allocated at the end of each page and
** stored on disk but not used by the higher level btree layer.
*/
#ifndef SQLITE_PAGE_RESERVE
#define SQLITE_PAGE_RESERVE 0
#endif
/*
** The total number of bytes stored on disk for each page.
*/
#define SQLITE_BLOCK_SIZE (SQLITE_PAGE_SIZE+SQLITE_PAGE_RESERVE)
/*
** The page cache as a whole is always in one of the following
@ -126,7 +113,7 @@ struct PgHdr {
u8 needSync; /* Sync journal before writing this page */
u8 alwaysRollback; /* Disable dont_rollback() for this page */
PgHdr *pDirty; /* Dirty pages sorted by PgHdr.pgno */
/* SQLITE_BLOCK_SIZE bytes of page data follow this header */
/* SQLITE_PAGE_SIZE bytes of page data follow this header */
/* Pager.nExtra bytes of local data follow the page data */
};
@ -136,7 +123,7 @@ struct PgHdr {
*/
#define PGHDR_TO_DATA(P) ((void*)(&(P)[1]))
#define DATA_TO_PGHDR(D) (&((PgHdr*)(D))[-1])
#define PGHDR_TO_EXTRA(P) ((void*)&((char*)(&(P)[1]))[SQLITE_BLOCK_SIZE])
#define PGHDR_TO_EXTRA(P) ((void*)&((char*)(&(P)[1]))[SQLITE_PAGE_SIZE])
/*
** How big to make the hash table used for locating in-memory pages
@ -217,7 +204,7 @@ struct Pager {
typedef struct PageRecord PageRecord;
struct PageRecord {
Pgno pgno; /* The page number */
char aData[SQLITE_BLOCK_SIZE]; /* Original data for page pgno */
char aData[SQLITE_PAGE_SIZE]; /* Original data for page pgno */
};
/*
@ -240,7 +227,7 @@ struct PageRecord {
**
** The sanity checking information for the 3rd journal format consists
** of a 32-bit checksum on each page of data. The checksum covers both
** the page number and the SQLITE_BLOCK_SIZE bytes of data for the page.
** the page number and the SQLITE_PAGE_SIZE bytes of data for the page.
** This cksum is initialized to a 32-bit random value that appears in the
** journal file right after the header. The random initializer is important,
** because garbage data that appears at the end of a journal is likely
@ -285,7 +272,7 @@ int journal_format = 3;
#define JOURNAL_HDR_SZ(X) \
(sizeof(aJournalMagic1) + sizeof(Pgno) + ((X)>=3)*2*sizeof(u32))
#define JOURNAL_PG_SZ(X) \
(SQLITE_BLOCK_SIZE + sizeof(Pgno) + ((X)>=3)*sizeof(u32))
(SQLITE_PAGE_SIZE + sizeof(Pgno) + ((X)>=3)*sizeof(u32))
/*
** Enable reference count tracking here:
@ -563,20 +550,20 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int format){
*/
pPg = pager_lookup(pPager, pgRec.pgno);
TRACE2("PLAYBACK %d\n", pgRec.pgno);
sqliteOsSeek(&pPager->fd, (pgRec.pgno-1)*(off_t)SQLITE_BLOCK_SIZE);
rc = sqliteOsWrite(&pPager->fd, pgRec.aData, SQLITE_BLOCK_SIZE);
sqliteOsSeek(&pPager->fd, (pgRec.pgno-1)*(off_t)SQLITE_PAGE_SIZE);
rc = sqliteOsWrite(&pPager->fd, pgRec.aData, SQLITE_PAGE_SIZE);
if( pPg ){
/* No page should ever be rolled back that is in use, except for page
** 1 which is held in use in order to keep the lock on the database
** active.
*/
assert( pPg->nRef==0 || pPg->pgno==1 );
memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_BLOCK_SIZE);
memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE);
memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
pPg->dirty = 0;
pPg->needSync = 0;
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 0);
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 2);
}
}
return rc;
@ -601,7 +588,7 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int format){
** database to during a rollback.
** * Zero or more pages instances, each as follows:
** + 4 byte page number.
** + SQLITE_BLOCK_SIZE bytes of data.
** + SQLITE_PAGE_SIZE bytes of data.
** + 4 byte checksum (format 3 only)
**
** When we speak of the journal header, we mean the first 4 bullets above.
@ -707,7 +694,7 @@ static int pager_playback(Pager *pPager, int useJournalSize){
goto end_playback;
}
assert( pPager->origDbSize==0 || pPager->origDbSize==mxPg );
rc = sqliteOsTruncate(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)mxPg);
rc = sqliteOsTruncate(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)mxPg);
if( rc!=SQLITE_OK ){
goto end_playback;
}
@ -732,20 +719,20 @@ static int pager_playback(Pager *pPager, int useJournalSize){
if( rc==SQLITE_OK ){
PgHdr *pPg;
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
char zBuf[SQLITE_BLOCK_SIZE];
char zBuf[SQLITE_PAGE_SIZE];
if( !pPg->dirty ) continue;
if( (int)pPg->pgno <= pPager->origDbSize ){
sqliteOsSeek(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)(pPg->pgno-1));
rc = sqliteOsRead(&pPager->fd, zBuf, SQLITE_BLOCK_SIZE);
sqliteOsSeek(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)(pPg->pgno-1));
rc = sqliteOsRead(&pPager->fd, zBuf, SQLITE_PAGE_SIZE);
if( rc ) break;
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, zBuf, 0);
}
}else{
memset(zBuf, 0, SQLITE_BLOCK_SIZE);
memset(zBuf, 0, SQLITE_PAGE_SIZE);
}
if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), SQLITE_BLOCK_SIZE) ){
memcpy(PGHDR_TO_DATA(pPg), zBuf, SQLITE_BLOCK_SIZE);
if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), SQLITE_PAGE_SIZE) ){
memcpy(PGHDR_TO_DATA(pPg), zBuf, SQLITE_PAGE_SIZE);
memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
}
pPg->needSync = 0;
@ -786,7 +773,7 @@ static int pager_ckpt_playback(Pager *pPager){
/* Truncate the database back to its original size.
*/
rc = sqliteOsTruncate(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)pPager->ckptSize);
rc = sqliteOsTruncate(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)pPager->ckptSize);
pPager->dbSize = pPager->ckptSize;
/* Figure out how many records are in the checkpoint journal.
@ -1024,7 +1011,7 @@ int sqlitepager_pagecount(Pager *pPager){
pPager->errMask |= PAGER_ERR_DISK;
return 0;
}
n /= SQLITE_BLOCK_SIZE;
n /= SQLITE_PAGE_SIZE;
if( pPager->state!=SQLITE_UNLOCK ){
pPager->dbSize = n;
}
@ -1052,7 +1039,7 @@ int sqlitepager_truncate(Pager *pPager, Pgno nPage){
return SQLITE_OK;
}
syncJournal(pPager);
rc = sqliteOsTruncate(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)nPage);
rc = sqliteOsTruncate(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)nPage);
if( rc==SQLITE_OK ){
pPager->dbSize = nPage;
}
@ -1259,11 +1246,11 @@ static int pager_write_pagelist(PgHdr *pList){
pPager = pList->pPager;
while( pList ){
assert( pList->dirty );
sqliteOsSeek(&pPager->fd, (pList->pgno-1)*(off_t)SQLITE_BLOCK_SIZE);
sqliteOsSeek(&pPager->fd, (pList->pgno-1)*(off_t)SQLITE_PAGE_SIZE);
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pList), 1);
}
rc = sqliteOsWrite(&pPager->fd, PGHDR_TO_DATA(pList), SQLITE_BLOCK_SIZE);
rc = sqliteOsWrite(&pPager->fd, PGHDR_TO_DATA(pList), SQLITE_PAGE_SIZE);
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pList), 0);
}
@ -1390,7 +1377,7 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){
pPager->nMiss++;
if( pPager->nPage<pPager->mxPage || pPager->pFirst==0 ){
/* Create a new page */
pPg = sqliteMallocRaw( sizeof(*pPg) + SQLITE_BLOCK_SIZE
pPg = sqliteMallocRaw( sizeof(*pPg) + SQLITE_PAGE_SIZE
+ sizeof(u32) + pPager->nExtra );
if( pPg==0 ){
pager_unwritelock(pPager);
@ -1522,19 +1509,19 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){
return rc;
}
if( pPager->dbSize<(int)pgno ){
memset(PGHDR_TO_DATA(pPg), 0, SQLITE_BLOCK_SIZE);
memset(PGHDR_TO_DATA(pPg), 0, SQLITE_PAGE_SIZE);
}else{
int rc;
sqliteOsSeek(&pPager->fd, (pgno-1)*(off_t)SQLITE_BLOCK_SIZE);
rc = sqliteOsRead(&pPager->fd, PGHDR_TO_DATA(pPg), SQLITE_BLOCK_SIZE);
sqliteOsSeek(&pPager->fd, (pgno-1)*(off_t)SQLITE_PAGE_SIZE);
rc = sqliteOsRead(&pPager->fd, PGHDR_TO_DATA(pPg), SQLITE_PAGE_SIZE);
if( rc!=SQLITE_OK ){
off_t fileSize;
if( sqliteOsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK
|| fileSize>=pgno*SQLITE_BLOCK_SIZE ){
|| fileSize>=pgno*SQLITE_PAGE_SIZE ){
sqlitepager_unref(PGHDR_TO_DATA(pPg));
return rc;
}else{
memset(PGHDR_TO_DATA(pPg), 0, SQLITE_BLOCK_SIZE);
memset(PGHDR_TO_DATA(pPg), 0, SQLITE_PAGE_SIZE);
}
}else if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 0);
@ -1817,11 +1804,11 @@ int sqlitepager_write(void *pData){
}
store32bits(pPg->pgno, pPg, -4);
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, pData, 1);
pPager->xCodec(pPager->pCodecArg, pData, 3);
}
rc = sqliteOsWrite(&pPager->jfd, &((char*)pData)[-4], szPg);
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, pData, 0);
pPager->xCodec(pPager->pCodecArg, pData, 2);
}
if( journal_format>=JOURNAL_FORMAT_3 ){
*(u32*)PGHDR_TO_EXTRA(pPg) = saved;
@ -1858,7 +1845,7 @@ int sqlitepager_write(void *pData){
if( pPager->ckptInUse && !pPg->inCkpt && (int)pPg->pgno<=pPager->ckptSize ){
assert( pPg->inJournal || (int)pPg->pgno>pPager->origDbSize );
store32bits(pPg->pgno, pPg, -4);
rc = sqliteOsWrite(&pPager->cpfd, &((char*)pData)[-4], SQLITE_BLOCK_SIZE+4);
rc = sqliteOsWrite(&pPager->cpfd, &((char*)pData)[-4], SQLITE_PAGE_SIZE+4);
if( rc!=SQLITE_OK ){
sqlitepager_rollback(pPager);
pPager->errMask |= PAGER_ERR_FULL;
@ -1900,7 +1887,7 @@ int sqlitepager_overwrite(Pager *pPager, Pgno pgno, void *pData){
if( rc==SQLITE_OK ){
rc = sqlitepager_write(pPage);
if( rc==SQLITE_OK ){
memcpy(pPage, pData, SQLITE_BLOCK_SIZE);
memcpy(pPage, pData, SQLITE_PAGE_SIZE);
}
sqlitepager_unref(pPage);
}

View File

@ -13,21 +13,42 @@
** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
** @(#) $Id: pager.h,v 1.24 2004/02/09 01:20:37 drh Exp $
** @(#) $Id: pager.h,v 1.25 2004/02/10 01:54:28 drh Exp $
*/
/*
** The size of one page
**
** You can change this value to another (reasonable) power of two
** such as 512, 2048, 4096, or 8192 and things will still work. But
** experiments show that a page size of 1024 gives the best speed.
** (The speed differences are minimal.)
** You can change this value to another (reasonable) value you want.
** It need not be a power of two, though the interface to the disk
** will likely be faster if it is.
**
** Experiments show that a page size of 1024 gives the best speed
** for common usages. The speed differences for different sizes
** such as 512, 2048, 4096, an so forth, is minimal. Note, however,
** that changing the page size results in a completely imcompatible
** file format.
*/
#ifndef SQLITE_PAGE_SIZE
#define SQLITE_PAGE_SIZE 1024
#endif
/*
** Number of extra bytes of data allocated at the end of each page and
** stored on disk but not used by the higher level btree layer. Changing
** this value results in a completely incompatible file format.
*/
#ifndef SQLITE_PAGE_RESERVE
#define SQLITE_PAGE_RESERVE 0
#endif
/*
** The total number of usable bytes stored on disk for each page.
** The usable bytes come at the beginning of the page and the reserve
** bytes come at the end.
*/
#define SQLITE_USABLE_SIZE (SQLITE_PAGE_SIZE-SQLITE_PAGE_RESERVE)
/*
** Maximum number of pages in one database. (This is a limitation of
** imposed by 4GB files size limits.)

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test2.c,v 1.15 2003/02/11 14:55:41 drh Exp $
** $Id: test2.c,v 1.16 2004/02/10 01:54:28 drh Exp $
*/
#include "os.h"
#include "sqliteInt.h"
@ -468,8 +468,8 @@ static int page_write(
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
strncpy((char*)pPage, argv[2], SQLITE_PAGE_SIZE-1);
((char*)pPage)[SQLITE_PAGE_SIZE-1] = 0;
strncpy((char*)pPage, argv[2], SQLITE_USABLE_SIZE-1);
((char*)pPage)[SQLITE_USABLE_SIZE-1] = 0;
return TCL_OK;
}
@ -525,6 +525,7 @@ static int fake_big_file(
*/
int Sqlitetest2_Init(Tcl_Interp *interp){
extern int sqlite_io_error_pending;
char zBuf[100];
static struct {
char *zName;
Tcl_CmdProc *xProc;
@ -556,5 +557,11 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
Tcl_LinkVar(interp, "journal_format",
(char*)&journal_format, TCL_LINK_INT);
#endif
sprintf(zBuf, "%d", SQLITE_PAGE_SIZE);
Tcl_SetVar(interp, "SQLITE_PAGE_SIZE", zBuf, TCL_GLOBAL_ONLY);
sprintf(zBuf, "%d", SQLITE_PAGE_RESERVE);
Tcl_SetVar(interp, "SQLITE_PAGE_RESERVE", zBuf, TCL_GLOBAL_ONLY);
sprintf(zBuf, "%d", SQLITE_USABLE_SIZE);
Tcl_SetVar(interp, "SQLITE_USABLE_SIZE", zBuf, TCL_GLOBAL_ONLY);
return TCL_OK;
}

View File

@ -11,13 +11,14 @@
# This file implements regression tests for SQLite library. The
# focus of this script is btree database backend
#
# $Id: btree.test,v 1.14 2003/02/12 14:09:45 drh Exp $
# $Id: btree.test,v 1.15 2004/02/10 01:54:28 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {[info commands btree_open]!=""} {
if {[info commands btree_open]!="" && $SQLITE_PAGE_SIZE==1024
&& $SQLITE_USABLE_SIZE==1024} {
# Basic functionality. Open and close a database.
#