1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

Ensure that the "Any prior cache entry associated with newKey is guaranteed not to be pinned" guarantee made to xRekey implementations is not violated.

FossilOrigin-Name: ecc3544e712041736af7c7b4f34864a1f2e30ff7
This commit is contained in:
dan
2014-10-24 20:57:03 +00:00
parent 23eba45d23
commit 31f4e99d44
4 changed files with 21 additions and 30 deletions

View File

@@ -6856,25 +6856,19 @@ static int balance_nonroot(
aPgFlags[i] = apNew[i]->pDbPage->flags;
}
for(i=0; i<nNew; i++){
Pgno iGt = (i==0 ? 0 : apNew[i-1]->pgno);
Pgno iMin = 0;
u16 flags = 0;
for(j=0; j<nNew; j++){
Pgno iPgno = aPgno[j];
if( iPgno>iGt && (iMin==0 || iPgno<iMin) ){
iMin = iPgno;
flags = aPgFlags[j];
}
int iBest = 0; /* aPgno[] index of page number to use */
Pgno pgno; /* Page number to use */
for(j=1; j<nNew; j++){
if( aPgno[j]<aPgno[iBest] ) iBest = j;
}
if( iMin==0 ){
/* This case can only occur if aPgno[] contains duplicate page
** numbers. Which can only happen if the database is corrupt. */
assert( CORRUPT_DB );
rc = SQLITE_CORRUPT_BKPT;
goto balance_cleanup;
}else if( apNew[i]->pgno!=iMin ){
sqlite3PagerRekey(apNew[i]->pDbPage, iMin, flags);
apNew[i]->pgno = iMin;
pgno = aPgno[iBest];
aPgno[iBest] = 0xffffffff;
if( iBest!=i ){
if( iBest>i ){
sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
}
sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
apNew[i]->pgno = pgno;
}
}