mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Use mmap() to read from the database file in rollback mode. This branch is unix only for now.
FossilOrigin-Name: 6f21d9cbf5d457e63a7282015a89ae785526cf6d
This commit is contained in:
31
src/btree.c
31
src/btree.c
@@ -2564,6 +2564,34 @@ int sqlite3BtreeNewDb(Btree *p){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** If the shared-btree passed as the only argument is holding references
|
||||
** to mmap pages, replace them with read/write pages. Return SQLITE_OK
|
||||
** if successful, or an error code otherwise.
|
||||
*/
|
||||
static int btreeSwapOutMmap(BtShared *pBt){
|
||||
BtCursor *pCsr;
|
||||
for(pCsr=pBt->pCursor; pCsr; pCsr=pCsr->pNext){
|
||||
int i;
|
||||
for(i=0; i<=pCsr->iPage; i++){
|
||||
MemPage *pPg = pCsr->apPage[i];
|
||||
if( pPg->pDbPage->flags & PGHDR_MMAP ){
|
||||
int rc;
|
||||
MemPage *pNew = 0;
|
||||
rc = btreeGetPage(pBt, pPg->pgno, &pNew, 0);
|
||||
if( rc==SQLITE_OK && i==pCsr->iPage ){
|
||||
pCsr->info.pCell = pNew->aData + (pCsr->info.pCell - pPg->aData);
|
||||
}
|
||||
pCsr->apPage[i] = pNew;
|
||||
releasePage(pPg);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to start a new transaction. A write-transaction
|
||||
** is started if the second argument is nonzero, otherwise a read-
|
||||
@@ -2670,6 +2698,9 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
|
||||
rc = SQLITE_READONLY;
|
||||
}else{
|
||||
rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = btreeSwapOutMmap(pBt);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = newDatabase(pBt);
|
||||
}
|
||||
|
Reference in New Issue
Block a user