diff options
author | drh <drh@noemail.net> | 2010-04-30 02:13:26 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2010-04-30 02:13:26 +0000 |
commit | 79e6c78ccce39af048334f7fb0ad12bdab82d3af (patch) | |
tree | 1f39611d627cce8a8ab4f2103fd930d67d5b1e6c /src | |
parent | 7ed91f2344f1cb6837e1fba1b83fba5b6ddce887 (diff) | |
download | sqlite-79e6c78ccce39af048334f7fb0ad12bdab82d3af.tar.gz sqlite-79e6c78ccce39af048334f7fb0ad12bdab82d3af.zip |
The first 6 WAL tests now work. It's a start.
FossilOrigin-Name: a92c1851da10acf51e7f6f086b8a23bd731940b3
Diffstat (limited to 'src')
-rw-r--r-- | src/os_unix.c | 13 | ||||
-rw-r--r-- | src/wal.c | 36 |
2 files changed, 28 insertions, 21 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index 0e525c073..8480b5f44 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4710,7 +4710,7 @@ static int unixShmSystemLock( u8 mask; /* Mask of bits in lockMask */ /* Access to the unixShmFile object is serialized by the caller */ - assert( sqlite3_mutex_held(pFile->mutex) ); + assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 ); /* Initialize the locking parameters */ memset(&f, 0, sizeof(f)); @@ -4732,13 +4732,15 @@ static int unixShmSystemLock( mask <<= 1; while( mask!=0 && (lockMask & mask)!=0 ){ f.l_len++; + mask <<= 1; } /* Verify that all bits set in lockMask are contiguous */ assert( mask==0 || (lockMask & ~(mask | (mask-1)))==0 ); /* Acquire the system-level lock */ - rc = (fcntl(pFile->h, lockOp, &f)==0) ? SQLITE_OK : SQLITE_BUSY; + rc = fcntl(pFile->h, lockOp, &f); + rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; /* Update the global lock state and do debug tracing */ #ifdef SQLITE_DEBUG @@ -4793,9 +4795,6 @@ static int unixShmUnlock( /* Access to the unixShmFile object is serialized by the caller */ assert( sqlite3_mutex_held(pFile->mutex) ); - /* We never try to unlock locks that we do not hold */ - assert( ((p->exclMask|p->sharedMask) & unlockMask)==unlockMask ); - /* Compute locks held by sibling connections */ for(pX=pFile->pFirst; pX; pX=pX->pNext){ if( pX==p ) continue; @@ -4960,7 +4959,7 @@ static int unixShmOpen( rc = SQLITE_NOMEM; goto shm_open_err; } - memset(pFile, 0, sizeof(pFile)); + memset(pFile, 0, sizeof(*pFile)); pFile->zFilename = (char*)&pFile[1]; memcpy(pFile->zFilename, zName, nName+1); pFile->h = -1; @@ -4983,7 +4982,7 @@ static int unixShmOpen( goto shm_open_err; } - pFile->h = open(zName, O_CREAT, 0664); + pFile->h = open(zName, O_RDWR|O_CREAT, 0664); if( pFile->h<0 ){ rc = SQLITE_CANTOPEN; goto shm_open_err; @@ -378,25 +378,26 @@ static void walIndexUnmap(Wal *pWal){ } /* -** Map the wal-index file into memory if it isn't already. +** Resize the wal-index file. If newSize is negative, leave the size +** unchanged. */ -static int walIndexMap(Wal *pWal){ - int rc = SQLITE_OK; - if( pWal->pWiData==0 ){ - rc = pWal->pVfs->xShmSize(pWal->pWIndex, -1, - &pWal->szWIndex, (void**)(char*)&pWal->pWiData); +static int walIndexRemap(Wal *pWal, int newSize){ + int rc; + walIndexUnmap(pWal); + rc = pWal->pVfs->xShmSize(pWal->pWIndex, newSize, + &pWal->szWIndex, (void**)(char*)&pWal->pWiData); + if( rc==SQLITE_OK && pWal->pWiData==0 ){ + assert( pWal->szWIndex==0 ); + pWal->pWiData = &pWal->iCallback; } return rc; } /* -** Resize the wal-index file. +** Map the wal-index file into memory if it isn't already. */ -static int walIndexRemap(Wal *pWal, int newSize){ - int rc; - walIndexUnmap(pWal); - rc = pWal->pVfs->xShmSize(pWal->pWIndex, newSize, - &pWal->szWIndex, (void**)(char*)&pWal->pWiData); +static int walIndexMap(Wal *pWal){ + int rc = walIndexRemap(pWal, -1); return rc; } @@ -576,12 +577,12 @@ int sqlite3WalOpen( pRet->pVfs = pVfs; pRet->pFd = (sqlite3_file *)&pRet[1]; zWal = pVfs->szOsFile + (char*)pRet->pFd; - sqlite3_snprintf(nWal, zWal, "%s-wal-index", zDb); + sqlite3_snprintf(nWal+11, zWal, "%s-wal-index", zDb); rc = pVfs->xShmOpen(pVfs, zWal, &pRet->pWIndex); if( rc ) goto wal_open_out; /* Open file handle on the write-ahead log file. */ - zWal[nWal-6] = 0; + zWal[nWal+4] = 0; flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL); rc = sqlite3OsOpen(pVfs, zWal, pRet->pFd, flags, &flags); @@ -787,11 +788,18 @@ int walIndexTryHdr(Wal *pWal, int *pChanged){ u32 aCksum[2] = {1, 1}; u32 aHdr[WALINDEX_HDR_NFIELD+2]; + if( pWal->szWIndex==0 ){ + int rc = walIndexRemap(pWal, WALINDEX_MMAP_INCREMENT); + if( rc ) return rc; + } + /* Read the header. The caller may or may not have locked the wal-index ** file, meaning it is possible that an inconsistent snapshot is read ** from the file. If this happens, return SQLITE_ERROR. The caller will ** retry. Or, if the caller has already locked the file and the header ** still looks inconsistent, it will run recovery. + ** + ** FIX-ME: It is no longer possible to have not locked the wal-index. */ memcpy(aHdr, pWal->pWiData, sizeof(aHdr)); walChecksumBytes((u8*)aHdr, sizeof(u32)*WALINDEX_HDR_NFIELD, aCksum); |