Add the max_page_count pragma used to limit the maximum size of a database

file.  Untested. (CVS 3948)

FossilOrigin-Name: b1b74f06688fd90fcaf54cf95e2e7beeb5fc1040
This commit is contained in:
drh
2007-05-08 14:51:36 +00:00
parent 17374e8f94
commit f8e632b630
9 changed files with 90 additions and 27 deletions
+10 -1
View File
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.377 2007/05/05 18:39:25 drh Exp $
** $Id: btree.c,v 1.378 2007/05/08 14:51:37 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@@ -1332,6 +1332,15 @@ int sqlite3BtreeGetPageSize(Btree *p){
int sqlite3BtreeGetReserve(Btree *p){
return p->pBt->pageSize - p->pBt->usableSize;
}
/*
** Set the maximum page count for a database if mxPage is positive.
** No changes are made if mxPage is 0 or negative.
** Regardless of the value of mxPage, return the maximum page count.
*/
int sqlite3BtreeMaxPageCount(Btree *p, int mxPage){
return sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage);
}
#endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */
/*
+2 -1
View File
@@ -13,7 +13,7 @@
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
**
** @(#) $Id: btree.h,v 1.80 2007/05/05 18:49:53 drh Exp $
** @(#) $Id: btree.h,v 1.81 2007/05/08 14:51:37 drh Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
@@ -67,6 +67,7 @@ int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
int sqlite3BtreeSyncDisabled(Btree*);
int sqlite3BtreeSetPageSize(Btree*,int,int);
int sqlite3BtreeGetPageSize(Btree*);
int sqlite3BtreeMaxPageCount(Btree*,int);
int sqlite3BtreeGetReserve(Btree*);
int sqlite3BtreeSetAutoVacuum(Btree *, int);
int sqlite3BtreeGetAutoVacuum(Btree *);
+5 -1
View File
@@ -12,7 +12,7 @@
**
** This file defines various limits of what SQLite can process.
**
** @(#) $Id: limits.h,v 1.2 2007/05/08 13:58:28 drh Exp $
** @(#) $Id: limits.h,v 1.3 2007/05/08 14:51:37 drh Exp $
*/
/*
@@ -126,6 +126,10 @@
/*
** Maximum number of pages in one database file.
**
** This is really just the default value for the max_page_count pragma.
** This value can be lowered (or raised) at run-time using that the
** max_page_count macro.
*/
#ifndef SQLITE_MAX_PAGE_COUNT
# define SQLITE_MAX_PAGE_COUNT 1073741823
+24 -7
View File
@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.336 2007/05/05 11:48:54 drh Exp $
** @(#) $Id: pager.c,v 1.337 2007/05/08 14:51:37 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -256,9 +256,9 @@ struct Pager {
int nExtra; /* Add this many bytes to each in-memory page */
int pageSize; /* Number of bytes in a page */
int nPage; /* Total number of in-memory pages */
int nMaxPage; /* High water mark of nPage */
int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */
int mxPage; /* Maximum number of pages to hold in cache */
Pgno mxPgno; /* Maximum allowed size of the database */
u8 *aInJournal; /* One bit for each page in the database file */
u8 *aInStmt; /* One bit for each page in the database */
char *zFilename; /* Name of the database file */
@@ -1751,8 +1751,8 @@ int sqlite3PagerOpen(
/* pPager->stmtSize = 0; */
/* pPager->stmtJSize = 0; */
/* pPager->nPage = 0; */
/* pPager->nMaxPage = 0; */
pPager->mxPage = 100;
pPager->mxPgno = SQLITE_MAX_PAGE_COUNT;
assert( PAGER_UNLOCK==0 );
/* pPager->state = PAGER_UNLOCK; */
/* pPager->errMask = 0; */
@@ -1829,6 +1829,21 @@ int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){
return pPager->pageSize;
}
/*
** Attempt to set the maximum database page count if mxPage is positive.
** Make no changes if mxPage is zero or negative. And never reduce the
** maximum page count below the current size of the database.
**
** Regardless of mxPage, return the current maximum page count.
*/
int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
if( mxPage>0 ){
pPager->mxPgno = mxPage;
}
sqlite3PagerPagecount(pPager);
return pPager->mxPgno;
}
/*
** The following set of routines are used to disable the simulated
** I/O error mechanism. These routines are used to avoid simulated
@@ -1914,6 +1929,9 @@ int sqlite3PagerPagecount(Pager *pPager){
if( n==(PENDING_BYTE/pPager->pageSize) ){
n++;
}
if( n>pPager->mxPgno ){
pPager->mxPgno = n;
}
return n;
}
@@ -2912,10 +2930,6 @@ static int pagerAllocatePage(Pager *pPager, PgHdr **ppPg){
pPg->pNextAll = pPager->pAll;
pPager->pAll = pPg;
pPager->nPage++;
if( pPager->nPage>pPager->nMaxPage ){
assert( pPager->nMaxPage==(pPager->nPage-1) );
pPager->nMaxPage++;
}
}else{
/* Recycle an existing page with a zero ref-count. */
rc = pager_recycle(pPager, 1, &pPg);
@@ -3060,6 +3074,9 @@ int sqlite3PagerAcquire(
** file, or by setting the entire page to zero.
*/
if( nMax<(int)pgno || MEMDB || (noContent && !pPager->alwaysRollback) ){
if( pgno>pPager->mxPgno ){
return SQLITE_FULL;
}
memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
pPg->needRead = noContent && !pPager->alwaysRollback;
IOTRACE(("ZERO %p %d\n", pPager, pgno));
+2 -1
View File
@@ -13,7 +13,7 @@
** 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.59 2007/05/08 01:08:49 drh Exp $
** @(#) $Id: pager.h,v 1.60 2007/05/08 14:51:37 drh Exp $
*/
#ifndef _PAGER_H_
@@ -60,6 +60,7 @@ void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int));
void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int));
int sqlite3PagerSetPagesize(Pager*, int);
int sqlite3PagerMaxPageCount(Pager*, int);
int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
void sqlite3PagerSetCachesize(Pager*, int);
int sqlite3PagerClose(Pager *pPager);
+22 -1
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.135 2007/05/08 01:08:49 drh Exp $
** $Id: pragma.c,v 1.136 2007/05/08 14:51:37 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -344,6 +344,27 @@ void sqlite3Pragma(
}
}else
/*
** PRAGMA [database.]max_page_count
** PRAGMA [database.]max_page_count=N
**
** The first form reports the current setting for the
** maximum number of pages in the database file. The
** second form attempts to change this setting. Both
** forms return the current setting.
*/
if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
Btree *pBt = pDb->pBt;
int newMax = 0;
if( zRight ){
newMax = atoi(zRight);
}
if( pBt ){
newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
}
returnSingleInt(pParse, "max_page_count", newMax);
}else
/*
** PRAGMA [database.]locking_mode
** PRAGMA [database.]locking_mode = (normal|exclusive)