1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

When closing a WAL connection, attempt an exclusive lock on the database file. If the lock is obtained, checkpoint the database and delete the wal and wal-index files.

FossilOrigin-Name: c05e7dca172719f33e245c08d0c0e8ab47e5a537
This commit is contained in:
dan
2010-04-30 15:49:27 +00:00
parent 6045461eee
commit a7ad518ef0
3 changed files with 34 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
C If\sa\sreader\sattempts\sto\supgrade\sto\sa\swriter,\sbut\sis\snot\sreading\sthe\smost\srecent\sdatabase\ssnapshot,\sreturn\sSQLITE_BUSY. C When\sclosing\sa\sWAL\sconnection,\sattempt\san\sexclusive\slock\son\sthe\sdatabase\sfile.\sIf\sthe\slock\sis\sobtained,\scheckpoint\sthe\sdatabase\sand\sdelete\sthe\swal\sand\swal-index\sfiles.
D 2010-04-30T15:24:44 D 2010-04-30T15:49:28
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -221,7 +221,7 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1 F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
F src/wal.c 94ebe9e477574baac105975088529f7b141be159 F src/wal.c e4a52d13bff093bc446886cf7b0dfacbc7c2e8a4
F src/wal.h c3f347ba8f1cde46d9bcc6fedaf3ed0aa4b53294 F src/wal.h c3f347ba8f1cde46d9bcc6fedaf3ed0aa4b53294
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c faadd9c2bf08868e5135192b44e0d753e363a885 F src/where.c faadd9c2bf08868e5135192b44e0d753e363a885
@@ -808,7 +808,7 @@ 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
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 4cbe49f13fed288f94ff305bcfd99df907bf7baf P 837d82a92977cbfa0963411daf8160d286a7ed32
R a532c500516c30c14fdbbd5b70d5c12a R 3059f2f53adc88a1128c0bd66d3f0bb8
U dan U dan
Z 18b7f313bb88e234cdae10ff0630f7fb Z 901b5f2ba561b4eab874813e39c862c1

View File

@@ -1 +1 @@
837d82a92977cbfa0963411daf8160d286a7ed32 c05e7dca172719f33e245c08d0c0e8ab47e5a537

View File

@@ -785,8 +785,35 @@ int sqlite3WalClose(
){ ){
int rc = SQLITE_OK; int rc = SQLITE_OK;
if( pWal ){ if( pWal ){
int isDelete = 0; /* True to unlink wal and wal-index files */
/* If an EXCLUSIVE lock can be obtained on the database file (using the
** ordinary, rollback-mode locking methods, this guarantees that the
** connection associated with this log file is the only connection to
** the database. In this case checkpoint the database and unlink both
** the wal and wal-index files.
**
** The EXCLUSIVE lock is not released before returning.
*/
rc = sqlite3OsLock(pFd, SQLITE_LOCK_EXCLUSIVE);
if( rc==SQLITE_OK ){
rc = walCheckpoint(pWal, pFd, sync_flags, zBuf);
if( rc==SQLITE_OK ){
isDelete = 1;
}
walIndexUnmap(pWal);
}
pWal->pVfs->xShmClose(pWal->pWIndex); pWal->pVfs->xShmClose(pWal->pWIndex);
sqlite3OsClose(pWal->pFd); sqlite3OsClose(pWal->pFd);
if( isDelete ){
int nWal;
char *zWal = &((char *)pWal->pFd)[pWal->pVfs->szOsFile];
sqlite3OsDelete(pWal->pVfs, zWal, 0);
nWal = sqlite3Strlen30(zWal);
memcpy(&zWal[nWal], "-index", 7);
pWal->pVfs->xShmDelete(pWal->pVfs, zWal);
}
sqlite3_free(pWal); sqlite3_free(pWal);
} }
return rc; return rc;