/ Check-in [77664841]
Login

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

Overview
Comment:If the sorter uses mmap'd temp files, ensure all pages of the temp file have been allocated before it is accessed. Otherwise, a disk-full condition might result in a SIGBUS exception.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 776648412c30dce206f1024ff849c2cb025bb006
User & Date: dan 2014-12-30 14:40:53
Context
2014-12-30
18:07
Fix problems with the "inmemory_journal" permutation. check-in: 79693f04 user: dan tags: trunk
14:40
If the sorter uses mmap'd temp files, ensure all pages of the temp file have been allocated before it is accessed. Otherwise, a disk-full condition might result in a SIGBUS exception. check-in: 77664841 user: dan tags: trunk
13:04
Make SQLITE_CONFIG_PCACHE_HDRSZ accurate (not an over-estimate) on 32-bit systems. check-in: 340b3477 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  3714   3714         ** the last byte in each block within the extended region. This
  3715   3715         ** is the same technique used by glibc to implement posix_fallocate()
  3716   3716         ** on systems that do not have a real fallocate() system call.
  3717   3717         */
  3718   3718         int nBlk = buf.st_blksize;  /* File-system block size */
  3719   3719         i64 iWrite;                 /* Next offset to write to */
  3720   3720   
  3721         -      if( robust_ftruncate(pFile->h, nSize) ){
  3722         -        pFile->lastErrno = errno;
  3723         -        return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
  3724         -      }
  3725   3721         iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
  3726   3722         while( iWrite<nSize ){
  3727   3723           int nWrite = seekAndWrite(pFile, iWrite, "", 1);
  3728   3724           if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  3729   3725           iWrite += nBlk;
  3730   3726         }
         3727  +      if( robust_ftruncate(pFile->h, nSize) ){
         3728  +        pFile->lastErrno = errno;
         3729  +        return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
         3730  +      }
  3731   3731   #endif
  3732   3732       }
  3733   3733     }
  3734   3734   
  3735   3735   #if SQLITE_MAX_MMAP_SIZE>0
  3736   3736     if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
  3737   3737       int rc;

Changes to src/vdbesort.c.

  1128   1128   ** the VFS has memory mapped it.
  1129   1129   **
  1130   1130   ** Whether or not the file does end up memory mapped of course depends on
  1131   1131   ** the specific VFS implementation.
  1132   1132   */
  1133   1133   static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
  1134   1134     if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
  1135         -    int rc = sqlite3OsTruncate(pFd, nByte);
  1136         -    if( rc==SQLITE_OK ){
  1137         -      void *p = 0;
  1138         -      sqlite3OsFetch(pFd, 0, (int)nByte, &p);
  1139         -      sqlite3OsUnfetch(pFd, 0, p);
  1140         -    }
         1135  +    void *p = 0;
         1136  +    int chunksize = 4*1024;
         1137  +    sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
         1138  +    sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
         1139  +    sqlite3OsFetch(pFd, 0, (int)nByte, &p);
         1140  +    sqlite3OsUnfetch(pFd, 0, p);
  1141   1141     }
  1142   1142   }
  1143   1143   #else
  1144   1144   # define vdbeSorterExtendFile(x,y,z)
  1145   1145   #endif
  1146   1146   
  1147   1147   /*