/ Check-in [64131724]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Experimental changes to permit a VFS to directly override the initial page size.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | pagePerSector
Files: files | file ages | folders
SHA1: 6413172435babe9097e4f961d4b88ddf68e2159d
User & Date: mistachkin 2017-01-23 21:12:15
Context
2017-01-23
21:12
Experimental changes to permit a VFS to directly override the initial page size. Leaf check-in: 64131724 user: mistachkin tags: pagePerSector
19:11
Document the --mmap option in the --help screen for kvtest. Enhance kvtest so that numeric arguments can have suffixes like "K" or "M". Add kvtest to the unix makefiles. check-in: 175bda87 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

   303    303   
   304    304   /*
   305    305   ** Allowed values for winFile.ctrlFlags
   306    306   */
   307    307   #define WINFILE_RDONLY          0x02   /* Connection is read only */
   308    308   #define WINFILE_PERSIST_WAL     0x04   /* Persistent WAL mode */
   309    309   #define WINFILE_PSOW            0x10   /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
          310  +#define WINFILE_PPS             0x20   /* SQLITE_IOCAP_PAGE_PER_SECTOR */
   310    311   
   311    312   /*
   312    313    * The size of the buffer used by sqlite3_win32_write_debug().
   313    314    */
   314    315   #ifndef SQLITE_WIN32_DBG_BUF_SIZE
   315    316   #  define SQLITE_WIN32_DBG_BUF_SIZE   ((int)(4096-sizeof(DWORD)))
   316    317   #endif
