mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Allow SQLITE_PAGE_SIZE to be redefined on the compiler command-line. (CVS 1217)
FossilOrigin-Name: 4c7bf714b5f3d2bb7366367ddf906141a7e36407
This commit is contained in:
79
src/pager.c
79
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.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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user