/ Check-in [f352ef57]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Various fixes and test case updates so that veryquick.test passes again.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | deferred-open
Files: files | file ages | folders
SHA1: f352ef57e39a9443b4bdf47fc2c9b01006fe3c10
User & Date: dan 2014-02-12 15:05:05
Context
2014-02-12
15:05
Various fixes and test case updates so that veryquick.test passes again. Leaf check-in: f352ef57 user: dan tags: deferred-open
14:43
Merge latest trunk changes. check-in: 4d7057c4 user: dan tags: deferred-open
2014-02-11
16:24
Increase the version number to 3.8.4 check-in: 0a8bcbbd user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  1440   1440     }else{
  1441   1441       rc = osFcntl(pFile->h, F_SETLK, pLock);
  1442   1442     }
  1443   1443     return rc;
  1444   1444   }
  1445   1445   
  1446   1446   static int unixOpen(sqlite3_vfs*, const char*, sqlite3_file*, int, int *);
         1447  +
         1448  +static int unixOpenAndLock(unixFile *pFile){
         1449  +  sqlite3_file *id = (sqlite3_file*)pFile;
         1450  +  int eOrigLock = pFile->eFileLock;
         1451  +  int rc;
         1452  +
         1453  +  assert( pFile->ctrlFlags & UNIXFILE_DEFERRED );
         1454  +  rc = unixOpen(pFile->pVfs, pFile->zPath, id, pFile->openFlags, 0);
         1455  +  if( rc==SQLITE_OK && eOrigLock ){
         1456  +    rc = id->pMethods->xLock(id, eOrigLock);
         1457  +  }
         1458  +  return rc;
         1459  +}
  1447   1460   
  1448   1461   /*
  1449   1462   ** Lock the file with the lock specified by parameter eFileLock - one
  1450   1463   ** of the following:
  1451   1464   **
  1452   1465   **     (1) SHARED_LOCK
  1453   1466   **     (2) RESERVED_LOCK
................................................................................
  1540   1553       if( eFileLock==SHARED_LOCK && osAccess(zPath, F_OK) && errno==ENOENT ){
  1541   1554         pFile->eFileLock = SHARED_LOCK;
  1542   1555         return SQLITE_OK;
  1543   1556       }
  1544   1557   
  1545   1558       /* Or, if the database file has been created or a write lock is 
  1546   1559       ** requested, open the database file now.  */
  1547         -    eOrigLock = pFile->eFileLock;
  1548         -    rc = unixOpen(pFile->pVfs, zPath, id, pFile->openFlags, 0);
  1549         -    if( rc==SQLITE_OK && eOrigLock ){
  1550         -      rc = unixLock(id, eOrigLock);
  1551         -    }
         1560  +    rc = unixOpenAndLock(pFile);
  1552   1561       if( rc!=SQLITE_OK ) return rc;
  1553   1562     }
  1554   1563     assert( (pFile->ctrlFlags & UNIXFILE_DEFERRED)==0 );
  1555   1564   
  1556   1565     /* Make sure the locking sequence is correct.
  1557   1566     **  (1) We never move from unlocked to anything higher than shared lock.
  1558   1567     **  (2) SQLite never explicitly requests a pending lock.
................................................................................
  3321   3330     int amt,
  3322   3331     sqlite3_int64 offset 
  3323   3332   ){
  3324   3333     unixFile *pFile = (unixFile*)id;
  3325   3334     int wrote = 0;
  3326   3335     assert( id );
  3327   3336     assert( amt>0 );
         3337  +
         3338  +  /* SQLite never actually calls xWrite on an empty file before obtaining
         3339  +  ** a RESERVED lock on it. So the following condition is never true if 
         3340  +  ** the VFS is being used directly by SQLite. But it may be if this module
         3341  +  ** is being used in some other way. By the multiplexor VFS, for example. */
         3342  +  if( pFile->ctrlFlags & UNIXFILE_DEFERRED ){
         3343  +    int rc = unixOpenAndLock(pFile);
         3344  +    if( rc!=SQLITE_OK ) return rc;
         3345  +  }
  3328   3346   
  3329   3347     /* If this is a database file (not a journal, master-journal or temp
  3330   3348     ** file), the bytes in the locking range should never be read or written. */
  3331   3349   #if 0
  3332   3350     assert( pFile->pUnused==0
  3333   3351          || offset>=PENDING_BYTE+512
  3334   3352          || offset+amt<=PENDING_BYTE 
................................................................................
  5230   5248     assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
  5231   5249   
  5232   5250     OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
  5233   5251     pNew->h = h;
  5234   5252     pNew->pVfs = pVfs;
  5235   5253     pNew->zPath = zFilename;
  5236   5254     pNew->ctrlFlags = (unsigned short)ctrlFlags;
  5237         -#if SQLITE_MAX_MMAP_SIZE>0
  5238         -  pNew->mmapSizeMax = sqlite3GlobalConfig.szMmap;
  5239         -#endif
  5240   5255     if( strcmp(pVfs->zName,"unix-excl")==0 ){
  5241   5256       pNew->ctrlFlags |= UNIXFILE_EXCL;
  5242   5257     }
  5243   5258   
  5244   5259   #if OS_VXWORKS
  5245   5260     pNew->pId = vxworksFindFileId(zFilename);
  5246   5261     if( pNew->pId==0 ){
................................................................................
  5868   5883       }
  5869   5884     }
  5870   5885   #endif
  5871   5886     
  5872   5887     rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
  5873   5888   
  5874   5889   open_finished:
         5890  +  if( rc!=SQLITE_OK ){
         5891  +    sqlite3_free(p->pUnused);
         5892  +    p->pUnused = 0;
         5893  +  }
  5875   5894     return rc;
  5876   5895   }
  5877   5896   
  5878   5897   static int unixOpenDeferred(
  5879   5898     sqlite3_vfs *pVfs,           /* The VFS for which this is the xOpen method */
  5880   5899     const char *zPath,           /* Pathname of file to be opened */
  5881   5900     sqlite3_file *pFile,         /* The file descriptor to be filled in */
................................................................................
  5885   5904     const int mask1 = SQLITE_OPEN_MAIN_DB | SQLITE_OPEN_READWRITE
  5886   5905                     | SQLITE_OPEN_CREATE;
  5887   5906     const int mask2 = SQLITE_OPEN_READONLY  | SQLITE_OPEN_DELETEONCLOSE
  5888   5907                     | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_AUTOPROXY;
  5889   5908   
  5890   5909     int rc;                         /* Return code */
  5891   5910     unixFile *p = (unixFile*)pFile; /* File object to populate */
         5911  +  const char *zUri = (flags & UNIXFILE_URI) ? zPath : 0;
  5892   5912   
  5893   5913     /* Zero the file object */
  5894   5914     memset(p, 0, sizeof(unixFile));
  5895         -  if( (flags & UNIXFILE_URI) 
  5896         -   && sqlite3_uri_boolean(zPath, "psow", SQLITE_POWERSAFE_OVERWRITE) 
  5897         -  ){
         5915  +  if( sqlite3_uri_boolean(zUri, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
  5898   5916       p->ctrlFlags |= UNIXFILE_PSOW;
  5899   5917     }
         5918  +#if SQLITE_MAX_MMAP_SIZE>0
         5919  +  p->mmapSizeMax = sqlite3GlobalConfig.szMmap;
         5920  +#endif
  5900   5921   
  5901   5922     /* If all the flags in mask1 are set, and all the flags in mask2 are
  5902   5923     ** clear, the file does not exist but the directory does and is
  5903   5924     ** writable, then this is a deferred open.  */
  5904   5925     if( zPath && (flags & (mask1 | mask2))==mask1 ){
  5905   5926       int posixrc;
  5906   5927       posixrc = osAccess(zPath, F_OK);
................................................................................
  5909   5930         int i;
  5910   5931         for(i=(int)strlen(zPath); i>1 && zPath[i]!='/'; i--);
  5911   5932         memcpy(zDirname, zPath, i);
  5912   5933         zDirname[i] = '\0';
  5913   5934         posixrc = osAccess(zDirname, W_OK);
  5914   5935         if( posixrc==0 ){
  5915   5936           p->pMethod = (**(finder_type*)pVfs->pAppData)(0, 0);
  5916         -        p->pVfs = pVfs;
  5917         -        p->h = -1;
  5918         -        p->ctrlFlags |= UNIXFILE_DEFERRED;
  5919         -        p->openFlags = flags;
  5920         -        p->zPath = zPath;
  5921         -        if( pOutFlags ) *pOutFlags = flags;
  5922         -        OpenCounter(+1);
  5923         -        return SQLITE_OK;
         5937  +        if( p->pMethod->xLock==unixLock ){
         5938  +          p->pVfs = pVfs;
         5939  +          p->h = -1;
         5940  +          p->ctrlFlags |= UNIXFILE_DEFERRED;
         5941  +          p->openFlags = flags;
         5942  +          p->zPath = zPath;
         5943  +          if( pOutFlags ) *pOutFlags = flags;
         5944  +          OpenCounter(+1);
         5945  +          return SQLITE_OK;
         5946  +        }
  5924   5947         }
  5925   5948       }
  5926   5949     }
  5927   5950   
  5928   5951     rc = unixOpen(pVfs, zPath, pFile, flags, pOutFlags);
  5929   5952     OpenCounter( rc==SQLITE_OK );
  5930   5953     return rc;

Changes to test/backup.test.

   321    321     db close
   322    322     db2 close
   323    323     incr iTest
   324    324   }
   325    325   }
   326    326   }
   327    327   
   328         -proc file_size {zFile} {
   329         -  if {[file exists $zFile]} {
   330         -    return [file size $zFile]
   331         -  }
   332         -  return 0
   333         -}
   334         -
   335    328   #--------------------------------------------------------------------
   336    329   do_test backup-3.$iTest.1 {
   337    330     catch { forcedelete test.db }
   338    331     catch { forcedelete test2.db }
   339    332     sqlite3 db test.db
   340    333     set iTab 1
   341    334   

Changes to test/backup4.test.

    19     19   # to become confused and continue using out-of-date cache data.
    20     20   #
    21     21   
    22     22   set testdir [file dirname $argv0]
    23     23   source $testdir/tester.tcl
    24     24   set testprefix backup4
    25     25   
    26         -proc file_size {zFile} {
    27         -  if {[file exists $zFile]} {
    28         -    return [file size $zFile]
    29         -  }
    30         -  return 0
    31         -}
    32         -
    33     26   #-------------------------------------------------------------------------
    34     27   # At one point this test was failing because [db] was using an out of
    35     28   # date schema in test case 1.2.
    36     29   #
    37     30   do_execsql_test 1.0 {
    38     31     CREATE TABLE t1(x, y, UNIQUE(x, y));
    39     32     INSERT INTO t1 VALUES('one', 'two');

Changes to test/incrvacuum.test.

    34     34       pragma auto_vacuum;
    35     35     }
    36     36   } $sqlite_options(default_autovacuum)
    37     37   do_test incrvacuum-1.2.0 {
    38     38     # File size is sometimes 1 instead of 0 due to the hack we put in
    39     39     # to work around ticket #3260.  Search for comments on #3260 in
    40     40     # os_unix.c.
    41         -  expr {[file size test.db] > 1}
           41  +  expr {[file_size test.db] > 1}
    42     42   } {0}
    43     43   do_test incrvacuum-1.2 {
    44     44     # This command will create the database.
    45     45     execsql {
    46     46       pragma auto_vacuum = 'full';
    47     47       pragma auto_vacuum;
    48     48     }
................................................................................
   696    696   sqlite3 db test.db  ;  set ::DB [sqlite3_connection_pointer db]
   697    697   sqlite3 db2 test.db
   698    698   
   699    699   do_test incrvacuum-13.1 {
   700    700     # File size is sometimes 1 instead of 0 due to the hack we put in
   701    701     # to work around ticket #3260.  Search for comments on #3260 in
   702    702     # os_unix.c.
   703         -  expr {[file size test.db]>1}
          703  +  expr {[file_size test.db]>1}
   704    704   } {0}
   705    705   do_test incrvacuum-13.2 {
   706    706     set ::STMT [sqlite3_prepare $::DB {PRAGMA auto_vacuum = 2} -1 DUMMY]
   707    707     execsql {
   708    708       PRAGMA auto_vacuum = none;
   709    709       PRAGMA default_cache_size = 1024;
   710    710       PRAGMA auto_vacuum;

Changes to test/io.test.

   387    387       forcedelete test.db test.db-journal
   388    388       sqlite3 db test.db -vfs devsym
   389    389       db eval {
   390    390         PRAGMA auto_vacuum=OFF;
   391    391       }
   392    392       # File size might be 1 due to the hack to work around ticket #3260.
   393    393       # Search for #3260 in os_unix.c for additional information.
   394         -    expr {[file size test.db]>1}
          394  +    expr {[file_size test.db]>1}
   395    395     } {0}
   396    396     do_test io-3.2 {
   397    397       execsql { CREATE TABLE abc(a, b) }
   398    398       nSync
   399    399       execsql {
   400    400         PRAGMA temp_store = memory;
   401    401         PRAGMA cache_size = 10;

Changes to test/pager1.test.

  1369   1369       CREATE TABLE t1(a, b);
  1370   1370       CREATE TABLE t2(a, b);
  1371   1371     } db2
  1372   1372     sqlite3_backup B db2 main db main
  1373   1373     list [B step 10000] [B finish]
  1374   1374   } {SQLITE_DONE SQLITE_OK}
  1375   1375   do_test pager1-9.4.2 {
  1376         -  list [file size test.db2] [file size test.db]
         1376  +  list [file_size test.db2] [file_size test.db]
  1377   1377   } {1024 0}
  1378   1378   db2 close
  1379   1379   
  1380   1380   #-------------------------------------------------------------------------
  1381   1381   # Test that regardless of the value returned by xSectorSize(), the
  1382   1382   # minimum effective sector-size is 512 and the maximum 65536 bytes.
  1383   1383   #

Changes to test/permutations.test.

   131    131   lappend ::testsuitelist xxx
   132    132   
   133    133   test_suite "veryquick" -prefix "" -description {
   134    134     "Very" quick test suite. Runs in less than 5 minutes on a workstation. 
   135    135     This test suite is the same as the "quick" tests, except that some files
   136    136     that test malloc and IO errors are omitted.
   137    137   } -files [
   138         -  test_set $allquicktests -exclude *malloc* *ioerr* *fault* \
   139         -    *multiplex* *quota* walbak.test
          138  +  test_set $allquicktests -exclude *malloc* *ioerr* *fault* 
   140    139   ]
   141    140   
   142    141   test_suite "mmap" -prefix "mm-" -description {
   143    142     Similar to veryquick. Except with memory mapping disabled.
   144    143   } -presql {
   145    144     pragma mmap_size = 268435456;
   146    145   } -files [

Changes to test/syscall.test.

   232    232   
   233    233   #-------------------------------------------------------------------------
   234    234   # 
   235    235   catch { db close }
   236    236   forcedelete test.db test.db2
   237    237   
   238    238   do_test 8.1 {
          239  +  close [open test.db w]
   239    240     sqlite3 db test.db
   240    241     file_control_chunksize_test db main 4096
   241         -  file size test.db
          242  +  file_size test.db
   242    243   } {0}
   243    244   foreach {tn hint size} {
   244    245     1  1000    4096 
   245    246     2  1000    4096 
   246    247     3  3000    4096 
   247    248     4  4096    4096 
   248    249     5  4197    8192 
   249    250   } {
   250    251     do_test 8.2.$tn {
   251    252       file_control_sizehint_test db main $hint
   252         -    file size test.db
          253  +    file_size test.db
   253    254     } $size
   254    255   }
   255    256   
   256    257   do_test 8.3 {
   257    258     db close
   258    259     forcedelete test.db test.db2
          260  +  close [open test.db w]
   259    261     sqlite3 db test.db
   260    262     file_control_chunksize_test db main 16
   261    263     file size test.db
   262    264   } {0}
   263    265   foreach {tn hint size} {
   264    266     1  5       16 
   265    267     2  13      16 

Changes to test/tester.tcl.

   180    180   proc copy_file {from to} {
   181    181     do_copy_file false $from $to
   182    182   }
   183    183   
   184    184   proc forcecopy {from to} {
   185    185     do_copy_file true $from $to
   186    186   }
          187  +
          188  +# If file $zFile exists in the file system, return its size in bytes. 
          189  +# Otherwise, return zero.
          190  +proc file_size {zFile} {
          191  +  if {[file exists $zFile]} {
          192  +    return [file size $zFile]
          193  +  }
          194  +  return 0
          195  +}
          196  +
   187    197   
   188    198   proc do_copy_file {force from to} {
   189    199     set nRetry [getFileRetries]     ;# Maximum number of retries.
   190    200     set nDelay [getFileRetryDelay]  ;# Delay in ms before retrying.
   191    201   
   192    202     # On windows, sometimes even a [file copy -force] can fail. The cause is
   193    203     # usually "tag-alongs" - programs like anti-virus software, automatic backup

Changes to test/uri.test.

    72     72       set uri  [string map [list PWD/ [test_pwd /]] $uri]
    73     73     }
    74     74   
    75     75     if {[file isdir $file]} {error "$file is a directory"}
    76     76     forcedelete $file
    77     77     do_test 1.$tn.1 { file exists $file } 0
    78     78     set DB [sqlite3_open $uri]
           79  +  sqlite3_exec $DB {CREATE TABLE t1(x)}
    79     80     do_test 1.$tn.2 { file exists $file } 1
    80     81     sqlite3_close $DB
    81     82     forcedelete $file
    82     83   
    83     84     do_test 1.$tn.3 { file exists $file } 0
    84     85     sqlite3 db xxx.db
    85     86     catchsql { ATTACH $uri AS aux }
           87  +  db eval {CREATE TABLE aux.t1(x)}
    86     88     do_test 1.$tn.4 { file exists $file } 1
    87     89     db close
    88     90   }
    89     91   
    90     92   #-------------------------------------------------------------------------
    91     93   # Test that URI query parameters are passed through to the VFS layer
    92     94   # correctly.

Changes to test/wal4.test.

    52     52     # deleted. In no case should the database file have been written, so
    53     53     # it should still be zero bytes in size regardless of whether or not
    54     54     # a fault was injected. Test these assertions:
    55     55     #
    56     56     if { $testrc==0 && [file exists test.db-wal] } { 
    57     57       error "Wal file was not deleted"
    58     58     }
    59         -  if { [file size test.db]!=0 } { 
    60         -    error "Db file grew to [file size test.db] bytes"
           59  +  if { [file_size test.db]!=0 } { 
           60  +    error "Db file grew to [file_size test.db] bytes"
    61     61     }
    62     62   }
    63     63   
    64     64   finish_test