]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
OFD locks are now mostly working, but need additional tests.
authordrh <drh@noemail.net>
Tue, 19 Jun 2018 19:01:01 +0000 (19:01 +0000)
committerdrh <drh@noemail.net>
Tue, 19 Jun 2018 19:01:01 +0000 (19:01 +0000)
FossilOrigin-Name: 4f1fb5c94b55c871f9ab70e19ee968f67082f70851c624028967ff11ac856e4a

manifest
manifest.uuid
src/global.c
src/main.c
src/os_unix.c
src/sqlite.h.in
src/sqliteInt.h
src/test1.c
src/test_malloc.c
test/unixexcl.test

index 02097260c7c0ee0768b14bc593ba098dcbd682f1..010293457baa860168e9d79e49ad5bf8c9a799b2 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Miscellaneous\scleanup\sof\sOFD\slogic.\s\sAdd\san\s#if\s0\sto\sdisable\sthe\suse\sof\nOFD\slogic,\stemporarily,\suntil\sI\scan\sget\sit\sto\sactually\swork.
-D 2018-06-19T17:19:46.493
+C OFD\slocks\sare\snow\smostly\sworking,\sbut\sneed\sadditional\stests.
+D 2018-06-19T19:01:01.578
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in bfc40f350586923e0419d2ea4b559c37ec10ee4b6e210e08c14401f8e340f0da
@@ -451,7 +451,7 @@ F src/expr.c 3ab855fb882d8758220edaf261d8d56ad2cb3736f92c818f4ae250ac4a2752a4
 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
 F src/fkey.c b1da9ef8dc834603bb0d28972378a7ce65897847f9a1e89ab800bbdf24c788ee
 F src/func.c e2e3c02621a528a472933fd4733a5da635676f1461be73293f6e9f62f18d4eaa
-F src/global.c 9bf034fd560bdd514715170ed8460bb7f823cec113f0569ef3f18a20c7ccd128
+F src/global.c 58ab3df86a891570fa8f8f171174999b2fe83da854f0f879553b63961d18fddd
 F src/hash.c a12580e143f10301ed5166ea4964ae2853d3905a511d4e0c44497245c7ce1f7a
 F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4
 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da
@@ -459,7 +459,7 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c bcacf6a0d277f8fa0e4f9ffecda544a2330ca4478f904cd89564c2dd86d0b16b
 F src/legacy.c 134ab3e3fae00a0f67a5187981d6935b24b337bcf0f4b3e5c9fa5763da95bf4e
 F src/loadext.c 6aae5739198d96c51ae6eb97c4a5b1744c22ed7a5a565a5399a717780d48a36b
-F src/main.c a086ab7d6e4e3f07bd5789d16f977d425f9482e7b3baeeb2f17bde0e6bfb2bc1
+F src/main.c 5ec5bc48f76ecbf464b2a481e3674c36f0a9ea9fb60e39adae8c7b692206028c
 F src/malloc.c 07295435093ce354c6d9063ac05a2eeae28bd251d2e63c48b3d67c12c76f7e18
 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de
@@ -479,7 +479,7 @@ F src/os.c 8aeb0b0f40f8f5b0da03fe49706695adaf42d2f516ab95abc72e86c245e119de
 F src/os.h 48388821692e87da174ea198bf96b1b2d9d83be5dfc908f673ee21fafbe0d432
 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
-F src/os_unix.c 71b17c32fce222f7dfd94dd62871dff3e645e5cd4a84d45b400469cbb39bba9f
+F src/os_unix.c 5713c9960370c3a60d7c95a12808aef1c25634291d78bd7bcebe0de90f594b30
 F src/os_win.c ac29c25cde4cfb4adacc59cdec4aa45698ca0e29164ea127859585ccd9faa354
 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
 F src/pager.c 1bb6a57fa0465296a4d6109a1a64610a0e7adde1f3acf3ef539a9d972908ce8f
