/ Check-in [a89b62c4]
Login

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

Overview
Comment:Omit unused batch-atomic-write code if SQLITE_ENABLE_BATCH_ATOMIC_WRITE is not defined.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | batch-atomic-write
Files: files | file ages | folders
SHA3-256: a89b62c4966cd297326e8712da40e0962d2328d7ba1f201d5abcec911eeef347
User & Date: drh 2017-07-22 16:00:34
Context
2017-07-22
16:32
Keep batch-atomic-writes turned on for journal_mode=MEMORY, but turn them off for synchronous=OFF. Refuse to compile with both SQLITE_MMAP_READWRITE and SQLITE_ENABLE_BATCH_ATOMIC_WRITE. Fix up some comments in the commit logic. check-in: 2e80e19e user: drh tags: batch-atomic-write
16:00
Omit unused batch-atomic-write code if SQLITE_ENABLE_BATCH_ATOMIC_WRITE is not defined. check-in: a89b62c4 user: drh tags: batch-atomic-write
2017-07-21
21:06
Use ioctl(F2FS_IOC_GET_FEATURES) to determine whether or not atomic batch writes are available. check-in: 532bbf1f user: dan tags: batch-atomic-write
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   323    323   ** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek()
   324    324   ** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
   325    325   */
   326    326   #ifdef __ANDROID__
   327    327   # define lseek lseek64
   328    328   #endif
   329    329   
          330  +#ifdef __linux__
          331  +/*
          332  +** Linux-specific IOCTL magic numbers used for controlling F2FS
          333  +*/
   330    334   #define F2FS_IOCTL_MAGIC        0xf5
   331    335   #define F2FS_IOC_START_ATOMIC_WRITE     _IO(F2FS_IOCTL_MAGIC, 1)
   332    336   #define F2FS_IOC_COMMIT_ATOMIC_WRITE    _IO(F2FS_IOCTL_MAGIC, 2)
   333    337   #define F2FS_IOC_START_VOLATILE_WRITE   _IO(F2FS_IOCTL_MAGIC, 3)
   334    338   #define F2FS_IOC_ABORT_VOLATILE_WRITE   _IO(F2FS_IOCTL_MAGIC, 5)
   335    339   #define F2FS_IOC_GET_FEATURES           _IOR(F2FS_IOCTL_MAGIC, 12, u32)
   336         -
   337    340   #define F2FS_FEATURE_ATOMIC_WRITE 0x0004
          341  +#endif /* __linux__ */
   338    342   
   339    343   
   340    344   /*
   341    345   ** Different Unix systems declare open() in different ways.  Same use
   342    346   ** open(const char*,int,mode_t).  Others use open(const char*,int,...).
   343    347   ** The difference is important when using a pointer to the function.
   344    348   **
................................................................................
  3785   3789   
  3786   3790   /*
  3787   3791   ** Information and control of an open file handle.
  3788   3792   */
  3789   3793   static int unixFileControl(sqlite3_file *id, int op, void *pArg){
  3790   3794     unixFile *pFile = (unixFile*)id;
  3791   3795     switch( op ){
         3796  +#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
  3792   3797       case SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: {
  3793   3798         int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE);
  3794   3799         return rc ? SQLITE_ERROR : SQLITE_OK;
  3795   3800       }
  3796   3801       case SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: {
  3797   3802         int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE);
  3798   3803         return rc ? SQLITE_ERROR : SQLITE_OK;
  3799   3804       }
  3800   3805       case SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: {
  3801   3806         int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE);
  3802   3807         return rc ? SQLITE_ERROR : SQLITE_OK;
  3803   3808       }
         3809  +#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
  3804   3810   
  3805   3811       case SQLITE_FCNTL_LOCKSTATE: {
  3806   3812         *(int*)pArg = pFile->eFileLock;
  3807   3813         return SQLITE_OK;
  3808   3814       }
  3809   3815       case SQLITE_FCNTL_LAST_ERRNO: {
  3810   3816         *(int*)pArg = pFile->lastErrno;
................................................................................
  3891   3897   ** characteristics. 
  3892   3898   **
  3893   3899   ** There are two versions of this function. One for QNX and one for all
  3894   3900   ** other systems.
  3895   3901   */
  3896   3902   #ifndef __QNXNTO__
  3897   3903   static void setDeviceCharacteristics(unixFile *pFd){
         3904  +  assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 );
  3898   3905     if( pFd->sectorSize==0 ){
         3906  +#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
  3899   3907       int res;
  3900   3908       u32 f = 0;
  3901         -    assert( pFd->deviceCharacteristics==0 );
  3902   3909   
  3903   3910       /* Check for support for F2FS atomic batch writes. */
  3904   3911       res = osIoctl(pFd->h, F2FS_IOC_GET_FEATURES, &f);
  3905   3912       if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){
  3906   3913         pFd->deviceCharacteristics = 
  3907   3914           SQLITE_IOCAP_BATCH_ATOMIC |
  3908   3915           SQLITE_IOCAP_ATOMIC |
  3909   3916           SQLITE_IOCAP_SEQUENTIAL |
  3910   3917           SQLITE_IOCAP_SAFE_APPEND;
  3911   3918       }
         3919  +#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
  3912   3920   
  3913   3921       /* Set the POWERSAFE_OVERWRITE flag if requested. */
  3914   3922       if( pFd->ctrlFlags & UNIXFILE_PSOW ){
  3915   3923         pFd->deviceCharacteristics |= SQLITE_IOCAP_POWERSAFE_OVERWRITE;
  3916   3924       }
  3917   3925   
  3918   3926       pFd->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;

Changes to src/pager.c.

  6395   6395         sqlite3_file *fd = pPager->fd;
  6396   6396   #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
  6397   6397         const int bBatch = zMaster==0    /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
  6398   6398           && (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC)
  6399   6399           && pPager->journalMode!=PAGER_JOURNALMODE_MEMORY
  6400   6400           && sqlite3JournalIsInMemory(pPager->jfd);
  6401   6401   #else
  6402         -      const int bBatch = 0;
         6402  +# define bBatch 0
  6403   6403   #endif
  6404   6404   
  6405   6405   #ifdef SQLITE_ENABLE_ATOMIC_WRITE
  6406   6406         if( bBatch==0 ){
  6407   6407           PgHdr *pPg;
  6408   6408           assert( isOpen(pPager->jfd) 
  6409   6409               || pPager->journalMode==PAGER_JOURNALMODE_OFF