mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Do not use the page containing locks for anything to avoid problems with
the manditory file locking on windows. (CVS 1595) FossilOrigin-Name: 5a814202777f381caf5337b37e11c9ab8b8f554a
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.166 2004/06/14 06:03:57 danielk1977 Exp $
|
||||
** $Id: btree.c,v 1.167 2004/06/15 01:40:29 drh Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** For a detailed discussion of BTrees, refer to
|
||||
@@ -207,6 +207,7 @@
|
||||
#include "sqliteInt.h"
|
||||
#include "pager.h"
|
||||
#include "btree.h"
|
||||
#include "os.h"
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
@@ -4146,6 +4147,10 @@ char *sqlite3BtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){
|
||||
}
|
||||
sCheck.anRef = sqliteMallocRaw( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) );
|
||||
for(i=0; i<=sCheck.nPage; i++){ sCheck.anRef[i] = 0; }
|
||||
i = PENDING_BYTE/pBt->pageSize + 1;
|
||||
if( i<=sCheck.nPage ){
|
||||
sCheck.anRef[i] = 1;
|
||||
}
|
||||
sCheck.zErrMsg = 0;
|
||||
|
||||
/* Check the integrity of the freelist
|
||||
|
||||
35
src/os.h
35
src/os.h
@@ -91,18 +91,13 @@
|
||||
#define EXCLUSIVE_LOCK 4
|
||||
|
||||
/*
|
||||
** Windows file locking notes:
|
||||
** File Locking Notes: (Mostly about windows but also some info for Unix)
|
||||
**
|
||||
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
|
||||
** those functions are not available. So we use only LockFile() and
|
||||
** UnlockFile().
|
||||
**
|
||||
** LockFile() prevents not just writing but also reading by other processes.
|
||||
** (This is a design error on the part of Windows, but there is nothing
|
||||
** we can do about that.) So the region used for locking is at the
|
||||
** end of the file where it is unlikely to ever interfere with an
|
||||
** actual read attempt.
|
||||
**
|
||||
** A SHARED_LOCK is obtained by locking a single randomly-chosen
|
||||
** byte out of a specific range of bytes. The lock byte is obtained at
|
||||
** random so two separate readers can probably access the file at the
|
||||
@@ -129,16 +124,32 @@
|
||||
** These #defines are available in os.h so that Unix can use the same
|
||||
** byte ranges for locking. This leaves open the possiblity of having
|
||||
** clients on win95, winNT, and unix all talking to the same shared file
|
||||
** and all locking correctly.
|
||||
** and all locking correctly. To do so would require that samba (or whatever
|
||||
** tool is being used for file sharing) implements locks correctly between
|
||||
** windows and unix. I'm guessing that isn't likely to happen, but by
|
||||
** using the same locking range we are at least open to the possibility.
|
||||
**
|
||||
** Locking in windows is manditory. For this reason, we cannot store
|
||||
** actual data in the bytes used for locking. The pager never allocates
|
||||
** the pages involved in locking therefore.
|
||||
** the pages involved in locking therefore. SHARED_SIZE is selected so
|
||||
** that all locks will fit on a single page even at the minimum page size.
|
||||
** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
|
||||
** is set high so that we don't have to allocate an unused page except
|
||||
** for very large databases. But one should test the page skipping logic
|
||||
** by setting PENDING_BYTE low and running the entire regression suite.
|
||||
**
|
||||
** Changing the value of PENDING_BYTE results in a subtly incompatible
|
||||
** file format. Depending on how it is changed, you might not notice
|
||||
** the incompatibility right away, even running a full regression test.
|
||||
** The default location of PENDING_BYTE is the first byte past the
|
||||
** 1GB boundary.
|
||||
**
|
||||
*/
|
||||
#define SHARED_SIZE 10238
|
||||
#define SHARED_FIRST (0x3fffffff - (SHARED_SIZE - 1))
|
||||
#define RESERVED_BYTE (SHARED_FIRST - 1)
|
||||
#define PENDING_BYTE (RESERVED_BYTE - 1)
|
||||
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
|
||||
/* #define PENDING_BYTE 0x5400 // Page 20 - for testing */
|
||||
#define RESERVED_BYTE (PENDING_BYTE+1)
|
||||
#define SHARED_FIRST (PENDING_BYTE+2)
|
||||
#define SHARED_SIZE 510
|
||||
|
||||
|
||||
int sqlite3OsDelete(const char*);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
** file simultaneously, or one process from reading the database while
|
||||
** another is writing.
|
||||
**
|
||||
** @(#) $Id: pager.c,v 1.126 2004/06/14 06:03:57 danielk1977 Exp $
|
||||
** @(#) $Id: pager.c,v 1.127 2004/06/15 01:40:29 drh Exp $
|
||||
*/
|
||||
#include "os.h" /* Must be first to enable large file support */
|
||||
#include "sqliteInt.h"
|
||||
@@ -1205,6 +1205,9 @@ int sqlite3pager_pagecount(Pager *pPager){
|
||||
return 0;
|
||||
}
|
||||
n /= SQLITE_PAGE_SIZE;
|
||||
if( !pPager->memDb && n==PENDING_BYTE/SQLITE_PAGE_SIZE ){
|
||||
n++;
|
||||
}
|
||||
if( pPager->state!=PAGER_UNLOCK ){
|
||||
pPager->dbSize = n;
|
||||
}
|
||||
@@ -2209,6 +2212,9 @@ int sqlite3pager_write(void *pData){
|
||||
*/
|
||||
if( pPager->dbSize<(int)pPg->pgno ){
|
||||
pPager->dbSize = pPg->pgno;
|
||||
if( !pPager->memDb && pPager->dbSize==PENDING_BYTE/pPager->pageSize ){
|
||||
pPager->dbSize++;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user