Fix the xCheckReservedLock() method of the flock VFS to avoid dropping the file-lock.

FossilOrigin-Name: 8ffaf85249ff38ceea037a6e96b3484c912f1c1aa55b8642297d592768661344
This commit is contained in:
dan 2024-10-09 15:40:07 +00:00
parent 4b0a2e0106
commit 48dd75df73
4 changed files with 74 additions and 50 deletions

View File

@ -1,5 +1,5 @@
C Improved\shandling\sof\sunicode\scharacters\sin\sthe\sLIKE\soptimization.\nFollow-up\sto\s[bce52ce2a6e7f3d3].
D 2024-10-09T11:52:29.532
C Fix\sthe\sxCheckReservedLock()\smethod\sof\sthe\sflock\sVFS\sto\savoid\sdropping\sthe\sfile-lock.
D 2024-10-09T15:40:07.361
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -753,7 +753,7 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63
F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06
F src/os_kv.c 4d39e1f1c180b11162c6dc4aa8ad34053873a639bac6baae23272fc03349986a
F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107
F src/os_unix.c 779e83666ecd535f6725497ba6da069c1d15138ff6a4ee123edad1ae0cdfbe83
F src/os_unix.c 4086be39edc253ca75d4f447972e26f6998023ab519d1a176e3b3a72fae609d0
F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
F src/pager.c b08600ebf0db90b6d1e9b8b6577c6fa3877cbe1a100bd0b2899e4c6e9adad4b3
@ -1405,7 +1405,7 @@ F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db
F test/lock2.test 5242d8ac4e2d59c403aebff606af449b455aceff
F test/lock3.test f271375930711ae044080f4fe6d6eda930870d00
F test/lock4.test 27143363eda1622f03c133efc8db808fc331afd973486cb571ea71cd717d37b8
F test/lock5.test 24693e40a805f71d80836f720d1f2034684a39b64f1e1990989002c7968c11ee
F test/lock5.test 51e9e2e8d5aed4ec470be19dfc0d630388a7444a8fc812ec8d08e46469a15726
F test/lock6.test ad5b387a3a8096afd3c68a55b9535056431b0cf5
F test/lock7.test 49f1eaff1cdc491cc5dee3669f3c671d9f172431
F test/lock_common.tcl 2f3f7f2e9637f93ccf609df48ef5b27a50278b6b1cd752b445d52262e5841413
@ -2216,8 +2216,11 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 1218a203483cecdc8c9abdc970ad68eba0dfa9cafbed95c63cefb7e8af8babee
R caf8280fa8e7a7de178081dbae97667f
U drh
Z 3adb35abb1bf3d691bca5f7e2785786d
P 9d0eb3980409115f2f6fd1720a03f34e3968c93be55feafdfef20bf5f711c17f
R 1326bd74517af8f0c3bf930ca135c7cd
T *branch * flock-vfs-fix
T *sym-flock-vfs-fix *
T -sym-trunk *
U dan
Z 010da7dfc98fb9ecd5cbc3e4ca08a182
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
9d0eb3980409115f2f6fd1720a03f34e3968c93be55feafdfef20bf5f711c17f
8ffaf85249ff38ceea037a6e96b3484c912f1c1aa55b8642297d592768661344

View File

@ -2464,54 +2464,29 @@ static int robust_flock(int fd, int op){
** is set to SQLITE_OK unless an I/O error occurs during lock checking.
*/
static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){
int rc = SQLITE_OK;
int reserved = 0;
unixFile *pFile = (unixFile*)id;
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
assert( pFile );
assert( pFile->eFileLock<=SHARED_LOCK );
/* Check if a thread in this process holds such a lock */
if( pFile->eFileLock>SHARED_LOCK ){
reserved = 1;
}
/* The flock VFS only ever takes exclusive locks (see function flockLock).
** Therefore, if this connection is holding any lock at all, no other
** connection may be holding a RESERVED lock. So set *pResOut to 0
** in this case.
**
** Or, this connection may be holding no lock. In that case, set *pResOut to
** 0 as well. The caller will then attempt to take an EXCLUSIVE lock on the
** db in order to roll the hot journal back. If there is another connection
** holding a lock, that attempt will fail and an SQLITE_BUSY returned to
** the user. With other VFS, we try to avoid this, in order to allow a reader
** to proceed while a writer is preparing its transaction. But that won't
** work with the flock VFS - as it always takes EXCLUSIVE locks - so it is
** not a problem in this case. */
*pResOut = 0;
/* Otherwise see if some other process holds it. */
if( !reserved ){
/* attempt to get the lock */
int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
if( !lrc ){
/* got the lock, unlock it */
lrc = robust_flock(pFile->h, LOCK_UN);
if ( lrc ) {
int tErrno = errno;
/* unlock failed with an error */
lrc = SQLITE_IOERR_UNLOCK;
storeLastErrno(pFile, tErrno);
rc = lrc;
}
} else {
int tErrno = errno;
reserved = 1;
/* someone else might have it reserved */
lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
if( IS_LOCK_ERROR(lrc) ){
storeLastErrno(pFile, tErrno);
rc = lrc;
}
}
}
OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
if( (rc & 0xff) == SQLITE_IOERR ){
rc = SQLITE_OK;
reserved=1;
}
#endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
*pResOut = reserved;
return rc;
return SQLITE_OK;
}
/*

View File

@ -146,6 +146,52 @@ do_test lock5-flock.8 {
db2 close
} {}
do_test lock5-flock.9 {
sqlite3 db test.db -vfs unix-flock
execsql {
SELECT * FROM t1
}
} {1 2}
do_test lock5-flock.10 {
sqlite3 db2 test.db -vfs unix-flock
execsql {
SELECT * FROM t1
} db2
} {1 2}
do_test lock5-flock.10 {
execsql {
PRAGMA cache_size = 1;
BEGIN;
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10000
)
INSERT INTO t1 SELECT i, i+1 FROM s;
}
catchsql {
SELECT * FROM t1
} db2
} {1 {database is locked}}
do_test lock5-flock.11 {
forcecopy test.db test.db2
forcecopy test.db-journal test.db2-journal
db2 close
sqlite3 db2 test.db2 -vfs unix-flock
catchsql {
SELECT * FROM t1
} db2
} {0 {1 2}}
do_test lock5-flock.12 {
file exists test.db2-journal
} 0
db close
db2 close
}
#####################################################################