@@ -497,15 +497,15 @@ F src/resolve.c 14602f46800ba182ea6a490e0f304127d29ac1f724bdadcc639e25d3223fcf6e
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
 F src/select.c 8d3176c5258cc83942815ebe75b4c1f8dcf62b5e0f4d37373a14ebf23c046f9f
 F src/shell.c.in 8578421c5fb2a972461b2a996f7173646e55e0dbd2a2eee30c8f5dc7d3dbadfd
-F src/sqlite.h.in a97be4beec01ea557809fe79a8e6befefa370bd7e3ba0c1a1abfe4c94ae59888
+F src/sqlite.h.in 77fde2a5afd91152daa67c7a7167699635c495d3fa733556f65049fbd5098542
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 9887b27e69c01e79c2cbe74ef73bf01af5b5703d6a7f0a4371e386d7249cb1c7
-F src/sqliteInt.h c8d304712b6b4e2150cbb5355b1a80427eee7b3ea1a6b5827afadf557360d7fe
+F src/sqliteInt.h 95836c91a6ce6606d157ff508e23a0c2d6ac7ac499d9495097a9e668f9b802df
 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
 F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
 F src/tclsqlite.c 916a92de77ec5cbe27818ca194d8cf0c58aa7ad5b87527098f6aa5a6068800ce
-F src/test1.c 553365d346ed17c099fef671204cdec6e40e701af62ef4f5527e4f2a08b98bb0
+F src/test1.c badad960c27f27130e6146d11c4bb06b1f31ce0216c5ee7878b37ca32c717598
 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
 F src/test3.c 61798bb0d38b915067a8c8e03f5a534b431181f802659a6616f9b4ff7d872644
 F src/test4.c 18ec393bb4d0ad1de729f0b94da7267270f3d8e6
@@ -532,7 +532,7 @@ F src/test_intarray.c 988fc61cb0ff539f4172c0d95f15287c92516f64
 F src/test_intarray.h f3b7672f5d1056eac563c0d6ea8480a660b1475c
 F src/test_journal.c 619f2aa10e0d7a5f87c0f06825bc61dfce1c6b9c7f3ad990fb13de6c3b8874a3
 F src/test_loadext.c 337056bae59f80b9eb00ba82088b39d0f4fe6dfd
-F src/test_malloc.c dec0aa821b230773aeb3dd11d652c1193f7cedb18a20b25659bc672288115242
+F src/test_malloc.c baf1888c5040ff190f318dbc25cfffc0bcbe5c9db5c7ccb911316e8337a08808
 F src/test_md5.c 7268e1e8c399d4a5e181b64ac20e1e6f3bc4dd9fc87abac02db145a3d951fa8c
 F src/test_multiplex.c e054459f7633f3ff8ce1245da724f9a8be189e4e
 F src/test_multiplex.h 5436d03f2d0501d04f3ed50a75819e190495b635
@@ -1511,7 +1511,7 @@ F test/unionvtab.test 595fb601de00188ca5e7c6dbe266c17a0faf234cf434ce85eccec1a929
 F test/unionvtabfault.test 26b6854d5aef9005cd630513025690bff1b7378ae9c97b81e2a3cbe84eee0f58
 F test/unique.test 93f8b2ef5ea51b9495f8d6493429b1fd0f465264
 F test/unique2.test 3674e9f2a3f1fbbfd4772ac74b7a97090d0f77d2
-F test/unixexcl.test d936ba2b06794018e136418addd59a2354eeae97
+F test/unixexcl.test 2efd77088afe73dd4b810f260121a5a2271f0c527f0788c70b414577daa104cd
 F test/unordered.test ffeea7747d5ba962a8009a20b7e53d68cbae05b063604c68702c5998eb50c981
 F test/update.test 1148de8d913e9817717990603aadeca07aab9ddbb10a30f167cbfd8d3a3ccb60
 F test/update2.test 5e67667e1c54017d964e626db765cf8bedcf87483c184f4c575bdb8c1dd2313e
@@ -1731,7 +1731,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 148f8dec9a26f11d343bfeb558fd12ba18d7f5d4d69da58fc8aa22f88e13c408
-R 83961ea01a7dee6aa8cd5a190f64b60a
+P d849ade396d2dda4ed18f8e44d19ab218f94ef41a76a99f937238253e716dc05
+R 018a532db3427b0e69c05b2d8fcf6e5e
 U drh
