1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Make selecting the asynchronous IO file-locking mode a runtime operation. Still untested. (CVS 6544)

FossilOrigin-Name: 577277e84a05707b8c21aa08bc5fc314c1ac38ac
This commit is contained in:
danielk1977
2009-04-24 10:13:05 +00:00
parent debcfd2dcb
commit 4598b8e4a1
4 changed files with 49 additions and 27 deletions

View File

@ -10,7 +10,7 @@
** **
************************************************************************* *************************************************************************
** **
** $Id: sqlite3async.c,v 1.2 2009/04/24 09:27:16 danielk1977 Exp $ ** $Id: sqlite3async.c,v 1.3 2009/04/24 10:13:06 danielk1977 Exp $
** **
** This file contains the implementation of an asynchronous IO backend ** This file contains the implementation of an asynchronous IO backend
** for SQLite. ** for SQLite.
@ -19,8 +19,10 @@
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ASYNCIO) #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ASYNCIO)
#include "sqlite3async.h" #include "sqlite3async.h"
#include "sqlite3.h"
#define ENABLE_FILE_LOCKING #include <stdarg.h>
#include <string.h>
#include <assert.h>
/* Useful macros used in several places */ /* Useful macros used in several places */
#define MIN(x,y) ((x)<(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y))
@ -34,6 +36,8 @@ typedef struct AsyncFileLock AsyncFileLock;
typedef struct AsyncLock AsyncLock; typedef struct AsyncLock AsyncLock;
/* Enable for debugging */ /* Enable for debugging */
#ifndef NDEBUG
#include <stdio.h>
static int sqlite3async_trace = 0; static int sqlite3async_trace = 0;
# define ASYNC_TRACE(X) if( sqlite3async_trace ) asyncTrace X # define ASYNC_TRACE(X) if( sqlite3async_trace ) asyncTrace X
static void asyncTrace(const char *zFormat, ...){ static void asyncTrace(const char *zFormat, ...){
@ -45,6 +49,7 @@ static void asyncTrace(const char *zFormat, ...){
fprintf(stderr, "[%d] %s", 0 /* (int)pthread_self() */, z); fprintf(stderr, "[%d] %s", 0 /* (int)pthread_self() */, z);
sqlite3_free(z); sqlite3_free(z);
} }
#endif
/* /*
** THREAD SAFETY NOTES ** THREAD SAFETY NOTES
@ -374,9 +379,10 @@ static struct TestAsyncStaticData {
AsyncLock *pLock; /* Linked list of all AsyncLock structures */ AsyncLock *pLock; /* Linked list of all AsyncLock structures */
volatile int ioDelay; /* Extra delay between write operations */ volatile int ioDelay; /* Extra delay between write operations */
volatile int eHalt; /* One of the SQLITEASYNC_HALT_XXX values */ volatile int eHalt; /* One of the SQLITEASYNC_HALT_XXX values */
volatile int bLockFiles; /* Current value of "lockfiles" parameter */
int ioError; /* True if an IO error has occurred */ int ioError; /* True if an IO error has occurred */
int nFile; /* Number of open files (from sqlite pov) */ int nFile; /* Number of open files (from sqlite pov) */
} async = { 0,0,0,0,0,0,0 }; } async = { 0,0,0,0,0,1,0,0 };
/* Possible values of AsyncWrite.op */ /* Possible values of AsyncWrite.op */
#define ASYNC_NOOP 0 #define ASYNC_NOOP 0
@ -456,11 +462,11 @@ struct AsyncWrite {
** structures, one for each handle currently open on the file. ** structures, one for each handle currently open on the file.
** **
** If the opened file is not a main-database (the SQLITE_OPEN_MAIN_DB is ** If the opened file is not a main-database (the SQLITE_OPEN_MAIN_DB is
** not passed to the sqlite3OsOpen() call), or if ENABLE_FILE_LOCKING is ** not passed to the sqlite3OsOpen() call), or if async.bLockFiles is
** not defined at compile time, variables AsyncLock.pFile and ** false, variables AsyncLock.pFile and AsyncLock.eLock are never used.
** AsyncLock.eLock are never used. Otherwise, pFile is a file handle ** Otherwise, pFile is a file handle opened on the file in question and
** opened on the file in question and used to obtain the file-system ** used to obtain the file-system locks required by database connections
** locks required by database connections within this process. ** within this process.
** **
** See comments above the asyncLock() function for more details on ** See comments above the asyncLock() function for more details on
** the implementation of database locking used by this backend. ** the implementation of database locking used by this backend.
@ -1064,8 +1070,7 @@ static int asyncOpen(
pLock = (AsyncLock *)sqlite3_malloc(nByte); pLock = (AsyncLock *)sqlite3_malloc(nByte);
if( pLock ){ if( pLock ){
memset(pLock, 0, nByte); memset(pLock, 0, nByte);
#ifdef ENABLE_FILE_LOCKING if( async.bLockFiles && (flags&SQLITE_OPEN_MAIN_DB) ){
if( flags&SQLITE_OPEN_MAIN_DB ){
pLock->pFile = (sqlite3_file *)&pLock[1]; pLock->pFile = (sqlite3_file *)&pLock[1];
rc = pVfs->xOpen(pVfs, pData->zName, pLock->pFile, flags, 0); rc = pVfs->xOpen(pVfs, pData->zName, pLock->pFile, flags, 0);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
@ -1073,7 +1078,6 @@ static int asyncOpen(
pLock = 0; pLock = 0;
} }
} }
#endif
if( pLock ){ if( pLock ){
pLock->nFile = pData->nName; pLock->nFile = pData->nName;
pLock->zFile = &((char *)(&pLock[1]))[pVfs->szOsFile]; pLock->zFile = &((char *)(&pLock[1]))[pVfs->szOsFile];
@ -1607,7 +1611,7 @@ int sqlite3async_control(int op, ...){
&& eWhen!=SQLITEASYNC_HALT_NOW && eWhen!=SQLITEASYNC_HALT_NOW
&& eWhen!=SQLITEASYNC_HALT_IDLE && eWhen!=SQLITEASYNC_HALT_IDLE
){ ){
return SQLITE_ERROR; return SQLITE_MISUSE;
} }
async.eHalt = eWhen; async.eHalt = eWhen;
async_mutex_enter(ASYNC_MUTEX_QUEUE); async_mutex_enter(ASYNC_MUTEX_QUEUE);
@ -1618,9 +1622,24 @@ int sqlite3async_control(int op, ...){
case SQLITEASYNC_DELAY: { case SQLITEASYNC_DELAY: {
int iDelay = va_arg(ap, int); int iDelay = va_arg(ap, int);
if( iDelay<0 ){
return SQLITE_MISUSE;
}
async.ioDelay = iDelay; async.ioDelay = iDelay;
break; break;
} }
case SQLITEASYNC_LOCKFILES: {
int bLock = va_arg(ap, int);
async_mutex_enter(ASYNC_MUTEX_QUEUE);
if( async.nFile || async.pQueueFirst ){
async_mutex_leave(ASYNC_MUTEX_QUEUE);
return SQLITE_MISUSE;
}
async.bLockFiles = bLock;
async_mutex_leave(ASYNC_MUTEX_QUEUE);
break;
}
case SQLITEASYNC_GET_HALT: { case SQLITEASYNC_GET_HALT: {
int *peWhen = va_arg(ap, int *); int *peWhen = va_arg(ap, int *);
@ -1632,6 +1651,11 @@ int sqlite3async_control(int op, ...){
*piDelay = async.ioDelay; *piDelay = async.ioDelay;
break; break;
} }
case SQLITEASYNC_GET_LOCKFILES: {
int *piDelay = va_arg(ap, int *);
*piDelay = async.bLockFiles;
break;
}
default: default:
return SQLITE_ERROR; return SQLITE_ERROR;

View File

@ -1,5 +1,5 @@
C Improve\scomments\sand\sdocumentation\sof\sthe\sasynchronous\sIO\sVFS\smodule.\s(CVS\s6543) C Make\sselecting\sthe\sasynchronous\sIO\sfile-locking\smode\sa\sruntime\soperation.\sStill\suntested.\s(CVS\s6544)
D 2009-04-24T09:27:16 D 2009-04-24T10:13:06
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -25,7 +25,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1 F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1
F ext/async/README.txt 0c541f418b14b415212264cbaaf51c924ec62e5b F ext/async/README.txt 0c541f418b14b415212264cbaaf51c924ec62e5b
F ext/async/sqlite3async.c 2975386c0422dc44e8beebbb85988524141ef8b9 F ext/async/sqlite3async.c 35eddf1c696c7ab9c92934dec9ff251896d93439
F ext/async/sqlite3async.h b6d74dbf9aa5a0ac4e79aa15a4d987f3552a0f75 F ext/async/sqlite3async.h b6d74dbf9aa5a0ac4e79aa15a4d987f3552a0f75
F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b
@ -176,7 +176,7 @@ F src/test6.c 1a0a7a1f179469044b065b4a88aab9faee114101
F src/test7.c b94e68c2236de76889d82b8d7d8e00ad6a4d80b1 F src/test7.c b94e68c2236de76889d82b8d7d8e00ad6a4d80b1
F src/test8.c b1061548f7ce3aeedea3cc4d649ee1487c2b4eaf F src/test8.c b1061548f7ce3aeedea3cc4d649ee1487c2b4eaf
F src/test9.c 963d380922f25c1c323712d05db01b19197ee6f7 F src/test9.c 963d380922f25c1c323712d05db01b19197ee6f7
F src/test_async.c 95c15d9085ea9a837a5c4332a9ae3a8df1afd2cd F src/test_async.c d17e8c21461474d807ca1ee6a51f21210df7cf64
F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
F src/test_backup.c 1384a18985a5a2d275c2662e48473bf1542ebd08 F src/test_backup.c 1384a18985a5a2d275c2662e48473bf1542ebd08
F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0 F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0
@ -723,7 +723,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 18fef3fcf61c137a89a83352f6769ed06845434a P 92bc6be2a86f8a68ceded2bc08fe7d6ff23b56fb
R 848783e3f0d8b2c2ee5a000cbb3565d6 R d1fe56ed7757cac24f050d623f1a6f33
U danielk1977 U danielk1977
Z a232dc6b75d11d81cd6e819ebf60dfe9 Z 741711df9244c68ea2afca1186c054bc

View File

@ -1 +1 @@
92bc6be2a86f8a68ceded2bc08fe7d6ff23b56fb 577277e84a05707b8c21aa08bc5fc314c1ac38ac

View File

@ -10,7 +10,7 @@
** **
************************************************************************* *************************************************************************
** **
** $Id: test_async.c,v 1.59 2009/04/23 14:58:40 danielk1977 Exp $ ** $Id: test_async.c,v 1.60 2009/04/24 10:13:06 danielk1977 Exp $
** **
** This file contains a binding of the asynchronous IO extension interface ** This file contains a binding of the asynchronous IO extension interface
** (defined in ext/async/sqlite3async.h) to Tcl. ** (defined in ext/async/sqlite3async.h) to Tcl.
@ -160,13 +160,11 @@ static int testAsyncStart(
rc = Tcl_CreateThread(&x, tclWriterThread, threadData, nStack, flags); rc = Tcl_CreateThread(&x, tclWriterThread, threadData, nStack, flags);
if( rc!=TCL_OK ){ if( rc!=TCL_OK ){
Tcl_AppendResult(interp, "Tcl_CreateThread() failed", 0);
return TCL_ERROR; return TCL_ERROR;
} }
while( isStarted==0 ){
#if 0 while( isStarted==0 ) { /* Busy loop */ }
sched_yield();
#endif
}
return TCL_OK; return TCL_OK;
} }