................................................................................
  3463   3464         OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  3464   3465         return SQLITE_OK;
  3465   3466       }
  3466   3467       case SQLITE_FCNTL_POWERSAFE_OVERWRITE: {
  3467   3468         winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
  3468   3469         OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  3469   3470         return SQLITE_OK;
         3471  +    }
         3472  +    case SQLITE_FCNTL_PAGE_PER_SECTOR: {
         3473  +      winModeBit(pFile, WINFILE_PPS, (int*)pArg);
         3474  +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
         3475  +      return SQLITE_OK;
  3470   3476       }
  3471   3477       case SQLITE_FCNTL_VFSNAME: {
  3472   3478         *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
  3473   3479         OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  3474   3480         return SQLITE_OK;
  3475   3481       }
  3476   3482       case SQLITE_FCNTL_WIN32_AV_RETRY: {
................................................................................
  3555   3561   
  3556   3562   /*
  3557   3563   ** Return a vector of device characteristics.
  3558   3564   */
  3559   3565   static int winDeviceCharacteristics(sqlite3_file *id){
  3560   3566     winFile *p = (winFile*)id;
  3561   3567     return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
         3568  +         ((p->ctrlFlags & WINFILE_PPS)?SQLITE_IOCAP_PAGE_PER_SECTOR:0) |
  3562   3569            ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0);
  3563   3570   }
  3564   3571   
  3565   3572   /*
  3566   3573   ** Windows will only let you create file view mappings
  3567   3574   ** on allocation size granularity boundaries.
  3568   3575   ** During sqlite3_os_init() we do a GetSystemInfo()
................................................................................
  5102   5109     pFile->pVfs = pVfs;
  5103   5110     pFile->h = h;
  5104   5111     if( isReadonly ){
  5105   5112       pFile->ctrlFlags |= WINFILE_RDONLY;
  5106   5113     }
  5107   5114     if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
  5108   5115       pFile->ctrlFlags |= WINFILE_PSOW;
         5116  +  }
         5117  +  if( sqlite3_uri_boolean(zName, "pps", 0) ){
         5118  +    pFile->ctrlFlags |= WINFILE_PPS;
  5109   5119     }
  5110   5120     pFile->lastErrno = NO_ERROR;
  5111   5121     pFile->zPath = zName;
  5112   5122   #if SQLITE_MAX_MMAP_SIZE>0
  5113   5123     pFile->hMap = NULL;
  5114   5124     pFile->pMapRegion = 0;
  5115   5125     pFile->mmapSize = 0;

Changes to src/pager.c.

  4759   4759       **    + The largest page size that can be written atomically.
  4760   4760       */
  4761   4761       if( rc==SQLITE_OK ){
  4762   4762         int iDc = sqlite3OsDeviceCharacteristics(pPager->fd);
  4763   4763         if( !readOnly ){
  4764   4764           setSectorSize(pPager);
  4765   4765           assert(SQLITE_DEFAULT_PAGE_SIZE<=SQLITE_MAX_DEFAULT_PAGE_SIZE);
  4766         -        if( szPageDflt<pPager->sectorSize ){
         4766  +        if( iDc&SQLITE_IOCAP_PAGE_PER_SECTOR ){
         4767  +          szPageDflt = (u32)pPager->sectorSize;
         4768  +        }else if( szPageDflt<pPager->sectorSize ){
  4767   4769             if( pPager->sectorSize>SQLITE_MAX_DEFAULT_PAGE_SIZE ){
  4768   4770               szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
  4769   4771             }else{
  4770   4772               szPageDflt = (u32)pPager->sectorSize;
  4771   4773             }
  4772   4774           }
  4773   4775   #ifdef SQLITE_ENABLE_ATOMIC_WRITE

Changes to src/sqlite.h.in.

   575    575   ** after reboot following a crash or power loss, the only bytes in a
   576    576   ** file that were written at the application level might have changed
   577    577   ** and that adjacent bytes, even bytes within the same sector are
   578    578   ** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
   579    579   ** flag indicates that a file cannot be deleted when open.  The
   580    580   ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
   581    581   ** read-only media and cannot be changed even by processes with
   582         -** elevated privileges.
          582  +** elevated privileges.  The SQLITE_IOCAP_PAGE_PER_SECTOR flag indicates
          583  +** the initial page size for new databases should set to the sector size
          584  +** reported by the VFS.
   583    585   */
   584    586   #define SQLITE_IOCAP_ATOMIC                 0x00000001
   585    587   #define SQLITE_IOCAP_ATOMIC512              0x00000002
   586    588   #define SQLITE_IOCAP_ATOMIC1K               0x00000004
   587    589   #define SQLITE_IOCAP_ATOMIC2K               0x00000008
   588    590   #define SQLITE_IOCAP_ATOMIC4K               0x00000010
   589    591   #define SQLITE_IOCAP_ATOMIC8K               0x00000020
................................................................................
   591    593   #define SQLITE_IOCAP_ATOMIC32K              0x00000080
   592    594   #define SQLITE_IOCAP_ATOMIC64K              0x00000100
   593    595   #define SQLITE_IOCAP_SAFE_APPEND            0x00000200
   594    596   #define SQLITE_IOCAP_SEQUENTIAL             0x00000400
   595    597   #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
   596    598   #define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
   597    599   #define SQLITE_IOCAP_IMMUTABLE              0x00002000
          600  +#define SQLITE_IOCAP_PAGE_PER_SECTOR        0x00004000
   598    601   
   599    602   /*
   600    603   ** CAPI3REF: File Locking Levels
   601    604   **
   602    605   ** SQLite uses one of these integer values as the second
   603    606   ** argument to calls it makes to the xLock() and xUnlock() methods
   604    607   ** of an [sqlite3_io_methods] object.
................................................................................
   725    728   ** <li> [SQLITE_IOCAP_ATOMIC32K]
   726    729   ** <li> [SQLITE_IOCAP_ATOMIC64K]
   727    730   ** <li> [SQLITE_IOCAP_SAFE_APPEND]
   728    731   ** <li> [SQLITE_IOCAP_SEQUENTIAL]
   729    732   ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
   730    733   ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
   731    734   ** <li> [SQLITE_IOCAP_IMMUTABLE]
          735  +** <li> [SQLITE_IOCAP_PAGE_PER_SECTOR]
   732    736   ** </ul>
   733    737   **
   734    738   ** The SQLITE_IOCAP_ATOMIC property means that all writes of
   735    739   ** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
   736    740   ** mean that writes of blocks that are nnn bytes in size and
   737    741   ** are aligned to an address which is an integer multiple of
   738    742   ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
................................................................................
  1008   1012   ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
  1009   1013   ** VFS should return SQLITE_NOTFOUND for this opcode.
  1010   1014   **
  1011   1015   ** <li>[[SQLITE_FCNTL_RBU]]
  1012   1016   ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
  1013   1017   ** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
  1014   1018   ** this opcode.  
         1019  +**
         1020  +** <li>[[SQLITE_FCNTL_PAGE_PER_SECTOR]]
         1021  +** ^The [SQLITE_FCNTL_PAGE_PER_SECTOR] opcode is used to set or query the
         1022  +** persistent "page-per-sector" or "PPS" setting. The PPS setting determines
         1023  +** the [SQLITE_IOCAP_PAGE_PER_SECTOR] bit of the xDeviceCharacteristics
         1024  +** methods. The fourth parameter to [sqlite3_file_control()] for this opcode
         1025  +** should be a pointer to an integer.  That integer is 0 to disable
         1026  +** page-per-sector mode or 1 to enable page-per-sector mode.  If the integer
         1027  +** is -1, then it is overwritten with the current page-per-sector mode setting.
  1015   1028   ** </ul>
  1016   1029   */
  1017   1030   #define SQLITE_FCNTL_LOCKSTATE               1
  1018   1031   #define SQLITE_FCNTL_GET_LOCKPROXYFILE       2
  1019   1032   #define SQLITE_FCNTL_SET_LOCKPROXYFILE       3
  1020   1033   #define SQLITE_FCNTL_LAST_ERRNO              4
  1021   1034   #define SQLITE_FCNTL_SIZE_HINT               5
................................................................................
  1039   1052   #define SQLITE_FCNTL_WAL_BLOCK              24
  1040   1053   #define SQLITE_FCNTL_ZIPVFS                 25
  1041   1054   #define SQLITE_FCNTL_RBU                    26
  1042   1055   #define SQLITE_FCNTL_VFS_POINTER            27
  1043   1056   #define SQLITE_FCNTL_JOURNAL_POINTER        28
  1044   1057   #define SQLITE_FCNTL_WIN32_GET_HANDLE       29
  1045   1058   #define SQLITE_FCNTL_PDB                    30
         1059  +#define SQLITE_FCNTL_PAGE_PER_SECTOR        31
  1046   1060   
  1047   1061   /* deprecated names */
  1048   1062   #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
  1049   1063   #define SQLITE_SET_LOCKPROXYFILE      SQLITE_FCNTL_SET_LOCKPROXYFILE
  1050   1064   #define SQLITE_LAST_ERRNO             SQLITE_FCNTL_LAST_ERRNO
  1051   1065   
  1052   1066