From: drh Date: Tue, 29 Nov 2005 18:37:15 +0000 (+0000) Subject: The crash tests now compile, at least. But they get wrong results. The X-Git-Tag: version-3.6.10~3368 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a23593dc087926bad0456a8d438078f20acd790;p=thirdparty%2Fsqlite.git The crash tests now compile, at least. But they get wrong results. The problem is fundamental and suggests I need to completely rethink how the new OS backend should work. (CVS 2792) FossilOrigin-Name: 966bc68e1bf4e0cc88407871c162ee3014160415 --- diff --git a/manifest b/manifest index 40df743861..319f47e197 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\sOsFile\sstructure\sopaque\swith\sits\sinternal\sstructure\sknown\sonly\sto\nthe\sappropriate\sos_*.c\simplementation.\s\sOmit\sthe\sos_unix.h\sand\sos_win.h\ninclude\sfiles.\s\sThe\scrash\stests\sare\sbroken\sby\sthis\spatch.\s(CVS\s2791) -D 2005-11-29T03:13:21 +C The\scrash\stests\snow\scompile,\sat\sleast.\s\sBut\sthey\sget\swrong\sresults.\s\sThe\nproblem\sis\sfundamental\sand\ssuggests\sI\sneed\sto\scompletely\srethink\show\sthe\nnew\sOS\sbackend\sshould\swork.\s(CVS\s2792) +D 2005-11-29T18:37:16 F Makefile.in eac4c98a32a0eae9d6bb2779ac74bbb5441758d3 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -76,7 +76,7 @@ F src/test2.c 02d639d515ddf99a3bbc00f640d8544ecb925a9b F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7 F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5 -F src/test6.c 0543cf075a0cfcc2f83a0810cb2a93d57a7eb602 +F src/test6.c 951effde62e2032a3d6702a33ba2c2c2f993f412 F src/tokenize.c bdb79702217af49eba44c2a3b4f5fc7bd9ed2917 F src/trigger.c aea0283a3ef729a3e9c8dc5dc1a11c9fcc0a12a7 F src/update.c fec7665138ccf2a2133f11dcd24c1134c6b33526 @@ -323,7 +323,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 1b4f2d89bbe833359cefcea580783fd92aa7b8ab -R 167d41b6779a94a69e79f7db1fd9daa9 +P 058f31753871b16b40fe4048e3adcee411e0f87d +R f03dc6c82442298d495305724980efdb U drh -Z 717f7b44d42f5a1bd0daf8e23da32026 +Z cd7ffca575734c25d3ac042458e8a016 diff --git a/manifest.uuid b/manifest.uuid index 71074c1ab4..8d82992eb3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -058f31753871b16b40fe4048e3adcee411e0f87d \ No newline at end of file +966bc68e1bf4e0cc88407871c162ee3014160415 \ No newline at end of file diff --git a/src/test6.c b/src/test6.c index 3407ff2b50..87e54f632f 100644 --- a/src/test6.c +++ b/src/test6.c @@ -18,7 +18,6 @@ #include "sqliteInt.h" #include "os.h" #include "tcl.h" -#if 0 /* ** A copy of the original sqlite3Io structure @@ -32,6 +31,7 @@ static struct sqlite3IoVtbl origIo; struct OsFile { u8 **apBlk; /* Array of blocks that have been written to. */ int nBlk; /* Size of apBlock. */ + i64 offset; /* Next character to be read from the file */ int nMaxWrite; /* Largest offset written to. */ char *zName; /* File name */ OsFile *pBase; /* Base class */ @@ -98,29 +98,30 @@ static int crashRequired(char const *zPath){ /* ** A list of all open files. */ -static OsTestFile *pAllFiles = 0; +static OsFile *pAllFiles = 0; /* ** Initialise the os_test.c specific fields of pFile. */ -static void initFile(OsFile **pId, char const *zName){ +static void initFile(OsFile **pId, char const *zName, OsFile *pBase){ OsFile *pFile = *pId = sqliteMalloc(sizeof(OsFile) + strlen(zName)+1); pFile->nMaxWrite = 0; + pFile->offset = 0; pFile->nBlk = 0; pFile->apBlk = 0; pFile->zName = (char *)(&pFile[1]); strcpy(pFile->zName, zName); - pFile->pBase = id; + pFile->pBase = pBase; pFile->pNext = pAllFiles; pAllFiles = pFile; } /* -** Undo the work done by initFile. Delete the OsTestFile structure +** Undo the work done by initFile. Delete the OsFile structure ** and unlink the structure from the pAllFiles list. */ -static void closeFile(OsFile *id){ - OsFile *pFile = id; +static void closeFile(OsFile **pId){ + OsFile *pFile = *pId; if( pFile==pAllFiles ){ pAllFiles = pFile->pNext; }else{ @@ -130,21 +131,14 @@ static void closeFile(OsFile *id){ } p->pNext = pFile->pNext; } - sqliteFree(pFile); -} - -/* -** Return the current seek offset from the start of the file. This -** is unix-only code. -*/ -static i64 osTell(OsFile *pFile){ - return lseek(pFile->pBase->h, 0, SEEK_CUR); + sqliteFree(*pId); + *pId = 0; } /* -** Load block 'blk' into the cache of pFile. +** Read block 'blk' off of the real disk file and into the cache of pFile. */ -static int cacheBlock(OsFile *pFile, int blk){ +static int readBlockIntoCache(OsFile *pFile, int blk){ if( blk>=pFile->nBlk ){ int n = ((pFile->nBlk * 2) + 100 + blk); /* if( pFile->nBlk==0 ){ printf("DIRTY %s\n", pFile->zName); } */ @@ -187,10 +181,8 @@ static int cacheBlock(OsFile *pFile, int blk){ static int writeCache2(OsFile *pFile, int crash){ int i; int nMax = pFile->nMaxWrite; - i64 offset; int rc = SQLITE_OK; - offset = osTell(pFile); for(i=0; inBlk; i++){ u8 *p = pFile->apBlk[i]; if( p ){ @@ -239,10 +231,6 @@ printf("Writing block %d of %s\n", i, pFile->zName); pFile->nBlk = 0; pFile->apBlk = 0; pFile->nMaxWrite = 0; - - if( rc==SQLITE_OK ){ - rc = origIo.xSeek(pFile->pBase, offset); - } return rc; } @@ -253,7 +241,7 @@ static int writeCache(OsFile *pFile){ if( pFile->apBlk ){ int c = crashRequired(pFile->zName); if( c ){ - OsTestFile *p; + OsFile *p; #ifdef TRACE_WRITECACHE printf("\nCrash during sync of %s\n", pFile->zName); #endif @@ -271,14 +259,19 @@ static int writeCache(OsFile *pFile){ /* ** Close the file. */ -static int crashClose(OsFile *id){ - if( id->pAux ) return SQLITE_OK; - if( id->isOpen ){ - /* printf("CLOSE %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */ - writeCache(id); - origIo.xClose(&id->pBase); +static int crashClose(OsFile **pId){ + OsFile *pFile = *pId; + if( pFile ){ + /* printf("CLOSE %s (%d blocks)\n", pFile->zName, pFile->nBlk); */ + writeCache(pFile); + origIo.xClose(&pFile->pBase); } - closeFile(id); + closeFile(pId); + return SQLITE_OK; +} + +static int crashSeek(OsFile *id, i64 offset){ + id->offset = offset; return SQLITE_OK; } @@ -289,9 +282,9 @@ static int crashRead(OsFile *id, void *pBuf, int amt){ int i; u8 *zCsr; int rc = SQLITE_OK; - OsTestFile *pFile = (OsTestFile*)id->pAux; + OsFile *pFile = id; - offset = osTell(pFile); + offset = pFile->offset; end = offset+amt; blk = (offset/BLOCKSIZE); @@ -313,9 +306,9 @@ static int crashRead(OsFile *id, void *pBuf, int amt){ u8 *pBlk = pFile->apBlk[i]; memcpy(zCsr, &pBlk[off], len); }else{ - rc = origIo.xSeek(id, BLOCK_OFFSET(i) + off); + rc = origIo.xSeek(id->pBase, BLOCK_OFFSET(i) + off); if( rc!=SQLITE_OK ) return rc; - rc = origIo.xRead(id, zCsr, len); + rc = origIo.xRead(id->pBase, zCsr, len); if( rc!=SQLITE_OK ) return rc; } @@ -323,7 +316,7 @@ static int crashRead(OsFile *id, void *pBuf, int amt){ } assert( zCsr==&((u8 *)pBuf)[amt] ); - rc = origIo.xSeek(id, end); + id->offset = end; return rc; } @@ -334,9 +327,8 @@ static int crashWrite(OsFile *id, const void *pBuf, int amt){ int i; const u8 *zCsr; int rc = SQLITE_OK; - OsTestFile *pFile = (OsTestFile*)id->pAux; - offset = osTell(pFile); + offset = id->offset; end = offset+amt; blk = (offset/BLOCKSIZE); @@ -347,11 +339,11 @@ static int crashWrite(OsFile *id, const void *pBuf, int amt){ int len = 0; /* Make sure the block is in the cache */ - rc = cacheBlock(pFile, i); + rc = readBlockIntoCache(id, i); if( rc!=SQLITE_OK ) return rc; /* Write into the cache */ - pBlk = pFile->apBlk[i]; + pBlk = id->apBlk[i]; assert( pBlk ); if( BLOCK_OFFSET(i) < offset ){ @@ -364,12 +356,11 @@ static int crashWrite(OsFile *id, const void *pBuf, int amt){ memcpy(&pBlk[off], zCsr, len); zCsr += len; } - if( pFile->nMaxWritenMaxWrite = end; + if( id->nMaxWritenMaxWrite = end; } assert( zCsr==&((u8 *)pBuf)[amt] ); - - rc = origIo.xSeek(id, end); + id->offset = end; return rc; } @@ -380,9 +371,8 @@ static int crashWrite(OsFile *id, const void *pBuf, int amt){ static int crashSync(OsFile *id, int dataOnly){ int rc; /* printf("SYNC %s (%d blocks)\n", (*id)->zName, (*id)->nBlk); */ - rc = writeCache((OsTestFile*)id->pAux); - if( rc!=SQLITE_OK ) return rc; - rc = origIo.xSync(id, dataOnly); + rc = writeCache(id); + /* if( rc!=SQLITE_OK ) return rc; rc = origIo.xSync(id->pBase, dataOnly); */ return rc; } @@ -392,9 +382,8 @@ static int crashSync(OsFile *id, int dataOnly){ ** is written to disk. */ static int crashTruncate(OsFile *id, i64 nByte){ - OsTestFile *pFile = (OsTestFile*)id->pAux; - pFile->nMaxWrite = nByte; - return origIo.xTruncate(id, nByte); + id->nMaxWrite = nByte; + return origIo.xTruncate(id->pBase, nByte); } /* @@ -402,10 +391,9 @@ static int crashTruncate(OsFile *id, i64 nByte){ ** the file, then return this size instead of the on-disk size. */ static int crashFileSize(OsFile *id, i64 *pSize){ - int rc = origIo.xFileSize(id, pSize); - OsTestFile *pFile = (OsTestFile*)id->pAux; - if( rc==SQLITE_OK && pSize && *pSizenMaxWrite ){ - *pSize = pFile->nMaxWrite; + int rc = origIo.xFileSize(id->pBase, pSize); + if( rc==SQLITE_OK && pSize && *pSizenMaxWrite ){ + *pSize = id->nMaxWrite; } return rc; } @@ -415,25 +403,66 @@ static int crashFileSize(OsFile *id, i64 *pSize){ ** initialise the os_test.c specific fields and then call the corresponding ** os_unix.c function to really open the file. */ -static int crashOpenReadWrite(const char *zFilename, OsFile *id, int *pRdonly){ - initFile(id, zFilename); - return origIo.xOpenReadWrite(zFilename, id, pRdonly); +static int crashOpenReadWrite(const char *zFilename, OsFile **pId,int *pRdonly){ + OsFile *pBase = 0; + int rc = origIo.xOpenReadWrite(zFilename, &pBase, pRdonly); + if( !rc ){ + initFile(pId, zFilename, pBase); + } + return rc; } -static int crashOpenExclusive(const char *zFilename, OsFile *id, int delFlag){ - initFile(id, zFilename); - return origIo.xOpenExclusive(zFilename, id, delFlag); +static int crashOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){ + OsFile *pBase = 0; + int rc = origIo.xOpenExclusive(zFilename, &pBase, delFlag); + if( !rc ){ + initFile(pId, zFilename, pBase); + } + return rc; } -static int crashOpenReadOnly(const char *zFilename, OsFile *id){ - initFile(id, zFilename); - return origIo.xOpenReadOnly(zFilename, id); +static int crashOpenReadOnly(const char *zFilename, OsFile **pId){ + OsFile *pBase = 0; + int rc = origIo.xOpenReadOnly(zFilename, &pBase); + if( !rc ){ + initFile(pId, zFilename, pBase); + } + return rc; } /* -** Make a copy of an OsFile object +** OpenDirectory and SyncDirectory are no-ops */ -static void crashCopyOsFile(OsFile *pDest, OsFile *pSrc){ - *pDest = *pSrc; - ((OsTestFile*)(pDest->pAux))->pBase = pDest; +static int crashOpenDir(const char *zName, OsFile *id){ + return SQLITE_OK; +} +static int crashSyncDir(const char *zName){ + return SQLITE_OK; +} + +/* +** Locking primitives are passed through into the underlying +** file descriptor. +*/ +int crashLock(OsFile *id, int lockType){ + return origIo.xLock(id->pBase, lockType); +} +int crashUnlock(OsFile *id, int lockType){ + return origIo.xUnlock(id->pBase, lockType); +} +int crashCheckReservedLock(OsFile *id){ + return origIo.xCheckReservedLock(id->pBase); +} +void crashSetFullSync(OsFile *id, int setting){ + return; /* This is a no-op */ +} +int crashLockState(OsFile *id){ + return origIo.xLockState(id->pBase); +} + +/* +** Return the underlying file handle. +*/ +int crashFileHandle(OsFile *id){ + return origIo.xFileHandle(id->pBase); } /* @@ -463,27 +492,37 @@ static int crashParamsObjCmd( } setCrashParams(delay, zFile); origIo = sqlite3Io; + /* xDelete unchanged */ + /* xFileExists unchanged */ + sqlite3Io.xOpenReadWrite = crashOpenReadWrite; + sqlite3Io.xOpenExclusive = crashOpenExclusive; + sqlite3Io.xOpenReadOnly = crashOpenReadOnly; + sqlite3Io.xOpenDirectory = crashOpenDir; + sqlite3Io.xSyncDirectory = crashSyncDir; + /* xTempFileName unchanged */ + /* xIsDirWritable unchanged */ + sqlite3Io.xClose = crashClose; sqlite3Io.xRead = crashRead; sqlite3Io.xWrite = crashWrite; - sqlite3Io.xClose = crashClose; + sqlite3Io.xSeek = crashSeek; sqlite3Io.xSync = crashSync; sqlite3Io.xTruncate = crashTruncate; sqlite3Io.xFileSize = crashFileSize; - sqlite3Io.xOpenReadWrite = crashOpenReadWrite; - sqlite3Io.xOpenExclusive = crashOpenExclusive; - sqlite3Io.xOpenReadOnly = crashOpenReadOnly; - sqlite3Io.xSet + /* xFullPathname unchanged */ + sqlite3Io.xLock = crashLock; + sqlite3Io.xUnlock = crashUnlock; + sqlite3Io.xCheckReservedLock = crashCheckReservedLock; + sqlite3Io.xSetFullSync = crashSetFullSync; + sqlite3Io.xFileHandle = crashFileHandle; + sqlite3Io.xLockState = crashLockState; return TCL_OK; } -#endif /* ** This procedure registers the TCL procedures defined in this file. */ int Sqlitetest6_Init(Tcl_Interp *interp){ -#if 0 Tcl_CreateObjCommand(interp, "sqlite3_crashparams", crashParamsObjCmd, 0, 0); -#endif return TCL_OK; }