Add the xShmPage method to the "crash" vfs in test6.c.

FossilOrigin-Name: 1008f536440840da7d56c01ec147a25295fd1fd4
This commit is contained in:
dan
2010-06-14 10:30:12 +00:00
parent 5d656852f7
commit 067f3165d8
4 changed files with 65 additions and 51 deletions
+7 -7
View File
@@ -1,5 +1,5 @@
C Add\ssome\sfault-injection\stests\sto\simprove\scoverage.
D 2010-06-14T07:53:26
C Add\sthe\sxShmPage\smethod\sto\sthe\s"crash"\svfs\sin\stest6.c.
D 2010-06-14T10:30:12
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -182,7 +182,7 @@ F src/test2.c e3f564ab1e9fd0b47b0c9e23e7054e38bf0836cf
F src/test3.c 4c21700c73a890a47fc685c1097bfb661346ac94
F src/test4.c ad03bb987ddedce928f4258c1e7fa4109a73497d
F src/test5.c cc55900118fa4add8ec9cf69fc4225a4662f76b1
F src/test6.c d3e1a771a7b445ec771e64f2af70df5285da8e4c
F src/test6.c 1b312541883ec9413734035deada4794ee339e67
F src/test7.c 3f2d63e4ccf97f8c2cf1a7fa0a3c8e2e2a354e6e
F src/test8.c f959db9a22d882013b64c92753fa793b2ce3bdea
F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60
@@ -226,7 +226,7 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
F src/wal.c 75c55049c0923418f10bbef842b846374637b595
F src/wal.c 7cf566b5c1cb9e1094bbbd9b188605ed83330e40
F src/wal.h 4ace25262452d17e7d3ec970c89ee17794004008
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c 1c895bef33d0dfc7ed90fb1f74120435d210ea56
@@ -820,7 +820,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P eade8bc238df580412f5cf1b91a91532ae671e46
R d24014573c5813c3e5f096c2f4031503
P 37b26d125f4b1d8e75bb38800fefd145611f94aa
R dea40a6fff442af044dc9e87dfed9d5b
U dan
Z e43653a42fa5b8fa5bb9c7db25e1bbd8
Z 06678e8838f3de5fe68cbedec2758b53
+1 -1
View File
@@ -1 +1 @@
37b26d125f4b1d8e75bb38800fefd145611f94aa
1008f536440840da7d56c01ec147a25295fd1fd4
+11 -1
View File
@@ -549,6 +549,15 @@ static void cfShmBarrier(sqlite3_file *pFile){
static int cfShmClose(sqlite3_file *pFile, int delFlag){
return sqlite3OsShmClose(((CrashFile*)pFile)->pRealFile, delFlag);
}
static int cfShmPage(
sqlite3_file *pFile, /* Handle open on database file */
int iPage, /* Page to retrieve */
int pgsz, /* Size of pages */
int w, /* True to extend file if necessary */
void volatile **pp /* OUT: Mapped memory */
){
return sqlite3OsShmPage(((CrashFile*)pFile)->pRealFile, iPage, pgsz, w, pp);
}
static const sqlite3_io_methods CrashFileVtab = {
@@ -571,7 +580,8 @@ static const sqlite3_io_methods CrashFileVtab = {
cfShmRelease, /* xShmRelease */
cfShmLock, /* xShmLock */
cfShmBarrier, /* xShmBarrier */
cfShmClose /* xShmClose */
cfShmClose, /* xShmClose */
cfShmPage /* xShmPage */
};
/*
+46 -42
View File
@@ -386,6 +386,12 @@ struct Wal {
#endif
};
/*
** Each page of the wal-index mapping contains a hash-table made up of
** an array of HASHTABLE_NSLOT elements of the following type.
*/
typedef u16 ht_slot;
/*
** Define the parameters of the hash tables in the wal-index file. There
** is a hash-table following every HASHTABLE_NPAGE page numbers in the
@@ -394,24 +400,24 @@ struct Wal {
** Changing any of these constants will alter the wal-index format and
** create incompatibilities.
*/
#define HASHTABLE_NPAGE 4096 /* Must be power of 2 and multiple of 256 */
#define HASHTABLE_DATATYPE u16
#define HASHTABLE_NPAGE 4096 /* Must be power of 2 */
#define HASHTABLE_HASH_1 383 /* Should be prime */
#define HASHTABLE_NSLOT (HASHTABLE_NPAGE*2) /* Must be a power of 2 */
#define HASHTABLE_NBYTE (sizeof(HASHTABLE_DATATYPE)*HASHTABLE_NSLOT)
/* The block of page numbers associated with the first hash-table in a
** wal-index is smaller than usual. This is so that there is a complete
** hash-table on each aligned 32KB page of the wal-index.
*/
#define HASHTABLE_NPAGE_ONE (4096 - (WALINDEX_HDR_SIZE/sizeof(u32)))
#define HASHTABLE_NPAGE_ONE (HASHTABLE_NPAGE - (WALINDEX_HDR_SIZE/sizeof(u32)))
/* The wal-index is divided into pages of HASHTABLE_PAGESIZE bytes each. */
#define HASHTABLE_PAGESIZE (HASHTABLE_NBYTE + HASHTABLE_NPAGE*sizeof(u32))
/* The wal-index is divided into pages of WALINDEX_PGSZ bytes each. */
#define WALINDEX_PGSZ ( \
sizeof(ht_slot)*HASHTABLE_NSLOT + HASHTABLE_NPAGE*sizeof(u32) \
)
/*
** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
** is broken into pages of HASHTABLE_PAGESIZE bytes. Wal-index pages are
** is broken into pages of WALINDEX_PGSZ bytes. Wal-index pages are
** numbered from zero.
**
** If this call is successful, *ppPage is set to point to the wal-index
@@ -437,7 +443,7 @@ static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){
/* Request a pointer to the required page from the VFS */
if( pWal->apWiData[iPage]==0 ){
rc = sqlite3OsShmPage(pWal->pDbFd, iPage, HASHTABLE_PAGESIZE,
rc = sqlite3OsShmPage(pWal->pDbFd, iPage, WALINDEX_PGSZ,
pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
);
}
@@ -479,15 +485,15 @@ static volatile WalIndexHdr *walIndexHdr(Wal *pWal){
** This functionality is used by the checkpoint code (see walCheckpoint()).
*/
struct WalIterator {
int iPrior; /* Last result returned from the iterator */
int nSegment; /* Size of the aSegment[] array */
int iPrior; /* Last result returned from the iterator */
int nSegment; /* Size of the aSegment[] array */
struct WalSegment {
int iNext; /* Next slot in aIndex[] not yet returned */
HASHTABLE_DATATYPE *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
u32 *aPgno; /* Array of page numbers. */
int nEntry; /* Max size of aPgno[] and aIndex[] arrays */
int iZero; /* Frame number associated with aPgno[0] */
} aSegment[1]; /* One for every 32KB page in the WAL */
} aSegment[1]; /* One for every 32KB page in the WAL */
};
/*
@@ -750,7 +756,7 @@ static int walNextHash(int iPriorHash){
static int walHashGet(
Wal *pWal, /* WAL handle */
int iHash, /* Find the iHash'th table */
volatile HASHTABLE_DATATYPE **paHash, /* OUT: Pointer to hash index */
volatile ht_slot **paHash, /* OUT: Pointer to hash index */
volatile u32 **paPgno, /* OUT: Pointer to page number array */
u32 *piZero /* OUT: Frame associated with *paPgno[0] */
){
@@ -762,9 +768,9 @@ static int walHashGet(
if( rc==SQLITE_OK ){
u32 iZero;
volatile HASHTABLE_DATATYPE *aHash;
volatile ht_slot *aHash;
aHash = (volatile HASHTABLE_DATATYPE *)&aPgno[HASHTABLE_NPAGE];
aHash = (volatile ht_slot *)&aPgno[HASHTABLE_NPAGE];
if( iHash==0 ){
aPgno = &aPgno[WALINDEX_HDR_SIZE/sizeof(u32)-1];
iZero = 0;
@@ -821,12 +827,12 @@ static u32 walFramePgno(Wal *pWal, u32 iFrame){
** actually needed.
*/
static void walCleanupHash(Wal *pWal){
volatile HASHTABLE_DATATYPE *aHash; /* Pointer to hash table to clear */
volatile u32 *aPgno; /* Page number array for hash table */
u32 iZero; /* frame == (aHash[x]+iZero) */
int iLimit = 0; /* Zero values greater than this */
int nByte; /* Number of bytes to zero in aPgno[] */
int i; /* Used to iterate through aHash[] */
volatile ht_slot *aHash; /* Pointer to hash table to clear */
volatile u32 *aPgno; /* Page number array for hash table */
u32 iZero; /* frame == (aHash[x]+iZero) */
int iLimit = 0; /* Zero values greater than this */
int nByte; /* Number of bytes to zero in aPgno[] */
int i; /* Used to iterate through aHash[] */
assert( pWal->writeLock );
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE-1 );
@@ -886,7 +892,7 @@ static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage){
int rc; /* Return code */
u32 iZero; /* One less than frame number of aPgno[1] */
volatile u32 *aPgno; /* Page number array */
volatile HASHTABLE_DATATYPE *aHash; /* Hash table */
volatile ht_slot *aHash; /* Hash table */
rc = walHashGet(pWal, walFramePage(iFrame), &aHash, &aPgno, &iZero);
@@ -1230,8 +1236,8 @@ static int walIteratorNext(
static void walMergesort(
u32 *aContent, /* Pages in wal */
HASHTABLE_DATATYPE *aBuffer, /* Buffer of at least *pnList items to use */
HASHTABLE_DATATYPE *aList, /* IN/OUT: List to sort */
ht_slot *aBuffer, /* Buffer of at least *pnList items to use */
ht_slot *aList, /* IN/OUT: List to sort */
int *pnList /* IN/OUT: Number of elements in aList[] */
){
int nList = *pnList;
@@ -1241,15 +1247,15 @@ static void walMergesort(
int iLeft = 0; /* Current index in aLeft */
int iRight = 0; /* Current index in aright */
int iOut = 0; /* Current index in output buffer */
HASHTABLE_DATATYPE *aLeft = aList; /* Left list */
HASHTABLE_DATATYPE *aRight = &aList[nLeft]; /* Right list */
ht_slot *aLeft = aList; /* Left list */
ht_slot *aRight = aList+nLeft;/* Right list */
/* TODO: Change to non-recursive version. */
walMergesort(aContent, aBuffer, aLeft, &nLeft);
walMergesort(aContent, aBuffer, aRight, &nRight);
while( iRight<nRight || iLeft<nLeft ){
HASHTABLE_DATATYPE logpage;
ht_slot logpage;
Pgno dbpage;
if( (iLeft<nLeft)
@@ -1303,13 +1309,13 @@ static void walIteratorFree(WalIterator *p){
** prior to the WalIterator object being destroyed.
*/
static int walIteratorInit(Wal *pWal, WalIterator **pp){
WalIterator *p; /* Return value */
int nSegment; /* Number of segments to merge */
u32 iLast; /* Last frame in log */
int nByte; /* Number of bytes to allocate */
int i; /* Iterator variable */
HASHTABLE_DATATYPE *aTmp; /* Temp space used by merge-sort */
HASHTABLE_DATATYPE *aSpace; /* Space at the end of the allocation */
WalIterator *p; /* Return value */
int nSegment; /* Number of segments to merge */
u32 iLast; /* Last frame in log */
int nByte; /* Number of bytes to allocate */
int i; /* Iterator variable */
ht_slot *aTmp; /* Temp space used by merge-sort */
ht_slot *aSpace; /* Space at the end of the allocation */
/* This routine only runs while holding SQLITE_SHM_CHECKPOINT. No other
** thread is able to write to shared memory while this routine is
@@ -1323,7 +1329,7 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){
nSegment = walFramePage(iLast) + 1;
nByte = sizeof(WalIterator)
+ nSegment*(sizeof(struct WalSegment))
+ (nSegment+1)*(HASHTABLE_NPAGE * sizeof(HASHTABLE_DATATYPE));
+ (nSegment+1)*(HASHTABLE_NPAGE * sizeof(ht_slot));
p = (WalIterator *)sqlite3_malloc(nByte);
if( !p ){
return SQLITE_NOMEM;
@@ -1332,10 +1338,10 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){
/* Allocate space for the WalIterator object */
p->nSegment = nSegment;
aSpace = (HASHTABLE_DATATYPE *)&p->aSegment[nSegment];
aSpace = (ht_slot *)&p->aSegment[nSegment];
aTmp = &aSpace[HASHTABLE_NPAGE*nSegment];
for(i=0; i<nSegment; i++){
volatile HASHTABLE_DATATYPE *aHash;
volatile ht_slot *aHash;
int j;
u32 iZero;
int nEntry;
@@ -1947,8 +1953,8 @@ int sqlite3WalRead(
** table after the current read-transaction had started.
*/
for(iHash=walFramePage(iLast); iHash>=0 && iRead==0; iHash--){
volatile HASHTABLE_DATATYPE *aHash; /* Pointer to hash table */
volatile u32 *aPgno; /* Pointer to array of page numbers */
volatile ht_slot *aHash; /* Pointer to hash table */
volatile u32 *aPgno; /* Pointer to array of page numbers */
u32 iZero; /* Frame number corresponding to aPgno[0] */
int iKey; /* Hash slot index */
int rc;
@@ -2073,14 +2079,13 @@ int sqlite3WalEndWriteTransaction(Wal *pWal){
int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
int rc = SQLITE_OK;
if( pWal->writeLock ){
int unused;
Pgno iMax = pWal->hdr.mxFrame;
Pgno iFrame;
/* Restore the clients cache of the wal-index header to the state it
** was in before the client began writing to the database.
*/
memcpy(&pWal->hdr, walIndexHdr(pWal), sizeof(WalIndexHdr));
memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
for(iFrame=pWal->hdr.mxFrame+1;
ALWAYS(rc==SQLITE_OK) && iFrame<=iMax;
@@ -2097,7 +2102,6 @@ int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
** page 1 is never written to the log until the transaction is
** committed. As a result, the call to xUndo may not fail.
*/
assert( pWal->writeLock );
assert( walFramePgno(pWal, iFrame)!=1 );
rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
}