-Z 043ea47a258168f0e14367c4e0b60a6e
+Z bf846025729235094c8cf265395fdfc1
index 1bbef0ffc23d96d9afe7f2583dd01287786e10f5..c5ba459a50e7293c841c72006d0855cbb794543e 100644 (file)
@@ -1 +1 @@
-d849ade396d2dda4ed18f8e44d19ab218f94ef41a76a99f937238253e716dc05
\ No newline at end of file
+4f1fb5c94b55c871f9ab70e19ee968f67082f70851c624028967ff11ac856e4a
\ No newline at end of file
index f0362d1e0445af428776d7f163dbfc2426eb60ae..aee5b66f67da4c63396af3cf964f3793ef7159d4 100644 (file)
@@ -240,6 +240,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
    0,                         /* xTestCallback */
 #endif
    0,                         /* bLocaltimeFault */
+   1,                         /* bOfdLocks */
    0x7ffffffe,                /* iOnceResetThreshold */
    SQLITE_DEFAULT_SORTERREF_SIZE   /* szSorterRef */
 };
index a2b994f9becde3e6734445b557a5604a88d30e0c..d19bd3e4805ca4ceb3e1457ed92aa158525faec2 100644 (file)
@@ -653,6 +653,11 @@ int sqlite3_config(int op, ...){
     }
 #endif /* SQLITE_ENABLE_SORTER_REFERENCES */
 
