Change the way threadsOverrideEachOthersLocks() works to avoid trying to write-lock a (potentially) read-only files. Also, assume that on non-linux systems threads do override each others locks. Ticket #3472. (CVS 5883)

FossilOrigin-Name: 8ecae0943b06102fe22133db0dcaf58ecbd39545
This commit is contained in:
danielk1977 2008-11-11 18:34:35 +00:00
parent a78c22c433
commit 41a6a61d94
4 changed files with 83 additions and 31 deletions

View File

@ -1,5 +1,5 @@
C Cleanup\sin\sflattenSubquery.\s\sAdd\sOOM\stests\sfor\sflattenSubquery.\s\sFix\sissues\nwith\sOOM\serrors\scauses\sproblems\sfor\sflattenSubquery.\s\sTicket\s#3485.\s(CVS\s5882)
D 2008-11-11T18:28:59
C Change\sthe\sway\sthreadsOverrideEachOthersLocks()\sworks\sto\savoid\strying\sto\swrite-lock\sa\s(potentially)\sread-only\sfiles.\sAlso,\sassume\sthat\son\snon-linux\ssystems\sthreads\sdo\soverride\seach\sothers\slocks.\sTicket\s#3472.\s(CVS\s5883)
D 2008-11-11T18:34:35
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 48172b58e444a9725ec482e0c022a564749acab4
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -136,7 +136,7 @@ F src/os.c 0b411644b87ad689d7250bbfd1834d99b81a3df4
F src/os.h ef8abeb9afc694b82dbd169a91c9b7e26db3c892
F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
F src/os_os2.c 63be0987dbeb42e9b08c831863d2a315953b86e1
F src/os_unix.c d17f694eda9d583676bcab87109efad42dd2abe1
F src/os_unix.c af390f03ebe339e63911aec2d4ccd1e53fde581e
F src/os_win.c e208cbbceac63c1dd881d0909de5a4679a2c6992
F src/pager.c 6b6f8eb4938d184d6612ea89631185dbace246b3
F src/pager.h 4a57b219c0765fe1870238064e3f46e4eb2cf5af
@ -575,6 +575,7 @@ F test/tkt3424.test 3171193ce340cff6b7ea81c03b8fa1cbc34ec36e
F test/tkt3442.test 33722a3fa4bdc0614448044eb5e28765aea28eb7
F test/tkt3457.test e9ca2b90f0eb1fb8be73a30d29aacb2e3abedeb9
F test/tkt3461.test 5a63e8d8ee5ce00f076b1e2f82aba5480a0f14ed
F test/tkt3472.test cc1fa004edd040dbc4c5c03327f8f3d3bbcd9ccb
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
F test/trace.test 951cd0f5f571e7f36bf7bfe04be70f90fb16fb00
F test/trans.test 2fd24cd7aa0b879d49a224cbd647d698f1e7ac5c
@ -654,7 +655,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 0659a666ff0a9fc81ee4df3c35e535164c79e588
R 4feb3b063e6492d2c3095674c86d05b4
U drh
Z ccf27dcefe10bea054f7ff323046db0d
P ea5f4baa041aed934600f0f96b84afb92a14bc47
R 67f50952a830fd72a8913f41885cf6a5
U danielk1977
Z df5f98daf78e83087123ba4df516fc8d

View File

@ -1 +1 @@
ea5f4baa041aed934600f0f96b84afb92a14bc47
8ecae0943b06102fe22133db0dcaf58ecbd39545

View File

@ -12,7 +12,7 @@
**
** This file contains code that is specific to Unix systems.
**
** $Id: os_unix.c,v 1.208 2008/11/07 00:06:18 drh Exp $
** $Id: os_unix.c,v 1.209 2008/11/11 18:34:35 danielk1977 Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_UNIX /* This file is used on unix only */
@ -493,16 +493,19 @@ static int lockTrace(int fd, int op, struct flock *p){
#define fcntl lockTrace
#endif /* SQLITE_LOCK_TRACE */
#ifdef __linux__
/*
** The testThreadLockingBehavior() routine launches two separate
** threads on this routine. This routine attempts to lock a file
** descriptor then returns. The success or failure of that attempt
** allows the testThreadLockingBehavior() procedure to determine
** whether or not threads can override each others locks.
*/
** This function is used as the main routine for a thread launched by
** testThreadLockingBehavior(). It tests whether the shared-lock obtained
** by the main thread in testThreadLockingBehavior() conflicts with a
** hypothetical write-lock obtained by this thread on the same file.
**
** The write-lock is not actually acquired, as this is not possible if
** the file is open in read-only mode (see ticket #3472).
*/
static void *threadLockingTest(void *pArg){
struct threadTestData *pData = (struct threadTestData*)pArg;
pData->result = fcntl(pData->fd, F_SETLK, &pData->lock);
pData->result = fcntl(pData->fd, F_GETLK, &pData->lock);
return pArg;
}
@ -513,26 +516,39 @@ static void *threadLockingTest(void *pArg){
*/
static void testThreadLockingBehavior(int fd_orig){
int fd;
struct threadTestData d[2];
pthread_t t[2];
int rc;
struct threadTestData d;
struct flock l;
pthread_t t;
fd = dup(fd_orig);
if( fd<0 ) return;
memset(d, 0, sizeof(d));
d[0].fd = fd;
d[0].lock.l_type = F_RDLCK;
d[0].lock.l_len = 1;
d[0].lock.l_start = 0;
d[0].lock.l_whence = SEEK_SET;
d[1] = d[0];
d[1].lock.l_type = F_WRLCK;
pthread_create(&t[0], 0, threadLockingTest, &d[0]);
pthread_create(&t[1], 0, threadLockingTest, &d[1]);
pthread_join(t[0], 0);
pthread_join(t[1], 0);
memset(&l, 0, sizeof(l));
l.l_type = F_RDLCK;
l.l_len = 1;
l.l_start = 0;
l.l_whence = SEEK_SET;
rc = fcntl(fd_orig, F_SETLK, &l);
if( rc!=0 ) return;
memset(&d, 0, sizeof(d));
d.fd = fd;
d.lock = l;
d.lock.l_type = F_WRLCK;
pthread_create(&t, 0, threadLockingTest, &d);
pthread_join(t, 0);
close(fd);
threadsOverrideEachOthersLocks = d[0].result==0 && d[1].result==0;
if( d.result!=0 ) return;
threadsOverrideEachOthersLocks = (d.lock.l_type==F_UNLCK);
}
#else
/*
** On anything other than linux, assume threads override each others locks.
*/
static void testThreadLockingBehavior(int fd_orig){
threadsOverrideEachOthersLocks = 1;
}
#endif /* __linux__ */
#endif /* SQLITE_THREADSAFE */
/*

35
test/tkt3472.test Normal file
View File

@ -0,0 +1,35 @@
# 2008 November 11
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# $Id: tkt3472.test,v 1.1 2008/11/11 18:34:35 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set ::correctvalue $threadsOverrideEachOthersLocks
puts "threadsOverrideEachOthersLocks = $::correctvalue"
do_test tkt3472-1.1 {
db close
set threadsOverrideEachOthersLocks -1
sqlite3 db test.db
set threadsOverrideEachOthersLocks
} $::correctvalue
do_test tkt3472-1.2 {
db close
set threadsOverrideEachOthersLocks -1
sqlite3 db test.db -readonly 1
set threadsOverrideEachOthersLocks
} $::correctvalue
finish_test