+    case SQLITE_CONFIG_OFD_LOCKS: {
+      sqlite3GlobalConfig.bOfdLocks = va_arg(ap, int);
+      break;
+    }
+
     default: {
       rc = SQLITE_ERROR;
       break;
index 0482424f8b571db27898ff27d3d713faa37d9c69..bc26a932e0af48e0ed99d0e6f99b63446b90157c 100644 (file)
@@ -1128,6 +1128,7 @@ static void vxworksReleaseFileId(struct vxworksFileId *pId){
 ** to locate a particular unixInodeInfo object.
 */
 struct unixFileId {
+  void *pExtra;
   dev_t dev;                  /* Device number */
 #if OS_VXWORKS
   struct vxworksFileId *pId;  /* Unique file ID for vxworks. */
@@ -1384,6 +1385,7 @@ static int findInodeInfo(
 
   memset(&fileId, 0, sizeof(fileId));
   fileId.dev = statbuf.st_dev;
+  if( UsesOfd(pFile) ) fileId.pExtra = pFile;
 #if OS_VXWORKS
   fileId.pId = pFile->pId;
 #else
@@ -3960,12 +3962,7 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
     }
 #endif
     case SQLITE_FCNTL_OFD_LOCKS: {
-      int x = *(int*)pArg;
-      if( x==0 ){
-        pFile->eSetLk = F_SETLK;
-        pFile->eGetLk = F_GETLK;
-      }
-      *(int*)pArg = pFile->eSetLk==F_OFD_SETLK;
+      *(int*)pArg = UsesOfd(pFile);
       return SQLITE_OK;
     }
 #if SQLITE_MAX_MMAP_SIZE>0
@@ -4413,6 +4410,7 @@ static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){
   lock.l_start = UNIX_SHM_DMS;
   lock.l_len = 1;
   lock.l_type = F_WRLCK;
+  lock.l_pid = 0;
   if( osFcntl(pShmNode->h, pDbFd->eGetLk, &lock)!=0 ) {
     rc = SQLITE_IOERR_LOCK;
   }else if( lock.l_type==F_UNLCK ){
@@ -5470,10 +5468,23 @@ static int fillInUnixFile(
 
   OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
   pNew->h = h;
+  pNew->pVfs = pVfs;
+  pNew->zPath = zFilename;
+  pNew->ctrlFlags = (u8)ctrlFlags;
+#if SQLITE_MAX_MMAP_SIZE>0
+  pNew->mmapSizeMax = sqlite3GlobalConfig.szMmap;
+#endif
+  if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
+                           "psow", SQLITE_POWERSAFE_OVERWRITE) ){
+    pNew->ctrlFlags |= UNIXFILE_PSOW;
+  }
+  if( strcmp(pVfs->zName,"unix-excl")==0 ){
+    pNew->ctrlFlags |= UNIXFILE_EXCL;
+  }
   pNew->eSetLk = F_SETLK;
   pNew->eGetLk = F_GETLK;
-#if HAVE_OFD_LOCKS && 0
-  {
+#if HAVE_OFD_LOCKS
+  if( sqlite3GlobalConfig.bOfdLocks && (pNew->ctrlFlags & UNIXFILE_EXCL)==0 ){
     struct flock lock;
     lock.l_whence = SEEK_SET;
     lock.l_start = RESERVED_BYTE;
@@ -5486,19 +5497,6 @@ static int fillInUnixFile(
     }
   }
 #endif
-  pNew->pVfs = pVfs;
-  pNew->zPath = zFilename;
-  pNew->ctrlFlags = (u8)ctrlFlags;
-#if SQLITE_MAX_MMAP_SIZE>0
-  pNew->mmapSizeMax = sqlite3GlobalConfig.szMmap;
-#endif
-  if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
-                           "psow", SQLITE_POWERSAFE_OVERWRITE) ){
-    pNew->ctrlFlags |= UNIXFILE_PSOW;
-  }
-  if( strcmp(pVfs->zName,"unix-excl")==0 ){
-    pNew->ctrlFlags |= UNIXFILE_EXCL;
-  }
 
 #if OS_VXWORKS
   pNew->pId = vxworksFindFileId(zFilename);
index cf2e6e14f6204a36dbf0eb0c2786d6dc22bc7723..14c6d592ae433f6a05dac367c2ad8548eb27319b 100644 (file)
@@ -1076,14 +1076,9 @@ struct sqlite3_io_methods {
 **
 ** <li>[[SQLITE_FCNTL_OFD_LOCKS]]
 ** The [SQLITE_FCNTL_OFD_LOCKS] opcode will query whether or not OFD
-** locking is currently being used for an open file, or disable the use
-** of OFD locking on the file.  The argument is a pointer to an integer
-** in the callers context.  If that integer is initially -1, then it is
-** set to 1 or 0 if the system is or is not using OFD locks for the file.
-** If the integer is initially 0, then OFD locks are disabled for the file.
-** This file-control is intended for testing and validation use only.
-** Applications that strive for correctness and error-free operation should
-** not mess with this file-control.
+** locking is currently being used for an open file.  The argument is
+** a pointer to an integer into which is written a value of 1 if OFD
+** locks are being used for the file and 0 if OFD locks are not used.
 ** </ul>
 */
 #define SQLITE_FCNTL_LOCKSTATE               1
@@ -1961,6 +1956,13 @@ struct sqlite3_mem_methods {
 ** negative value for this option restores the default behaviour.
 ** This option is only available if SQLite is compiled with the
 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
+**
+** [[SQLITE_CONFIG_OFD_LOCKS]]
+** <dt>SQLITE_CONFIG_OFD_LOCKS
+** <dd>The SQLITE_CONFIG_OFD_LOCKS option accepts a single parameter
+** of type (int).  If the value is true then OFD Locks are used on systems
+** that support that feature.  If the vlaue is false, then OFD locks are
+** never used.
 ** </dl>
 */
 #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
@@ -1991,6 +1993,7 @@ struct sqlite3_mem_methods {
 #define SQLITE_CONFIG_STMTJRNL_SPILL      26  /* int nByte */
 #define SQLITE_CONFIG_SMALL_MALLOC        27  /* boolean */
 #define SQLITE_CONFIG_SORTERREF_SIZE      28  /* int nByte */
+#define SQLITE_CONFIG_OFD_LOCKS           29  /* int */
 
 /*
 ** CAPI3REF: Database Connection Configuration Options
index 61804670057a28ff5a08ae6ed78289337342b7cf..6056abe360a5ee073c8a03552f07fb4092571510 100644 (file)
@@ -3370,6 +3370,7 @@ struct Sqlite3Config {
   int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
 #endif
   int bLocaltimeFault;              /* True to fail localtime() calls */
+  int bOfdLocks;                    /* Use OFD locks on supported systems */
   int iOnceResetThreshold;          /* When to reset OP_Once counters */
   u32 szSorterRef;                  /* Min size in bytes to use sorter-refs */
 };
index 63920bd26acc62ef132a7f827790a09a2f4d2b02..5eed09a6081322ca52575dd024e296b205dff729 100644 (file)
@@ -5964,13 +5964,10 @@ static int SQLITE_TCLAPI file_control_persist_wal(
 }
 
 /*
-** tclcmd:   file_control_ofd_locks DB ?DISABLE?
+** tclcmd:   file_control_ofd_locks DB
 **
 ** Run sqlite3_file_control() to query the OFD lock capability.  Return
 ** true if OFD locks are available and false if not.
-**
-** If the DISABLE argument is true, then disable OFD locking, if it is
-** enabled.  The returned value will show that OFD locks are disabled.
 */
 static int SQLITE_TCLAPI file_control_ofd_locks(
   ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
@@ -5982,16 +5979,15 @@ static int SQLITE_TCLAPI file_control_ofd_locks(
   int rc;
   int b = 0;
 
-  if( objc!=2 && objc!=3 ){
+  if( objc!=2 ){
     Tcl_AppendResult(interp, "wrong # args: should be \"",
-        Tcl_GetStringFromObj(objv[0], 0), " DB ?DISABLE?", 0);
+        Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
     return TCL_ERROR;
   }
   if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
     return TCL_ERROR;
   }
-  if( objc==3 && Tcl_GetIntFromObj(interp, objv[2], &b) ) return TCL_ERROR;
-  b = b ? 0 : -1;
+  b = 0;
   rc = sqlite3_file_control(db,NULL,SQLITE_FCNTL_OFD_LOCKS,(void*)&b);
   Tcl_AppendResult(interp, (rc==SQLITE_OK && b) ? "1" : "0", (char*)0);
   return TCL_OK;  
index 32a03e71911e847d8a986aa762adc8952205b50c..a519fdb24613c1d79e05d7cf4d1658925e61b291 100644 (file)
@@ -1274,6 +1274,31 @@ static int SQLITE_TCLAPI test_config_pmasz(
   return TCL_OK;
 }
 
+/*
+** Usage:    sqlite3_config_ofd_locks  INTEGER
+**
+** Enable or disable the use of OFD locks.
+*/
+static int SQLITE_TCLAPI test_config_ofd_locks(
+  void * clientData, 
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+  int eOk;
+
+  if( objc!=2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "BOOL");
+    return TCL_ERROR;
+  }
+  if( Tcl_GetIntFromObj(interp, objv[1], &eOk) ){
+    return TCL_ERROR;
+  }
+
+  sqlite3_config(SQLITE_CONFIG_OFD_LOCKS, eOk);
+
+  return TCL_OK;
+}
 
 /*
 ** Usage:    sqlite3_dump_memsys3  FILENAME
@@ -1530,6 +1555,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
      { "sqlite3_config_uri",         test_config_uri               ,0 },
      { "sqlite3_config_cis",         test_config_cis               ,0 },
      { "sqlite3_config_pmasz",       test_config_pmasz             ,0 },
+     { "sqlite3_config_ofd_locks",   test_config_ofd_locks         ,0 },
      { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,0 },
      { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },
      { "sqlite3_dump_memsys5",       test_dump_memsys3             ,5 },
index 8e9c4644d154f090dd804b4979cb6b7010a667a2..18945426cea4f9ab06c0fe976c4c7b3c94d1beec 100644 (file)
@@ -24,6 +24,9 @@ if {$::tcl_platform(platform)!="unix" || [info commands test_syscall]==""} {
 } 
 set testprefix unixexcl
 
+catch {db close}
+sqlite3_shutdown
+sqlite3_config_ofd_locks 0
 
 
 # Test that when using VFS "unix-excl", the first time the database is read
@@ -126,4 +129,8 @@ do_multiclient_test tn {
   }
 }
 
+catch {db close}
+sqlite3_shutdown
+sqlite3_config_ofd_locks 1
+
 finish_test